IntermediateTopic 62 of 104Electronics & Embedded
Timers and counters
Peripheral blocks for delays, PWM and event measurement.
In depth
Timers count clock cycles with prescalers to generate delays, periodic interrupts, input capture (measure pulse width), output compare and PWM. Resolution and overflow period depend on clock and register width. Watchdog and RTC timers serve special roles.
Key points
- Timer period=(prescaler×count)/f_clk
- Capture for frequency measurement
- SysTick
ExampleA 1 ms tick from a 16 MHz clock with prescale 16 and count 1000.
Timers generate precise delays, pulse trains and event measurements without using the processor, which is essential for timing-critical embedded work.
What is Timers and counters?
Peripheral blocks for delays, PWM and event measurement.
Why is it important to understand timers and counters?
Timers generate precise delays, pulse trains and event measurements without using the processor, which is essential for timing-critical embedded work.
What is a prescaler?
A divider that reduces the timer clock so a larger time range can be covered, at the cost of coarser resolution.
Why use hardware timers rather than software loops?
Software loops are imprecise because interrupts and other code change their timing, while hardware timers keep accurate time independently.
How is Timers and counters used in practice?
Typical applications include generating a 1 kHz sample tick for a control loop, measuring the period of an input pulse for a speed sensor and creating PWM output for a motor driver using a hardware timer.
What should I learn before Timers and counters?
Study "GPIO" first (topic 61 of 104 in Electronics & Embedded). It covers the groundwork this topic builds on.
What are the key points of Timers and counters?
Timer period=(prescaler×count)/f_clk. Capture for frequency measurement. SysTick.
Can you give an example of Timers and counters?
A 1 ms tick from a 16 MHz clock with prescale 16 and count 1000.
What comes after Timers and counters?
The next topic is "PWM", which builds directly on this one.
How difficult is Timers and counters?
It is classed as Intermediate in Electronics & Embedded (topic 62 of 104). It is an intermediate topic. Work through the beginner topics in Electronics & Embedded first.