Sign in

username:

password:



Not a member?

Search 68hc12



Search tips

Subscribe to 68hc12



68hc12 by Keywords

68HC1 | 812A4 | 9S12DP256 | Bootloader | CodeWarrior | D60A | Debugger | DP256 | ECT | EEPROM | EVB | Flash | HC1 | HCS12 | I2C | IAR | ICC1 | Interrupts | LCD | M68KIT912DP256 | MC9S12DP256 | MC9S12DP256B | Metrowerks | Motor | MSCAN | Multilink | PLL | Quadrature | SDI | SPI | Transceiver | XFC

Ads

Discussion Groups

Discussion Groups | 68HC12 | Re: resolution for PWM driven servo on HCS12

Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).

resolution for PWM driven servo on HCS12 - Steve Auch-Schwelk - Sep 30 16:16:00 2004

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?





(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )


Re: resolution for PWM driven servo on HCS12 - Edward Karpicz - Sep 30 23:28:00 2004

> 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?





(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: resolution for PWM driven servo on HCS12 - Steve Auch-Schwelk - Oct 4 15:56:00 2004


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?






(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

RE: Re: resolution for PWM driven servo on HCS12 - Justin Nicolaides - Oct 4 16:50:00 2004

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





(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

RE: Re: resolution for PWM driven servo on HCS12 - Jonathan Masters - Oct 4 17:00:00 2004

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?

Yahoo! Groups Sponsor ADVERTISEMENT

<http://us.ard.yahoo.com/SIG=129cpc4lb/M=298184.5285298.6392945.3001176/
D=groups/S=1706554205:HM/EXP=1097010156/A=2319498/R=0/SIG=11thfntfp/*htt
p:/www.netflix.com/Default?mqso=60185352&partid=5285298> click here <http://us.adserver.yahoo.com/l?M=298184.5285298.6392945.3001176/D=group
s/S=:HM/A=2319498/rand=257676248>

_____

> Service. [Non-text portions of this message have been removed]




(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: resolution for PWM driven servo on HCS12 - Author Unknown - Oct 4 19:15:00 2004


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.... [Non-text portions of this message have been removed]




(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: resolution for PWM driven servo on HCS12 - Mike - Oct 4 23:34:00 2004

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





(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: resolution for PWM driven servo on HCS12 - Edward Karpicz - Oct 5 2:21:00 2004

> 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,
PWMDTY=12012. 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=20ms, tdty=1.25-1.75ms, ECLK=8MHz, 8bit mode
if possible.

First calculate longest period without prescaler. It's
T0=2^8 / ECLK=32us.

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)/N=1250
PWMDTY(1.75ms)=1750

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?




(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: resolution for PWM driven servo on HCS12 - Edward Karpicz - Oct 5 8:58:00 2004

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=2500
PWMDTY(1.75ms)=3500

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,
> PWMDTY=12012. 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=20ms, tdty=1.25-1.75ms, ECLK=8MHz, 8bit
mode
> if possible.
>
> First calculate longest period without prescaler. It's
> T0=2^8 / ECLK=32us.
>
> 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)/N=1250
> PWMDTY(1.75ms)=1750
>
> 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





(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: resolution for PWM driven servo on HCS12 - Steve Auch-Schwelk - Oct 8 2:44:00 2004



Hi Mike,

Thanks for your input.
I must admit that I have avoided the capture/compare functionality of
the hcs12 up until now becauase I don't fully understand it, and have
yet to find a consise functional description. I did read through the
provided block user guide, but found the descriptions too detailed,
and I could't see the "big picture". What can the capture/compare
timers do that a "normal" timer cannot? What would be an example of
an application?

thanks

Steve

--- In , "Mike" <mike@b...> wrote:
> 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" <steve_auch@y...>
> 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
> >
> >
> >
> >
> >
> >
> >
> >
>






(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: resolution for PWM driven servo on HCS12 - Jefferson Smith - Oct 8 18:12:00 2004


Perhaps I could write a big picture of ECT (Enhanced Capture Timer
module), having used it extensively for servos.

Probably my biggest advantage to using the ECT is the number of servos
increased. I don't use PWM for the servo because it would only drive
one servo for every two PWM registers (practically). When I use an
Output Compare (OC), I actually drive between 8 and 16 servos on a
single output! The disadvantage is perhaps more code, and perhaps more
processor time. Still, a worth-while advantage to use this hardware to
accellerate and keep accurate. I don't even need an interrupt because
the OC changes the output without waiting for software to service it.

Following is an overall picture.

Both Output Compare (OC) and Input Capture (IC) are based on the
hardware time clock. That is, they look at the register TCNT to
determine what "time" it is. TCNT is a 16-bit free-running counter
with prescaler from the bus clock. That gives a steady count, not
affected by any sort of software loop. Reading this value would give
you a timestamp. You notice of course, this can't tell time of day
because it would roll over to zero quite often during one day. An
ideal use, however, is to time pulse widths withing a 20 mS cycle.

The basic function of an OC is to tell the output exactly when it
should change state. Example: Configure TC0 as an OC in toggle mode.
Write TC0=0xe477. The hardware continously compares that value with
TCNT. When TCNT arrives at 0xe477, it will immediately set the flag
C0F and toggle the output pin PT0. Now to toggle again 500 uS from
then, set TC0 = (0xe477 + 500). That assumes TCNT is scaled to 1 uS (1
MHz). When TC0 compares with TCNT again, the output toggles again. The
limitation the maximum time you could add because it's only a 16-bit
timer.

The basic function of IC is to capture when the state changed on the
timer input pin. Say you had TC1 configured as IC, detecting rising
edges. When bit C1F in TFLG1 is detected, read TC1 to find exactly
what TCNT was when the change took place. Clear C1F and do something
else while waiting. When C1F is detected again, read TC1 and subtract
the previous captured value. That would tell the width of the pulse
from an external source.

To drive one servo with an Output Compare (OC), you could do something
like below.

variable Servo1 = desired servo pulse width (clock counts)

ServoLoop:
If C0F is not set, goto ServoLoop
If PT0 is low, goto ServoLow
configure output to go low
TC0 = TC0 + Servo1
goto ServoLoop
ServoLow:
configure output to go high
TC0 = TC0 + (20000 - Servo1)
goto ServoLoop

Jeff Smith
Robotronics, Inc.

--- In , "Steve Auch-Schwelk" <steve_auch@y...>
wrote: > Hi Mike,
>
> Thanks for your input.
> I must admit that I have avoided the capture/compare functionality
of
> the hcs12 up until now becauase I don't fully understand it, and
have
> yet to find a consise functional description. I did read through
the
> provided block user guide, but found the descriptions too detailed,
> and I could't see the "big picture". What can the capture/compare
> timers do that a "normal" timer cannot? What would be an example of
> an application?
>
> thanks
>
> Steve





(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: resolution for PWM driven servo on HCS12 - Mike - Oct 8 22:59:00 2004

Hi,
Jefferson Smith explained the usage of OC for driving RC Servos perfectly.
To add to that, you can drive up to 10 servos from two OC output by chaining
the pulse and using a shift register chip like LM4017. One OC is set for
the 20ms period and the other is the pulse chain.
Good luck
Mike
----- Original Message -----
From: "Jefferson Smith" <>
To: <>
Sent: Saturday, October 09, 2004 1:12 AM
Subject: [68HC12] Re: resolution for PWM driven servo on HCS12 >
>
> Perhaps I could write a big picture of ECT (Enhanced Capture Timer
> module), having used it extensively for servos.
>
> Probably my biggest advantage to using the ECT is the number of servos
> increased. I don't use PWM for the servo because it would only drive
> one servo for every two PWM registers (practically). When I use an
> Output Compare (OC), I actually drive between 8 and 16 servos on a
> single output! The disadvantage is perhaps more code, and perhaps more
> processor time. Still, a worth-while advantage to use this hardware to
> accellerate and keep accurate. I don't even need an interrupt because
> the OC changes the output without waiting for software to service it.
>
> Following is an overall picture.
>
> Both Output Compare (OC) and Input Capture (IC) are based on the
> hardware time clock. That is, they look at the register TCNT to
> determine what "time" it is. TCNT is a 16-bit free-running counter
> with prescaler from the bus clock. That gives a steady count, not
> affected by any sort of software loop. Reading this value would give
> you a timestamp. You notice of course, this can't tell time of day
> because it would roll over to zero quite often during one day. An
> ideal use, however, is to time pulse widths withing a 20 mS cycle.
>
> The basic function of an OC is to tell the output exactly when it
> should change state. Example: Configure TC0 as an OC in toggle mode.
> Write TC0=0xe477. The hardware continously compares that value with
> TCNT. When TCNT arrives at 0xe477, it will immediately set the flag
> C0F and toggle the output pin PT0. Now to toggle again 500 uS from
> then, set TC0 = (0xe477 + 500). That assumes TCNT is scaled to 1 uS (1
> MHz). When TC0 compares with TCNT again, the output toggles again. The
> limitation the maximum time you could add because it's only a 16-bit
> timer.
>
> The basic function of IC is to capture when the state changed on the
> timer input pin. Say you had TC1 configured as IC, detecting rising
> edges. When bit C1F in TFLG1 is detected, read TC1 to find exactly
> what TCNT was when the change took place. Clear C1F and do something
> else while waiting. When C1F is detected again, read TC1 and subtract
> the previous captured value. That would tell the width of the pulse
> from an external source.
>
> To drive one servo with an Output Compare (OC), you could do something
> like below.
>
> variable Servo1 = desired servo pulse width (clock counts)
>
> ServoLoop:
> If C0F is not set, goto ServoLoop
> If PT0 is low, goto ServoLow
> configure output to go low
> TC0 = TC0 + Servo1
> goto ServoLoop
> ServoLow:
> configure output to go high
> TC0 = TC0 + (20000 - Servo1)
> goto ServoLoop
>
> Jeff Smith
> Robotronics, Inc.
>
> --- In , "Steve Auch-Schwelk" <steve_auch@y...>
> wrote:
> >
> >
> > Hi Mike,
> >
> > Thanks for your input.
> > I must admit that I have avoided the capture/compare functionality
> of
> > the hcs12 up until now becauase I don't fully understand it, and
> have
> > yet to find a consise functional description. I did read through
> the
> > provided block user guide, but found the descriptions too detailed,
> > and I could't see the "big picture". What can the capture/compare
> > timers do that a "normal" timer cannot? What would be an example of
> > an application?
> >
> > thanks
> >
> > Steve
> >
>
> Yahoo! Groups Links




(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: resolution for PWM driven servo on HCS12 - Steve Auch-Schwelk - Oct 9 16:02:00 2004


Thanks for the description Jeff, I now understand the concept of the
ECT.
One question about the specifics. Do you actively have to write in
the new pulse length when TCNT=TCO. In this case it seems that you
either have to actively poll (as in your example code), or I presume
that an interrupt could also be triggered, which could then be
serviced to do this.

In your text you say:
"I don't even need an interrupt because the OC changes the output
without waiting for software to service it."

But do you still have to react to the change to set the new TCO? Or
is there a way to have TCO "toggle" between the two values that I
have overseen? Steve

--- In , "Jefferson Smith" <imajeff84663@y...>
wrote:
>
> Perhaps I could write a big picture of ECT (Enhanced Capture Timer
> module), having used it extensively for servos.
>
> Probably my biggest advantage to using the ECT is the number of
servos
> increased. I don't use PWM for the servo because it would only drive
> one servo for every two PWM registers (practically). When I use an
> Output Compare (OC), I actually drive between 8 and 16 servos on a
> single output! The disadvantage is perhaps more code, and perhaps
more
> processor time. Still, a worth-while advantage to use this hardware
to
> accellerate and keep accurate. I don't even need an interrupt
because
> the OC changes the output without waiting for software to service
it.
>
> Following is an overall picture.
>
> Both Output Compare (OC) and Input Capture (IC) are based on the
> hardware time clock. That is, they look at the register TCNT to
> determine what "time" it is. TCNT is a 16-bit free-running counter
> with prescaler from the bus clock. That gives a steady count, not
> affected by any sort of software loop. Reading this value would give
> you a timestamp. You notice of course, this can't tell time of day
> because it would roll over to zero quite often during one day. An
> ideal use, however, is to time pulse widths withing a 20 mS cycle.
>
> The basic function of an OC is to tell the output exactly when it
> should change state. Example: Configure TC0 as an OC in toggle mode.
> Write TC0=0xe477. The hardware continously compares that value with
> TCNT. When TCNT arrives at 0xe477, it will immediately set the flag
> C0F and toggle the output pin PT0. Now to toggle again 500 uS from
> then, set TC0 = (0xe477 + 500). That assumes TCNT is scaled to 1 uS
(1
> MHz). When TC0 compares with TCNT again, the output toggles again.
The
> limitation the maximum time you could add because it's only a 16-bit
> timer.
>
> The basic function of IC is to capture when the state changed on the
> timer input pin. Say you had TC1 configured as IC, detecting rising
> edges. When bit C1F in TFLG1 is detected, read TC1 to find exactly
> what TCNT was when the change took place. Clear C1F and do something
> else while waiting. When C1F is detected again, read TC1 and
subtract
> the previous captured value. That would tell the width of the pulse
> from an external source.
>
> To drive one servo with an Output Compare (OC), you could do
something
> like below.
>
> variable Servo1 = desired servo pulse width (clock counts)
>
> ServoLoop:
> If C0F is not set, goto ServoLoop
> If PT0 is low, goto ServoLow
> configure output to go low
> TC0 = TC0 + Servo1
> goto ServoLoop
> ServoLow:
> configure output to go high
> TC0 = TC0 + (20000 - Servo1)
> goto ServoLoop
>
> Jeff Smith
> Robotronics, Inc.
>
> --- In , "Steve Auch-Schwelk"
<steve_auch@y...>
> wrote:
> >
> >
> > Hi Mike,
> >
> > Thanks for your input.
> > I must admit that I have avoided the capture/compare functionality
> of
> > the hcs12 up until now becauase I don't fully understand it, and
> have
> > yet to find a consise functional description. I did read through
> the
> > provided block user guide, but found the descriptions too
detailed,
> > and I could't see the "big picture". What can the capture/compare
> > timers do that a "normal" timer cannot? What would be an example
of
> > an application?
> >
> > thanks
> >
> > Steve
>





(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: resolution for PWM driven servo on HCS12 - SS - Oct 11 20:18:00 2004

Hi

Could you maybe give an example of where to use 10 servos at a time - a
model airplane maybe?

----- Original Message -----
From: "Mike" <>
To: <>
Sent: Friday, October 08, 2004 8:59 PM
Subject: Re: [68HC12] Re: resolution for PWM driven servo on HCS12 >
> Hi,
> Jefferson Smith explained the usage of OC for driving RC Servos perfectly.
> To add to that, you can drive up to 10 servos from two OC output by
chaining
> the pulse and using a shift register chip like LM4017. One OC is set for
> the 20ms period and the other is the pulse chain.
> Good luck
> Mike
> ----- Original Message -----
> From: "Jefferson Smith" <>
> To: <>
> Sent: Saturday, October 09, 2004 1:12 AM
> Subject: [68HC12] Re: resolution for PWM driven servo on HCS12 > >
> >
> > Perhaps I could write a big picture of ECT (Enhanced Capture Timer
> > module), having used it extensively for servos.
> >
> > Probably my biggest advantage to using the ECT is the number of servos
> > increased. I don't use PWM for the servo because it would only drive
> > one servo for every two PWM registers (practically). When I use an
> > Output Compare (OC), I actually drive between 8 and 16 servos on a
> > single output! The disadvantage is perhaps more code, and perhaps more
> > processor time. Still, a worth-while advantage to use this hardware to
> > accellerate and keep accurate. I don't even need an interrupt because
> > the OC changes the output without waiting for software to service it.
> >
> > Following is an overall picture.
> >
> > Both Output Compare (OC) and Input Capture (IC) are based on the
> > hardware time clock. That is, they look at the register TCNT to
> > determine what "time" it is. TCNT is a 16-bit free-running counter
> > with prescaler from the bus clock. That gives a steady count, not
> > affected by any sort of software loop. Reading this value would give
> > you a timestamp. You notice of course, this can't tell time of day
> > because it would roll over to zero quite often during one day. An
> > ideal use, however, is to time pulse widths withing a 20 mS cycle.
> >
> > The basic function of an OC is to tell the output exactly when it
> > should change state. Example: Configure TC0 as an OC in toggle mode.
> > Write TC0=0xe477. The hardware continously compares that value with
> > TCNT. When TCNT arrives at 0xe477, it will immediately set the flag
> > C0F and toggle the output pin PT0. Now to toggle again 500 uS from
> > then, set TC0 = (0xe477 + 500). That assumes TCNT is scaled to 1 uS (1
> > MHz). When TC0 compares with TCNT again, the output toggles again. The
> > limitation the maximum time you could add because it's only a 16-bit
> > timer.
> >
> > The basic function of IC is to capture when the state changed on the
> > timer input pin. Say you had TC1 configured as IC, detecting rising
> > edges. When bit C1F in TFLG1 is detected, read TC1 to find exactly
> > what TCNT was when the change took place. Clear C1F and do something
> > else while waiting. When C1F is detected again, read TC1 and subtract
> > the previous captured value. That would tell the width of the pulse
> > from an external source.
> >
> > To drive one servo with an Output Compare (OC), you could do something
> > like below.
> >
> > variable Servo1 = desired servo pulse width (clock counts)
> >
> > ServoLoop:
> > If C0F is not set, goto ServoLoop
> > If PT0 is low, goto ServoLow
> > configure output to go low
> > TC0 = TC0 + Servo1
> > goto ServoLoop
> > ServoLow:
> > configure output to go high
> > TC0 = TC0 + (20000 - Servo1)
> > goto ServoLoop
> >
> > Jeff Smith
> > Robotronics, Inc.
> >
> > --- In , "Steve Auch-Schwelk" <steve_auch@y...>
> > wrote:
> > >
> > >
> > > Hi Mike,
> > >
> > > Thanks for your input.
> > > I must admit that I have avoided the capture/compare functionality
> > of
> > > the hcs12 up until now becauase I don't fully understand it, and
> > have
> > > yet to find a consise functional description. I did read through
> > the
> > > provided block user guide, but found the descriptions too detailed,
> > > and I could't see the "big picture". What can the capture/compare
> > > timers do that a "normal" timer cannot? What would be an example of
> > > an application?
> > >
> > > thanks
> > >
> > > Steve
> > >
> >
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> >
> >
> Yahoo! Groups Links




(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: resolution for PWM driven servo on HCS12 - Mike - Oct 11 22:45:00 2004

Hi,
RC servo are very efficient and relatively low cost device and can be used
anywhere in applications where you need position control. The PWM driving
method is used even in MIL-STD servos. In Robotic applications RC servos are
very popular.
I brought the usage of the LM 4017 just to show how to save output pins.
Mike
----- Original Message -----
From: "SS" <>
To: <>
Sent: Tuesday, October 12, 2004 3:18 AM
Subject: Re: [68HC12] Re: resolution for PWM driven servo on HCS12 >
> Hi
>
> Could you maybe give an example of where to use 10 servos at a time - a
> model airplane maybe?
>
> ----- Original Message -----
> From: "Mike" <>
> To: <>
> Sent: Friday, October 08, 2004 8:59 PM
> Subject: Re: [68HC12] Re: resolution for PWM driven servo on HCS12 > >
> > Hi,
> > Jefferson Smith explained the usage of OC for driving RC Servos
perfectly.
> > To add to that, you can drive up to 10 servos from two OC output by
> chaining
> > the pulse and using a shift register chip like LM4017. One OC is set
for
> > the 20ms period and the other is the pulse chain.
> > Good luck
> > Mike
> > ----- Original Message -----
> > From: "Jefferson Smith" <>
> > To: <>
> > Sent: Saturday, October 09, 2004 1:12 AM
> > Subject: [68HC12] Re: resolution for PWM driven servo on HCS12
> >
> >
> > >
> > >
> > > Perhaps I could write a big picture of ECT (Enhanced Capture Timer
> > > module), having used it extensively for servos.
> > >
> > > Probably my biggest advantage to using the ECT is the number of servos
> > > increased. I don't use PWM for the servo because it would only drive
> > > one servo for every two PWM registers (practically). When I use an
> > > Output Compare (OC), I actually drive between 8 and 16 servos on a
> > > single output! The disadvantage is perhaps more code, and perhaps more
> > > processor time. Still, a worth-while advantage to use this hardware to
> > > accellerate and keep accurate. I don't even need an interrupt because
> > > the OC changes the output without waiting for software to service it.
> > >
> > > Following is an overall picture.
> > >
> > > Both Output Compare (OC) and Input Capture (IC) are based on the
> > > hardware time clock. That is, they look at the register TCNT to
> > > determine what "time" it is. TCNT is a 16-bit free-running counter
> > > with prescaler from the bus clock. That gives a steady count, not
> > > affected by any sort of software loop. Reading this value would give
> > > you a timestamp. You notice of course, this can't tell time of day
> > > because it would roll over to zero quite often during one day. An
> > > ideal use, however, is to time pulse widths withing a 20 mS cycle.
> > >
> > > The basic function of an OC is to tell the output exactly when it
> > > should change state. Example: Configure TC0 as an OC in toggle mode.
> > > Write TC0=0xe477. The hardware continously compares that value with
> > > TCNT. When TCNT arrives at 0xe477, it will immediately set the flag
> > > C0F and toggle the output pin PT0. Now to toggle again 500 uS from
> > > then, set TC0 = (0xe477 + 500). That assumes TCNT is scaled to 1 uS (1
> > > MHz). When TC0 compares with TCNT again, the output toggles again. The
> > > limitation the maximum time you could add because it's only a 16-bit
> > > timer.
> > >
> > > The basic function of IC is to capture when the state changed on the
> > > timer input pin. Say you had TC1 configured as IC, detecting rising
> > > edges. When bit C1F in TFLG1 is detected, read TC1 to find exactly
> > > what TCNT was when the change took place. Clear C1F and do something
> > > else while waiting. When C1F is detected again, read TC1 and subtract
> > > the previous captured value. That would tell the width of the pulse
> > > from an external source.
> > >
> > > To drive one servo with an Output Compare (OC), you could do something
> > > like below.
> > >
> > > variable Servo1 = desired servo pulse width (clock counts)
> > >
> > > ServoLoop:
> > > If C0F is not set, goto ServoLoop
> > > If PT0 is low, goto ServoLow
> > > configure output to go low
> > > TC0 = TC0 + Servo1
> > > goto ServoLoop
> > > ServoLow:
> > > configure output to go high
> > > TC0 = TC0 + (20000 - Servo1)
> > > goto ServoLoop
> > >
> > > Jeff Smith
> > > Robotronics, Inc.
> > >
> > > --- In , "Steve Auch-Schwelk" <steve_auch@y...>
> > > wrote:
> > > >
> > > >
> > > > Hi Mike,
> > > >
> > > > Thanks for your input.
> > > > I must admit that I have avoided the capture/compare functionality
> > > of
> > > > the hcs12 up until now becauase I don't fully understand it, and
> > > have
> > > > yet to find a consise functional description. I did read through
> > > the
> > > > provided block user guide, but found the descriptions too detailed,
> > > > and I could't see the "big picture". What can the capture/compare
> > > > timers do that a "normal" timer cannot? What would be an example of
> > > > an application?
> > > >
> > > > thanks
> > > >
> > > > Steve
> > > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Links




(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: resolution for PWM driven servo on HCS12 - John Tobias - Oct 12 1:05:00 2004

How can you instruct the servo to run in two different direction (either
clockwise or counter clockwise)?.

>From: "Mike" <>
>Reply-To:
>To: <>
>Subject: Re: [68HC12] Re: resolution for PWM driven servo on HCS12
>Date: Tue, 12 Oct 2004 05:45:55 +0200 _________________________________________________________________
Check out Election 2004 for up-to-date election news, plus voter tools and
more! http://special.msn.com/msn/election2004.armx [Non-text portions of this message have been removed]




(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: resolution for PWM driven servo on HCS12 - Mike - Oct 12 5:39:00 2004

RC servo works this way: The input is a PWM signal with period of 20 ms and
pulse width between 0.9-2.2 ms. At 1.5 ms pulse width the servo is centered,
0.9 ms it will go to one direction and 2.2 to the other. very simple and
efficient.
Mike

----- Original Message -----
From: "John Tobias" <>
To: <>
Sent: Tuesday, October 12, 2004 8:05 AM
Subject: Re: [68HC12] Re: resolution for PWM driven servo on HCS12 >
> How can you instruct the servo to run in two different direction (either
> clockwise or counter clockwise)?.
>
> >From: "Mike" <>
> >Reply-To:
> >To: <>
> >Subject: Re: [68HC12] Re: resolution for PWM driven servo on HCS12
> >Date: Tue, 12 Oct 2004 05:45:55 +0200
> >
>
> _________________________________________________________________
> Check out Election 2004 for up-to-date election news, plus voter tools and
> more! http://special.msn.com/msn/election2004.armx > [Non-text portions of this message have been removed] > Yahoo! Groups Links




(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: resolution for PWM driven servo on HCS12 - John Tobias - Oct 12 15:16:00 2004

Mike,

I don't know how to convert the 1.5ms and 0.9-2.2ms in the actual value and
which registers of PWM should I put that value to run in one direction and
other way around.
Could you pls send me some instructions and how to get the relative value of
1.5, 0.9-2.2ms pulse width.

Thanks,

John

>From: "Mike" <>
>Reply-To:
>To: <>
>Subject: Re: [68HC12] Re: resolution for PWM driven servo on HCS12
>Date: Tue, 12 Oct 2004 12:39:17 +0200 _________________________________________________________________
Check out Election 2004 for up-to-date election news, plus voter tools and
more! http://special.msn.com/msn/election2004.armx [Non-text portions of this message have been removed]





(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: resolution for PWM driven servo on HCS12 - Mike - Oct 12 15:36:00 2004

John,
I don't use the PWM register to produce the servo signal. I use the Timer OC
feature because I think it is more simple.
The algorithm is very simple: I prescale the timer by 4 (on 8 mHz bus) so 1
ms is represented by 2000 counts.
on 1st OC set pin to high then set the next OC to the desired PWM: TC0+=
PWM (for pt0 pin...)
on 2nd OC set pin low then set next OC to TC0+=40000-PWM (for the 20 ms
period)
then go back to the beginning.
Hope it helps
Mike

----- Original Message -----
From: "John Tobias" <>
To: <>
Sent: Tuesday, October 12, 2004 10:16 PM
Subject: Re: [68HC12] Re: resolution for PWM driven servo on HCS12 >
> Mike,
>
> I don't know how to convert the 1.5ms and 0.9-2.2ms in the actual value
and
> which registers of PWM should I put that value to run in one direction and
> other way around.
> Could you pls send me some instructions and how to get the relative value
of
> 1.5, 0.9-2.2ms pulse width.
>
> Thanks,
>
> John
>
> >From: "Mike" <>
> >Reply-To:
> >To: <>
> >Subject: Re: [68HC12] Re: resolution for PWM driven servo on HCS12
> >Date: Tue, 12 Oct 2004 12:39:17 +0200
> >
>
> _________________________________________________________________
> Check out Election 2004 for up-to-date election news, plus voter tools and
> more! http://special.msn.com/msn/election2004.armx > [Non-text portions of this message have been removed] > Yahoo! Groups Links




(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: resolution for PWM driven servo on HCS12 - John Tobias - Oct 14 15:45:00 2004

Stephen,

Thanks for your input but I've done that before to disable the feedback loop
and it works fine with my program and my motor. But in my last attempt to
replace the potentiometer I've destroyed 2 of my servos for unknown reason
maybe I overheat the Iron to remove the soldered potentiometer in the
circuit to replace a resistors then damaged one of the parts of the circuit.
(My soldering experience is not good when it comes into a small parts of the
circuit so that's why I am little bit afraid to do it again in my 6 servos).

So I followed the instructions to these link
http://www.junun.org/MarkIII/Manual/Appendix.jsp#Servos
so no need to use soldering Iron to replace any parts of the circuit but I
have to calibrate the servo to stay in the middle when I feed 1.5ms. Then, I
could run the servo in either clockwise or counter clockwise if I will feed
it <1.5ms or >1.5ms pulse. But, my problem is I don't have experience,
proper education on hcs12, how to get the ms pulse...

Well, I'll do my effort to have a proper education, experience on the hcs12
controller. So I will not disturbing anybody especially some of the
conservatives in the list... :)

Thanks again,
-John

>From: "Stephen Trier" <>
>Reply-To:
>To:
>Subject: Re: [68HC12] Re: resolution for PWM driven servo on HCS12
>Date: Thu, 14 Oct 2004 12:14:39 -0400 _________________________________________________________________
Don’t just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/ [Non-text portions of this message have been removed]




(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )