PDA

View Full Version : IsoMax Control Flow


hotstepper
07-21-04, 03:57 PM
Hi

My application demands that I call a specific sub-routine when certain conditions are satisfied. To check for the program structure, I have tried a sample program where I toggle the LEds based on what input I recieve over the serial port. The program works fine, but I have observed that it sometimes get stuck in a sub-routine and the control is not returned back to the calling routine as expected.

What I am trying to do is, toggle the RED, GRN, YEL LEDs based on the inputs from the keyboard ( simulating data recieved on the serial port ) letters R, G, Y respectively. Now, according to my code on pressing any of these keys once the corresponding LED has to blink. There is a delay between switching the LED OFF and switching it ON again. The delay statement used has been picked up from a sample program downloaded from this site. On running the program continuously it sometimes happens that it gets stuck in any of the sub-routines. I say this as the LED doesnt toggle and successive inputs are just ignored. Can you please go through the program code and let me know where I am going wrong.

------------------------------------------------------------------------------------
VARIABLE X

MACHINE MAC
ON-MACHINE MAC
APPEND-STATE ST1
APPEND-STATE ST2


: WAIT ( -- ) TCFTICKS @
BEGIN
TCFTICKS @ OVER -
100 > UNTIL
DROP
; EEWORD

: LOOPRED
REDLED OFF
WAIT
REDLED ON
; EEWORD

: LOOPGRN
GRNLED OFF
WAIT
GRNLED ON
; EEWORD

: LOOPYEL
YELLED OFF
WAIT
YELLED ON
; EEWORD


IN-STATE ST1
CONDITION
CAUSES SCI0 RX X !
THEN-STATE ST2 TO-HAPPEN

IN-STATE ST2
CONDITION
CAUSES X @ 71 = IF
LOOPGRN
THEN

X @ 89 = IF
LOOPYEL
THEN

X @ 82 = IF
LOOPRED
THEN
THEN-STATE ST1 TO-HAPPEN

: START
SET-STATE ST1
INSTALL MAC
EVERY 5000 CYCLES SCHEDULE-RUNS MAC
;

------------------------------------------------------------------------------------
I also have doubts about the WAIT routine. I have gone through the explanation for TCFTICKS in the manual and tried changing the period to 50000 using

DECIMAL 50000 PERIOD

and there by giving a value of 600 in the WAIT routine, to count 6seconds. But, my observation says that the WAIT routine holds for no more than 2 seconds at this value. Can you please help me out with this as well, I mean how do I exactly measure 1 second programatically using IsoMAx.

Thanks

Hotstepper

nmitech
07-22-04, 04:02 PM
I have afew comments about your program,

1. SET-STATE ST1 will cause compiling error when download. It should be ST1 SET-STATE

2. 5000 CYCLES produces 1000 Ticks intead of 100. You can leave 100 ticks in the WAIT routine and change the CYCLES to 50000, either way. If you have it right, you won't miss any second, maybe afew milliseconds

3. Try to use EEWORD, IN-EE for all variables, new definitions, machines, and states such as
VARIABLE X EEWORD

MACHINE MAC EEWORD
ON-MACHINE MAC
APPEND-STATE ST1 EEWORD
APPEND-STATE ST2 EEWORD

THEN-STATE xxx TO-HAPPEN IN-EE

or not to use any "EE" words at all, else partial of your program will be loaded in ram and partial will be loaded in flash and if you forget to SCRUB it before you load the new program then you will expecting some weird behaviors and eventually program will crash. I would recommend to use "EE" words to avoid later you may scratching the head when all the certain the program won't download by adding afew more lines to the program. Just makesure to added "SCRUB" to the beginning of your program for it to erase the previous program in flash each time you start a new download.

4. Maybe you should use the LOOPINDEX to replace the WAIT loop, or the inputs will be ignored during 1 second delay loop, WAIT.