摩尔电路设计输出不同步变化
The output does not change synchronously on Moore circuit design
我正在设计一个控制交通灯的摩尔机器。
这是我的源代码的一部分。
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
我正在设计一个控制交通灯的摩尔机器。
这是我的源代码的一部分。
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