Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • RTL Foundations36
  • Combinational Design25
  • Sequential Design27
    • Flip-Flops and Registers
    • Counters and Timers
      • Counting as Controlled State Evolution
      • Up/Down Counter with Reload
      • A Prescaler Feeding a Timer Tick
      • Watchdog Timer Example
      • A Gray-Code Counter
      • Mini Project: a Programmable Timer
    • Shift Registers and LFSRs
    • Pipelining
    • Stalls, Bubbles and Hazards
    • Retiming
  • FSM & Control27
  • Timing & Clocking39
  • Reset & CDC34
  • Memory & Buses57
  • Advanced RTL28
  • Senior & Interview76
  • Glossary and Notation
Loading lesson

←Sequential Design
  1. Topics
  2. RTL Design
  3. Sequential Design
  4. Counters and Timers
On this page

    Part 3 of 9Part 3 of 9/SequentialIntermediate

    Counters and Timers

    Counters as small state machines: modulo counts, up/down with reload, prescalers that make tick enables, and a watchdog.

    • 6topics
    • 6lessons

    Topics in this section

    1. 1Counting as Controlled State Evolution1 lesson
    2. 2Up/Down Counter with Reload1 lesson
    3. 3A Prescaler Feeding a Timer Tick1 lesson
    4. 4Watchdog Timer Example1 lesson
    5. 5A Gray-Code Counter1 lesson
    6. 6Mini Project: a Programmable Timer1 lesson

    A counter is a register with next-value rules for increment, decrement, reload, and wrap. Terminal-count decode turns those counts into ticks, done flags, and timeouts.

    The structure shared by every counter: a register, next-value logic, and decode of interesting values.

    Lessons in this topic

    6 lessons, about 32 min

    1. 1Counting as Controlled State EvolutionYou can write a free-running and a modulo-M counter, place the terminal-count pulse at M-1, and name the usual off-by-one mistakes.3 min
    2. 2Up/Down Counter with ReloadYou can write an up/down counter with load, enable and direction, order the priority chain, and choose between wrapping and saturating limits.3 min
    3. 3A Prescaler Feeding a Timer TickYou can build a prescaler and timer from a tick enable, predict which edge produces and which consumes a tick, and size the counter for a given interval.5 min
    4. 4Watchdog Timer ExampleYou can build a watchdog with kick, disable and a sticky timeout, and list the design questions to settle before coding it.3 min
    5. 5A Gray-Code CounterYou can convert between binary and Gray by hand, write a Gray counter in either RTL style, and say which moduli keep the one-bit property at the wrap.8 min
    6. 6Mini Project: a Programmable TimerYou can write a priority-ordered timer with prescaler, load, one-shot and auto-reload modes and a write-1-to-clear flag, check it against a cycle model, and count its flops in Yosys.10 min
    Check yourself A 4-bit counter counts 0, 1, …, 15, 0. How many different states does it have, and what limits its period?

    16 states. The period is 2⁴ = 16 clock cycles, set by the register width; a modulo-M counter shortens it to M by resetting at M−1.

    “Design a mod-N counter”, “divide the clock by 3”, and “design a watchdog” are staple questions. The tick-enable pattern in this topic is the right answer to most clock-division questions.

    Revision sheet

    The whole topic on one page, taken from each lesson's Remember box. Read it before an interview, or print it.

    Counting as Controlled State Evolution

    • An N-bit free-running counter has a period of 2^N cycles.

    • A modulo-M counter wraps after M-1, and tc is high while count holds M-1.

    • Decode tc with >=, not ==, so an out-of-range value cannot lock the counter. Guard the width for M = 1.

    Up/Down Counter with Reload

    • Priority is reset, then load, then enabled counting.

    • Wrap suits addresses and pointers; saturate suits levels, credits and gain values.

    • Test it against a plain-integer reference model with random stimulus to find limit and priority bugs.

    A Prescaler Feeding a Timer Tick

    • Slow logic acts only when tick is high, all on the same clock.

    • A tick is produced after one edge and consumed at the next, because both blocks read old values.

    • start wins over a coincident tick; the elapsed time to expiry depends on the start phase.

    Rule of thumb: prefer a tick enable to a divided clock unless a real clock output is needed.

    Watchdog Timer Example

    • A kick or a disable clears the counter; TIMEOUT kick-free cycles set a sticky timeout.

    • Only reset clears a fired timeout.

    • A safety-related watchdog needs its own low-frequency clock source.

    A Gray-Code Counter

    • Binary to Gray is g = b XOR (b >> 1). Gray to binary is a prefix XOR from the top bit down.

    • Register the Gray value: convert the next binary count before the flop, and send only flop outputs across a crossing.

    • Only an even modulus can stay one-bit at the wrap, and only when it uses the codes centred in the cycle; an odd modulus never can.

    Rule of thumb: a Gray count is safe to cross only if it comes straight from flops and moves by exactly one step at a time.

    Mini Project: a Programmable Timer

    • A period is (psc + 1) x (top + 1) cycles; compare with >= so a smaller limit written mid-count ends the period at once.

    • Match on the step that lands on cmp, not on count == cmp, or the flag sets again while the count waits.

    • A sticky flag's set must beat its clear, or a match in the clearing cycle is lost.

    Rule of thumb: for every flag, write down what happens when set and clear arrive in the same cycle, then test exactly that cycle.

    Practise it

    • Code lab: Enable counter

    • Practice question: Parameterised up/down counter with wrap or saturate

    • Code lab: Up/down counter

    • Practice question: Gray code counter for a CDC-friendly FIFO pointer

    • Practice question: FSM Gray encoding for low power and CDC safety

    • Interview: run a mock interview on this topic

    PreviousNext: Counting as Controlled State Evolution

    Up next

    Up nextCounting as Controlled State Evolution

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Flip-Flops and Registers
    • Shift Registers and LFSRs
    • Pipelining