Week 2 · Day 10 · 7 hours

Verilog RTL I – Counters/Timers

Combinational, arithmetic, sequential, counters, timers

Daily plan

What you will learn and practise

Complete the stages in order and retain the requested evidence.

Theory · 2h

Counter architectures
Modulo and terminal count
Timer/reload/timeout
Interrupt generation
Watchdog concept

Guided lab · 2h

1. Up/down/up-down counters
2. Enable/load counter
3. MOD-10/MOD-N
4. Ring/Johnson/Gray counters
5. Free-running/event counters

Independent lab · 2h

6. Clock divider
7. Programmable counter
8. One-shot timer
9. Periodic timer
10. Timeout generator
11. Timer IRQ
12. Watchdog timer

Debug and assignment · 1h

Week-2 coding assessment
Mini-project: programmable timer with IRQ

Expected deliverable

Programmable timer RTL + TB

Practical work

Build counters and timer/control RTL culminating in a programmable timer with timeout and interrupt behavior.

Setup
  1. Create project_workspace/week2_verilog_rtl1/day10 and assessment subdirectories.
  2. Define counter/timer requirements before implementation.
  3. Use a self-checking testbench for the programmable timer.
Execution steps
  1. Implement up, down and up/down counters.
  2. Add enable/load and MOD-10/MOD-N behavior.
  3. Implement ring, Johnson, Gray and free-running/event counters.
  4. Implement clock-divider and programmable-counter exercises.
  5. Implement one-shot and periodic timer behavior.
  6. Implement timeout generation and timer IRQ.
  7. Study watchdog behavior and implement the assigned watchdog exercise.
  8. Complete the programmable timer with IRQ mini-project and self-checking testbench.
Written assignment
  1. Explain terminal count and modulo behavior.
  2. Compare free-running, one-shot and periodic timer operation.
  3. Explain reload and timeout behavior for a programmable timer.
  4. Describe when an interrupt should assert and how the testbench proves it.
  5. Explain the purpose of a watchdog timer and what event normally prevents timeout.
Debug challenge

Debug off-by-one terminal count, reload/timeout timing and interrupt assertion defects; preserve failing and corrected evidence.

Evidence to retain
  • counter/timer RTL
  • programmable timer + IRQ RTL
  • self-checking TB
  • waveform/log evidence
  • written answers and debug report
Completion criteria
  • Counter boundaries and modulo wrap are correct
  • Timer reload/timeout behavior matches specification
  • IRQ timing is verified automatically
  • Mini-project is ready for the Week 2 assessment
Executable lab

Build, run and retain evidence

project_workspace/week2_verilog_rtl1/day10_timer/

Required files
  • rtl/counter.v
  • rtl/mod_counter.v
  • rtl/timer.v
  • rtl/watchdog.v
  • tb/tb_timer.v
Mandatory tests
  • Counter wrap and terminal count
  • Enable/load behavior
  • MOD-N boundary
  • One-shot expiry
  • Periodic reload
  • Timeout cycle
  • IRQ assertion timing
  • Watchdog kick before expiry and missing-kick timeout
Compile
iverilog -g2012 -Wall -o sim/day10.vvp rtl/*.v tb/tb_timer.v
Run
vvp sim/day10.vvp | tee logs/day10_timer.log
Waveform
gtkwave sim/day10_timer.vcd
PASS criteria
  • No off-by-one terminal-count failures
  • Timer reload/timeout matches specification
  • IRQ timing checked automatically
  • Watchdog cases PASS
  • Log and VCD retained
Knowledge check

Review before completing Day 10

  1. MCQ

    What is the classic timer error when terminal-count timing is defined incorrectly?

    Review answer

    An off-by-one timeout.

  2. Code reading

    For a periodic timer, what normally happens after expiry?

    Review answer

    It reloads its programmed period and continues counting.

  3. Debug

    IRQ asserts one clock later than specified. Which conditions should be checked?

    Review answer

    Terminal-count comparison and whether IRQ is asserted at count==1, count==0, or the following cycle.

  4. Short answer

    What distinguishes a watchdog from an ordinary periodic timer?

    Review answer

    A watchdog expects a service/kick before expiry; missing service triggers the timeout action.

Skills and assessment traceability

Counters / Timers

  • counter boundaries
  • modulo/terminal count
  • timer reload/timeout
  • IRQ timing
  • watchdog

Assessment: Q5

Weekly checkpoint

Verilog RTL I

2.5 h · 100 marks · RTL + TB + waveform

Review Week 2 assignment →