Interrupt rate is not as advertised

In the Sparki library (version 1.0.5.4b), comments state that the interrupt that’s used to update the motors (and RGB LED, etc.) occurs every 100us, but I believe this number is incorrect. Assorted debug of why the robot was not behaving as I expected got me to suspect that the interrupt rate is actually one interrupt every 200us.

To test this hypothesis, I added code to the interrupt routine ISR(TIMER4_COMPA_vect) to assert a pin whenever the routine is executing, and then I hooked the pin to an oscilloscope. Indeed, I see a pulse every 200us. (See attached image.)

I have not debugged further, but something in this code…

[code] // Set up the scheduler routine to run every 100uS, based off Timer4 interrupt
cli(); // disable all interrupts
TCCR4A = 0;
TCCR4B = 0;
TCNT4 = 0;

OCR4A = 48; // compare match register 16MHz/32/10000Hz
TCCR4B |= (1 << WGM12); // CTC mode
TCCR4B = 0x06; // CLK/32 prescaler (32 = 2^(0110-1))
TIMSK4 |= (1 << OCIE4A); // enable Timer4 compare interrupt A
sei(); // enable all interrupts[/code]

from SparkiClass::begin() must be wrong. If nobody else sees the problem, I’ll have to crack open the books to see how exactly the timer configuration registers work.

On the other hand, one interrupt every 200us may actually be better than 100us. Based on the 'scope trace, the interrupt routine consumes about 34us, so with a 100us interval, 34% of available processing time is eaten by the interrupt routine. At 200us, it’s only 17%. Do any of Sparki’s functions absolutely need 100us?

In any case, it would be nice if the comments or the code were corrected, so that it actually does what it says it does.


Nobody wants to talk about interrupts? :open_mouth: :wink:

I’d be thrilled if I could get a statement from ArcBotics on whether the interrupt interval will stay at 200us in future libraries or whether it will be fixed to 100us as is written in the current comments.

Looks like 200uS it is. I’ll update the comment.

Okay. Thanks.