More About Timers

Timers can be configured to run at various frequencies and operate in different modes.  In addition to generating interrupts, they are also used to control the PWM pins.  The links below are excellent resources for understanding how to configure and use timers:

Timer Libraries

There are a number of Arduino 'timer' libraries available on the web. Many simply monitor millis() and require constant polling as we did in part 1 of this series.  But there are a few that actually let you configure timers to generate interrupts.

Paul Stoffregan's excellent TimerOne and TimerThree libraries take care of many of the low-level details of timer interrupt configuration.  (Note that TimerThree is not applicable to the UNO.  It can be used with the Leonardo, Mega and some of the Teensy boards)

Pin Change Interrupts

For when 2 is not enough

The Arduino UNO has only 2 external interrupt pins.  But what if you need more than 2 interrupts?  Fortunately, the Arduino UNO supports “pin change” interrupts on all pins.

Pin change interrupts are similar to external interrupts.  The difference is that one interrupt is generated for a change in state on any of the 8 associated pins.  These are a little more complex to handle, since you have to track the last known state of all 8 pins to figure out which of the 8 pins caused the interrupt.

The PinChangeInt library at the Arduino Playground implements a handy interface for pin change interrupts: http://playground.arduino.cc/Main/PinChangeInt

This guide was first published on Dec 01, 2014. It was last updated on Mar 27, 2024.

This page (Libraries and Links) was last updated on Mar 08, 2024.

Text editor powered by tinymce.