Chapter 3free
Clocks and timers
Where the chip's speed comes from, and a timer that counts time for you.
3.1
Clocks: where the speed comes from
TheoryfreeA clock is the heartbeat of the chip: a steady train of pulses that every instruction and every peripheral follows.
3.2How a timer counts
TheoryfreeA timer is a peripheral that counts clock pulses on its own, while the CPU does other work.
3.3Start a timer and read its counter
Hands-onfreeWe set TIM1 to count 1000 times per second (16 MHz clock, prescaler 15999), start it, and read its counter twice, one second apart.