Ben Wirz wrote: > > Hello Everyone, > > I need to produce a variable PWM output based on a 8 bit hex number > that corresponds to the percentage duty cycle of the PWM. My basic idea was > use the interupt on overflow feature of timer0. > > So the waveform would look like this: > > -------------------- > | | | > | | | > ---------- --------------- > > $FF-PWM PWM > > The pseudo code would look something like this: > > Interupt_Service_Routine > > If the output was low last time > { > set the output high > set timer0 to $FF - PWM > //Set Timer to Over Flow PWM latter > } > else > { > set the output low > set timer0 to PWM > //Set Timer to Over Flow $FF-PWM latter > } > > End_Service_Routine > > Ok, well that seems simple enough to implement to me but what I > would really like to do is try this with one of the cheaper noninterupt > based PICs. The problem is that the PIC will also be doing serial comms so > it can't be totally tied up with making the PWM signal although there isn't > alot else going on. > > I would appreciate comment and suggestions on both the interupt and > noninterupt based methods. > > Thanks Guys, > > Ben > > Ben Wirz For Microchip PIC Products including the Simm Stick > development system and Easy PIC'n Book, as well > Wirz Electronics as Motor Control, Polaroid Sonar Units, and more > ben@wirz.com Hobbyist Robotic & Electronic Supplies, visit: > http://www.wirz.com/ OK Ben, I have done a lot of work in PWM for controling R/C servos In my requirement there is a 15-20 mSec refresh of a 1-2 mSec pulse. My code generates the Pulse output based on the clock speed and I use the fact that I have a 5 mSec window to do other things. I calculated the fastest ans slowest time through the rest of my code and ensured that it was less than 5 Msecs. this then alowed me to calculate a constant time to get the 20Msec Duty cycle. If you are interested in the code i can send it to you. BTW I control 2 O/Ps for two servos but the timings will allow up to 7 Servos IE 7*2 Msecs = 14 Msecs giving me a fixed time of 1 Msec and a variable time of 5 Msec to do my other stuff. -- Cheers Peter .......... ================================== New Ideas come from those who didn't know it wasn't possible ==================================