>-----Original Message----- >From: Robert B. [mailto:piclist@NERDULATOR.NET] >Sent: 22 April 2004 17:18 >To: PICLIST@MITVMA.MIT.EDU >Subject: [PIC:] Slow PWM signal in hardware > > >I need a PWM signal with the following specifications (from the >manufacturer): period 17ms, minimum duty 1ms, maximum duty 2ms. > >I'm using a PIC16F873A on this project, and would really >really really like to generate the PWM in hardware. Reading >the chip's datasheet implies that the slowest PWM signal on >the CCP1/2 is 1.2kHz (about 20x too fast). Are there any >clever tricks that can slow it down to about a 17ms period? >All the timers and interrupts are free for use, but like I >said if there's a way to get the PWM module to do it that >would be ideal. If all else fails I can cobble together an >interrupt to do it, but the code is fairly time critical so it >would need to be really quick. > >Thanks! Sounds like a model servo control pulse... Sorry to be the bearer of bad news but the only way to slow the hardware PWM is to run a lower clock frequency. I've had this exact same problem before and wished for a bigger pre-scaler on the PWM. The good news is that if you can spare two CCP's I *think* you should be able to run a software PWM under interrupts with minimal CPU overhead. 1) Configure both CCP's for compare mode. 2) Configure CCP1 to compare at a timer count relating to 17ms and use the special event trigger to reset Timer1 and also set the CCP1 pin high. 3)Configure CCP2 to compare at a timer count relating to 1-2ms. Unfortunately you can't make it clear the CCP1 pin automaticaly, so you will need to use an interrupt. However, this will be very quick and only occurs once per 17ms. In operation, when CCP1 is triggered by a match after 17ms, the CCP1 pin will be set high and the timer will be reset. After a period of 1-2ms CCP2 will be triggered by a match and you clear the CCP1 pin in your interrupt. This gives you 16 bit resolution from 0-100% duty cycle, or about 11.5 bit resolution for your 1ms range. Regards Mike ======================================================================= This e-mail is intended for the person it is addressed to only. The information contained in it may be confidential and/or protected by law. If you are not the intended recipient of this message, you must not make any use of this information, or copy or show it to any person. Please contact us immediately to tell us that you have received this e-mail, and return the original to us. Any use, forwarding, printing or copying of this message is strictly prohibited. No part of this message can be considered a request for goods or services. ======================================================================= Any questions about Bookham's E-Mail service should be directed to postmaster@bookham.com. -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics