----- Original Message ----- From: "Martin Buehler" To: Sent: Thursday, December 20, 2001 9:20 AM Subject: [PIC]: slow pwm > i need to generate a pwm signal with variable duty cycle, with a period of > about 1s. > as far as i understand, with the 16f872 it is possible to get a period of > up to 65ms, when running the pic at 4mhz. > what is the best way to get a slower period? Try this: Set up Timer0 with a period equal to or better than the resolution you need and count clock cycles, and a counter in software that consists of as many registers as you need to count one second worth of overflows. Then get the timer to generate an interrupt when it overflows. Write an interrupt service routine that reloads the timer and increments the software counter. The ISR also sets/resets the port pin after comparing the value of the counter with the trigger value, and resets the counter at the end of the PWM period. In the main loop outside of interrupt space you can set the trigger point for the pulse by adjusting the trigger value of the software counter. /\/\/\/*=Martin -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.