Lost Timer1 overflow interrupts

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
bla
Posts: 9
Joined: Tue Jul 26, 2011 10:25 pm

Lost Timer1 overflow interrupts

Post by bla » Tue Aug 30, 2011 8:44 pm

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?

bla
Posts: 9
Joined: Tue Jul 26, 2011 10:25 pm

Re: Lost Timer1 overflow interrupts

Post by bla » Wed Aug 31, 2011 1:59 pm

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...

Daid
Rank 2
Rank 2
Posts: 55
Joined: Mon Apr 18, 2011 12:19 pm

Re: Lost Timer1 overflow interrupts

Post by Daid » Wed Aug 31, 2011 4:36 pm

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...

Post Reply