Timers and Counters
Hardware Timing, Counters
What are Timers/Counters
• Hardware provided module which counts
▫ Timers count clock cycles
▫ Counters count arbitrary signal change
• Counts up to threshold then sets interrupt flag
▫ CPU can poll for interrupt flag – software polling
▫ CPU can be interrupted by flag – interrupt driven
Timer/Counter Components
• Clock Prescaler (divider)
• Clock source selection
▫ In the presence of multiple clocks
• N-bit timer/counter – Actual Count value
• Compare registers
• Capture registers – for precise capture of time of
event
• Control Logic
• Status/Control Registers – Defines behavior
Timer Hardware
Prescaler
Sync
Edge Detect
Clock Select
Counter
Control
Logic
Compare
Register
>=
==MAX
==0
Interrupt Request
Timer CTL reg
Clear
Up/Down
Enable
Clock Prescaler
• The clock prescaler modifies the rate at which a
timer changes
▫ Allows timer/counter register to cover a larger range
• For a timer, log2(Range*Clock Freq) is a lower
bound on the number of counter bits required
▫ Assuming no prescaling
• Range AND precision define the # of bits
required
▫ If you don’t need as high of precision, you may
prescale the clock to achieve a higher range from same
# of bits