INx Question
8136mike
Posts: 2
I have a loop in which I want to continually monitor two inputs, IN3 & IN13. But not both INs at the same time. One time the loop will be set up to monitor IN3 another time IN13. How can I change a 3 to 13 or 13 to 3 prior to the loop starting something like:
x var word
x = 3
loop:
if INx = 1 then do something
pause 3000
etc
etc
goto loop
I thought I could do it by saying x = 3 or x = 13, however INx will not compile.
I'm using Stamp 2.0. Do I need 2.5?
x var word
x = 3
loop:
if INx = 1 then do something
pause 3000
etc
etc
goto loop
I thought I could do it by saying x = 3 or x = 13, however INx will not compile.
I'm using Stamp 2.0. Do I need 2.5?
Comments
x = IN3
if x = 1 then do something
IF (INS >> (10*X + 3)) & 1 = 1 THEN
There are other ways to do the same thing, but this is the most straightforward.
The variable x is an offset in bits from in0, so in0(0) is the same as in0, and in0(13) is the same as in13.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Would you tell me where the INS bits can be accessed by an index as you mentioned? I just looked in the programming guide and am unable find it.
Regards,
DJ
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If you DEBUG INS(3), you will get the current value of W0, three up in the array of words. The index is sequential, small-endian. That also applies to the array of 256 bits. IN0 refers to the least significant bit of INS, and also to the least significant bit of the 256 bit memory array. So IN0(13) is the same as IN13. IN0(255) is the same as W12.bit15. The array is a bit array because IN0 is a bit. When referring to INS(3) it was a word, because INS is a word.
The offset can start anywhere in the array. For example, IN3(10) is also the same as IN13.
This sort of addressing is the same across the Stamp 2 family; very useful, despite being somewhat of a "secret".
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thanks for the reply. Both of your recommendations are just what I need. I did not mention in my initial inquiry, but I wanted to use only one line of code to look at IN3 or IN13 as it went though the loop. I had a solution with doing a skip a line routine but wanted to use only one line of code for efficiency purposes.
Thanks again.
8136mike
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
where x is 1 or 2 (%00000001 or %00000010)
so Case 1 = in1 high when x=2
Case 2 = in0 high when x=1
Case 0 = in0 or in1 = 0 when x = 1 or 2
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
Post Edited (metron9) : 5/19/2010 8:54:56 PM GMT
...wow! I never would have made that connection based on the material at hand.
I'm going to print your answer and stick it in the INS section of the manual.
Thanks again,
DJ
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My solution only uses one statement to both compare and branch as Tracy's and Mike's solution however my solution allows branching to multiple address for multiple inputs with one statement.
I also would note the speed of Mike's solution may be slower as it involves multiplication shifting and Boolean logic to make the branch.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!