I want to drive a piezo and there are two ways. Maximum volume comes alternating both signals at the same time like this:
DDRD|=_BV(6) | _BV(7);
TCCR2A=_BV(COM2A0) | _BV(COM2B0) | _BV(WGM21);
TCCR2B=_BV(FOC2A) | _BV(CS22) | _BV(CS21);
OCR2A=127;
OCR2B=127;
If I want half volume I can set the OCR2B higher than OCR2A.
Does anyone see an issue with this method? Could the two get out of sync with each other (as if the FOC2A) somehow? Would it be better to do something that forces these directly? Like set the COM2A1:0 bits to clear, set the COM2B1:0 bits to set, then write FOC2A and FOC2B to clear one and set the other, then change both the COM2A/COM2B bits to toggle again?