Controlling a servo motor with PWM

Started by Marc La***rt January 31, 2007
Hello,

Im trying to learn how to use the pulse width modulation feature of
the MC9S12DP256C by using it to control a simple futaba servo motor.
however I cant seem to get any movement out of it and im not exactly
sure why. I have the white command wire conencted to PortP0 and code
as followed:


$HC12
ORG $0D00

PWEN: equ $0042 ; PWM enable register
PWPER0: equ $004C ; PWM period channel for channel 0
PWCLK: equ $0040 ; PWM clocks and concatenate
PWDTY0: equ $0050 ; PWM duty cycle for channel 1
PWPOL: equ $0041 ; PWM clock select and polarity
PWSCAL0:equ $0044 ; PWM Scale register 0
PWCTL: equ $0054 ; PWM control register

org $08FA

MOVB #$00,PWCTL ; Left aligned pulses
MOVB #$00,PWCLK ; Do not Concate
MOVB #$11,PWPOL ; S0 is the source clock for ch1
MOVB #$F0,PWSCAL0 ; Set up an initial frequency
MOVB #$0F,PWEN ; Enable PWM
MOVB #$A5,PWPER0 ; Set channel 0 period
return: MOVB #$10,PWDTY0 ; right turn
jsr delay ; go to delay
MOVB #$18,PWDTY0 ; straight ahead
jsr delay
bra return ; start again

delay: ldx #$07FF ; x count
decrx: dex ; decrement x
ldy #$0FFF ; y count
decry: dey ; decrement y
cpy #$00 ; end of inner loop?
bne decry ; no, decrement y again
cpx #$00 ; end of outer loop?
bne decrx ; no, decrement x again
rts ; end delay


Any help is greatly appreciated

Thanks
Marc
--- In 6..., "Marc La***rt" wrote:
> Im trying to learn how to use the pulse width modulation feature of
> the MC9S12DP256C by using it to control a simple futaba servo motor.
> however I cant seem to get any movement out of it and im not exactly
> sure why. I have the white command wire conencted to PortP0 and code
> as followed:

Hint #1; Either use a scope or LED in place of the servo (white wire)
to "see" what the P0 output is doing. That helps eliminate some
possible hardware problems until the software is working.
--- In 6..., "Marc La***rt" wrote:
> Im trying to learn how to use the pulse width modulation feature of
> the MC9S12DP256C by using it to control a simple futaba servo motor.

These are the questions I come up with:

How are you telling the MCU to start at $08FA?

What is your bus speed and how did you verify it?

Did you calculate the pulse width you are applying to make sure it's
in range [1 mS to 2 mS]? Also rising edges should be at least 15 mS
apart. You don't even mention what you think any of the timing is.
--- In 6..., "Jefferson Smith" wrote:
>
> --- In 6..., "Marc La***rt" wrote:
> > Im trying to learn how to use the pulse width modulation feature of
> > the MC9S12DP256C by using it to control a simple futaba servo motor.
> > however I cant seem to get any movement out of it and im not exactly
> > sure why. I have the white command wire conencted to PortP0 and code
> > as followed:
>
> Hint #1; Either use a scope or LED in place of the servo (white wire)
> to "see" what the P0 output is doing. That helps eliminate some
> possible hardware problems until the software is working.

For scopeless students it is possible to use a voltmeter.

Depending on type and settings it can measure average, peak or RMS.

Apart from peak measurement they can asses if the software doeas
actuallty vary the output.

For the really poor students at five volts they can use a led or the
tongue, crative is the key.

Cheers,

Theo
I have had some use for a small earphone with small alligator clips, nice to
get a quick indication of any activity on e.g pwm signals, RS-232
communication links etc.

If you are a musician you should (with some practice) be able to get extra
information like baud rate etc :)

Anders
> -----Original Message-----
> From: 6... [mailto:6...]
> On Behalf Of theobee00
> Sent: Tuesday, February 06, 2007 5:43 AM
> To: 6...
> Subject: [68HC12] Re: Controlling a servo motor with PWM
>
> --- In 6..., "Jefferson Smith"
> wrote:
> >
> > --- In 6..., "Marc La***rt" wrote:
> > > Im trying to learn how to use the pulse width modulation
> feature of
> > > the MC9S12DP256C by using it to control a simple futaba
> servo motor.
> > > however I cant seem to get any movement out of it and im
> not exactly
> > > sure why. I have the white command wire conencted to
> PortP0 and code
> > > as followed:
> >
> > Hint #1; Either use a scope or LED in place of the servo
> (white wire)
> > to "see" what the P0 output is doing. That helps eliminate some
> > possible hardware problems until the software is working.
>
> For scopeless students it is possible to use a voltmeter.
>
> Depending on type and settings it can measure average, peak or RMS.
>
> Apart from peak measurement they can asses if the software doeas
> actuallty vary the output.
>
> For the really poor students at five volts they can use a led or the
> tongue, crative is the key.
>
> Cheers,
>
> Theo
>
> Yahoo! Groups Links
>
check the following:

1-is the polarity of the Pulses correct, e.g. is the (center) 1.5 ms pulse negativ or positive?

2-is the repetition-rate correct (about 20 ms pause, 1.5 ms Puls)

3-when you use the proposed earphone, you are able to determine if the pulses are positive /negative

peter heimes
MEDOS AG

-----Ursprgliche Nachricht-----
Von: 6... [mailto:6...]Im Auftrag von Marc La***rt
Gesendet: Donnerstag, 1. Februar 2007 01:53
An: 6...
Betreff: [SPAM] - [68HC12] Controlling a servo motor with PWM - Der Bayes'sche Filter hat eine Spam-Mitteilung entdeckt.

Hello,

Im trying to learn how to use the pulse width modulation feature of
the MC9S12DP256C by using it to control a simple futaba servo motor.
however I cant seem to get any movement out of it and im not exactly
sure why. I have the white command wire conencted to PortP0 and code
as followed:


$HC12
ORG $0D00

PWEN: equ $0042 ; PWM enable register
PWPER0: equ $004C ; PWM period channel for channel 0
PWCLK: equ $0040 ; PWM clocks and concatenate
PWDTY0: equ $0050 ; PWM duty cycle for channel 1
PWPOL: equ $0041 ; PWM clock select and polarity
PWSCAL0:equ $0044 ; PWM Scale register 0
PWCTL: equ $0054 ; PWM control register

org $08FA

MOVB #$00,PWCTL ; Left aligned pulses
MOVB #$00,PWCLK ; Do not Concate
MOVB #$11,PWPOL ; S0 is the source clock for ch1
MOVB #$F0,PWSCAL0 ; Set up an initial frequency
MOVB #$0F,PWEN ; Enable PWM
MOVB #$A5,PWPER0 ; Set channel 0 period
return: MOVB #$10,PWDTY0 ; right turn
jsr delay ; go to delay
MOVB #$18,PWDTY0 ; straight ahead
jsr delay
bra return ; start again

delay: ldx #$07FF ; x count
decrx: dex ; decrement x
ldy #$0FFF ; y count
decry: dey ; decrement y
cpy #$00 ; end of inner loop?
bne decry ; no, decrement y again
cpx #$00 ; end of outer loop?
bne decrx ; no, decrement x again
rts ; end delay


Any help is greatly appreciated

Thanks
Marc
--- In 6..., "Anders Friberg" wrote:

> I have had some use for a small earphone with small alligator clips, nice to
> get a quick indication of any activity on e.g pwm signals, RS-232
> communication links etc.
>
> If you are a musician you should (with some practice) be able to get extra
> information like baud rate etc :)

Good stuff, I forgot about that one, although square waves are not very compatible with music:-)

Somewhere in my misspent youth, when I was building gadgets instead of chasing the girls like I should have, I made a probe type thingy.

It consisted of a high gain adjustable amp and a rectifier along the way, wonderful to probe inside radios and amplifiers, you could pick of signals from the antenna right through to the speaker outputs.

Ears are much neglected when it comes to trouble shooting, they really are amazingly good at picking up a signal out of a multitude of others.

Probably less good with the higher frequencys of micros, but next time I need to do some radiation testing I will give it a go and see if it is any good at localisng RF noise.

Thanks for the reminder.

Cheers,

Theo

>
> > -----Original Message-----
> > From: 6... [mailto:6...]
> > On Behalf Of theobee00
> > Sent: Tuesday, February 06, 2007 5:43 AM
> > To: 6...
> > Subject: [68HC12] Re: Controlling a servo motor with PWM
> >
> > --- In 6..., "Jefferson Smith"
> > wrote:
> > >
> > > --- In 6..., "Marc La***rt" wrote:
> > > > Im trying to learn how to use the pulse width modulation
> > feature of
> > > > the MC9S12DP256C by using it to control a simple futaba
> > servo motor.
> > > > however I cant seem to get any movement out of it and im
> > not exactly
> > > > sure why. I have the white command wire conencted to
> > PortP0 and code
> > > > as followed:
> > >
> > > Hint #1; Either use a scope or LED in place of the servo
> > (white wire)
> > > to "see" what the P0 output is doing. That helps eliminate some
> > > possible hardware problems until the software is working.
> >
> > For scopeless students it is possible to use a voltmeter.
> >
> > Depending on type and settings it can measure average, peak or RMS.
> >
> > Apart from peak measurement they can asses if the software doeas
> > actuallty vary the output.
> >
> > For the really poor students at five volts they can use a led or the
> > tongue, crative is the key.
> >
> > Cheers,
> >
> > Theo
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
>