OPtimize PWM state machine.