To use the interrupt for the Timer/Counter, an ISR (Interrupt Service Routine) must be written.
Specifically relating to enabling the interrupt for the Timer/Counter, the WGM12 (Waveform Generation Mode) in the TCCR1B must be set so the TCNT1 CTCs (Clears on Timer Compare). The Timer Mask TIMSK must set the OCIE1A (Output Compare Interrupt Enable). This bit is related to the OCR1A. Alternatively, the OCIE1B and OCR1B could be used.
The OCR1A must be equal to the count that will invoke the interrupt.
The function that resides outside of the main function is the interrupt service routine.
ISR(TIMER1_COMP_vect)
{
Do something when the timer interrupt hits.
}
Comments and Additional Information
Have some code to share? Or additional information? Respond here:
You need to be logged in to save a response on this page. The response must be constructive, helpful, supplimentary or to correct the existing video, code or narrative content.