trying to fix the bitlash re-entrant issue
Refactor PWM event handler. Also fix type error for setmode