Section 2 · 11 min read
Sequential circuits
Latches, flip-flops and their conversions, timing constraints, ripple and synchronous counters, shift registers, ring and Johnson counters, LFSRs and finite state machine design, with worked GATE problems.
On this page
What makes a circuit sequential
A sequential circuit has memory. Its outputs depend on the current inputs and on the stored state, and the state changes over time. In synchronous circuits all flip-flops change on the same clock edge; in asynchronous circuits (such as ripple counters) different elements change at different times.
GATE favourites: trace a counter for a few clocks, find the modulus of a counter with a reset gate, compute the maximum clock frequency, convert one flip-flop type to another, and count the states of a sequence detector.
Latches
SR latch
Two cross-coupled NOR gates make an SR latch with active-high inputs:
| Meaning | |||
|---|---|---|---|
| 0 | 0 | hold | |
| 0 | 1 | 0 | reset |
| 1 | 0 | 1 | set |
| 1 | 1 | invalid | both outputs forced to 0 |
With both NOR outputs are 0, so and are no longer complements. If both inputs then return to 0 together, the final state depends on gate delays (a race), and the latch may oscillate before settling.
The NAND version has active-low inputs (, ). Its forbidden input is , which forces both outputs to 1.
Gated D latch
Adding an enable and setting removes the invalid case. While enable is 1, follows (the latch is transparent); while enable is 0, holds. A latch is level-sensitive.
Flip-flops
A flip-flop is edge-triggered: it samples its inputs at a clock edge and holds between edges. A positive edge-triggered D flip-flop is usually built as two D latches in master-slave arrangement with opposite enables.
Characteristic equations and excitation tables
| Type | Characteristic equation | Behaviour |
|---|---|---|
| SR | , with | set, reset, hold |
| JK | like SR, but toggles | |
| D | copies D | |
| T | toggles when |
Excitation tables give the inputs needed for each transition ( = don't care):
| 0 X | 0 X | 0 | 0 | |
| 1 0 | 1 X | 1 | 1 | |
| 0 1 | X 1 | 0 | 1 | |
| X 0 | X 0 | 1 | 0 |
The JK table has the most don't-cares, which is why JK designs often give the simplest input logic.
Converting one flip-flop to another
To make flip-flop type Y from type X, write the characteristic equation of Y and drive X's inputs to produce it.
- T from D: .
- JK from D: .
- D from JK: , .
- T from JK: .
- D from T: .
Race-around
In a level-triggered JK flip-flop with , the output keeps toggling for as long as the clock is high, if the clock pulse is longer than the propagation delay. The final value is unpredictable. Fixes: master-slave construction (output changes once per clock period) or true edge triggering.
Timing
Three parameters of a flip-flop:
- : clock-to-output delay.
- : input must be stable this long before the edge.
- : input must stay stable this long after the edge.
For a path from flip-flop 1 through combinational logic to flip-flop 2:
Here is how much later the clock reaches the capturing flip-flop than the launching one. Positive skew relaxes the setup (frequency) constraint and tightens the hold constraint. If skew is not mentioned, take it as zero. Hold violations cannot be fixed by slowing the clock.
Counters
Ripple (asynchronous) counters
Each flip-flop is a T flip-flop with (or a JK with ). The first one is clocked by the system clock; each later one is clocked by the previous output. With negative-edge flip-flops clocked from , the counter counts up. With positive-edge flip-flops clocked from , it counts down. (Clocking from reverses each case.)
Delay: the worst-case transition (for example 0111 to 1000) ripples through all stages, so the outputs settle after . If the count is decoded, add the decoder delay. Maximum frequency .
Mod-N with asynchronous clear. To make a mod-N ripple counter, detect state with a gate on the bits that are 1 in and use it to clear all flip-flops. State appears briefly (a glitch) and the counter goes to 0, so the stable states are to . If the clear is synchronous (takes effect at the next clock), you must detect instead.
Synchronous counters
All flip-flops share the clock. The binary up counter with T flip-flops uses and . The delay is one flip-flop delay plus the gate delay of the AND chain, not .
Design steps for any synchronous counter or state machine:
- List the states and transitions; choose a state assignment.
- Write the present-state / next-state table.
- Use the excitation table to get each flip-flop's inputs.
- Minimize each input with a K-map, using unused states as don't-cares.
- Check that the unused states eventually lead into the main cycle (self-starting).
Number of flip-flops
A counter with states needs at least flip-flops in binary encoding. A ring counter needs flip-flops for states, and a Johnson counter needs .
Shift registers, ring and Johnson counters
A shift register moves its contents one position per clock. Serial in, serial out (SISO): loading bits takes clocks, and at that point the first bit is already at the output; shifting the remaining bits out takes more clocks, so clocks in total.
| Counter | Feedback | States used | Decoding |
|---|---|---|---|
| Ring ( flip-flops) | last output to first input | none needed (one-hot) | |
| Johnson ( flip-flops) | complement of last output to first input | one 2-input AND per state | |
| Binary ( flip-flops) | counting logic | -input AND per state |
A 4-bit Johnson counter from 0000: 0000, 1000, 1100, 1110, 1111, 0111, 0011, 0001, then back to 0000. Unused states: .
Linear feedback shift registers (LFSR)
An LFSR feeds back the XOR of selected bits. With the right taps an -bit LFSR passes through all nonzero states before repeating (maximal length). The all-zero state maps to itself, so it is never part of the main cycle.
Finite state machines
- Moore machine: output depends only on the present state.
- Mealy machine: output depends on the present state and the present input.
For the same behaviour, a Mealy machine needs the same number of states or fewer. A sequence detector for a pattern of length (overlapping) needs states as Mealy and as Moore. For non-overlapping detection, after a match the machine returns to the start state instead of the longest matching suffix, but the state count is the same.
State minimization. Two states are equivalent if, for every input sequence, they produce the same outputs. Partition refinement: start by grouping states with identical outputs, then split groups whose members go to different groups on some input, and repeat until stable. Each final group is one state.
Worked examples
Worked example 1: Designing a mod-6 counter with T flip-flops
Design a synchronous counter that counts 0, 1, 2, 3, 4, 5, 0, ...
Solution. For a T flip-flop, exactly when the bit changes, so .
| State | Next | |
|---|---|---|
| 000 | 001 | 001 |
| 001 | 010 | 011 |
| 010 | 011 | 001 |
| 011 | 100 | 111 |
| 100 | 101 | 001 |
| 101 | 000 | 101 |
| 110 | X | XXX |
| 111 | X | XXX |
- in every used state.
- in states 1 and 3; 0 in 5. With 6 and 7 as don't-cares: .
- in states 3 and 5. Using 7 as don't-care: .
Self-start check: from 110, gives 111; from 111, , , gives 010, which is in the main cycle. The counter is self-starting.
Worked example 2: Clock frequency with skew
ns, longest logic delay 12 ns, shortest logic delay 1 ns, ns, ns. The clock reaches the capturing flip-flop 2 ns after the launching flip-flop. Find and check hold.
Solution. Setup: ns, so MHz.
Hold: ns must be at least ns. It is, so no hold violation.
Worked example 3: Mod-N ripple counter
A 4-bit ripple up counter has a 2-input NAND driving its active-low asynchronous clear, with inputs and . What is the modulus? If each flip-flop has a 10 ns delay, what is the maximum clock frequency without decoding?
Solution. The clear fires at the first count with , which is . Stable states are 0 to 9: a mod-10 (decade) counter.
The worst-case ripple goes through all 4 flip-flops: ns, so MHz. (A strict analysis also adds the clear path delay for the 9 to 0 transition, which questions sometimes include.)
Worked example 4: Moore detector for 101
Design a Moore machine that outputs 1 when the last three inputs are 101 (overlapping). Trace it on input 1101011010.
Solution. States record the longest suffix of the input that is a prefix of 101:
| State | Meaning | Output | Next on 0 | Next on 1 |
|---|---|---|---|---|
| nothing | 0 | |||
| "1" | 0 | |||
| "10" | 0 | |||
| "101" | 1 |
From , an input 0 leaves suffix "10" (), and an input 1 leaves "1" (). That is where overlap is handled.
Trace on 1101011010: states after each bit are . Outputs: 0001010010. Detections end at positions 4, 6 and 9.
Four states for a 3-bit pattern, as expected for Moore (). The Mealy version needs 3.
Worked example 5: Converting JK to D behaviour
A D flip-flop must behave as a JK flip-flop. What logic drives ?
Solution. The JK characteristic equation is . A D flip-flop gives , so : two AND gates, one OR gate and an inverter on (using from the flip-flop).
Common traps
- Counting the glitch state as part of a mod-N ripple counter with asynchronous clear. With a synchronous clear, detect .
- Using for a synchronous counter's period. That formula is for ripple counters.
- Ignoring setup time or adding hold time into the clock period.
- Getting the skew sign wrong. Late capture clock helps setup, hurts hold.
- Taking the JK excitation as . is a don't-care.
- Assuming a Johnson counter has or states. It has .
- Forgetting overlap when building detectors: after a match, go to the longest suffix that is still a prefix.
- Starting an LFSR in the all-zero state.
Quick revision
- SR NOR latch: invalid. NAND latch: invalid.
- : SR ; JK ; D ; T .
- JK excitation: : ; : .
- T from D: . JK from D: .
- ; hold: .
- Ripple counter .
- Mod-N with async clear: detect ; stable states to .
- Ring: states. Johnson: states. Binary: . Maximal LFSR: .
- Sequence detector of length : Mealy states, Moore .
- Minimum flip-flops for states: .