EngineerPlay

Flip-flops and counters practice

A flip-flop changes only on a clock edge: D copies D, T toggles while T = 1, JK sets, resets or toggles, and SR forbids S = R = 1. Chained T flip-flops make a ripple counter: n of them count 2ⁿ states and divide the clock by 2ⁿ.

What Q becomes in an SR or D flip-flop (and the forbidden S = R = 1), how many flip-flops a counter needs, and the frequency out of a chain of T flip-flops.

The SR flip-flop holds Q as shown, its inputs are held at the levels on their wires, and one clock pulse arrives. What is Q after the pulse?

A SR flip-flop with its inputs on its wires, Q at the start and one clock pulse on its clock wireLabels shown, in drawing order: S, R, Q, Q̄, 0, Q = 1.SRQQ̄00Q = 1

How to solve these

Flip-flops. An SR flip-flop is set by S = 1 and reset by R = 1; S = R = 1 is not allowed. A D flip-flop copies D into Q at the clock edge. A T flip-flop changes Q at every edge while T = 1. A JK flip-flop sets with J, resets with K, keeps Q when J = K = 0 and changes it when J = K = 1.

Edges. A triangle on the clock input means the flip-flop reacts to an edge, not a level; a bubble in front of it means the falling edge. In a timing diagram, read the inputs just before each edge the flip-flop reacts to.

Counters. n flip-flops have 2ⁿ states, so counting 0 to 59 needs 6. In a ripple counter each T flip-flop halves the frequency: four of them turn 64 kHz into 4 kHz. A NAND gate that clears the flip-flops at the count N makes a MOD-N counter, which shows 0 to N − 1 and divides by N. A counter goes round: a 4-bit counter at 9 shows 4 after 11 more pulses (9 + 11 = 20 = 16 + 4).

Shift registers. At each clock pulse every bit moves one flip-flop on and a new bit comes in. Fed back from the last Q, the register is a ring counter (n states); fed back from the last Q̄, a Johnson counter (2n states).

Delay. In a ripple counter the delays add up: 4 flip-flops of 10 ns settle after 40 ns, so the clock may be at most 25 MHz.

Worked example

The JK flip-flop holds Q as shown, its inputs are held at the levels on their wires, and 2 clock pulses arrive. What is Q after the pulses?

A JK flip-flop with its inputs on its wires, Q at the start and 2 clock pulses on its clock wireLabels shown, in drawing order: J, K, Q, Q̄, 0, 1, Q = 1.JKQQ̄01Q = 1
Show the working
  1. Write down what is given: J = 0, K = 1, Q = 1.
  2. A JK flip-flop: J = 1, K = 0 sets Q to 1; J = 0, K = 1 resets it to 0; J = K = 0 keeps Q; J = K = 1 changes Q.
  3. Pulse by pulse: Q = 0, Q = 0.
  4. Check: the inputs stay the same, so every pulse follows the same rule. Answer: Q = 0.

Remember: T: Q changes at each edge while T is high. JK: J sets Q, K resets it, both high changes Q, both low keeps it. Formula sheet

Questions

How many flip-flops does a counter need?

The least n with 2ⁿ at least the number of states. A decade counter (0 to 9, 10 states) needs 4, because 2³ = 8 is too few and 2⁴ = 16 is enough; a counter for seconds (0 to 59) needs 6.

What frequency comes out of a ripple counter?

Each T flip-flop with T = 1 halves it, so n of them divide by 2ⁿ: 64 kHz through 4 flip-flops gives 4 kHz. A MOD-N counter divides by N, so a MOD-10 counter turns 1 kHz into 100 Hz.

What does a bubble on a flip-flop's clock input mean?

The flip-flop reacts to the falling edge, when the clock goes from 1 to 0. Without the bubble it reacts to the rising edge. In a ripple counter this, and whether each stage is clocked from Q or Q̄, decides if it counts up or down.

How are these answers checked?

Each question is generated fresh and its answer computed by code. A separate test rebuilds the circuit from the drawing and simulates it edge by edge with its own truth tables, and reads the timing diagrams off the drawn waves.