Flip-flops
A flip-flop is a circuit that stores one bit, a 0 or a 1, and holds it until it is told to change. The most common, the D flip-flop, copies its data input D to its output Q at each rising clock edge, and holds it until the next one.
Qnext = D
where Qnext is the output after the clock rises and D the data input at that moment; between edges, Q holds.
Flip-flops are the memory inside registers, counters and every processor.
What is a flip-flop?
A flip-flop is a circuit with two stable states, 0 and 1, that stays in whichever one it was last put in, so it stores a single bit of information.
It is built from logic gates wired so their outputs feed back into their inputs. That feedback is what lets it remember, unlike a plain gate, whose output depends only on its inputs right now.
How does an SR latch work?
An SR latch is two NOR gates, each output feeding the other’s input: S sets Q to 1, R resets it to 0, and with both at 0 it holds whatever it was.
Figure 1 shows the hold: the same inputs give Q = 1 or Q = 0 depending on what came before. Setting S and R to 1 together forces both outputs to 0, so circuits avoid it. A 555 timer has an SR flip-flop inside, set and reset by its two comparators.
Hold, S = 0 and R = 0: each gate’s output keeps the other’s in place, so Q stays 1, as it was before. That is one bit of memory.
How does a D flip-flop work?
A D flip-flop copies its data input D to its output Q at the instant the clock rises, its clock edge, and ignores D the rest of the time.
That makes it predictable: everything in a circuit clocked by the same signal changes together, once per cycle, after its inputs have had time to settle. In Figure 2, a short pulse on D between edges changes nothing. D flip-flops are the most widely used kind, the building block of registers and processors.
Edge 1: the clock rises while D is 1, so Q becomes 1 and holds it until the next rising edge.
What are the types of flip-flops?
The four types are SR, D, JK and T: SR sets and resets, D stores its input, JK is an SR without the forbidden input, and T toggles.
A JK flip-flop acts like an SR with J for set and K for reset, but J = K = 1 toggles Q instead of being forbidden. Tie J and K together and you have a T flip-flop, which flips its output on every clock edge while T is 1. Most are now built as D flip-flops with a little extra logic.
What is the difference between a latch and a flip-flop?
A latch is level-triggered: while enabled, its output follows its input. A flip-flop is edge-triggered: it changes only at the clock edge.
A gated D latch is transparent while its enable is high, so any glitch on D passes straight through. A D flip-flop is two latches in a row, enabled on opposite halves of the clock, so only the value at the edge gets through. Latches are smaller; flip-flops are safer to design with.
What are flip-flops used for?
Flip-flops store data in registers, count pulses, divide frequencies, and line up signals with a clock, in everything from timers to processors.
Chain toggle flip-flops and each halves the frequency of the one before, so together they count in binary, as Figure 3 shows. That is how a watch turns its crystal’s 32,768 Hz into one tick a second, and how an oscillator clock becomes slower ones. Flip-flops also debounce switches and hold a microcontroller’s pin states.
5 pulses: Q0 toggles on every pulse and each later flip-flop toggles when the one before it falls from 1 to 0, so Q2 Q1 Q0 reads 101, 5 in binary.
How do you work out a counter’s flip-flops and frequency?
To work out a counter, divide the input frequency by 2 for each toggle stage, and find the smallest n with 2n at least the number of states: a count of 10 needs 4 flip-flops.
Example 1: a frequency divider
A 32,768 Hz watch crystal drives a chain of 15 toggle flip-flops. What frequency comes out of the last one?
- Given
- a 32,768 Hz watch crystal driving 15 toggle flip-flops in a chain
- Find
- the frequency out of the last one
- Solution
- f = 32,768 Hz ÷ 215 = 32,768 Hz ÷ 32,768 = 1 Hz
- Answer
- 1 Hz, one tick a second
Example 2: flip-flops for a counter
A counter must count from 0 to 59 and then start again. How many flip-flops does it need?
- Given
- a binary counter that must count from 0 to 59, 60 states
- Find
- the fewest flip-flops it needs
- Solution
- n flip-flops give 2n states, so find the smallest n with 2n ≥ 6025 = 32 is too few; 26 = 64 is enough
- Answer
- 6 flip-flops
Summary
Key equations
- Qnext = D a D flip-flop
- fout = fin ÷ 2n n toggle stages
- states = 2n an n-bit counter
Key terms
- Latch
- Follows its input while enabled.
- Clock edge
- The moment the clock changes.
- Toggle
- Flip to the opposite state.
- Register
- Flip-flops storing a word.
Practice problems
-
An SR latch has S = 0 and R = 0. What does Q do?
With neither set nor reset active, the cross-coupled gates hold each other in place.
-
A D flip-flop has D = 1 when the clock rises. What is Q afterwards?
Q copies D at the rising edge, so Q = 1 until the next edge.
-
Which input is not allowed on a NOR SR latch?
Both outputs go to 0, and releasing both together leaves the latch in an unpredictable state.
-
A 1 MHz clock drives 4 toggle flip-flops in a chain. What comes out?
1 MHz ÷ 2⁴ = 1,000,000 ÷ 16 = 62.5 kHz.
-
How many flip-flops does a counter from 0 to 15 need?
It needs 16 states, and 2⁴ = 16.
FAQ
Why is it called a flip-flop?
Because it flips into one state and flops back to the other, staying in each until told to change.
What is the difference between a flip-flop and a register?
A register is a row of flip-flops sharing one clock, storing a whole number or word at once, such as 8 bits.
Is a flip-flop memory?
Yes, one bit of it. Static RAM and processor registers are built from flip-flop-like cells; they lose their data when power goes.
What does the clock do in a flip-flop?
It sets the moment the flip-flop samples its input. A rising-edge flip-flop acts as the clock goes from 0 to 1 and ignores its inputs otherwise.
What is a JK flip-flop?
A flip-flop with J (set) and K (reset) inputs, where J = K = 1 toggles the output instead of being forbidden as it is in an SR latch.
Does a 555 timer have a flip-flop?
Yes. Its two comparators set and reset an internal SR flip-flop, which drives the output and the discharge transistor.
What is metastability?
When D changes too close to the clock edge, a flip-flop can hang between 0 and 1 for a moment before settling. Two flip-flops in a row reduce the risk.