在Moore电路设计中,输出不会同步变化



我正在设计一台控制红绿灯的Moore机器。

这是我源代码的一部分。

always @(negedge resetn or posedge clk) begin
if ( !resetn )   // reset is allowed
state <= S0;
else if ( push_button == 2'b01 ) begin 
case ( state )
S0 : state <= S1;
S1 : state <= S2;
S2 : state <= S1;
S3 : state <= S3;
default : state <= state;
endcase
end

else if ( push_button == 2'b10 ) begin 
case ( state )
S0 : state <= S3;
S1 : state <= S3;
S2 : state <= S2;
S3 : state <= S1;
default : state <= state;
endcase
end
else
state <= state;
end

always @(posedge clk) begin
case ( state )
S0 : led_output = 6'b111111;
S1 : led_output = 6'b010100;
S2 : led_output = 6'b100010;
S3 : led_output = 6'b110110;   
default : led_output = 6'b000000;
endcase
end

endmodule

我希望这段代码在输入(按钮(时改变它们的状态,同时也改变输出值。但问题是,在模拟测试时,状态确实会立即改变,而输出值不会。

例如,假设初始状态为S0,我给出了按钮输入2'b10。然后,状态确实变为S3,但输出不会变为6'b110110

你能给我一个提示或回答这个问题吗?

您对led_output使用时序逻辑,这意味着它将在state之后更改1个时钟周期。您可以使用组合逻辑,使led_output在与state:相同的周期中发生变化

always @* begin
case ( state )
S0 : led_output = 6'b111111;
S1 : led_output = 6'b010100;
S2 : led_output = 6'b100010;
S3 : led_output = 6'b110110;   
default : led_output = 6'b000000;
endcase
end

最新更新