Shop OBEX P1 Docs P2 Docs Learn Events
waitpeq need help to understand State? - Mask? — Parallax Forums

waitpeq need help to understand State? - Mask?

Using Propeller manual v1.0 page 326. The state part compares the pin(s) against? another pin? Mask is the pin to monitor? I used this program.
CON
_clkmode = xtal1 + pll16x_clkfreq = 5_000_000
PUB start
dira[0]:= 1dira[2]:= 0
dira[3]:= 0repeat
waitpeq(%0100, %1100, 0)outa[0]:= 1
I have buttons wired up for pins 2 and 3 and the led lights up when the right combination of buttons is pushed. I an under the idea that %0100 is " = " to the pin #2 on the 40 pin chip with zero pin " = " to pin #one. When I change the pins to pin # 5 %1011 and pin #6 %0110 also dira[5]:= 0 and dira[6]:= 0. No led lights when I push buttons? Having trouble understanding State and Mask commands. I have read through the two pages that ex plane the command but still not getting it. The person who wrote this explanation needs to under stand that "me not so smart". This person needs to turn off some of there higher level logic functions to bring themselves down to my level which could kill them. Better explanation (simpler) for me. Thank you very much.

Comments

  • CON
    _cklmode = xtal1 + pll16xcklfreq = 5_000_000
    PUB start
    dira[0]:= 1dira[2]:= 0
    dira[3]:= 0repeat
    waitpeq(%0100, %1100, 0)outa[0]:= 1
    This is the program. something happened when I send the post???

  • COM
    ''' _clkmode = xtal1 + pll16x
    '''_clkfreq = 5_000_000
    PUB start
    ''' dira[0]:= 1
    ''' dira[2]:= 0
    '''dira[3]:= 0
    '''repeat
    ''''''waitpeq(%0100, %1100, 0)
    ''''''outa[0]:= 1

  • Let me confuse you even more!

    I have this 5 position switch from parallax 5-position-switch/ connected to pins 11 through 15.

    I use "waitpne" to pause execution of the program until the switch is used. Then I grab the state and use "waitpeq" to pause execution until the switch is released.

    #include "simpletools.h"
    
    #define PINS 15
    
    
    int main()
    {
      int i;
      int x;
      int t;
    
      i = 0x1f;
      x = i << 11;
    
      t = 0;
      while (1)
      {
        waitpne(x, x);
        i = input(PINS) | (input(PINS-1) << 1) | (input(PINS-2) << 2) | (input(PINS-3) << 3) | (input(PINS-4) << 4);
        if (i != 0x1f)
        {
          if ((i & 0x01) == 0)
            printi("Pin 15\n");
          if ((i & 0x02) == 0)
            printi("Pin 14\n");
          if ((i & 0x04) == 0)
            printi("Pin 13\n");
          if ((i & 0x08) == 0)
            printi("Pin 12\n");
          if ((i & 0x10) == 0)
            printi("Pin 11\n");
          printi("Button: %x\n", i);
          waitpeq(x, x);
        }
        printi("Loop: %d\n", t++);
        pause(1000);
      }
    
      while(1)
      {
        pause(1000);    
      }  
    }
    

    So my bit pattern is 11111 or 0x1f in hex. Now I need to move it two pins 11 through 15 so I shift the value left 11 positions to make the mask equal the pins and equals pattern. In this case when the switch is not used all the pins are pulled high.

    As soon as the switch is used the pattern no longer equals 0x1f and execution continues.

    The value of x is 0x3e0000 or 4,063,232.

    Mike

  • AribaAriba Posts: 2,690
    edited 2023-03-29 21:13

    every bit in the mask and the state corresponds to a pin. bit0 to P0, bit1 to P1 and so on.

    The mask parameter defines which pins are used and which not. If you set the corresponding bit to '1' the pin state is read, if you
    set it to '0' the pin is not used and the state bit for this pin is always '0'.

    The state parameter defines what state you want for every used pin. Not used pins state bits must be '0'. For the used pins you can define
    if they need to be '1' or '0' to terminate the wait.

    If you use WAITPEQ it waits until the used pins have the state you define. If you use WAITPNE it waits until they have not the given
    state.

    In your code example, you use P2 and P3. And your state parameter says: P2 must read '1' and P3 must read '0':

    CON
      _cklmode = xtal1 + pll16x
      _cklfreq = 5_000_000
    
    PUB start
      dira[0]:= 1
      dira[2]:= 0
      dira[3]:= 0
      repeat
        waitpeq(%0100, %1100, 0)
    '      P3==0_||     ||_P2 used
    '       P2==1_|     |_P3 used  (others read always 0)
    '
        outa[0]:= 1
    

    Andy

  • Still not getting it. Waitpeq(State, Mask, Port). Page 326 Propeller Manual V1.0 Explanation "Wait for Pin(s) to equal," I am assuming using binary % to tell the Propeller what pin or pins to keep an eye on. Pin three := 1100 and Pin two:= 0100. The Waitpeq will wait for the pins given to be Positive - Positive or Negative - Negative. I am using the 40 pin propeller so Port would be 0 or A. I do not under stand Pins. It looks like it can handle only two pins at a time? This program works (I do not know why???). If I change the numbers Five:= %1010 and eleven:= %1101 and change dira[5]:= 0 and dira[11]:= 0 nothing happens??? Any simple input would be welcome. Thank you very much. 3 apr 2023(mon)

  • The P1 has 32 pins and each pin is a bit position in the register and not the pin number. So pin 1 or P0 is bit position 0.

    If the switch is using pin 4 or P3 you need to set the mask to that position %00000000000000000000000000001000.

    If another switch is using pin 19 or P14 you need to set mask to that position %00000000000000000100000000001000.

    Now the state needs to match the mask pattern or it will wait for forever. This is a mask where you want P14 low and P0 high: %00000000000000000000000000001000.

    Binary numbers start from the Right and go Left so Pin 0 and 2 would be: %0101 or 0x05 in hex or 5 in decimal which is loaded into the register for comparison.

    Calculating this by hand can be confusing so by using the shift operator it makes it easy to get the mask into the right spot.

    For example I need to test pin 19 or P14 so I would use %1 << 14 to move the 1 over 14 positions to the left %100000000000000.

    Mike

  • JonnyMacJonnyMac Posts: 9,102
    edited 2023-04-03 21:48

    Sometimes you have to hear a thing from a few angles before "Aha!"
    -- state is what you're looking for
    -- mask is applied (ANDed) to ina[31..0] (the result is compared with state).

    If you have

      waitpeq(%1010, %1111, 0)
    

    ...the code will hold here until ina[3..0] are equal to %1010 (P0 low, P1 high, P2 low, P3 high)

    The purpose of mask is to isolate the pins you want to consider. The purpose of state is to describe the level of each pin being considered.

  • waitpeq(state,mask,0) is really just a (hardware magic accelerated) shorthand for

    repeat until (ina & mask) == state
    
  • And waitpne(state,mask,0) is shorthand for

    repeat until (ina & mask) <> state

    That is sometimes what you want instead of the complementary waitpeq.

    waitpne(%0100, %1100,0)
    Drops thru when the pin state of the two masked pins is %00, %10 or %11.

    waitpeq(%0100, %1100,0)
    Drops thru only when the pin state of the two masked pins is %01.

    Consider which form will give the action you want.

Sign In or Register to comment.