I've recently found I'm seeing some issues with interrupts colliding, and I thought I'd check here with the experts to see if there are any tricks to minimize the problem.
This is currently on an ATmega8535.
I'm using two external interrupts to measure wheel RPM - a sensor on the wheels triggers the interrupts once per revolution and the interrupt routine calculates the RPM based on the elapsed count on the 16bit counter/timer 1
I'm also using an internal interrupt with a compare register on the 16 bit timer for a servo controller of the 1 to 2 msec pulse type. Here the interrupt routine toggles the output pin and updates the compare register based on how long it needs to wait for the next change.
The servo controller works great when the external interrupts aren't being triggered (e.g., wheels stopped). However, when I do run the wheels and trigger those external interrupts, the servo twitches, I assume because the external interrupts are throwing off the timing of the running of the internal interrupt that sets the servo control pulse timing
Here are my ideas:
+ increase the clock speed from 1MHz to 8MHz (adjust prescalers) so interrupts run faster
+ Change the RPM interrupt routines so that they save the counter value but then re-enable interrupts before doing any calculations
+ Switch to another ATmega that has a spare timer/counter I can use for the servo signal - this is a viable option, but it would be nice to stick with the current chip and the higher resolution I currently get on the servo control with my interrupt routine
I've also wondered if I can set some mode on the 16bit timer with a compare register so that the output pin is toggled by hardware when the compare matches, but then still have an interrupt routine that runs to calculate the next compare value.
Sorry for the long post, but this kind of brain teaser is what I like about programming, and I'm hoping someone with more knowledge will enjoy it too.