Can anyone let me know if they have some suggestions for the HCS12 prescale, scale, clock, and period, and duty settings for running a standard servo (666Hz+/-130Hz or 1.25-1.75ms). My oscilator is 16MHz, so the bus clock is at 8MHz. It seems that the resolution at these frequencies is pretty poor (or have I done the math wrong?). Can anyone suggest, from their experience, what the most versatile values are? |
|
resolution for PWM driven servo on HCS12
Started by ●September 30, 2004
Reply by ●October 1, 20042004-10-01
> Can anyone let me know if they have some suggestions for the HCS12 > prescale, scale, clock, and period, and duty settings for running a > standard servo (666Hz+/-130Hz or 1.25-1.75ms). > > My oscilator is 16MHz, so the bus clock is at 8MHz. It seems that the > resolution at these frequencies is pretty poor (or have I done the > math wrong?). Poor resolution? log2(8M/666) gives ~13.5 bits of resolution. Maximal PWMPER =8M/666~12012. Edward > > Can anyone suggest, from their experience, what the most versatile > values are? |
|
Reply by ●October 4, 20042004-10-04
Thanks for the effort Edward, but your reply didn't really help me understand my problem. Perhaps I didn't express myself clearly, so it looks like I will have to lay my ignorance bare, and hope that you (or someone) can tell me where the error in my logic is. Servo's have a PWM period of 20ms (this is the time at which the pulse must be repeated). Irrespective of my clock selection values, the PWM Channel Period Registers (PWMPERx) is one byte(0-255). If I set my clock rate, so that the PWMPERx multiplied by the (scaled) clock rate = 20ms, I have the maximum possible resolution for my duty, which is 20ms/255, or 78 microseconds. The entire range of the servo control pulse is 1.25 to 1.75ms, or a delta of 500 microseconds. Therefore I have 500/78 = 6 possible values that I can set my servo to. Where are my 13 bits of resolution? thanks Steve --- In , "Edward Karpicz" <karpicz@a...> wrote: > > Can anyone let me know if they have some suggestions for the HCS12 > > prescale, scale, clock, and period, and duty settings for running a > > standard servo (666Hz+/-130Hz or 1.25-1.75ms). > > > > My oscilator is 16MHz, so the bus clock is at 8MHz. It seems that the > > resolution at these frequencies is pretty poor (or have I done the > > math wrong?). > > Poor resolution? log2(8M/666) gives ~13.5 bits of resolution. Maximal > PWMPER =8M/666~12012. > > Edward > > > > Can anyone suggest, from their experience, what the most versatile > > values are? |
|
Reply by ●October 4, 20042004-10-04
You can use PWM concatenate mode to get 16 bits of resolution. This will
cut your number of channels in half, but is the easiest way to control an RC servo. The PWM8B8C document describes how to do this. -- Justin > -----Original Message----- > From: Steve Auch-Schwelk [mailto:] > Sent: Monday, October 04, 2004 2:56 PM > To: > Subject: [68HC12] Re: resolution for PWM driven servo on HCS12 > > Thanks for the effort Edward, but your reply didn't really help me > understand my problem. Perhaps I didn't express myself clearly, so it > looks like I will have to lay my ignorance bare, and hope that you > (or someone) can tell me where the error in my logic is. > > Servo's have a PWM period of 20ms (this is the time at which the > pulse must be repeated). Irrespective of my clock selection values, > the PWM Channel Period Registers (PWMPERx) is one byte(0-255). > > If I set my clock rate, so that the PWMPERx multiplied by the (scaled) > clock rate = 20ms, I have the maximum possible resolution for my > duty, which is 20ms/255, or 78 microseconds. > > The entire range of the servo control pulse is 1.25 to 1.75ms, or a > delta of 500 microseconds. > > Therefore I have 500/78 = 6 possible values that I can set my servo > to. > > Where are my 13 bits of resolution? > > thanks > > Steve > --- In , "Edward Karpicz" <karpicz@a...> wrote: > > > Can anyone let me know if they have some suggestions for the > HCS12 > > > prescale, scale, clock, and period, and duty settings for running > a > > > standard servo (666Hz+/-130Hz or 1.25-1.75ms). > > > > > > My oscilator is 16MHz, so the bus clock is at 8MHz. It seems that > the > > > resolution at these frequencies is pretty poor (or have I done > the > > > math wrong?). > > > > Poor resolution? log2(8M/666) gives ~13.5 bits of resolution. > Maximal > > PWMPER =8M/666~12012. > > > > Edward > > > > > > > > > > Can anyone suggest, from their experience, what the most > versatile > > > values are? > > > Yahoo! Groups Links > |
Reply by ●October 4, 20042004-10-04
Steve, Instead of using the PWM, why don't you use the timer module. In the original HC12A4, there was no PWM. You could however setup TC7 as the timer period (16bits). The timer counter can be cleared whenever a compare occurs on TC7 and the outputs pin outputs could also be cleared simultaneously. Then use any of the other timer compares to provide the pulse width for the servo. All a bus speed of 8Mhz, the resolution is 125nS, or over the 1250-1750uS range a total of 4000 values. The only thing I can see to watch is that the maximum period using the TC7 method. Obviously the maximum period is 0.125 * 65536 = 8.192mS, not the 20mS that you quoted. You did however quote 666Hz in the earlier post, which is well within this range. I would agree that your PWM is unlikely to work like you want, but think that a timer compare method might work much better. Jonathan Masters. -----Original Message----- From: Steve Auch-Schwelk [mailto:] Sent: Tuesday, 5 October 2004 6:56 AM To: Subject: [68HC12] Re: resolution for PWM driven servo on HCS12 Thanks for the effort Edward, but your reply didn't really help me understand my problem. Perhaps I didn't express myself clearly, so it looks like I will have to lay my ignorance bare, and hope that you (or someone) can tell me where the error in my logic is. Servo's have a PWM period of 20ms (this is the time at which the pulse must be repeated). Irrespective of my clock selection values, the PWM Channel Period Registers (PWMPERx) is one byte(0-255). If I set my clock rate, so that the PWMPERx multiplied by the (scaled) clock rate = 20ms, I have the maximum possible resolution for my duty, which is 20ms/255, or 78 microseconds. The entire range of the servo control pulse is 1.25 to 1.75ms, or a delta of 500 microseconds. Therefore I have 500/78 = 6 possible values that I can set my servo to. Where are my 13 bits of resolution? thanks Steve --- In , "Edward Karpicz" <karpicz@a...> wrote: > > Can anyone let me know if they have some suggestions for the HCS12 > > prescale, scale, clock, and period, and duty settings for running a > > standard servo (666Hz+/-130Hz or 1.25-1.75ms). > > > > My oscilator is 16MHz, so the bus clock is at 8MHz. It seems that the > > resolution at these frequencies is pretty poor (or have I done the > > math wrong?). > > Poor resolution? log2(8M/666) gives ~13.5 bits of resolution. Maximal > PWMPER =8M/666~12012. > > Edward > > > > Can anyone suggest, from their experience, what the most versatile > > values are? <http://us.ard.yahoo.com/SIG9cpc4lb/M)8184.5285298.6392945.3001176/ D=groups/S06554205:HM/EXP97010156/A#19498/R=0/SIGthfntfp/*htt p:/www.netflix.com/Default?mqso`185352&partidR85298> click here <http://us.adserver.yahoo.com/l?M)8184.5285298.6392945.3001176/D=group s/S=:HM/A#19498/rand%7676248> _____ > Service. |
Reply by ●October 4, 20042004-10-04
In a message dated 10/4/04 6:01:28 P.M. Eastern Daylight Time, writes: All a bus speed of 8Mhz, the resolution is 125nS, or over the 1250-1750uS range a total of 4000 values. ========================= The little servo has a 1 turn pot for position feedback. Lets say the pot has a throw of about 270 degrees,,,, so 9 bit resolution thru that range would give 512 postions in 270 deg, or about 0.5 degrees of resolution... I think one would be hard pressed to find an analog servo amp that could respond to a 10 or 12 bit signal that changed way down in the last couple of bits... signal to noise ratio.... |
Reply by ●October 5, 20042004-10-05
Hi, I use the Output compare feature to drive RC servo. Prescale the timer by 4 and you will get a 2048 steps resolution and 20 ms period. Works great. Mike ----- Original Message ----- From: "Steve Auch-Schwelk" <> To: <> Sent: Monday, October 04, 2004 10:56 PM Subject: [68HC12] Re: resolution for PWM driven servo on HCS12 > > > Thanks for the effort Edward, but your reply didn't really help me > understand my problem. Perhaps I didn't express myself clearly, so it > looks like I will have to lay my ignorance bare, and hope that you > (or someone) can tell me where the error in my logic is. > > Servo's have a PWM period of 20ms (this is the time at which the > pulse must be repeated). Irrespective of my clock selection values, > the PWM Channel Period Registers (PWMPERx) is one byte(0-255). > > If I set my clock rate, so that the PWMPERx multiplied by the (scaled) > clock rate = 20ms, I have the maximum possible resolution for my > duty, which is 20ms/255, or 78 microseconds. > > The entire range of the servo control pulse is 1.25 to 1.75ms, or a > delta of 500 microseconds. > > Therefore I have 500/78 = 6 possible values that I can set my servo > to. > > Where are my 13 bits of resolution? > > thanks > > Steve > --- In , "Edward Karpicz" <karpicz@a...> wrote: > > > Can anyone let me know if they have some suggestions for the > HCS12 > > > prescale, scale, clock, and period, and duty settings for running > a > > > standard servo (666Hz+/-130Hz or 1.25-1.75ms). > > > > > > My oscilator is 16MHz, so the bus clock is at 8MHz. It seems that > the > > > resolution at these frequencies is pretty poor (or have I done > the > > > math wrong?). > > > > Poor resolution? log2(8M/666) gives ~13.5 bits of resolution. > Maximal > > PWMPER =8M/666~12012. > > > > Edward > > > > > > > > > > Can anyone suggest, from their experience, what the most > versatile > > > values are? > > > Yahoo! Groups Links > |
|
Reply by ●October 5, 20042004-10-05
> Thanks for the effort Edward, but your reply didn't really help me > understand my problem. Perhaps I didn't express myself clearly, so it > looks like I will have to lay my ignorance bare, and hope that you > (or someone) can tell me where the error in my logic is. > > Servo's have a PWM period of 20ms (this is the time at which the > pulse must be repeated). Irrespective of my clock selection values, > the PWM Channel Period Registers (PWMPERx) is one byte(0-255). > > If I set my clock rate, so that the PWMPERx multiplied by the (scaled) > clock rate = 20ms, I have the maximum possible resolution for my > duty, which is 20ms/255, or 78 microseconds. > > The entire range of the servo control pulse is 1.25 to 1.75ms, or a > delta of 500 microseconds. > > Therefore I have 500/78 = 6 possible values that I can set my servo > to. Right, but previously you were asking about 666Hz, not 50Hz. > > Where are my 13 bits of resolution? HCS12 PWM module can operate in 16bit mode. With 8MHz PWM module clock and 666Hz target PWM period - prescaler would be=1, PWMDTY012. PWMDTY could be any from zero to PWMDTY. I don't understand what physical sense has frequency you specified in previous post. Was it reciprocal of average target pulse width? What for did you calculate it? Ok. Tpwm ms, tdty=1.25-1.75ms, ECLK=8MHz, 8bit mode if possible. First calculate longest period without prescaler. It's T0=2^8 / ECLK2us. Find prescaler N. N=2 ^ ceil(log2(Tpwm/ T0)) = 1024. PWM module doesn't have such prescaler. Either use timer or 16bits mode. Again for 16bits: T0=2^16 / ECLK=8.192ms N=2 ^ ceil(log2(Tpwm/T0))=8 PWMPER=(Tpwm * ECLK)/N = 20000 PWMDTY(1.25ms)= (1.25ms * ECLK)/N50 PWMDTY(1.75ms)50 If you want better resolution - use timer. Without prescaler you can have _prescaler_ times better resolution. Edward > > thanks > > Steve > > --- In , "Edward Karpicz" <karpicz@a...> wrote: > > > > Can anyone let me know if they have some suggestions for the > > HCS12 > > > > prescale, scale, clock, and period, and duty settings for running > > a > > > > standard servo (666Hz+/-130Hz or 1.25-1.75ms). > > > > > > > > My oscilator is 16MHz, so the bus clock is at 8MHz. It seems that > > the > > > > resolution at these frequencies is pretty poor (or have I done > > the > > > > math wrong?). > > > > > > Poor resolution? log2(8M/666) gives ~13.5 bits of resolution. > > Maximal > > > PWMPER =8M/666~12012. > > > > > > Edward > > > > > > > > > > > > > > Can anyone suggest, from their experience, what the most > > versatile > > > > values are? |
Reply by ●October 5, 20042004-10-05
Ups, formulas should have floor probably (largest integer not greater than) instead of ceil. And T0=2^16 / ECLK=8.192ms N=2 ^ floor(log2(Tpwm/T0))=4 PWMPER=(Tpwm * ECLK)/N = 40000 PWMDTY(1.25ms)= (1.25ms * ECLK)/N%00 PWMDTY(1.75ms)500 Edward > > > Thanks for the effort Edward, but your reply didn't really > help me > > understand my problem. Perhaps I didn't express myself > clearly, so it > > looks like I will have to lay my ignorance bare, and hope > that you > > (or someone) can tell me where the error in my logic is. > > > > Servo's have a PWM period of 20ms (this is the time at > which the > > pulse must be repeated). Irrespective of my clock > selection values, > > the PWM Channel Period Registers (PWMPERx) is one > byte(0-255). > > > > If I set my clock rate, so that the PWMPERx multiplied by > the (scaled) > > clock rate = 20ms, I have the maximum possible resolution > for my > > duty, which is 20ms/255, or 78 microseconds. > > > > The entire range of the servo control pulse is 1.25 to > 1.75ms, or a > > delta of 500 microseconds. > > > > Therefore I have 500/78 = 6 possible values that I can set > my servo > > to. > Right, but previously you were asking about 666Hz, not > 50Hz. > > > > > Where are my 13 bits of resolution? > > HCS12 PWM module can operate in 16bit mode. With 8MHz > PWM module clock > and 666Hz target PWM period - prescaler would be=1, > PWMDTY012. PWMDTY > could be any from zero to PWMDTY. I don't understand what > physical > sense has frequency you specified in previous post. Was it > reciprocal > of average target pulse width? What for did you calculate > it? > > Ok. Tpwm ms, tdty=1.25-1.75ms, ECLK=8MHz, 8bit mode > if possible. > > First calculate longest period without prescaler. It's > T0=2^8 / ECLK2us. > > Find prescaler N. > N=2 ^ ceil(log2(Tpwm/ T0)) = 1024. > > PWM module doesn't have such prescaler. Either use timer or > 16bits mode. > > Again for 16bits: > T0=2^16 / ECLK=8.192ms > N=2 ^ ceil(log2(Tpwm/T0))=8 > > PWMPER=(Tpwm * ECLK)/N = 20000 > > PWMDTY(1.25ms)= (1.25ms * ECLK)/N50 > PWMDTY(1.75ms)50 > > If you want better resolution - use timer. Without > prescaler you > can have _prescaler_ times better resolution. > > Edward > > > > > thanks > > > > Steve > > > --- In , "Edward Karpicz" > <karpicz@a...> wrote: > > > > > Can anyone let me know if they have some suggestions > for the > > > HCS12 > > > > > prescale, scale, clock, and period, and duty > settings for running > > > a > > > > > standard servo (666Hz+/-130Hz or 1.25-1.75ms). > > > > > > > > > > My oscilator is 16MHz, so the bus clock is at 8MHz. > It seems that > > > the > > > > > resolution at these frequencies is pretty poor (or > have I done > > > the > > > > > math wrong?). > > > > > > > > Poor resolution? log2(8M/666) gives ~13.5 bits of > resolution. > > > Maximal > > > > PWMPER =8M/666~12012. > > > > > > > > Edward > > > > > > > > > > > > > > > > > > Can anyone suggest, from their experience, what the > most > > > versatile > > > > > values are? > > > ------------------------ Yahoo! Groups Sponsor --------------------~--> > $9.95 domain names from Yahoo!. Register anything. > http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/dN_tlB/TM > ---------------------- ----------~-> > > > Yahoo! Groups Links > |
|
Reply by ●October 8, 20042004-10-08
Thanks for the clarificatoin and advice Edward. I decided to go for the double register PWM solution that you suggested, and it works well. I might in the future have to switch to another of the suggestions if my PWM channels run low. What do you think of the suggestion to use the output compare channel? Advantages, disagvantages? Steve --- In , "Edward Karpicz" <karpicz@a...> wrote: > Ups, formulas should have floor probably (largest integer > not greater than) > instead of ceil. > > And > T0=2^16 / ECLK=8.192ms > N=2 ^ floor(log2(Tpwm/T0))=4 > > PWMPER=(Tpwm * ECLK)/N = 40000 > > PWMDTY(1.25ms)= (1.25ms * ECLK)/N%00 > PWMDTY(1.75ms)500 > > Edward > > > > > > > Thanks for the effort Edward, but your reply didn't > really > > help me > > > understand my problem. Perhaps I didn't express myself > > clearly, so it > > > looks like I will have to lay my ignorance bare, and > hope > > that you > > > (or someone) can tell me where the error in my logic is. > > > > > > Servo's have a PWM period of 20ms (this is the time at > > which the > > > pulse must be repeated). Irrespective of my clock > > selection values, > > > the PWM Channel Period Registers (PWMPERx) is one > > byte(0-255). > > > > > > If I set my clock rate, so that the PWMPERx multiplied > by > > the (scaled) > > > clock rate = 20ms, I have the maximum possible > resolution > > for my > > > duty, which is 20ms/255, or 78 microseconds. > > > > > > The entire range of the servo control pulse is 1.25 to > > 1.75ms, or a > > > delta of 500 microseconds. > > > > > > Therefore I have 500/78 = 6 possible values that I can > set > > my servo > > > to. > > > > > > Right, but previously you were asking about 666Hz, not > > 50Hz. > > > > > > > > Where are my 13 bits of resolution? > > > > HCS12 PWM module can operate in 16bit mode. With 8MHz > > PWM module clock > > and 666Hz target PWM period - prescaler would be=1, > > PWMDTY012. PWMDTY > > could be any from zero to PWMDTY. I don't understand what > > physical > > sense has frequency you specified in previous post. Was > it > > reciprocal > > of average target pulse width? What for did you calculate > > it? > > > > Ok. Tpwm ms, tdty=1.25-1.75ms, ECLK=8MHz, 8bit > mode > > if possible. > > > > First calculate longest period without prescaler. It's > > T0=2^8 / ECLK2us. > > > > Find prescaler N. > > N=2 ^ ceil(log2(Tpwm/ T0)) = 1024. > > > > PWM module doesn't have such prescaler. Either use timer > or > > 16bits mode. > > > > Again for 16bits: > > T0=2^16 / ECLK=8.192ms > > N=2 ^ ceil(log2(Tpwm/T0))=8 > > > > PWMPER=(Tpwm * ECLK)/N = 20000 > > > > PWMDTY(1.25ms)= (1.25ms * ECLK)/N50 > > PWMDTY(1.75ms)50 > > > > If you want better resolution - use timer. Without > > prescaler you > > can have _prescaler_ times better resolution. > > > > Edward > > > > > > > > thanks > > > > > > Steve > > > > --- In , "Edward Karpicz" > > <karpicz@a...> wrote: > > > > > > Can anyone let me know if they have some > suggestions > > for the > > > > HCS12 > > > > > > prescale, scale, clock, and period, and duty > > settings for running > > > > a > > > > > > standard servo (666Hz+/-130Hz or 1.25-1.75ms). > > > > > > > > > > > > My oscilator is 16MHz, so the bus clock is at > 8MHz. > > It seems that > > > > the > > > > > > resolution at these frequencies is pretty poor (or > > have I done > > > > the > > > > > > math wrong?). > > > > > > > > > > Poor resolution? log2(8M/666) gives ~13.5 bits > of > > resolution. > > > > Maximal > > > > > PWMPER =8M/666~12012. > > > > > > > > > > Edward > > > > > > > > > > > > > > > > > > > > > > Can anyone suggest, from their experience, what > the > > most > > > > versatile > > > > > > values are? > > > > > > > > > > ------------------------ Yahoo! Groups > Sponsor --------------------~--> > > $9.95 domain names from Yahoo!. Register anything. > > http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/dN_tlB/TM > > ---------------------- > ----------~-> > > > > > > Yahoo! Groups Links > > > > > > > > > > > > |