PDA

View Full Version : Quick and dirty RC Servo example


xar
05-16-03, 12:41 PM
Hello,
just assembled my new robot, and the line sensors and Sharp are working okay.
No output from the PWM.
Is there a quick way to test pin by pin generating a "neutral" position?
TIA,


Giuseppe Marullo

nmitech
05-16-03, 01:25 PM
Quick test to generate PWM signals,

DECIMAL 25000 PWMA0 PWM-PERIOD ( specify period )
HEX
8000 PWMA0 PWM-OUT ( produce 50% duty cycle on PWMA0 )
xxxx PWMA1 PWM-OUT
xxxx PWMA2 PWM-OUT
.....
.....
..... PWMA5 PWM-OUT

DECIMAL ???? PWMB0 PWM-PERIOD
HEX
xxxx PWMB0 PWM-OUT
....
....
.... PWMB5 PWM-OUT

Here is the appnote for setting up PWM, Timer, etc...
http://www.newmicros.com/store/product_manual/IOglossary.pdf

Dave
05-16-03, 02:26 PM
Hi Giuseppe,
On the IsoPod download page, their is the Lynx 5 Robotic Arm code. It's not quick, but would allow testing of up to 5 servos on the PWMA section, for not only a "neutral" position but any other as well, and test different velocities. If servos are connected to PWMA0 and A1, these would correspond to the RBASE and SHLDR definitions used, so typing
RBASE 400 GO ( HEX BASE
would move a servo attached to PWMA0 to near one end of it's allowed movement,
RBASE 0 GO ( HEX BASE
moves to the other
RBASE 200 GO
should provide a center pulse. in HEX number
Additional notes in the code allow setting of how fast a servo moves to a given position. This was just using the code up to but not including the test words at the end of the Lynx 5 code.

xar
05-16-03, 03:20 PM
Thanks to all,
Dave I need to test the Mike3 sumo code with standard RC servos(50Hz 1.5mS etc. etc).
I can't say if the sumo program is running or not, but its led don't change.

It has autostart feature but I suppose it should at least generate neutral position signal for both servos.

I tried snipplets of code to test the ADC and it works.
I tried to display PB0 and PB1 values(two line sensors) and they work.

Now I need something able to tell me that the pins are actually generating pulses, I am a little worried.
I will try asap the routines keeping an eye on the scope.

Is it possible to use them as general purpose I/O(to test the basic functionality)?
Thanks,

Giuseppe

Dave
05-16-03, 04:38 PM
Unfortunately I don't have the Mike3 code, but from memory, the LEDs don't react to the servo output. They react to sensor inputs, showing you that either the line sensors, or front Sharp sensors have made a detection. Once the robot is powered with this code, it should be generating a 1.5 ms center pulse. That should allow tuning the servos to a stop position, slightly adjusting the potentiometers inside (had to file a slot to accept a jewelers flat screwdriver through the servo output ). The servos were plugged into PWMA0 and PWMA1. Buttons were placed on PA0 to PA3 to start various functions based on them being grounded. IE: pressing button 1 on PA0 started the Line Following mode (with an additional hand wave in front of sensors to begin), button 2 on PA1 started Minisumo (with a 5 second start delay) These could be in different pins, but pretty sure the servos were on the PWMA0 and PWMA1 outputs. Also, the "center" will vary on the servos depending on the battery charge, so some drift can occur as they drain.
And yes, a statement such as
PWMA0 ON
can be used to turn that pin fully on, however this would probably drive an RC servo all the way one direction, not a limited pulse. It would be visible on an oscilloscope though. In the App Note NMItech mentioned, there is also a short snippet in the PWM section that should actually drive a servo, and show a pulse on the oscilloscope.

xar
05-16-03, 09:01 PM
it works. The pin is okay and the pwm is coming out as I like. Next I will try to understand why the program does not work but the hw is okay.
The motors now run as expected.
Thanks again,

Giuseppe

xar
06-16-03, 05:50 PM
I am trying to achieve well over 20KHz of PWM on the Isopod but a quick calculation:

0x100(minimum PWM-PERIOD parameter) x

1/2.5e6 (2.5MHz period) = 9.765KHz (maximum PWM freq)


How could I use IsoMax commands to reach at least 22KHz PWM?

I am planning to use locked anti-phase and the motor is noisy at lower frequencies.

Dave
06-16-03, 06:08 PM
In order to go beyond the 9.7 kHz limit, you have to go to configuring the PWM registers directly. Here's some code I've used for 4 channel complemetary mode, with varying the frequency with the PER#

( E03 PWM OUtput Control Register PMOUT 8C0C 10 001100 00 001100 current
( 10 Output Pad Enable and nonwritable
( 000000 OUtput Control Enables - software control disabled
( 00 nonwritable
( 000000 OUtput Control Bits - in complimentary, all inactive

( E0C PWM deadtime register PWMDEADTM
( 0000 0000 first 8 read only
(


( EOF PWM Configure Register PWMCFG
( 0001 Edge aligned PWM
( 0000 top side polarity
( 0000 bottom side polarity
( 0 INDEP 4-5 ( 1 independant 0 complimentary
( 1 INDEP 2-3
( 0 INDEP 0-1
( 0 write protect, allows writing
( 0001 0000 0000 0100
( 1 0 0 4
( change to 1008 for 4-5 indep, 2-3 and 0-1 complimentary


( PWM H BRIDGE DRIVE 40 KHz - 2625A00 40Mhz clock divided by
( 400hex or 1024 decimal ~ 40 kHz 39062
( 800 ~ 20 kHz 19531
( 1000 ~ 10 kHz 9765
( 2000 ~ 4882 kHz
( Use FREQ to change modulus - 400 FREQ
( Use PWML to change duty cycle as a portion of FREQ - if 400 is FREQ,
( then 0 to 400 can go into PWML

HEX

VARIABLE PER#

400 PER# !

: PWML DUP E06 ! E08 ! E00 C@ DROP 03 E00 ! ;

: INIT

PER# @ E05 ! ( SET MODULO FOR PWM COUNT
0 E0C ! ( GET RID OF DEADBAND
0 E0D !
0 E0E !
1008 E0F ! ( EDGE ALIGN PWA0/1 COMP PWA2/3 COMP


PER# @ 2/ PWML ( HALF for 50 %

8000 E03 ! ( TURNS ON OUTPUT LAST THING

;

: FREQ PER# ! INIT ;

xar
06-20-03, 12:43 PM
Thanks Dave,
I have an enlightment now, I will try as soon I have a little time.