Hi Mike, >> On 4/26/07, Phillip wrote: >>> So I've got a project where I need to replace a small sensor that >>> outputs a 50Hz frequency with a PWM duty cycle of 30-70%. [RobH] >> I don't know how hard your choice for the 12F629 is, but I >> would use a 12F683 with built-in hardware PWM. Very easy to >> program. On the PIC-page of my site you can find some examples >> (dimmers) written in C. http://www;robh.nl/picsoft.php. [Michael.Rigby-Jones] > The CCP module will not generate PWM as low as 50Hz unless you are running a very low speed clock. According to my calculation the maximum Fosc would be 819.2 KHz (which I don't consider 'very' low). But with hardware PWM the PIC mainline has nothing to do, so who cares? > If the OP's requirements are literaly as simple as producing a 50Hz, 50% duty square wave, it could be done with pure software delays, e.g. in C: > > while(1) { > GP0 = 1; > DelayMs(10); > GP0 = 0; > DelayMs(10); > } But when the duty cycle must be variable (controlled by a potmeter, light sensor, etc.) this simple loop won't do. A big advantage with hardware PWM of the CCP module is that the PIC mainline can be dedicated to controlling the duty cycle with whatever number of instructions are needed without having to bother about the PWM frequency. > If the duty cycle needs to be controlled, using a timer interrupt as Jinx suggested may simply things. Of course, but still more complicated than using the CCP module. Regards, Rob. -- Rob Hamerling, Vianen, NL (http://www.robh.nl/) -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist