Your idea seemed really novel, but I didn't think I could make it work in a timely fashion. Instead I just used a pretty simple interrupt routine on timer1. Since it's a fixed period of 60Hz, I just subtract off the duty time (stored as a number of timer cycles) to make two variables, "high_time" and "low_time" (both also some relevant quantity of timer cycles), then have the interrupt change a single pin between a high/low state and reset the timer for the corresponding up/down time. This way I can set the duty cycle from anywhere in the code by writing to a single variable. The interrupt always resets the timer, so the PWM should theoretically always be running. I realize it's not perfect, and that with repeated successive writes to the duty variable my period could be modified to about 58 or 62Hz, but I'm not concerned about it since the max error is fairly small. Also the system runs closed loop so it will automaticall correct for any errors the slightly incorrect timebase might incur. A few people mentioned I might be driving an RC servo, and indeed it's not too far off. The pwm signal is interfacing a serious high-current motor controller which is driving a 50A DC gearhead motor. The motor controller has about 8 FET-looking devices in it, all attached to a heatsink with a fan blowing across them. I'm guessing there's probably just an H-bridge in there with a uChip interface for the PWM. This is my first attempt at using interrupts for anything really useful, and I must say it was easier than I anticipated. Thanks again to everybody who responded! ----- Original Message ----- From: "Michael Rigby-Jones" To: Sent: Friday, April 23, 2004 1:44 AM Subject: Re: [PIC:] Slow PWM signal in hardware > >-----Original Message----- > >From: Robert B. [mailto:piclist@NERDULATOR.NET] > >Sent: 23 April 2004 03:23 > >To: PICLIST@MITVMA.MIT.EDU > >Subject: Re: [PIC:] Slow PWM signal in hardware > > > > > >Thanks for the suggestions. I wound up just doing it in > >software with (as > >usual) a crude hack that works pretty well. It was way less > >painful than I thought it would be, actually! Is there a > >reason Microchip doesn't make this a little easier? It seems > >it would be a fairly common task at least. > > > > > > Microchip optimised the CCP to give as high frequency as possible whilst > still maintainging good resolution, which is generaly more usefull for the > majority of applications that would use the PWM as an analog output. > However, adding an extra few stategs on the pre-scaler would certainly have > increased it's usefulness for this type of application. > > BTW, I tried my suggestion using the simulator and couldn't get it to work. > Microchips documentation isn't overly clear, but it looks like if you > configure both CCP's for compare mode, they will both use the special > trigger mode which clears Timer1. That or my test program was complete > rubbish and I'm not ruling that out! > > 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 PICList is archived three different > ways. See http://www.piclist.com/#archives for details. -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.