我在设计一台摩尔控制交通灯的机器。
这是我的源代码的一部分。
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。
你能给我一个提示或回答这个问题吗?
发布于 2020-09-29 17:22:04
您对led_output使用顺序逻辑,这意味着它将在state之后改变一个时钟周期。您可以使用组合逻辑代替,这将导致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
endhttps://stackoverflow.com/questions/64124472
复制相似问题