D触发器的输出不符合预期
Output of D flip-flop not as expected
这是异步重置。当我将重置从 1 更改为 0 时,D 触发器不会立即将输出从 0 提高到 1。但是当我添加 @always ( posedge clk 或 posedge reset 或 negedge reset )它立即改变
Verilog:
module dff_async_reset (
data , // Data Input
clk , // Clock Input
reset , // Reset input
q // Q output
);
//-----------Input Ports---------------
input data, clk, reset ;
//-----------Output Ports---------------
output q;
//------------Internal Variables--------
reg q;
//-------------Code Starts Here---------
always @ ( posedge clk or posedge reset)
begin
if (reset)
q =0;
else
q <= data;
end
endmodule //End Of Module dff_async_reset
对应波形:
它完全按照您的要求进行操作:模仿具有异步高电平有效复位的触发器。您代码中的以下行
always @ (posedge clk or posedge reset)
表示:"execute this procedural block when clk
makes the transition 0 --> 1
or when reset
makes the transition 0 --> 1
." 换句话说,当 reset
进行转换 1 --> 0
时,将不会评估此 always 块。
你的值q
只会在clk
的上升沿更新,如果你想设计一个触发器,这正是你想要的。
当您将 negedge reset
添加到您的敏感列表时,当您离开重置状态(在您的逻辑中是 1 --> 0
)时,它确实会立即改变。 然而,这通常是不希望的。 相反,you should synchronize the deassertion of your reset to your clock signal。引用上述网站:
The way most of the designs have been modelled needs asynchronous
reset assertion and synchronous de-assertion. The requirement of most
of the designs these days is:
- When reset is asserted, it propagates to all designs; brings them to reset state whether or not clock is toggling; i.e. assertion should
be asynchronous
- When reset is deasserted, wait for a clock edge, and then, move the system to next state as per the FSM (Finite State Machine); i.e.
deassertion should be synchronous
这是异步重置。当我将重置从 1 更改为 0 时,D 触发器不会立即将输出从 0 提高到 1。但是当我添加 @always ( posedge clk 或 posedge reset 或 negedge reset )它立即改变
Verilog:
module dff_async_reset (
data , // Data Input
clk , // Clock Input
reset , // Reset input
q // Q output
);
//-----------Input Ports---------------
input data, clk, reset ;
//-----------Output Ports---------------
output q;
//------------Internal Variables--------
reg q;
//-------------Code Starts Here---------
always @ ( posedge clk or posedge reset)
begin
if (reset)
q =0;
else
q <= data;
end
endmodule //End Of Module dff_async_reset
对应波形:
它完全按照您的要求进行操作:模仿具有异步高电平有效复位的触发器。您代码中的以下行
always @ (posedge clk or posedge reset)
表示:"execute this procedural block when clk
makes the transition 0 --> 1
or when reset
makes the transition 0 --> 1
." 换句话说,当 reset
进行转换 1 --> 0
时,将不会评估此 always 块。
你的值q
只会在clk
的上升沿更新,如果你想设计一个触发器,这正是你想要的。
当您将 negedge reset
添加到您的敏感列表时,当您离开重置状态(在您的逻辑中是 1 --> 0
)时,它确实会立即改变。 然而,这通常是不希望的。 相反,you should synchronize the deassertion of your reset to your clock signal。引用上述网站:
The way most of the designs have been modelled needs asynchronous reset assertion and synchronous de-assertion. The requirement of most of the designs these days is:
- When reset is asserted, it propagates to all designs; brings them to reset state whether or not clock is toggling; i.e. assertion should be asynchronous
- When reset is deasserted, wait for a clock edge, and then, move the system to next state as per the FSM (Finite State Machine); i.e. deassertion should be synchronous