View Full Version : LOOPVARS Syntax
g_jilek
12-30-02, 01:47 PM
I’ve been going through the examples in the IsoPod manual and I’ve come upon a snag. The code for the BLINKGRN example does not function for me. The Pod does not want to define the variables with the code “100 0 LOOPVAR CNT”. Is there something that I’m missing here? I haven’t tried to put in the grayed-out code. Ok it liked the grayed out code. Why did I have to use the grayed-out code? I used WORDS to download the POD’s word list and I saw that the word LOOPVARS was listed. Using this word did not work either. What is the proper IsoMax syntax for –LOOPVAR, LOOPVAR or LOOPVARS to define the variable CNT?
g_jilek
01-03-03, 01:34 PM
I've been playing with the Pod for the past few days and the grayed text
: LOOPVAR <BUILDS HERE P, 1- DUP , , DOES>
P@ DUP @ 0= IF DUP 1 + @ SWAP ! TRUE ELSE 1-! FALSE THEN ;
along with
50 LOOPVAR CNT
provides the proper syntax for this type of delay. This code also seems to be able to build a number of different count and decrement variables. The following modification to BLINKGRN shows this.
BLINKGRN+
MACHINE BLINKGRN+
ON-MACHINE BLINKGRN+
APPEND-STATE BG1
APPEND-STATE BG2
: -LOOPVAR <BUILDS HERE P, 1- DUP , , DOES>
P@ DUP @ 0= IF DUP 1 + @ SWAP ! TRUE ELSE 1-! FALSE THEN ;
100 -LOOPVAR CNT
: -LOOPVAR1 <BUILDS HERE P, 1- DUP , , DOES>
P@ DUP @ 0= IF DUP 1 + @ SWAP ! TRUE ELSE 1-! FALSE THEN ;
400 -LOOPVAR1 CNT1
IN-STATE BG1 CONDITION CNT
CAUSES GRNLED OFF THEN-STATE BG2 TO-HAPPEN
IN-STATE BG2 CONDITION CNT1
CAUSES GRNLED ON THEN-STATE BG1 TO-HAPPEN
BG1 SET-STATE INSTALL BLINKGRN+
EVERY 12500 CYCLES SCHEDULE-RUNS BLINKGRN
nmitech
01-03-03, 02:21 PM
g_jilek,
LOOPVARS is built-in V0.3 word, but it uses as static declaration, FROM n TO n BY COUNTER-IS name (or perhaps LOOPVAR name), with three methods:
name RESET ...resets the counter to its starting (FROM) value
name VALUE ...returns the current value of the counter
name COUNT ...adds incremented to counter, and returns end-of-count flag
LOOPVAR word is not yet implement in V0.3 so you may use the gray text for now or similarly you can do this,
eg.
FROM 100 TO 0 BY -1 COUNTER-IS CNT
IN-STATE
BG1
CONDITION
CNT COUNT
CAUSES
GRNLED OFF
THEN-STATE
BG2
TO-HAPPEN
.......
g_jilek
01-03-03, 05:19 PM
nmitech
Thanks for the reply.
I'm new to Forth and Forth-Based programming and I'm still feeling a bit bewildered by its structure. The IsoMax state machines make sense to me, but I have run into a bit of a head scratcher.
I wrote a couple of machines using the onboard LED's.
The first one I did was a single switch toggle, File: REDTOG. This one worked out ok, the LOOPVAR is not really necessary but is there as a debounce.
The next one I attempted was an interlocking switching array. I also got this one working. File: INTERLOCKEDLEDS2. I included a feature to cancel all the LED's by pressing any two of the switches. The only problem with this was that it would sometimes turn on another LED before they were canceled, so I attempted to put a delay on the switches so that the cancel would take precedence over turning on another LED. I haven't been able to make the machine function. File: INTERLOCKEDLEDS4. The code will load ok and initialize but as soon as a button is pressed the Pod will lock-up or re-boot or sometimes it will send back a lowercase y with an oomlout over it. Any help you can give me would be appreciated.
Gerard Jilek
nmitech
01-03-03, 06:22 PM
g_jilek,
Please zip those files and email to me at nmitech@newmicros.com. Somehow the forum does not allow to upload the attachment files for some reasons.... They all 0 byte files.
g_jilek
01-03-03, 09:58 PM
Here is a much simpler single switch toggle using the Word TOGGLE.
MACHINE LEDTOGGLE
ON-MACHINE LEDTOGGLE
APPEND-STATE LEDTOG
APPEND-STATE TOGINT
APPEND-STATE WAIT
IN-STATE TOGINT CONDITION REDLED ON? REDLED OFF? OR
CAUSES REDLED OFF THEN-STATE LEDTOG TO-HAPPEN
IN-STATE LEDTOG CONDITION PB5 OFF?
CAUSES REDLED TOGGLE THEN-STATE WAIT TO-HAPPEN
IN-STATE WAIT CONDITION PB5 ON?
CAUSES THEN-STATE LEDTOG TO-HAPPEN
TOGINT SET-STATE INSTALL LEDTOGGLE
EVERY 50000 CYCLES SCHEDULE-RUNS LEDTOGGLE
Also here are previous files attached as a Zip file.
g_jilek
01-06-03, 03:28 AM
I had planned to next use the interlocked LEDs to experiment with the TRINARIES, but when I upload the statement the Pod returns AT-ADDRESS ?. I've used the address listed in the manual for the GPIO and I've tried some of the addresses listed in the WORDS dump. Nothing gets past the AT-ADDRESS portion of the statement.
Thank you for any assistance you can give me.
Gerard Jilek
nmitech
01-06-03, 12:29 PM
AT-ADDRESS ?
The correct word is AT-ADDR
eg.
DEFINE LED CLR-MASK 01 SET-MASK 02 AT-ADDR FB1 FOR-OUTPUT
nmitech
01-07-03, 11:08 AM
g_jilek, this post is regarding to your programs INTERLOCKEDLEDS2 & INTERLOCKEDLEDS4. Both of your programs contain CONDITION(s) has more than two values to compare but only used a single boolean expression, OR/AND. This will leave extra value(s) on stack each time the STATE is processsed; therefore the stack will blow up at some points and this will cause the program crash. Look at your CONDITION(s) below,
IN-STATE ISAINT
CONDITION REDLED ON? YELLED ON? GRNLED ON? OR
CAUSES REDLED OFF YELLED OFF GRNLED OFF
THEN-STATE LEDSOFF
TO-HAPPEN
it should read,
IN-STATE ISAINT
CONDITION REDLED ON? YELLED ON? OR GRNLED ON? OR
CAUSES REDLED OFF YELLED OFF GRNLED OFF
THEN-STATE LEDSOFF
TO-HAPPEN
Another example,
IN-STATE PBREL
CONDITION CNT PB5 ON? PB6 ON? PB7 ON? AND
CAUSES THEN-STATE LEDSOFF
TO-HAPPEN
it should read,
IN-STATE PBREL
CONDITION CNT PB5 ON? AND PB6 ON? AND PB7 ON? AND
CAUSES THEN-STATE LEDSOFF
TO-HAPPEN
g_jilek
01-07-03, 11:28 AM
nmitech
Thank you. The info helped a lot.
g_jilek
vBulletin v3.0.7, Copyright ©2000-2012, Jelsoft Enterprises Ltd.