L
leon
Guest
Please consider this piece of code:
I have 2 always (*) combinatorial blocks and one sequnetial block. c_to
from the first combinatorial loop feeds into the second always(*) block
which produces c_ld which triggers the first. Although this is
synthesizable code the NC simulator I use freezes on this code as it is
toggling between the 2 always(*) blocks. However if I place #1 to the
first c_to assignment then it works or if I comment it out and use an
else clause it works as well.
Does this work with other simulators or is this a bug in NC or a
violation of verilog LRM. Please view c_to as a nor gate connected to
cnt but this is a race in the simulator... Any comments anyone!!
module test
(
input clk,
input rst_n,
input a,
input [3:0] b,
output wire [6:1] c
);
reg [8:0] cnt;
reg [2:0] fsm_state;
reg [8:0] c_cnt;
reg [2:0] c_fsm_state;
reg c_to;
reg c_ld;
reg [6:1] c_c;
assign c = c_c;
always @(*)
begin
c_cnt = cnt;
c_to = 0; // Comment this line
if (c_ld)
c_cnt = {b, 5'b0};
else
c_cnt = cnt - 1;
if (cnt == 0)
c_to = 1'b1;
/*else // Uncomment this line and the next
c_to = 0;*/
end // always @ (*)
always @(*)
begin
c_fsm_state = fsm_state;
c_ld = 0;
c_c = 0;
case (fsm_state)
3'd0:
begin
if (a)
begin
c_ld = 1'b1;
c_fsm_state = 3'd1;
end // if (gain_change)
c_c = 0;
end // case: 3'd0
3'd1:
begin
if (c_to)
begin
c_fsm_state = 3'd2;
c_ld = 1'b1;
end
c_c = 6'b100000;
end
default:
begin
c_fsm_state = 0;
c_ld = 0;
c_c = 0;
end
endcase // case(fsm_state)
end // always @ (*)
always @(posedge clk or negedge rst_n)
if (~rst_n)
begin
fsm_state <= 0;
cnt <= 0;
end
else
begin
fsm_state <= c_fsm_state;
cnt <= c_cnt;
end
endmodule
I have 2 always (*) combinatorial blocks and one sequnetial block. c_to
from the first combinatorial loop feeds into the second always(*) block
which produces c_ld which triggers the first. Although this is
synthesizable code the NC simulator I use freezes on this code as it is
toggling between the 2 always(*) blocks. However if I place #1 to the
first c_to assignment then it works or if I comment it out and use an
else clause it works as well.
Does this work with other simulators or is this a bug in NC or a
violation of verilog LRM. Please view c_to as a nor gate connected to
cnt but this is a race in the simulator... Any comments anyone!!
module test
(
input clk,
input rst_n,
input a,
input [3:0] b,
output wire [6:1] c
);
reg [8:0] cnt;
reg [2:0] fsm_state;
reg [8:0] c_cnt;
reg [2:0] c_fsm_state;
reg c_to;
reg c_ld;
reg [6:1] c_c;
assign c = c_c;
always @(*)
begin
c_cnt = cnt;
c_to = 0; // Comment this line
if (c_ld)
c_cnt = {b, 5'b0};
else
c_cnt = cnt - 1;
if (cnt == 0)
c_to = 1'b1;
/*else // Uncomment this line and the next
c_to = 0;*/
end // always @ (*)
always @(*)
begin
c_fsm_state = fsm_state;
c_ld = 0;
c_c = 0;
case (fsm_state)
3'd0:
begin
if (a)
begin
c_ld = 1'b1;
c_fsm_state = 3'd1;
end // if (gain_change)
c_c = 0;
end // case: 3'd0
3'd1:
begin
if (c_to)
begin
c_fsm_state = 3'd2;
c_ld = 1'b1;
end
c_c = 6'b100000;
end
default:
begin
c_fsm_state = 0;
c_ld = 0;
c_c = 0;
end
endcase // case(fsm_state)
end // always @ (*)
always @(posedge clk or negedge rst_n)
if (~rst_n)
begin
fsm_state <= 0;
cnt <= 0;
end
else
begin
fsm_state <= c_fsm_state;
cnt <= c_cnt;
end
endmodule