1. A PWM controller for providing to a power switch a PWM signal determining an ON time and an OFF time of the power switch, the PWM controller comprising:a peak detector for detecting a voltage peak of a line voltage generated by rectifying an alternating-current input voltage;
an OFF-time control unit for controlling the PWM signal and determining the OFF time in response to a compensation voltage, wherein the compensation voltage is in response to an output voltage of a power supply comprising the power switch and the PWM controller; and
an ON-time control unit for controlling the PWM signal and determining the ON time in response to the compensation voltage and the voltage peak, wherein the ON-time control unit is configured to make the ON time not less than a minimum ON time, and the minimum ON time is determined in response to the voltage peak;
wherein the ON-time control unit comprises a ramp signal generator for providing a ramp signal compared with the compensation voltage to determine the ON time; and
the ramp signal generator provides a charging current in response to the voltage peak to charge a capacitor and generate the ramp signal.