Arduino Timer Interrupts
Interrupts are used to handle events that do not happen during the sequential execution of a program. There are two types of interrupts for the Arduino microcontroller. Hardware / external interrupt and Timer interrupt. We will focus on Timer interrupts of Arduino. Depending on the timer mode which is selected the timer will start by increasing its value until it reaches its maximum count then go back to 0. This creates a triangle shaped curve which the timer follows. This will cause the interrupt to occur as the value increases from 0-255 in the case of Timer2 and then goes back to 0 and repeats again.
Timer interrupts in Arduino pause the sequential execution of a program loop() function for a predefined number of seconds (timed intervals) to execute a different set of commands. After the set commands are executed, the program resumes again from the same position. The Arduino comes with three timers known as Timer0 (8-bit timer), Timer1 (16-bit timer), and Timer2 (8-bit timer). They act as a clock and are used to keep track of time based events. These timers will be programmed using registers which we will learn about.
There are following Timer pinout in Board
Our user guide will focus on learning how to generate Timer1 and Timer2 interrupts of Arduino.
- Timer1 can generate Compare Match, Overflow and Input Capture interruptions. In compare match, the interrupt is triggered when the timer value in the register is equal to the compare value. If we set the compare value equal to 50 then whenever the Timer1 will reach this value an interrupt will be called
- The next type of interrupt is overflow. This is triggered whenever the timer value reaches its maximum value.
- The last type of interrupt is input capture. Whenever an external trigger occurs, the value gets saved in a different register.
Comments
Post a Comment