porting PWM.cpp to PWM.c