PDA

View Full Version : Help needed to "shorten" time between pulses



Xypher
11-18-2009, 11:23 PM
I am writing a program to control a 4 Channel r/c toy.

However, the time taken for each cycle of 4 channels is too slow. The receiver needs to be updated every 20ms. 50 times a second. However each full PPM output takes 75-100ms at least. Partly due to RCTIME function. Is there anyway to control it more effectively? At the current level, its impossible to control any r/c toy I think.

Would PWMPAL be the best tool for this job?


Somebody said...
' {$STAMP BS2}
' {$PBASIC 2.5}

' Control servos with accelerometer


rawx VAR Word
rawy VAR Word
x VAR Word
y VAR Word
time VAR Word
throttle VAR Word
header VAR Word

DO
PULSIN 8, 1, rawx 'data from accelerometer
PULSIN 9, 1, rawy 'data from accelerometer

y =5 * rawy / 12 - 290 'formula to convert raw data to pulse to control servos

x =5 * rawx / 12 - 290 'formula to convert raw data to pulse to control servos

HIGH 8 'receive data from potentiometer to control motor
RCTIME 8, 1, time

throttle = 10 * time + 490 'convert data to pulse

PULSOUT 7, x
PULSOUT 7, x
PULSOUT 7, throttle
PULSOUT 7, y
header = 10000 - x - x - y - throttle 'calculate the pulse require to fill up remaining 20ms

PULSOUT 7, header 'pulse to reset



LOOP



Thanks.

Mike Green
11-19-2009, 12:19 AM
A Stamp can only do one thing at a time and nothing is overlapped. With 4 R/C pulses, that's maybe as much as 10ms spent just generating the pulses themselves leaving only 10ms for other things. You have two accelerometers you want to read and a potentiometer and the time to read these has to come out of the 10ms that's left. You need to reduce the width of the "leftover" pulse to compensate. Remember that the units for both PULSIN and PULSOUT are 2us on a BS2. Your "leftover" pulse should be:

header = 10000 -x - x - throttle - y - rawx - rawy - time

You also need to check for no time left like:

IF header > 0 THEN PULSOUT 7, 2*header

Phil Pilgrim (PhiPi)
11-19-2009, 12:44 AM
Xypher,

Is there any reason you need to read all three sensor outputs in every transmit cycle? Perhaps you could save time by rotating through them, reading just one per cycle.

-Phil

Beau Schwabe (Parallax)
11-19-2009, 12:07 PM
Xypher,

Phil's suggestion is the way to do it in a single threaded environment. Basically you have an Index counter set to count to "N" and recycle...

Pseudo Code




Index = Index + 1

If Index = 1
PULSIN 8, 1, rawx 'data from accelerometer
PULSIN 9, 1, rawy 'data from accelerometer

If Index = 2
y =5 * rawy / 12 - 290 'formula to convert raw data to pulse to control servos
x =5 * rawx / 12 - 290 'formula to convert raw data to pulse to control servos

If Index = 3
HIGH 8 'receive data from potentiometer to control motor
RCTIME 8, 1, time

If Index = 4
throttle = 10 * time + 490 'convert data to pulse

Index = 0 ' Reset Index count
Flag = 1 ' Flag ensures that we've completed the loop at least once before sending out pulses

If Flag = 1
PULSOUT 7, x
PULSOUT 7, x
PULSOUT 7, throttle
PULSOUT 7, y
header = 10000 - x - x - y - throttle 'calculate the pulse require to fill up remaining 20ms
PULSOUT 7, header 'pulse to reset



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

Xypher
11-25-2009, 01:42 PM
Thanks Beau for the code.

However, due to RC TIME, the pulse is still too long for my receiver. Is there any other way to control the motor without RC TIME?

Mike Green
11-25-2009, 02:10 PM
Look at the chapter in the Stamp Manual on the RCTIME statement. You might be able to change the capacitor value to use a shorter time period for the RCTIME. You'll probably get less resolution, but it may be enough for your purpose. If not, you'll just have to use some kind of external analog to digital converter to measure the voltage at the pot wiper if it's connected between +5V and ground.

Xypher
12-15-2009, 03:25 PM
http://img42.imageshack.us/img42/5967/waveform.jpg

May I know why this kind of waveform appears instead of the usual pulsout waveform?


Somebody said...
DO

PULSOUT 5,750
PAUSE 12
PULSOUT 5,700
PAUSE 12
PULSOUT 5,650
PAUSE 12
PULSOUT 5,600
PAUSE 12

LOOP


I used this program to test the waveform but it still looks wrong.

Thanks!

Phil Pilgrim (PhiPi)
12-15-2009, 05:09 PM
It looks like you forgot to connect your scope's ground lead to Vss, or else you've got the input set for AC coupling.

-Phil