I’ve run across a rather interesting problem.
So I have a timer (SparkIntervalTimer) running at ~30kHz. I also have an external interrupt that happens at 120Hz. In my ISR for the 30kHz timer I write data to some shift registers.
The problem is as soon as I start writing to the shift registers, I see the 120Hz external interrupt start happening very sporadically between 140Hz and 1kHz! This 120Hz external interrupt is coming from a zero cross detector. I’ve put my scope on this line and can confirm that the signal is not changing to 1kHz. It’s rock solid.
So I’ve narrowed down the issue to 3 lines of code. 647, 668, and 672. Setting the latch pin high/low. And writing the SPI byte. If I comment out these 3 lines of code, the external interrupt stays at 120Hz. If I bring the SPI write back, or the latch pin high/low back, or both back, then my external interrupt starts acting crazy again. I really don’t know what to think about this. It would be easy enough to move the code from the ISR to the main loop and just set a flag in the ISR to run the code next time the main loop runs, but I would really like to know why this is happening? I’m not terribly familiar with interrupt do’s/don’ts so please enlighten me
So I just tried moving to code to the main loop and just set a flag in the ISR to say it should be executed. Same problem… Now I’m really confused. So I guess this means it doesn’t have anything to do with the interrupt, but instead purely with pin state changes…
Here is my code: