MEGA 2560 - Odd Timer Behavior first loop and intermittent thereafter

If you still want to have a square wave you could set the OCRnx values always to the half of the ICRn when changing the TOP value ( ICRn ).
And you need not mangle with 8-bit registers. You can use the 16bit register adress as e.g OCR3B ( without H/L ) . The compiler handles this correctly.

That many pointer values you use makes it complicated and ineffective. You will have one interrupt per timer. Therefore the ISR knows about the timer registers, no need to handle this with pointers.

1 Like