14 / 37 · Concept
Flip-flops, enable and control priority
Define hold, load and reset through next-state equations and avoid unintended clock gating.
Lessons are free to read. Enroll to save your learning progress.
A register stores the result of a next-state function
Let be the value just before the clock edge, the input accepted at that edge, and the updated value. A registerRegister A circuit that stores multiple bits of state. The synchronous registers in this course store their specified inputs at a clock edge. Learn more with reset before enable follows
When enable is 0, changes to D do not change the stored value. Omitting this hold path in sequential RTL differs from omitting an assignment in combinational logic. Holding state is part of the register's specification.
module enabled_register (
input logic clk, rst, en,
input logic [7:0] d,
output logic [7:0] q
);
always_ff @(posedge clk) begin
if (rst) q <= 8'b0;
else if (en) q <= d;
end
endmoduleThis is a synchronous active-high reset. At an edge where reset and enable are both 1, the circuit stores 0. Reversing the priority changes the function, so capture priority in code and tests, not only in comments.
Each column below records one rising edgeRising edge The instant at which the clock changes from 0 to 1. Distinguish it from a level, which refers to the entire interval during which CLK=1. Learn more. Inputs are sampled just before the edge; a state labeled “after” is its value immediately after the update. Column alignment shows sample order, not physical propagation delayPropagation delay The time from an input change until the output settles to the correct value. Logical equivalence and timing behavior are separate properties. Learn more. Initial Q=0xA5. The first column holds, the second writes, and the third has simultaneous reset and enable.
View waveform data
| Signal | Wave | Bus values |
|---|---|---|
| edge | 2345 | E0 → E1 → E2 → E3 |
| reset | 0.10 | |
| enable | 01.0 | |
| D | 2.34 | 3C → 99 → 77 |
| Q after | 234. | A5 → 3C → 00 |
Enable does not mean directly chopping the clock
Using an arbitrary combinational expression such as gated_clk = clk & en as a clock can create short pulses or unintended edges when en changes. Mapping clock-enable RTL to cells is the responsibility of synthesis and implementation. Clock gating for power reduction is designed separately with appropriate cells and timing verification.
Control priority becomes visible when reset, load, enable and similar controls overlap. Activating them only one at a time is insufficient. For example, starting from q=A5, en=0 with d=3C must hold the value; en=1 at the next edge must store 3C.
Try it yourself
Starting with q=0xA5, pass an edge with rst=1, en=1 and d=0x3C, then another with rst=0 and en=0. What is q after each edge?
Read the explanation
At the first edge, reset wins and q becomes 0. At the next, enable is 0, so q remains 0. If reset were nested inside en, it could be missed when en=0; test that combination separately too.