PDA

View Full Version : Problem saving program


Newbie
04-29-04, 06:58 AM
I am trying to save my program to IsoPod, but everytime I cut off power and reapply, the program starts ok, but the values being output are wrong. Any idea what could be wrong? Missing an EEWORD? The program works fine if I just send it to the IsoPod and start it, but as soon as turn it off and back on, it gets messed up again.

HEX

: DSP8@ ( -- d )
00 FC2 !
PA1 ON
PA2 ON
FC1 @
PA2 OFF
; EEWORD

: DSP8! ( d -- )
FF FC2 !
PA1 OFF
FC1 !
PA2 ON
PA2 OFF
; EEWORD

: CMD> ( -- d ) PA0 OFF DSP8@ ; EEWORD
: LCD> ( -- d ) PA0 ON DSP8@ ; EEWORD
: WNB ( -- ) BEGIN CMD> 80 AND 0= ?TERMINAL OR UNTIL ; EEWORD
: >CMD ( d -- ) PA0 OFF DSP8! WNB ; EEWORD
: >LCD ( d -- ) PA0 ON DSP8! WNB ; EEWORD

: DSP-INIT ( -- )

3F FB1 !
7F FB2 !
0 FB3 !
FF FC1 !
FF FC2 !
0 FC3 !

38 >CMD
38 >CMD
6 >CMD
F >CMD
C >CMD
1 >CMD
80 >CMD
; EEWORD

: CLEAR WNB 1 >CMD ; EEWORD
: HOME WNB 2 >CMD ; EEWORD
: CRLF WNB C0 >CMD ; EEWORD
: MOVE-CURSOR WNB 80 OR >CMD ; EEWORD
: RIGHT-UPPER-CORNER 27 MOVE-CURSOR ; EEWORD
: CURSOR? WNB CMD> 7F AND ; EEWORD
: DSP>L WNB 10 >CMD CURSOR? 27 > IF RIGHT-UPPER-CORNER THEN ; EEWORD
: DSP>R WNB 14 >CMD CURSOR? 27 > IF HOME THEN ; EEWORD

: DSP-EMIT WNB >LCD ; EEWORD

: DSP-SPACE BL DSP-EMIT ; EEWORD
: DSP-SPACES 0 MAX BEGIN ?DUP WHILE 1- DSP-SPACE REPEAT ; EEWORD

: DSP-TYPE
BEGIN
DUP 0= NOT
WHILE
1- SWAP DUP C@ DSP-EMIT 1+ SWAP
REPEAT
2DROP
; EEWORD

DECIMAL
: .DSP ( n -- ) DUP ABS 0 <# #S SIGN #> DSP-TYPE ; EEWORD
: 2.DSP ( n -- ) DUP ABS 0 <# # # 46 HOLD #S SIGN #> DSP-TYPE ; EEWORD

PHERE
0 P,
0 P,
0 P,
0 P,
0 P,
0 P,
0 P,
0 P,
31500 P,
27000 P,
22500 P,
18000 P,
13500 P,
9000 P,
4500 P,
000 P,
CONSTANT CONV-TBL-GRAY2DEC EEWORD

VARIABLE DEG
-1 ALLOT
5 ALLOT
DEG 5 ERASE
CR DEG 5 EXPECT
DEG:
EEWORD

VARIABLE FSECS
-1 ALLOT
7 ALLOT
FSECS 7 ERASE
CR FSECS 7 EXPECT
FSECS:
EEWORD

VARIABLE SAFE
-1 ALLOT
8 ALLOT
SAFE 8 ERASE
CR SAFE 8 EXPECT
SAFE
EEWORD

VARIABLE NTE
-1 ALLOT
7 ALLOT
NTE 7 ERASE
CR NTE 7 EXPECT
NTE
EEWORD

VARIABLE VER
-1 ALLOT
11 ALLOT
VER 11 ERASE
CR VER 11 EXPECT
VERSION 1.0
EEWORD

VARIABLE NUM1 EEWORD
VARIABLE NUM2 EEWORD
VARIABLE VOLTAGE EEWORD

: GETDATA
PORTA GETBYTE
2/ 2/ 2/ 2/
CONV-TBL-GRAY2DEC + P@
; EEWORD

: BOOTSCREEN
REDLED OFF GRNLED OFF YELLED OFF
DSP-INIT
NTE 7 DSP-TYPE
CRLF
VER 11 DSP-TYPE
; EEWORD

: BATTLOW
DECIMAL
ADC0 ANALOGIN
VOLTAGE !
DROP
VOLTAGE @ 20000 <
IF
PWMA1 ON
ELSE
PWMA1 OFF
THEN
; EEWORD

: DEGREES
GETDATA
NUM1 !
DROP
; EEWORD

: COMPARE
BATTLOW
NUM2 @ NUM1 !
GETDATA
NUM2 !
NUM2 @ 560 <
NUM2 @ NUM1 @ = NOT
AND
IF
DSP-INIT
SAFE 8 DSP-TYPE
DEGREES
THEN
NUM2 @ NUM1 @ = NOT
IF
DSP-INIT
DEG 5 DSP-TYPE
NUM2 @ 2.DSP
CRLF
FSECS 7 DSP-TYPE
NUM2 @ 7 / 2.DSP
DEGREES
THEN
; EEWORD

LOOPINDEX 2SEC/100
1 2SEC/100 START
200 2SEC/100 END
EEWORD

MACHINE 2SEC EEWORD
ON-MACHINE 2SEC
APPEND-STATE WAIT2S EEWORD
APPEND-STATE DO-COMPARE EEWORD

IN-STATE
WAIT2S
CONDITION
2SEC/100 COUNT
CAUSES
( NOTHING, REALLY
THEN-STATE
DO-COMPARE
TO-HAPPEN IN-EE

IN-STATE
DO-COMPARE
CONDITION
TRUE
CAUSES
COMPARE
THEN-STATE
DO-COMPARE
TO-HAPPEN IN-EE

: STARTUP
DECIMAL
PWMA0 ON
BOOTSCREEN
2SEC/100 RESET
50000 PERIOD
ISOMAX-START
WAIT2S SET-STATE
INSTALL 2SEC
; EEWORD

SAVE-RAM

RMDumse
04-29-04, 07:47 AM
Originally posted by Newbie
I am trying to save my program to IsoPod, but everytime I cut off power and reapply, the program starts ok, but the values being output are wrong. Any idea what could be wrong? Missing an EEWORD? The program works fine if I just send it to the IsoPod and start it, but as soon as turn it off and back on, it gets messed up again.


Yes, this looks like a tricky one. It well might be a missing EEWORD, a very typical way to loose operation between a download and a power cycle. But... I've been through the obvious places and not seen any missing. (VARIABLEs are very often overlooked.)

But problems like that usually crash the operation, because a word that was left in RAM isn't there after power cycling, so when the program goes to that address to execute... nothing makes sense and the program gets lost.

In any case, you can do a WORDS listing and look for addresses which are out of order, in the RAM locations, rather than the FLASH locations, to have a final verification on whether all the words made it to Flash or not.

So I suspect this one is something else, because you operate (not crash) but don't have the right values. Certainly variables are not initialized and I don't see you specifically setting them. You might put

0 NUM1 !
0 NUM2 !
0 VOLTAGE !

in STARTUP to be sure the variables always come up with the same values in them.

BTW, I see the SAVE-RAM statement. Where's the AUTOSTART? Or are you just typing STARTUP after the power cycle to get going?

Newbie
04-29-04, 08:21 AM
You might put
0 NUM1 !
0 NUM2 !
0 VOLTAGE ! in STARTUP to be sure the variables always come up with the same values

This is something I had already thought of and tried out, but it didn't change anything, so I left it out.

In any case, you can do a WORDS listing and look for addresses which are out of order, in the RAM locations, rather than the FLASH locations, to have a final verification on whether all the words made it to Flash or not.

I have just done this, and it appears everything made it to flash ok.

BTW, I see the SAVE-RAM statement. Where's the AUTOSTART? Or are you just typing STARTUP after the power cycle to get going?

Yes, I'm just typing STARTUP, as I didn't want it to autostart until I was sure everything was ok with the program.

Any other ideas? Could it be a problem with the lookup table for my encoder. The weird thing is that the look up table has whole numbers in increments of 4500 (45.00 after scaling), like 45, 90, 135, etc. for degrees, but after cycling power, it comes up with values like 35.06, 55.31.

RMDumse
04-29-04, 08:35 AM
Ah! Good hint. Notice at the top of your program you put the system in HEX. But at power up, it will be in DECIMAL. Try including HEX in your STARTUP.

OR

Try to change the CONV-TBL-GRAY2DEC to DECIMAL when loading it, then return to HEX again for the rest of your program.

You see the problem? CONV-TBL-GRAY2DEC is not DEC at all, but is entered as HEX.

Newbie
04-29-04, 09:13 AM
I'm sorry, I'm still a little confused as to where to enter HEX. I put it as the first line in STARTUP and tested it, and it did the same thing. I also tried typing DECIMAL right before the lookup table and HEX right after it, which also did not change anything. Is this what you meant, or am I a total noob?

Newbie
04-29-04, 09:48 AM
Another thing I forgot to mention is that each time I run the program, the numbers it outputs are different. There is no consistency, and no noticeable pattern. Everytime I cycle power, it gives me different numbers.

RMDumse
04-29-04, 09:55 AM
Naw, my bad. In the Navy we used to say, "Belay my last" when we made a mistake in communications.

I was too anxious to think I'd found the problem. I missed the DECIMAL above .DSP so none of the HEX/DECIMAL suggestions I just made were useful, however, sounds like you did what I asked okay anyway, but it didn't help.

So we're back in head scratching mode...

Newbie
04-30-04, 08:00 AM
I'm still thinking it might be a problem with that conversion table, i'm just not sure what that problem is. Could you explain how the table works to convert grey code, as I don't really understand that part that well. What I'm trying to do is take this 8 position encoder and assign angle values to each position.

EDIT: It acts like it's not even using the table. I changed all the values in the table and reran the program, and the results stayed the same.

RMDumse
04-30-04, 12:38 PM
I think you're right. It's the table. I bet the table changes after a power cycle. Add this to your source code before the SAVE-RAM and try it to be sure the table is in place. Then power cycle, and try using it again.

: TBL 16 CONV-TBL-GRAY2DEC DUMP ; EEWORD

I bet I mislead you on the way EEWORD worked (or put another way, EEWORD works different in this version of the language as compared to the last).

Let's rebuild the table another way


0 CONSTANT CONV-TBL-GRAY2DEC
0 P,
0 P,
0 P,
0 P,
0 P,
0 P,
0 P,
31500 P,
27000 P,
22500 P,
18000 P,
13500 P,
9000 P,
4500 P,
000 P,
EEWORD

This way we create the constant 0 at the address CONV-TBL-GRAY2DEC and follow it with 15 more constants. We move the whole thing into Flash with EEWORD.

Let me know...

Newbie
05-03-04, 07:07 AM
Unfortunately, the new table didn't work. It appears that the only time it is actually using the table is the first time I load the original code, and if I have the CONSTANT CONV-TBL-GRAY2DEC EEWORD after the table. Otherwise, such as when I try the new table, instead of taking values from it, it just spits out 321.48, SAFE, 321.46, SAFE, 321.44, etc... The only time I can actually get the numbers to change is if I change the 0 in front of CONSTANT to a different number. For instance, if I changed it to 10, it spit out 321.52, SAFE, 321.50, etc. I have no idea where the 321.XX is coming from, it gives me this even if I change all the numbers in the table to 0. I'm so confused :confused:

nmitech
05-03-04, 12:03 PM
You may create your constant table this way also. Please see this related link,

http://www.newmicros.com/discussion/showthread.php?postid=2931

Newbie
05-03-04, 12:18 PM
Thanks! It works! Finally! I love you! (in a strictly platonic way) Thanks to all for the help.

Newbie
05-04-04, 01:05 PM
I may have spoken too soon. The program was working good yesterday (with limited testing), but today it is only working about 50% of the time. Half the time it acts normally, and half the time the bootscreen comes up, then the first position is displayed, and then it freezes up. I tried going back and looking for maybe a stack overflow or something, but didn't see anything obvious (at least not to me). Any ideas?

RMDumse
05-04-04, 01:11 PM
I haven't delved into it deeply, but just to mention something to look at...

: DEGREES
GETDATA
NUM1 !
DROP
; EEWORD

Doesn't GETDATA return one value on stack? which NUM1 ! consumes, so what is the DROP for?

Newbie
05-05-04, 08:06 AM
Thanks Randy, it's now working as normal again. I had two DROP's in there that didn't need to be there. Thanks again for all your help.