Skip to content
BetterDL

Wraparound (counter)

Also called: wrap round, counter rollover, rollover, counter wraparound

What a counter does after its last state: an up counter goes from its maximum back to 0, and a down counter goes from 0 back to its maximum.

A counter has a fixed number of states, its modulus, so it can't keep counting forever. When it passes its last state it wraps around, like a car odometer going from 99999 to 00000.

The wrap isn't an error. It's the same as overflow in unsigned addition: the carry out of the top bit is simply dropped, because there's no flip-flop to hold it. The terminal count output tells the rest of the circuit when a wrap is about to happen, and that's how counters are cascaded.

Mathematically, a counter counts modulo N. After k edges from a start value s:

  • up: (s + k) mod N
  • down: (s − k) mod N, adding N if the result is negative.
startCLKCLKCLKCLKCLKCLKCLKCLK000001010011100101110111

Worked examples

Example

Up past the top

A 4-bit up counter starts at 1110 (14). Where is it after 5 edges?

  1. 1.

    14 + 5 = 19.

  2. 2.

    19 mod 16 = 3.

  3. 3.

    So 0011. Listing it: 14, 15, 0, 1, 2, 3 ✓.

Example

Down past zero

A mod-10 down counter starts at 2. Where is it after 4 edges?

  1. 1.

    2 − 4 = −2.

  2. 2.

    Add 10: 8.

  3. 3.

    Listing it: 2, 1, 0, 9, 8 ✓.

Common mistakes

  • Writing the next state after 111 as 1000. A 3-bit counter has no fourth bit, so it goes to 000.

  • Wrapping a mod-N counter at 2ⁿ instead of at N. A BCD counter goes from 9 to 0, not on to 10.

Practice Wraparound (counter)

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Wraparound (counter) is taught in Counters.