PDA

View Full Version : PWM not working on flash


subot.robot
08-18-05, 02:24 AM
I wrote a program for servopod to send pwm signal to servo motors . I have stored this program on to flash. This program is running ( which i inferred by using a sequence of led on off commands) on the flash. But PWM commands are not working. When the same program is run from the terminal it is working. Can u please help me figure out why this might have happened. I am pasting my program here. I have been able to run the RAM version of the same program without changing any connections on the servopod. The program is a simple one. there are 4 states. it starts at RON, then to RFORWARD, then RBACKWARD then ROFF. The LED commands in each state is working, but PWM statements are not working. I think I have added EEWORD, IN-EE where ever necessary, plz let me know if I have missed out somewhere. Can u please let me know where i have gone wrong?

SCRUB

: PARAMETERPWM
DECIMAL 32767 PWMA0 PWM-PERIOD

PWMA0 INDEPENDENT
PWMA2 INDEPENDENT
PWMA4 INDEPENDENT
; EEWORD

LOOPINDEX MAX-COUNTER EEWORD
DECIMAL 200 MAX-COUNTER END
1 MAX-COUNTER START

MACHINE MAX-ROBOT EEWORD
ON-MACHINE MAX-ROBOT
APPEND-STATE RON EEWORD
APPEND-STATE ROFF EEWORD
APPEND-STATE RFORWARD EEWORD
APPEND-STATE RBACKWARD EEWORD

REDLED OFF
GRNLED OFF
YELLED OFF

IN-STATE RON
CONDITION MAX-COUNTER COUNT
CAUSES
GRNLED ON
YELLED OFF
REDLED OFF
DECIMAL 10000 PWMA1 PWM-OUT
DECIMAL 10000 PWMA2 PWM-OUT
DECIMAL 7500 PWMA3 PWM-OUT
THEN-STATE RFORWARD
TO-HAPPEN IN-EE

IN-STATE RFORWARD
CONDITION MAX-COUNTER COUNT
CAUSES
YELLED ON
REDLED OFF
GRNLED OFF
DECIMAL 4500 PWMA1 PWM-OUT
DECIMAL 5500 PWMA2 PWM-OUT
DECIMAL 6500 PWMA3 PWM-OUT
THEN-STATE RBACKWARD
TO-HAPPEN IN-EE

IN-STATE RBACKWARD
CONDITION MAX-COUNTER COUNT
CAUSES
REDLED ON
YELLED OFF
GRNLED OFF
PWMA1 OFF
PWMA2 OFF
PWMA3 OFF
THEN-STATE ROFF
TO-HAPPEN IN-EE


: MAIN
DECIMAL
RON SET-STATE
EVERY 50000 CYCLES SCHEDULE-RUNS MAX-ROBOT
; EEWORD

HEX 3C00 AUTOSTART MAIN
SAVE-RAM

Thanks
Subot.robot

RMDumse
08-18-05, 09:33 AM
Can u please let me know where i have gone wrong?

You've done well, in making a workd to turn on the PWM parameters, but if you look, you never call it on power up. So it needs to be added to your autostarted routine before the schedule runs is started up.

SCRUB

: PARAMETERPWM
DECIMAL 32767 PWMA0 PWM-PERIOD

PWMA0 INDEPENDENT
PWMA2 INDEPENDENT
PWMA4 INDEPENDENT
; EEWORD

...

: MAIN
DECIMAL
REDLED OFF
GRNLED OFF
YELLED OFF
PARAMETERPWM
RON SET-STATE
EVERY 50000 CYCLES SCHEDULE-RUNS MAX-ROBOT
; EEWORD


Something else, you set the LED's off interactively. You may want to do that when MAIN starts.

: MAIN
DECIMAL
REDLED OFF
GRNLED OFF
YELLED OFF
PARAMETERPWM
RON SET-STATE
EVERY 50000 CYCLES SCHEDULE-RUNS MAX-ROBOT
; EEWORD

Something else I want to warn you about. You use DECIMAL inside your definitions. That's fine if you want the machine to go into decimal _when it runs_, But! If you want the number inside the definition to be translated into binary from decimal, you need to interactively set the base with the DECIMAL action before going into the compiling mode. So in the following two examples the numbers inside the definition would be translated from decimal to the internal binary storage of the computer.


DECIMAL
: PARAMETERPWM
32767 PWMA0 PWM-PERIOD

PWMA0 INDEPENDENT
PWMA2 INDEPENDENT
PWMA4 INDEPENDENT
; EEWORD

...

DECIMAL
: MAIN
REDLED OFF
GRNLED OFF
YELLED OFF
PARAMETERPWM
RON SET-STATE
EVERY 50000 CYCLES SCHEDULE-RUNS MAX-ROBOT
; EEWORD


This is the wrong way to do it.

HEX
: PARAMETERPWM
DECIMAL 32767 PWMA0 PWM-PERIOD

PWMA0 INDEPENDENT
PWMA2 INDEPENDENT
PWMA4 INDEPENDENT
; EEWORD

...

: MAIN
DECIMAL
REDLED OFF
GRNLED OFF
YELLED OFF
PARAMETERPWM
RON SET-STATE
EVERY 50000 CYCLES SCHEDULE-RUNS MAX-ROBOT
; EEWORD

because both those numbers would be translated at compile time into hex values in the definition (50000 hex gets truncated to 0000 btw which is bad). Yet later when MAIN runs, the compiled command DECIMAL will run, and set the base to DECIMAL, but unfortunately, the compiled HEX values will still be the same binary value.

It is good to remember, there are no number bases inside the computer, only ones and zeros (binary). Only when it has to talk to you, does it have any formating as decimal or hex or whatever. So the choice of number base is usually an interactive decision when you enter numbers, or a compiled one when you output numbers.

subot.robot
08-20-05, 01:09 AM
Thanks a lot, RMDumse. With ur guidance I was able to control the robot from servopod in our robotics lab. Also thanks for enlightening me about the number bases and where they should be used in the program. I will be soon adding more sensors to it and write advanced programs for servopod to control and run the robot.

Regards
Subot.robot