> -----Original Message----- > From: michael brown [SMTP:spam-me@HOUSTON.RR.COM] > Sent: Wednesday, February 05, 2003 4:18 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: Questions about PWM using TMR2? and CCP > > Hello all, > > I'm posting using OE today as I can't run MPLAB in Linux yet, please > don't send me any quoted-printable stuff. ;-) > > I'm trying to figure out the hardware PWM feature of the 16F628. My > John Peatman book leaves a little to be desired here. :-/ Fortunately > the datasheet actually seems more clear about things in this instance. > I would like to use this feature to control an ordinary R/C servo motor > (1 - 2ms width) approx 50 times/sec (20ms period?). It appears that my > using a 4Mhz crystal may preclude the ability to do this. It looks like > the longest period I can come up with is 244hz (about 4ms?) allowing for > a full but unnecessary (for me) 10 bits worth of PW precision. ;-) > > Questions: > 1) Am I getting this stuff right? > Looks good so far! > 2) Would it be a bad thing to try and drive the servo using a 4ms period > since that is still longer than my longest pulse width requirement? > Possibly. Servos are generaly very tolerant of the PWM period. However, this is quite a long way from 20ms and not all servos are the same, so it would be worth trying this for the particular servo you wish to use. > 3) Since (AIUI) the PWM function uses TMR2 (though all other > capture/compare modes use TMR1), is there no way to use the postscaler > to increase the period? > Unfortunately the post-scaler only affects the rate at which the TMR2IF flag is set. The only way to go slower after you have set 1:16 pre-scale and PR2=255 is to use a slower clock. > 4) If not, is there any way to use TMR1 instead > Not through the hardware, it could be used as a timebase for a software solution though. > I would like to do this with the hardware automatically toggling the > line at the correct rate, without having to handle anything in > interrupts. > I know what you mean, I prefer to have proper hardware peripherals I can set and forget rather than software buring up my CPU cycles. However, in the case of a servo control, the PWM period is so slow that an interrupt driven solution would have negligible overhead. There are also lots of code samples on the net. Regards Mike -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu