pwm_decode: use state logic, tests