TimerOneThree library for ATmega1284P

atmega1284pThe arduino TimerOne library described at http://playground.arduino.cc/Code/Timer1 is the starting point for this lib. In the original library that can be found at http://code.google.com/p/arduino-timerone/downloads/list the pwm pins are (sort of) hard-coded to fit to the ATmega168P / 328P (the chip of the Uno R3 board). I simply changed them to the pin settings of the ATmega1284P using maniacbug’s pinout. Then I doubled the code and adapted it to timer3 of the ATmega1284P and it’s pins.

The code of the TimerOneThree library can be downloaded from my (very first 🙂  ) github repository at https://github.com/heliosoph/TimerOneThree.

Download and install

All files can be downloaded in acomplete zip archive. In the libraries folder of your arduino IDE create a new folder named TimerOneThree. Extract the archive and put all files into this new folder. Then restart your arduino IDE.

Usage of the library

To make use of the library type at the beginning of your sketch:

#include <TimerOneThree.h>

Then you can use it in the same way as the original TimerOne but also for timer3. A complete documentation of the TimerOne library can be found at http://playground.arduino.cc/Code/Timer1. When you want to use timer3 instead of timer1 simply type e. g.


This sets timer3 to a period of 2000 microseconds.

Pin assignment

The assignment of the pins on the ATmega1284 is taken from maniacbug’s mighty 1284p project: http://maniacbug.wordpress.com/2011/11/27/arduino-on-atmega1284p-4/. The pins are:

  • pin 6: Timer3A
  • pin 7: Timer3B
  • pin 13: Timer1A
  • pin 12: Timer1B

When you want to use timer3A for pwm with a duty cycle of 50% then type:

Timer3.pwm(6, 511); // duty cycle goes from 0 to 1023



Leave a Reply

Your email address will not be published. Required fields are marked *

88 − = 85