Verilog RTL I – Counters/Timers
Combinational, arithmetic, sequential, counters, timers
What you will learn and practise
Complete the stages in order and retain the requested evidence.
Counter architectures
Modulo and terminal count
Timer/reload/timeout
Interrupt generation
Watchdog concept
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
6. Clock divider
7. Programmable counter
8. One-shot timer
9. Periodic timer
10. Timeout generator
11. Timer IRQ
12. Watchdog timer
Week-2 coding assessment
Mini-project: programmable timer with IRQ
Programmable timer RTL + TB
Build counters and timer/control RTL culminating in a programmable timer with timeout and interrupt behavior.
- Create project_workspace/week2_verilog_rtl1/day10 and assessment subdirectories.
- Define counter/timer requirements before implementation.
- Use a self-checking testbench for the programmable timer.
- Implement up, down and up/down counters.
- Add enable/load and MOD-10/MOD-N behavior.
- Implement ring, Johnson, Gray and free-running/event counters.
- Implement clock-divider and programmable-counter exercises.
- Implement one-shot and periodic timer behavior.
- Implement timeout generation and timer IRQ.
- Study watchdog behavior and implement the assigned watchdog exercise.
- Complete the programmable timer with IRQ mini-project and self-checking testbench.
- Explain terminal count and modulo behavior.
- Compare free-running, one-shot and periodic timer operation.
- Explain reload and timeout behavior for a programmable timer.
- Describe when an interrupt should assert and how the testbench proves it.
- Explain the purpose of a watchdog timer and what event normally prevents timeout.
Debug off-by-one terminal count, reload/timeout timing and interrupt assertion defects; preserve failing and corrected evidence.
- counter/timer RTL
- programmable timer + IRQ RTL
- self-checking TB
- waveform/log evidence
- written answers and debug report
- 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
Build, run and retain evidence
project_workspace/week2_verilog_rtl1/day10_timer/
rtl/counter.vrtl/mod_counter.vrtl/timer.vrtl/watchdog.vtb/tb_timer.v
- 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
iverilog -g2012 -Wall -o sim/day10.vvp rtl/*.v tb/tb_timer.vRunvvp sim/day10.vvp | tee logs/day10_timer.logWaveformgtkwave sim/day10_timer.vcd- No off-by-one terminal-count failures
- Timer reload/timeout matches specification
- IRQ timing checked automatically
- Watchdog cases PASS
- Log and VCD retained
Review before completing Day 10
- MCQ
What is the classic timer error when terminal-count timing is defined incorrectly?
Review answer
An off-by-one timeout.
- Code reading
For a periodic timer, what normally happens after expiry?
Review answer
It reloads its programmed period and continues counting.
- 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.
- 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.
Counters / Timers
- counter boundaries
- modulo/terminal count
- timer reload/timeout
- IRQ timing
- watchdog
Assessment: Q5
Verilog RTL I
2.5 h · 100 marks · RTL + TB + waveform
Review Week 2 assignment →