Working version with external pwm device