If I enable interrupts in the middle of an interrupt, what will happen?
I have a DAC interrupt to update my sound, and I also have a servo interrupt. The servos will most likely jitter if the DAC interrupt triggers just before they update... I had this issue with another project a long time ago. At that time I was just using a piezo speaker for my sound, so I just checked to see if the servo interrupt was about to trigger and skipped that sample, but with my new board the sound is output through an amp and so skipping samples would be heard more easily.
There's a few different strategies I'm considering here.
The first is to just let the servos twitch occasionally. That's not particularly appealing though.
The second is to either skip a sample when the servo is about to trigger, or delay the sample and play it on the next DAC update. The first method keeps the sound at the same speed but may cause pops if there is too large a discontinuity between samples. The second may slow down the sound sightly and cause warbling, though since the servos don't update too fast this would probably not be noticeable as it was when I was skipping samples to update my LEDs at 60fps. (I've since patched that issue by adding another data bus.)
And the third is to delay the sample, but only long enough for the servo interrupt to finish. This would reduce any glitches in the audio to an absolute minimum and I'm fairly certain it would be unnoticeable, since the servo interrupt is time sensitive, but very short. This is why I want to know if I can enable interrupts within an interrupt.
If I can't do that, or it would be a bad idea to (I guess the millisecond timer could get called while I'm in the middle of the servo interrupt if I enabled all interrupts) then is there some simple way I could cause the DAC interrupt to trigger right after the servo interrupt if it needs to be called? Or call the servo interrupt at the right time from within the DAC interrupt? I assume I could mess with the DAC interrupt counter but I'd like to keep things as simple as possible.
I did notice the DAC interrupt seems to call another interrupt to fill the SD card. Or perhaps it is just turning it on to be called once. I'm not sure. But I also seem to recall seeing interrupts enabled and disabled in an interrupt somewhere. Which is why I'm asking about that.