changed clock processing for better clock accuracy with pwm enabled