EmbeddedRelated.com
Forums

lower PWM freq. for driving a Servo

Started by Stefan February 18, 2004
Hello!

I've got a problem using the PWM module of my PIC18Fxx2 to drive a R/C
Servo.
My PIC runs at 20MHz which I cannot change. The lowest frequency, that
I can get is then 1.22kHz (using x16 prescaler and PR2=0xFF) which is
too fast for the Servo.
Is there some way of using the postscaler to get down the frequency?
Trying to change the postscaler apparently made no difference.
Though I read in the datasheet of the PIC that "The postscaler could
be used to have a servo update rate at a different frequency than the
PWM output."

Hope you can help me in this matter!
Thanks,
Stefan
On 18 Feb 2004 05:24:57 -0800, news@stefan-strobl.de (Stefan) wrote:

>Hello! > >I've got a problem using the PWM module of my PIC18Fxx2 to drive a R/C >Servo. >My PIC runs at 20MHz which I cannot change. The lowest frequency, that >I can get is then 1.22kHz (using x16 prescaler and PR2=0xFF) which is >too fast for the Servo. >Is there some way of using the postscaler to get down the frequency?
One solution is to avoid using the PWM mode of the timers in the PIC. Instead, use the Output Compare mode. It involves a little more work on your part because you will have to respond to each OC interrupt and adjust the Compare Register for the next OC event. But for low frequencies, you have plenty of CPU time to do it, especially if you are running at 20MHz. I once wrote a PWM routine for a 12C671 running at 4MHz. It was capable of 0 to 100% duty cycle at 2000 Hz or lower. -Robert Scott Ypsilanti, Michigan (Reply through this forum, not by direct e-mail to me, as automatic reply address is fake.)