FPGARelated.com
Fundamentals

Counters

Counting in hardware

Counters are the Swiss army knife of digital design. Need a timer? Counter. Address generator? Counter. Frequency divider? Counter. Baud rate generator? Counter. They're one of the simplest sequential circuits and one of the most useful.

Interactive Binary Counter

Watch bits toggle as the counter advances. Each bit toggles at half the rate of the one to its right:

How Counters Work

A binary counter is a register that adds 1 (or subtracts 1) to its value on every clock cycle. An N-bit counter counts from 0 to 2N−1, then wraps around to 0. This is called overflow or rollover.

Watch the bits carefully: the rightmost bit (LSB) toggles every cycle. The next bit toggles every 2 cycles. The next every 4 cycles. Each bit toggles at half the frequency of the one to its right. This is why counters double as frequency dividers.

A modulo counter (mod-N) counts from 0 to N−1, then resets. If you have a 100 MHz clock and need a 1 Hz signal, you use a mod-100,000,000 counter, and the output toggles once every 100 million cycles.

Key Insight: Each bit in a binary counter toggles at half the frequency of the previous bit, making counters natural frequency dividers. A mod-N counter wraps at a specific value, enabling precise timing generation.
Try it: Set the mod value to 6 and watch: the counter counts 0, 1, 2, 3, 4, 5, then resets to 0. Now switch to 8-bit mode with no mod limit and watch it count to 255. That rollover back to 0 is exactly what happens in hardware.

Why This Matters for FPGA Design

  • LED blinker - the classic first FPGA project is just a counter driving an LED
  • Baud rate generation - UART timing comes from mod-N counters
  • Memory addressing - counters generate sequential read/write addresses for BRAM
  • PWM generation - comparing a counter against a threshold creates pulse-width modulation
  • Watchdog timers - counters that reset on activity, trigger on timeout

Frequently Asked Questions

How does a binary counter work?

A binary counter is a register that increments its value by 1 on each clock cycle. An N-bit counter counts from 0 to 2^N - 1, then wraps around to 0 (overflow). For example, a 3-bit counter counts 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, ... The carry chain from bit to bit is what makes each position toggle at half the rate of the previous one.

What is a modulo counter?

A modulo-N counter counts from 0 to N-1 and then resets to 0, instead of counting through all possible values. For example, a mod-6 counter counts 0, 1, 2, 3, 4, 5, 0, 1, ... Modulo counters are built by detecting the maximum value and resetting. They are essential for generating precise timing, such as dividing a 100 MHz clock down to exactly 1 Hz.

Quick Check

Test your understanding of the key concepts from this lesson.