1 minute read

In these last 3 videos , Lars introduced timers.

I faintly remember learning about timers in my undergrad degree, but I don’t remember understanding why they were needed. Now I can understand it a bit more.

In a nutshell, what I’ve picked up is that you need to do is to enable your timer, bind it to a clock source, decide if you want to count up or down, and configure the period.

The period is based on your clock frequency, with certain prescalers applied. Once the counter/timer expires, you can bind an interrupt to be called, or you can flip an output to generate a pulsed waveform.

Without searching too much into it, there are many functions I can think of that need to be run at regular intervals. In the world of web/application development, we typically have things that need to be refreshed periodically, things that need to be polled, notifications to send etc.

In the embedded world, we may want to blink leds, send data in via ports, send data out etc. I can see that timers would be a much more efficient way to do this (as opposed to trying to do it in the main loop).

We first went through a simple configuration, to trigger an interrupt at the end of the timer countdown. Then we moved onto using multiple PWM channels using a single timer.

Really exciting stuff! At least I can make a cool set of christmas lights now :)

4 channel PWM leds

Updated: