Skip to content
code0.HDL

Clock, reset and enable

The clock's period, edge and cycle; the enable that chooses between updating and holding; and reset by kind, polarity and priority, including why a clear wins over an enable.

In this chapter

  • Locate the rising edge, the period and the cycle on a clock
  • Predict a register with an enable that chooses between updating and holding
  • Apply a reset by kind, polarity and priority, including a clear that wins over an enable
Concepts in this chapter
  • Clock period, edge, cycle
  • Enable: update or hold
  • Reset kinds, polarity, priority
Prerequisite concepts

1. The clock repeats, and a register moves only at the rising edge

A clock is a signal that alternates between 0 and 1 at a fixed rate. The moment it goes from 0 to 1 is a rising edge, and the time from one rising edge to the next is the period. One period is a clock cycle. The registers in this chapter update at rising edges, so we track their state one edge at a time; combinational signals can still change between edges.

TermMeaningExample
Rising edgethe moment the clock goes from 0 to 1when a register stores D
Periodthe time between two rising edges10 ns
Frequencyperiods per seconda 10 ns period is 100 MHz
Cyclewhat the circuit does during one periodthe interval that one edge ends

With a 10 ns period, three cycles take 30 ns. In the ideal model, an initial state and the inputs at each edge determine the register's state. Physical inputs must also satisfy setup and hold timing around the edge. The experiments assume that timing is met and predict state by counting edges.

The experiments in this unit number cycles from 0. Cycle 0 begins with the register holding its initial value and ends with edge 0. Each row of a table is one cycle: the column "inputs sampled at the edge" holds what the inputs were just before that edge, and "after the edge" holds what that edge stored.

Note. The register model of this primer is fixed: one clock, rising edge, synchronous clear. Falling-edge registers and designs with several clocks appear in the language lessons where they are needed.

2. Enable chooses between updating and holding

An enable tells a register whether this edge should store anything. With en = 1 the edge stores d; with en = 0 the edge comes and goes and the register keeps its current value.

enWhat the edge doesNext value
1updated
0holdthe current q

The enable does not add a second moment of storing: the edge is still the only one. In the experiment, leave en at 1, change d several times (0, 1, 0, 1), and press the edge once. Only the d present at the edge reaches q. Then lower en to 0, change d and press more edges. q stays where it is.

Concept experiment · dff-enable

A browser model of the circuit, not a compiled design. The real toolchain runs in the examples.

Inputs

Outputs

q
0

No edge has happened yet. Set the inputs, then apply a clock edge.

Caution. With en = 0, changing d does not affect the stored value. In a feedback-MUX implementation, the register's next value is its current q, rather than the external d.

Check

Between two edges d went 0, 1, 0, and at the edge it is 0. en is 1. What is q after the edge?

Your answer

3. A reset returns a register to a chosen value

A reset makes a register take a value chosen by the designer when the reset condition applies. A register without reset or explicit initialization typically starts as x in a four-state RTL simulation. A reset input alone does not initialize it until that reset is applied. When reading a reset circuit, check its timing, polarity and priority relative to other updates.

AxisChoicesMeaning
Kindsynchronous / asynchronousa synchronous reset acts at the next rising edge; an asynchronous reset acts the moment the reset signal becomes active, without waiting for an edge
Polarityactive-high / active-lowactive-high resets when the signal is 1, active-low when it is 0; active-low signals often end in _n
Priorityreset before enable in this counterwhen clear and enable are both 1, clear selects 0 rather than the incremented value

In this unit's counter, counter4, the clear input is a synchronous, active-high functional clear. When clear is 1 at an edge, q becomes 0 whatever enable says; only when clear is 0 does enable choose between counting and holding. The count runs from 0 to 15 and wraps to 0 after 15.

clear at the edgeenable at the edgeNext q
10 or 10
01q + 1 (0 after 15)
00q

Take q = 2 and an edge with clear = 1 and enable = 1: the next value is 0, not 3. If the next cycle has clear = 0 and enable = 1, the count goes from 0 to 1. The table below writes this out cycle by cycle.

Cycleclearenableq before the edgeq after the edge
00101
10112
21120
30101
40011

Reproduce it in the experiment: set enable to 1 and press two edges, raise clear as well and press one edge, lower clear and press one edge, lower enable and press one more. The "after the edge" column of the lab table should match the table above.

Concept experiment · counter4

A browser model of the circuit, not a compiled design. The real toolchain runs in the examples.

Inputs

Outputs

q
0

No edge has happened yet. Set the inputs, then apply a clock edge.

Check

q is 7, and at the edge both clear and enable are 1. What is q after the edge?

Check

An asynchronous active-high reset becomes 1 at some instant between two edges. When does the register take its initial value?

Your answer

Note. The default reset differs by language. The Verilog that the BSV compiler generates has a synchronous, active-low reset (RST_N) by default. Chisel's default reset is synchronous and active-high. In Verilog the reset is whatever the code says: checking the reset only at the clock edge makes it synchronous, and reacting to the reset signal's own change as well makes it asynchronous. Each language path shows how that is written.

4. Fill in the state table

The clear and enable columns are the values sampled at each cycle's edge. Write q after the edge. Cycle 0 starts with q = 0, and the compare button names the first cycle that differs.

Predict, then compare · counter4

Fill in each cell before comparing. Empty cells count as a mismatch.

State table
Cycleclearinputs sampled at the edgeenableinputs sampled at the edgeqafter the edge
011
101
201
300
411
501
600

5. Variation: a register that captures and keeps a value

Enables are not only for counters. To take a sensor reading at one chosen moment and keep it unchanged until the next, one register whose en is raised only at that moment is enough. While en is 0, d may change as it likes; q keeps the last value that was captured.

In the table, d is the sensor and en marks the capture moments. Write q after each edge.

Predict, then compare · dff-enable

Fill in each cell before comparing. Empty cells count as a mismatch.

State table
Cycledinputs sampled at the edgeeninputs sampled at the edgeqafter the edge
011
100
210
301
410
511

6. Summary

  • The clock repeats and a register stores only at the rising edge. One cycle runs from one rising edge to the next, and the experiments number cycles from 0.
  • However an input moves between edges, only its value at the edge is stored.
  • Enable picks the next value: d (update) or the current q (hold).
  • Resets are described by kind (synchronous or asynchronous), polarity (active-high or active-low) and priority (before enable). The clear of counter4 is synchronous, active-high and wins over enable.
  • Default resets differ by language; follow each language path's description.

The next chapter draws these tables along a time axis as waveforms and separates the moment inputs are driven from the moment outputs are observed.

Checkpoint

Answer the checks in this chapter