Erlen Primer · all experiments

Electrical · Digital · Investigate

A counter that miscounts

This counter miscounts. Which of three ways is it built wrong, and what puts it right?

A counter that miscounts: the bench

The bench

A 4-bit counter on a breadboard counts presses of a push-button, and miscounts. The button pulls its line down against R1, 82 kΩ; R2, 18 kΩ, takes it on to C1, which the design wants at 1 µF; U1, a 74HC14 Schmitt inverter, turns C1's voltage into DB, high while the button is pressed. U2, a 74HC74, brings DB into step with the clock: U2A takes it at a clock edge, U2B a clock later, and an AND makes CE, high for one clock a press. Bits 0 to 3 are two more 74HC74s, shown on four LEDs: each bit toggles at a clock edge when CE and every bit below it are 1, through a 74HC86's XORs and a carry chain of 74HC08 ANDs. The clock is a function generator's square wave, 100 kHz to 16 MHz. A mixed-signal scope has its logic probes on the board and one probe on C1. The bench supply was left at 12 V by the last group; 74HC parts are rated 2 to 6 V. One thing on this board is built wrong.

What you do

Controls

  • Supply output: Off or On
  • Supply set to: 0 to 3
  • Clock: 0 to 6
  • Scope time base: 0 to 2

Buttons

  • Press the button
  • Clear the count
  • Record the capture

Stockroom

  • C1, the debounce capacitor: As built · A new 1 µF, marked 105
  • U2A, the synchroniser: As built · In, between DB and U2B
  • Bit 3's clock: As built · The clock, with the carry as its enable

Unknown

  • Board: why it miscounts

Predictions

  • The button's contacts close once each press. On the scope, the button's own line will…
  • With nothing on it built wrong, a counter that counts every press at 1 MHz is clocked at 16 MHz. It will…

To work out

  • With bit 3 on the clock like the others, what is the fastest clock this counter counts every press at, at the supply you have set? Measure CE against the clock edge on the scope; add three ANDs for the carry, bit 3's XOR and the 74HC74's setup time. In MHz, three significant figures. (MHz)

To conclude

  • This board miscounts because…

Results kept

  • Captures: Changed, Supply, Clock, Before, After, Button line edges, DB after the press (ms), DB rises, Bit 3 flips, CE after the clock edge (ns), Least setup time (ns)

What you find

  • The button's own line fell and rose several times in one press: its contacts bounce for a millisecond or so before they settle, on every board.
  • The contacts bounced, and DB still rose once: through R2, C1 takes nearly 20 ms to fall to the Schmitt inverter's threshold, far longer than the bounce, and the inverter's two thresholds give one clean edge.
  • CE rose a fixed time after a clock edge, U2A's delay and one AND's: synchronised, a press reaches the counter just after an edge, never just before one.
  • With CE in step with the clock, a bit's input still changed inside its setup time: the clock is too fast for the path from U2A through the carry chain.

What is simplified

Every delay is TI's typical figure for the part at the supply chosen, into the datasheet's 50 pF, and every setup time TI's minimum; real parts vary, and wires add nothing here. A gate is a pure delay that swallows any pulse no longer than its delay. A flip-flop whose input changed inside its setup time takes the old or the new value, by a seeded draw, and settles at once: a real one can hang between the two for a while. A clock whose pulses are shorter than the 74HC74's minimum pulse width clocks nothing. Each press's bounce is a seeded pattern inside the range Ganssle measured, and the generator's square wave is perfect and runs from 0 V to the supply. The scope's probes load nothing, and its threshold is set to half the supply.

Topics

digital logic, counter, flip-flop, contact bounce, debounce, schmitt trigger, glitch, hazard, race, gated clock, setup time, hold time, metastability, synchroniser, propagation delay, maximum clock frequency, timing, logic analyser, mixed-signal oscilloscope, 74hc, breadboard, troubleshooting