Guest
Hey everyone,
I'm unsure about how a verilog state machine should behave if the
next_stage block is triggered by a signal on the rising edge of the
clock. What's happening my state machine is that the current_state and
next_state are changing at the exact same time and i'm not sure if
that is correct behavior?
initial begin
I_write = 0;
RESET = 0;
# 90 RESET = 1;
# 15 RESET = 0;
# 82.5 I_write = 1;
# 15 I_write = 0;
end
always@(I_write or time_update or current_state) // combinatorial
block
begin
case(current_state)
IDLE:begin
if(I_write)
begin
$display($time, "print1 %b %b %b", RESET, current_state,
next_state);
next_state = WR_DATA;
end
else if(time_update)
begin
$display($time, "print2 %b %b %b", RESET, current_state,
next_state);
next_state = WR_TIME;
end
else
begin
$display($time, "print3 %b %b %b", RESET, current_state,
next_state);
next_state = IDLE;
end
end
WR_TIME:begin
if(time_update) begin
$display($time, "print4 %b %b %b", RESET, current_state,
next_state);
next_state = IDLE;
end
end
WR_DATA:begin
if(I_write)
begin
$display($time, "print5 %b %b %b", RESET, current_state,
next_state);
next_state = WR_DATA;
end
else
begin
$display($time, "print6 %b %b %b", RESET, current_state,
next_state);
next_state = IDLE;
end
end
endcase
end
always@(posedge clk or posedge RESET) //sequential block
begin
if(RESET)
begin
$display($time, "print7 %b %b %b", RESET, current_state,
next_state);
current_state <= IDLE;
end
else
begin
$display($time, "print8 %b %b %b", RESET, current_state,
next_state);
current_state <= next_state;
end
end
This gives the following output:
.......
# 188print1 0 000 000
# 188print8 0 000 010
# 188print5 0 010 010
# 203print6 0 010 010
# 203print8 0 010 000
# 203print3 0 000 000
# 218print8 0 000 000
# 233print8 0 000 000
# 248print8 0 000 000
# 263print8 0 000 000
# 278print8 0 000 000
......
where at time 203 the current_stage and next_stage change at exactly
the same time.
I'm unsure if this is correct behavior as i think the current_stage
should change on the next rising clk edge after the next_stage changes
and not at the same time - is that correct?
Am i missing something from my state machine?
Any help would be appreciated.
Cheers,
Rob.
I'm unsure about how a verilog state machine should behave if the
next_stage block is triggered by a signal on the rising edge of the
clock. What's happening my state machine is that the current_state and
next_state are changing at the exact same time and i'm not sure if
that is correct behavior?
initial begin
I_write = 0;
RESET = 0;
# 90 RESET = 1;
# 15 RESET = 0;
# 82.5 I_write = 1;
# 15 I_write = 0;
end
always@(I_write or time_update or current_state) // combinatorial
block
begin
case(current_state)
IDLE:begin
if(I_write)
begin
$display($time, "print1 %b %b %b", RESET, current_state,
next_state);
next_state = WR_DATA;
end
else if(time_update)
begin
$display($time, "print2 %b %b %b", RESET, current_state,
next_state);
next_state = WR_TIME;
end
else
begin
$display($time, "print3 %b %b %b", RESET, current_state,
next_state);
next_state = IDLE;
end
end
WR_TIME:begin
if(time_update) begin
$display($time, "print4 %b %b %b", RESET, current_state,
next_state);
next_state = IDLE;
end
end
WR_DATA:begin
if(I_write)
begin
$display($time, "print5 %b %b %b", RESET, current_state,
next_state);
next_state = WR_DATA;
end
else
begin
$display($time, "print6 %b %b %b", RESET, current_state,
next_state);
next_state = IDLE;
end
end
endcase
end
always@(posedge clk or posedge RESET) //sequential block
begin
if(RESET)
begin
$display($time, "print7 %b %b %b", RESET, current_state,
next_state);
current_state <= IDLE;
end
else
begin
$display($time, "print8 %b %b %b", RESET, current_state,
next_state);
current_state <= next_state;
end
end
This gives the following output:
.......
# 188print1 0 000 000
# 188print8 0 000 010
# 188print5 0 010 010
# 203print6 0 010 010
# 203print8 0 010 000
# 203print3 0 000 000
# 218print8 0 000 000
# 233print8 0 000 000
# 248print8 0 000 000
# 263print8 0 000 000
# 278print8 0 000 000
......
where at time 203 the current_stage and next_stage change at exactly
the same time.
I'm unsure if this is correct behavior as i think the current_stage
should change on the next rising clk edge after the next_stage changes
and not at the same time - is that correct?
Am i missing something from my state machine?
Any help would be appreciated.
Cheers,
Rob.