added PWM function, still some bugs