

Therefore there is a trick to slow down the clock rates.

This is likely too fast for most timer applications! At 256 an overflow occurs and the timers start again from 0. For example, the 8 bit timers count from 0 to 255 each time. This means Timer0, Timer1 and Timer2 increase 16 million times per second. The system clock of the Arduino Uno is 16 MHz (CPU frequency).
#USING ARDUINO AS TIMER CODE#
We can write code in the Arduino program what should happen in case of an interrupt. This is the magic! We can configure the controller so that an interrupt is triggered when the timer overflow occurs. The next incrementing step is not 256, instead an overflow occurs, which makes the timer become 0 again. the highest count that an 8-bit-timer can reach is 2^8 – 1 = 255. The count register of a timer can not be incremented arbitrarily long. One of these ‘certain counts’ is for example the overflow. This becomes useful, if an action is executed at certain counter values. Instead of coding instructions in the program that are executed regularly and increment a register by 1, the microcontroller does this all by itself!
#USING ARDUINO AS TIMER HOW TO#
This might also be interesting for you: How to control an Arduino via Bluetooth List of componentsĪ timer is basically nothing else than a certain register in the microcontroller, which is increased (or decreased) continuously by 1 under hardware control. You can find the Arduino code at the end of the post. We explain what timer interrupts are and how to use them.

The delay() and millis() functions are probably sufficient for most applications, but if you don’t want to pause the whole program or achieve a 100% exact clock time it makes sense to use Arduino Timer Interrupts. If the requirements are higher you can also use millis() or nanos() as timer. This will pause the program of the Arduino for the appropriate amount of time. If you want to achieve a regular time interval with the Arduino you can simply use the delay() function.
