Timer1 is an AVR and Arduino compatible software library for the ATmega168 microcontroller. It provides a user friendly interface for taking advantage of two commonly used features of an on-chip hardware timer:
- pulse width modulated analog voltage
- timer overflow interrupt handling.
Initially this library was built to address the fact that Arduino’s analogWrite() function does not provide a mechanism to change the period or frequency of any of the timers which drive hardware based pulse width modulation, but it has since grown to accommodate the interrupt handling features as they are related and just downright useful.
Some of the things we have used the library for on projects in house include:
- CPU independent servo control
- Frequency generation in the audible range (digital synthesis)
- Integrated hardware / software PWM control for independently variable analog voltages on 12 pins simultaneously (4x RGB leds)
You can download the library and learn much more about the project by visiting our page on the Arduino Playground at: http://www.arduino.cc/playground/Code/Timer1




Peter
07/01/2009 at 12:59 pm // PermalinkHow do you use this library to send PWM signals to 12 pins? The documentation seems to state that the TimerOne signals are only limited to pins 9 and 10. It would be great to be able to send the PWM signals to more pins!
Thanks!
Jesse
07/01/2009 at 2:28 pm // PermalinkThe ATmega168 has 3 timers, each providing 2 hardware based waveform generators. This means that there are 6 total hardware PWM pins available. In order to generate PWM output on 12 pins, I used the attachInterrupt method to trigger a custom function (check out http://www.arduino.cc/playground/Main/PWMallPins) that manages all of the PWM control in software. Using the software method means there is an inherent trade off between resolution, frequency, and free CPU time for your application.
Royce
19/02/2009 at 8:33 pm // PermalinkThanks a bunch for the lib! I’m going to teach PWM signal generation to some budding roboticists this weekend. I’m pleased I’ll be able to do it in Arduino without cheating and writing to the registers directly. I like your interface even better than BASCOMs. That terse little bit in TimerOne::setPeriod is slick.
Doug Bradbury
17/07/2011 at 8:18 pm // PermalinkThanks for the library! You just saved me a bunch of time digging through the datasheet!