Timer1 Compare register, when does it really trigger? start or end?

Hi,

When starting a timer in compare mode. when does the interrupt exactly get triggered?

in example: Timer1, 8x prescale, compare register at say 5000. assuming 16Mhz this will activate an interrupt every 0.0025 seconds. or every 2500 micros.

Fine that's all great, but when?

Does it fire at 0 or at 5000? Does it fire as soon as the timer get's started or only when the compare register reaches 5000?

Thanks!

Helpful link: AVR timers - TIMER1

Does it fire at 0 or at 5000?
Does it fire as soon as the timer get’s started or only when the compare register reaches 5000?

As 0 is the “clear” value, it would be useless to fire the timer on 0 unless we want to configure a count-down timer. (Note: The PWM is an enhanced Output Compare Mode. In this mode, the timer can also count down, as opposed to the other modes which only use an up-counting timer.)

For count-up and compare:

In compare mode we load a register called Output Compare Register with a value of our choice and the timer will compare the current value of timer with that of Output Compare Register continuously and when they match the following things can be configured to happen.

A related Output Compare Pin can be made to go high,low or toggle automatically. This mode is ideal for generating square waves of different frequency.
It can be used to generate PWM signals used to implement a DAC digital to analog converter which can be used to control the speed of DC motors.
Simply generate an interrupt and call our handler.
On a compare match we can configure the timer to reset it self to 0. This is called CTC – Clear Timer on Compare match.

The compare feature is not present in the 8 bit TIMER0 of the ATmega8 so we will use the TIMER1 which is a 16 Bit timer. First we need to setup the timer’s prescaler as described in the Timer0 tutorial. Please see this tutorial for a basic introduction of TIMERs.

The TIMER1 has two compare units so it has two output compare register OC1A and OC1B. The ’1′ in the name signifies that they are for timer ’1′.

Thank you,

That is very clear.

When it compares equal to the comparison register. Bear in mind that the count is zero relative so if you want 10 counts the comparison register should be 9.