I want to use a Nano to perform a control function and communication. I have an input that is high during the positive half of the AC cycle and low during the negative half of the AC cycle (50 or 60 Hz.) It transitions very close to the zero crossing (less than 100 us). I want to optionally turn on an I/O bit very close after the zero crossing.
A change mode interrupt on pin 2 at zero level seems ideal and gets in and out of ISR fast with little or no perturbation of other interrupts.
In addition I want to do some processing that takes about 1 ms every half cycle. When in the half cycle it is performed is not critical but it is critical that it always be completed within the half cycle (about 8.3 ms).
Finally I am communicating with I2C and a console. These actions can be carried out over seconds and can be interrupted.
I could tack the processing onto the ISR but my concern is that with interrupts disabled for up to a ms that it might interfere with any other interrupt activity or communication that is going on. I could re-enable interrupts in the ISR after the first critical action but my concern is that if some other source happens to interrupt there could be two problems. The work would not get done in the half cycle and there might be recursion that would screw up the ISR. The recursion might be worse than failure to complete the ms of processing.
Do you have a suggestion how I might otherwise organize this? I have read Mr. Gammon's article and plan to start with a single ISR to do both tasks and a main loop to do the communication and I2C.
I have previously done all of these without combining them.