Programming: Timer/Counter Interrupt Specifics

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. }
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.