Page 1 of 1

Lost Timer1 overflow interrupts

Posted: Tue Aug 30, 2011 8:44 pm
by bla
In a project, Timer1 runs with 50 kHz (I cannot go lower for hardware reasons). The timer is used for PWM purposes and (via the overflow interrupts) also for a real time clock. I cannot use another timer for this clock.
The real time clock works perfectly when USB is disconnected. If USB data is being transmitted, however, it runs slightly slower (by 0.5% or so). It seems that intermittent overflow interrupts get lost. My ATMega168 runs at 20 MHz, so at a timer frequency of 50 kHz an overflow occurs every 400 cycles. For the interrupt to be occasionally missed it would take to disable them for more than 400 cycles... is that a likely cause?

Re: Lost Timer1 overflow interrupts

Posted: Wed Aug 31, 2011 1:59 pm
by bla
What is the longest amount of cycles V-USB disables the interrupts (for example because of running another interrupt on its own)?
Are the functions usbFunctionSetup, usbFunctionRead and/or usbFunctionWrite called from interrupts? I'm doing a lot of stuff in those functions...

Re: Lost Timer1 overflow interrupts

Posted: Wed Aug 31, 2011 4:36 pm
by Daid
USB has data 8 bytes per packet. The usbdrvasm20.inc say "106.666667 cycles per byte" so it's at least 800 cycles busy with the interrupt, and this doesn't even include the start/end/stuffing.
This also matches the 1.5Mbit/s low speed USB spec. Which means 8 bytes will take 0.043ms while 50khz is an interrupt every 0.02ms.

What you are trying to do is just not possible...