I am working on a project that requires synchronization between two outputs.
So my program is like
digitalWrite(2,HIGH);
analogWrite(3,20);
something like that.
However, the two outputs have a different frequency so they cannot synchronize. The difference is about twenty-something Hz. Is there anything I can do to synchronize the two outputs or to minimize the difference? Thank you.
If you want two outputs to change state at the exact same state, make sure they're on the same PORT and use a register call setting or clearing both bit in the same instruction.
Of course it's hard to do this when one of the signals is PWM.
As you apparently have a steady delay between the two, make me wonder: does analogWrite() reset the counter related to that output (TCNT2 in case of pin 3)? If not, the delay should vary.