PDA

View Full Version : PWM Output Question


rcorreia
04-07-03, 01:47 PM
I'm using an IsoPod with the RC Servo Adapter to control 18 standard size servos. I'm using a 9.6V 1600mAh NiMH batter pack,
voltage regulated to 5 volts. I'm splitting the load between two 7805 voltage regulators to try and keep them from going into
thermal overload if the current draw gets too high.

I'm having a strange problem. If I command the servos to move individually at the IsoMax prompt everything is fine. However if I use the code below
to move from a centered position to a "sitting" position the IsoPod resets and the servos are all set to extreme positions. (ie extended as far as they will go
in a given direction)

( uses the PWM Example code found elsewhere on the forum )

: CENTER-ALL
HEX
( HIPS RED )
240 B RC
250 8 RC
1DD 5 RC
200 10 RC
200 12 RC
200 2 RC

( HIPS BLACK )
1DD A RC
1D0 7 RC
300 4 RC

1D5 F RC
31A 11 RC
1F5 1 RC

( KNEES )
220 9 RC
240 6 RC
210 3 RC
1F0 0 RC
1DD D RC
260 E RC
;

: SITTING
HEX
( HIPS RED )
240 B RC
250 8 RC
1DD 5 RC
200 10 RC
200 12 RC
200 2 RC

( HIPS BLACK )
DD A RC
CC 7 RC
300 4 RC
DD F RC
2FF 11 RC
2FF 1 RC

( KNEES )
2B0 9 RC
2B0 6 RC
1BB 3 RC
155 0 RC
145 D RC
2FF E RC
;

I was thinking the problem might be related to the sudden current draw required when moving all of the servo at once except for two things:

a) the IsoPod is using a completely isolated power supply from the servos so I'm not sure why it would reset and
b) It only happens when executing CENTER-ALL and then SITTING, not when executing a CENTER-ALL after an RCINIT for example.

If I cut & paste the contents of the SITTING function into NMITerm everything works fine as each call to move a servo is executed with what seems to be just
a slight pause between calls.

Anyone have any idea what I am doing wrong here?

Thanks,

Rob

Dave
04-07-03, 03:45 PM
Hi Rob,
The supply used on the robot isn't quite isolated, in that a single pack is supplying both regulators. In a similar hexapod running 18 servos, we've had a 4 cell pack connected to supply the IsoPod, and another 4 cell pack (unregulated) to supply servo power, with the grounds tied together. This would be the same weight as a single 9.6 pack and would allow better isolation from the current draw of many servos. Depending on what servos are running, current draw can be fairly substantual.

rcorreia
04-07-03, 04:01 PM
Hello Dave,

Sorry, I wan't to clear on that. I am actually using two seperate battery packs for the Robot. One for the Servos and another for the IsoPod.

The battery pack for the IsoPod is an unregulated 7 volt supply.

I'm not using a common ground though. (At least I don't think so) I'm not sharing the ground between the two battery packs.

Rob.

Dave
04-07-03, 04:41 PM
Thank you Rob,
for the extra information. A common ground between the 2 power sources should be used, otherwise the drive signals are not based on a common reference. It might work on a single servo, however under the load of several, the differing grounds could shift in reference to each other unless connected.

rcorreia
04-07-03, 04:45 PM
Sounds good. I'll give that a try!

Thanks for your help.

Rob.

rcorreia
04-09-03, 07:17 PM
Switching to a shared ground didn' t seem to solve the problem. I came across something else interesting after editing the code a bit.

It seems the file will download (into IsoMax) just fine until it gets to a certain line of code. The line of code itself doesn't seem to matter as I can add spaces, or extra methods before the problem, and the line on which it stops will remain the same. eg line 128 everytime.

It almost seems as though there is a hidden character or something similar screwing up the download. I also own a 68332 max-forth based board. I haven't used it in a while but I could have sworn I had a similar problem with it. I can't remember what I did to resolve it.

Any ideas anyone?

Rob.

Dave
04-10-03, 10:42 AM
Hi Rob,
Looking at the Annotated RC servo code posted here : http://www.newmicros.com/discussion/showthread.php?threadid=349 shows that it is loaded in flash with IN-EE and EEWORD. What is above posted appears to be loaded in RAM, which disappears when the IsoPod is no longer powered or resets. Perhaps loading all code, both addtional used for driving servos and the initialization code all in flash might work better. Loading in RAM may mean that once a glitch happens at line 128, there is no more room left in RAM to load additional code. On the Download page http://www.newmicros.com/store/product_details/download.html there are additional notes about IsoMax Flash & Autostart in the App notes Program section, as well as more at IsoMax - MaxFORTH about Autostarting and SAVE-RAM words. These additions may help. Each new load of course requires an initial SCRUB, but you should be able to rewrite 100,000 times. Perhaps posting the code could show any other possible problems.

rcorreia
04-10-03, 04:25 PM
Hi Dave,

Here is the complete Code listing, 95% of it was ripped off from another posting in the forum. I'll also try saving the functions into EE to see if that helps.

HEX

: HALFSPEEDCPU F413 FA1 ! 82 F00 ! ; ( DIV BY 2

HALFSPEEDCPU

C3 CONSTANT PWMCTL# ( DIV BY 8
( VARIABLE LOSTOP 4E2 LOSTOP !
VARIABLE LOSTOP 2E4 LOSTOP !

( VARIABLE HISTOP 9C4 HISTOP !
VARIABLE HISTOP B9A HISTOP !

VARIABLE PER# 5161 PER# ! ( 61A8 for 50 Hz, 5161 for 60 Hz

VARIABLE SCALE# 3E8 SCALE# !

: MIDWAY HISTOP @ LOSTOP @ + 2/ ;

: 8* 2* 2* 2* ; ( 8 * WITHOUT THE SPEED PENALTY

: SETPWM ( val n -- )
DUP 6 U<
IF
E00
ELSE
6 -
E20
THEN
>R R@ 6 + + ! R@ @ DROP PWMCTL# R> !
;

: SETTMRCMP ( val n -- ) 8* D00 + 2DUP 1+ ! PER# @ ROT - SWAP ! ;

: RCINIT
8000 E03 !
0 E0D !
0 E0E !
000E E0F ! ( CENTER ALIGN FOR DIV BY 2
PER# @ E05 !
8000 E23 !
0 E2D !
0 E2E !
000E E2F ! ( CENTER ALIGN FOR DIV BY 2
PER# @ E25 !

C 0
DO
MIDWAY I SETPWM
LOOP

C 0
DO
3824 I 8* D06 + ! ( DIVIDE BY 16 SAME AS PWM ASSUME HALFSPEED CPU
MIDWAY I SETTMRCMP
0001 I 8* D07 + !
LOOP
;

: RC ( COUNT FROM 0 TO SCALE#, THEN 0-11D PWM #
SWAP 0 MAX SCALE# @ MIN HISTOP @ LOSTOP @ - SCALE# @ */ LOSTOP @ + SWAP
0 MAX 1C MIN
DUP C U<
IF
SETPWM
ELSE
C - SETTMRCMP
THEN
;

: RC? ( COUNT --- SCALED VALUE
0 MAX 1C MIN
DUP C U<
IF
DUP 6 U< IF E06 ELSE E20 THEN +
ELSE
C - 8* D01 +
THEN
@ LOSTOP @ - SCALE# @ HISTOP @ LOSTOP @ - */
;


: CENTER-ALL
HEX
( HIPS RED )
240 B RC
250 8 RC
1DD 5 RC
200 10 RC
200 12 RC
200 2 RC

( HIPS BLACK )
1DD A RC
1D0 7 RC
300 4 RC

1D5 F RC
31A 11 RC
1F5 1 RC

( KNEES )
220 9 RC
240 6 RC
210 3 RC
1F0 0 RC
1DD D RC
260 E RC
;

: SITTING
240 B RC
250 8 RC
1DD 5 RC
200 10 RC
200 12 RC
200 2 RC

DD A RC
CC 7 RC
300 4 RC
DD F RC
2FF 11 RC
2FF 1 RC

2B0 9 RC
2B0 6 RC
1BB 3 RC
155 0 RC
145 D RC
2FF E RC
;
RCINIT
CENTER-ALL

Dave
04-10-03, 05:14 PM
Just loaded the above code onto a V2 IsoPod, IsoMax ver 0.5, under NMITerm 0.9.71, and got no errors, no aborts. Not sure what is wrong exactly, should also work with previous and newer versions of NMITerm and IsoMax back to version 0.3. I'm guessing the Abort-Continue buttons show up during download. At that point, there should be on screen something that has the problem word followed by a question mark like

PROB ?

as that word isn't in the dictionary or hasn't been previously defined. Perhaps there is a ( too close to something somewhere. Line 128 seems to be

260 E RC

which shouldn't be giving any problems, though perhaps the ; semicolon to complete the definition afterwards isn't getting in.

rcorreia
04-10-03, 05:36 PM
Dave,

I'm running IsoMax V 0.5.

I'm sure you have other things better to do but here is some more info. If I take the Hexopod code from your site when I try to load it, it stops at the LOOPVAR DL line. It complains about the DL I assume because it doesn't seem to be defined. So fine I remove that line, knowing that is needed within the machine definitions but I want to see how far it will load.

After removing the line I start it up again and then it stops at the line

ON-MACHINE-W

As with my code, it just stops. No complaint from IsoMax or NMiTerm. When I hit enter I am given the Abort/Continue option from NMiTerm. Continue doesn't work and then I have to abort the download and reset the IsoPod to carry on.

This is just bizarre. It seems almost like by removing those lines my text editor placed something else in the file that is screwing up the upload, I just don't see how that's possible, I mean it's just ASCII. At any rate the modified code that causes me problems is listed below.

( Program start )
HEX

: HALFSPEEDCPU F413 FA1 ! 82 F00 ! ; ( DIV BY 2

HALFSPEEDCPU

C3 CONSTANT PWMCTL# ( DIV BY 8
( VARIABLE LOSTOP 4E2 LOSTOP !
VARIABLE LOSTOP 2E4 LOSTOP !
( VARIABLE HISTOP 9C4 HISTOP !
VARIABLE HISTOP B9A HISTOP !
VARIABLE PER# 61A8 PER# ! ( 61A8 for 50 Hz, 5161 for 60 Hz
VARIABLE SCALE# 3E8 SCALE# !

: MIDWAY HISTOP @ LOSTOP @ + 2/ ;

: 8* 2* 2* 2* ; ( 8 * WITHOUT THE SPEED PENALTY

: SETPWM ( val n -- )
DUP 6 U<
IF
E00
ELSE
6 -
E20
THEN
>R R@ 6 + + ! R@ @ DROP PWMCTL# R> !
;

: SETTMRCMP ( val n -- ) 8* D00 + 2DUP 1+ ! PER# @ ROT - SWAP ! ;

: RCINIT
8000 E03 !
0 E0D !
0 E0E !
000E E0F ! ( CENTER ALIGN FOR DIV BY 2
PER# @ E05 !
8000 E23 !
0 E2D !
0 E2E !
000E E2F ! ( CENTER ALIGN FOR DIV BY 2
PER# @ E25 !
C 0
DO
MIDWAY I SETPWM
LOOP
C 0
DO
3824 I 8* D06 + ! ( DIVIDE BY 16 SAME AS PWM ASSUME HALFSPEED CPU
MIDWAY I SETTMRCMP
0001 I 8* D07 + !
LOOP
;

( INVERT PATTERN
( 0111 0000 1111 1100 0000
( RULE: > 6 AND < C OR > 16 AND < 19
( DECIMAL COUNT ON SERVOS
( RULE:: DUP 6 U< NOT OVER C U< AND
( RULE:: DUP 16 U< NOT OVER 19 U< AND
( RULE:: OR

: INVRC
DUP 6 U< NOT OVER C U< AND
OVER DUP 10 U< NOT SWAP 13 U< AND OR NOT
IF SWAP NEGATE SCALE# @ + SWAP THEN
;

: RC ( COUNT FROM 0 TO SCALE#, THEN 0-11D PWM #
INVRC
SWAP 0 MAX SCALE# @ MIN HISTOP @ LOSTOP @ - SCALE# @ */ LOSTOP @ + SWAP
0 MAX 1C MIN
DUP C U<
IF
SETPWM
ELSE
C - SETTMRCMP
THEN
;

( : RC? ( COUNT --- SCALED VALUE
( 0 MAX 1C MIN
( DUP C U<
( IF
( DUP 6 U< IF E06 ELSE E20 THEN +
( ELSE
( C - 8* D01 +
( THEN
( @ LOSTOP @ - SCALE# @ HISTOP @ LOSTOP @ - */
( ;

( : %PWM 64 MIN 0 MAX E05 @ 64 */ E07 ! E00 @ DROP C3 E00 ! ;
( : %PWMX
( 6 MIN 0 MAX >R ( limit channel and put away on return stack
( 64 MIN 0 MAX ( limit percent
( E05 @ 64 */ ( scale to PER#
( R> E06 + ! ( add channel # and install time
( E00 @ DROP C3 E00 ! ( force load
( ;

: -LOOPVAR

P@ DUP @ 0= IF DUP 1 + @ SWAP ! TRUE ELSE 1-! FALSE THEN ;

( ...continue )
DECIMAL

( 13 TILT DN TO UP
( 12 PAN RIGHT TO LEFT

( 2,1,0 9,10,11
( 5,4,3 6,7,8
( 17,18,19 14,15,16

( 900 CONSTANT 900
( 100 CONSTANT 100
600 CONSTANT UP
400 CONSTANT DN

: SL ( SHOULDERS LEFT TRIPOD
DUP 9 RC
DUP 3 RC
16 RC
;

: SR ( SHOULDERS RIGHT TRIPOD
DUP 6 RC
DUP 19 RC
0 RC
;

: KL ( KNEES LEFT TRIPOD
DUP 10 RC
DUP 15 RC
4 RC
;

: KR ( KNEES RIGHT TRIPOD
DUP 7 RC
DUP 18 RC
1 RC
;

: LL ( LEGTIPS LEFT TRIPOD
DUP 11 RC
DUP 14 RC
5 RC
;

: LR ( LEGTIPS RIGHT TRIPOD
DUP 2 RC
DUP 8 RC
17 RC
;


MACHINE W
ON-MACHINE W
APPEND-STATE W0
APPEND-STATE W1
APPEND-STATE W2
APPEND-STATE W3
APPEND-STATE W4
APPEND-STATE W5
APPEND-STATE W6

IN-STATE W0
CONDITION TRUE
CAUSES RCINIT
THEN-STATE W1
TO-HAPPEN

IN-STATE W1
CONDITION DL
CAUSES UP SL DN SR UP 12 RC
THEN-STATE W2
TO-HAPPEN

IN-STATE W2
CONDITION DL
CAUSES DN KL
THEN-STATE W3
TO-HAPPEN

IN-STATE W3
CONDITION DL
CAUSES UP KR
THEN-STATE W4
TO-HAPPEN

IN-STATE W4
CONDITION DL
CAUSES DN SL UP SR DN 12 RC ( S4
THEN-STATE W5
TO-HAPPEN

IN-STATE W5
CONDITION DL
CAUSES DN KR ( S1
THEN-STATE W6
TO-HAPPEN

IN-STATE W6
CONDITION DL
CAUSES UP KL ( S1
THEN-STATE W1
TO-HAPPEN

W0 SET-STATE ( INSTALL
DECIMAL
EVERY 10000 CYCLES SCHEDULE-RUNS W

Dave
04-10-03, 06:06 PM
hEY rOB (Don't ya love typing in cap locks?)
I loaded the above program and got the same error, stopping at the ON-MACHINE W section. Then I tried loading just the initial code, before the state machine section, loaded fine, also loaded just the state machine section (using COLD to clear RAM), loaded fine (with errors for undefined words). If loading the top section without the state machine, then typing WORDS to see what's there, it shows 7FF2 as the address of the last WORD defined. Anything more being attempted to load into RAM will lock up, and erase what you already have. So it locks when attempting to define the machine afterwards. It seems using the EEWORD and IN-EE to get the program to flash should help out. The downloads on the Page above should help get things into flash, including the Autostart, App note and SAVE-RAM texts.

rcorreia
04-10-03, 11:15 PM
Hey Dave,

So is this an IsoMax .5 memory management bug?

It sounds like it would probably do this with any code.

Rob.

RMDumse
04-11-03, 07:17 AM
There is limited RAM on the chip. When you're out your out. But the RAM really wasn't intended to hold programs per sa. It was meant to develop a new word until you were happy with it, then send it to Flash for storage. This frees the RAM for reuse for the next word.

EEWORD relinks the last definition and moves it to Flash. RAM is reallocated.

(History of the word: was created on the HC11 which has EEPROM and not Flash so the name became EEWORD.)

It's a bit amazing you can put so many definitions in such a small amount of RAM. But the ultimate goal is to get it into Flash, where it can be autostarted, and run every time the board powers up.

rcorreia
04-11-03, 10:53 AM
Hey, that works for me.

I'm just stuck in the mindset of some past boards I've used that had a crap load of RAM but no EEPROM. I can move pretty well all that code into the EEPROM.

Thanks you both for your help!

Rob.