AS0 is 1, that is what make it an ansyncrone timer. The timer runs
from the 32768 Hz crystal as it should.
do you write to the OCR0 or TCNT0 just before entering sleep mode?
Yes I do.
As you can see belove, I update the OCR0 to a new value every time.
The code belove will show the problem. Every 6th time the mainloop will
wait until the interrupt flag have been set before entering sleep. When
this result in that the output compare match is not serviced until the
next time there is an ocr match. Since the OCR0 haven't been updated, it
will count another 256, insteed of 32.
If the sleepmode is idle, every thing works as expected. The interrupt
is serviced right after the sleep instruction.
The following code is for IAR compiler, but it should be clear enough.
(We are helping a customer that use that compiler, sorry)