16 / 36 · Konzept
Flip-flops and clock enable
Specify the priority of reset, enable and hold.
Lektionen sind frei lesbar. Schreibe dich ein, um deinen Fortschritt zu speichern.
Die Übersetzung ist noch nicht verfügbar. Die Originallektion wird angezeigt. (English)
Learning goals
- Control storage using clock enable.
- Give reset priority over enable.
Holding a value is part of the behavior.
A flip-flop stores a value at a clock edge. Executing q<=d only when en=1 makes q hold when en=0. This differs from gating a clock with arbitrary combinational logic.
Placing if(rst) first gives reset priority even when rst and en are both 1. With synchronous reset, rst alone does not change q without a clock edge.
always_ff @(posedge clk) begin
if (rst) q <= 1'b0;
else if (en) q <= d;
endDistinguish a register hold from an incomplete combinational assignment.
A conditional non-assignment in always_ff can intentionally hold stored state. In always_comb, assign outputs on every path to avoid unintended latches.
Test reset=1/en=1, reset=0/en=0 and reset=0/en=1 separately. Your test must distinguish reset, hold and capture.
Selbst ausprobieren
With q=1, d=0, rst=0 and en=0, what is q after the next rising edge?
Erklärung lesen
en=0 holds the previous value, so q remains 1.