EN

Counters

Timing diagram of each counter type and design of a frequency divider

1. Simulator

Counter
kHz

2. Frequency divider

Divider
kHz

What a counter is

A counter is a sequential circuit that advances one state with each clock pulse and goes through a fixed sequence: 0, 1, 2… up to its modulus and back to the start. It is built with flip-flops, one per bit. It is used to count parts or pulses, divide frequencies, generate delays and timings, step through memory addresses or share time in a multiplexed display.

Asynchronous and synchronous

Modulo N and decade

To count up to a number that is not a power of 2, a state is detected and the counter is reset. With an asynchronous reset (74HC93, 74HC161) N itself is detected: the counter reaches N for an instant and is cleared at once, producing a very short and unreliable pulse. With a synchronous reset (74HC163) N − 1 is detected and the clearing happens on the next edge, with no false states. The decade counter is a modulo 10 that counts in BCD, from 0 to 9, and is chained to count in decimal, digit by digit.

\[ f_{out} = \frac{f_{clock}}{N} \qquad n_{flip\text{-}flops} = \lceil \log_2 N \rceil \]

In a modulo N that is not a power of 2, the highest output does not have a 50 % duty cycle. If a symmetrical square wave is needed, divide by N/2 and then by 2 with one more flip-flop. A 32.768 kHz clock, the one in quartz watches, gives exactly 1 Hz after 15 divisions by 2.

Ring and Johnson

They are shift registers with feedback. The ring counter circulates a single 1: with n flip-flops it has n states and each one is decoded directly by an output, with no gates; it is used to sequence steps. The Johnson counter feeds back the inverted output and achieves 2n states with n flip-flops; each state is decoded with a two-input AND. The CD4017 is a 5-flip-flop Johnson with 10 decoded outputs, widely used for LED sequences.

Common ICs

ICTypeNotes
74HC934-bit asynchronous binaryTwo stages (÷2 and ÷8), asynchronous reset
74HC390Dual asynchronous decadeEach half divides by 2 and by 5
74HC1614-bit synchronous binarySynchronous parallel load, asynchronous reset
74HC1634-bit synchronous binarySynchronous parallel load and reset: the handiest for modulo N
74HC1934-bit up/down binarySeparate clocks for counting up and down, parallel load
CD4017Johnson decade10 decoded outputs
CD4040 / CD406012 and 14-stage binaryFrequency dividers; the CD4060 includes the oscillator

In a microcontroller, counters are the timers: the same circuit counting the internal clock or pulses on a pin, with comparators that generate interrupts or PWM.

Related: latches and flip-flops, state machines (a counter is a state machine with no inputs), magnitude comparators and BCD to 7-segment decoder.