Hi Patrick, thanks for the reply. I think you might have kick started my mind again. While I could reload the PWM counters, there really isn't any need. After I load them the first time, they are locked to the main counter. Because both counters are counting to 0xFF, there really isn't any need to reload the value. The PWM counter will roll over at the exact same time in relation to the main counter every time if I don't touch it. Essentially, the initial value offsets the PWM counter from the main counter, and because they count to the same value, the offset stays constant. Of course, this brings up the problem of when in the cycle to change the PWM counter values. I guess the time to do this is when the main counter rolls over. I think what I will do is test the desired values in the mainline, and if one has changed, set a flag. When the main counter rolls over, I will test that flag in the ISR. If it is set, I will reload all the values. I figure I might as well just reload them all rather than trying to test them and see if one has changed. Actually, looking again at the TSTFSZ operand, I might change my plan. I think I will have a byte wide register, and if one of the PWM values changes, I will set the corresponding bit in that register. Then testing it for zero is a single instruction, and if one of them is set, I can reload only that counter. I would love to see any code you have, I am most familiar with the 16f series anyways, so that shouldn't be a problem. Porting it to 18f should be trivial as well. Hope to hear from you soon! Josh -- A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. -Douglas Adams Patrick J wrote: > > Hi Josh, > You can put the counterupdates in the interrupt routine if u want > to control the PWM freq. independently from your mainloop. > > First of all I'd like to present a way to think about how it works: > Think of it as 2 cam-wheels (like in a washing machine) > One wheel sets the PWM output to 0 once each turn. > The other one sets the PWM output to 1 once each turn. > > Now if these two wheels were on the same axle, and u start > turning the axle around... the axle rpm decides the PWM-freq. > And the phase-difference between the wheels decides the > pulsefactor 0-100%. So it is perfectly okay that the counters > roll over, they are supposed to ! > > You do not need to reload the counters unless u want to change > the pulsefactor. And then all you do is add say 1 to the PWM- > counter and the phase will shift slightly. > > Above method is dead simple and works like a charm, the routine > below is more complicated and doesnt offer anything extra (i think) > *ducks* > > I prolly could dig up some code I wrote using above techinqe > for a recent project if ure interested... for the 877 tho. > I figured id put it on piclist.com but no time to mess w that now :-) -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.