Shop OBEX P1 Docs P2 Docs Learn Events
Bit masking on WAITPEQ — Parallax Forums

Bit masking on WAITPEQ

Sniper KingSniper King Posts: 221
edited 2008-08-28 19:14 in Propeller 1
In the case of WAITPEQ what would be the bit mask for 10

Is it 1010 or is it 1000000000
considering the example has

waitpeq(%0100, %1100, 0) 'Wait for P3 & P2 to be low & high

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Ouch, thats not suppose to be hot!··


Michael King
Application Engineer
R&D
Digital Technology Group

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-08-28 19:08
    The easiest way to form bitmasks is using the |< operator. Say you want to mask P7 and P3, the mask would be := |< 7 | |< P3. Also make sure that your state variable does not have a bit set in any position in which the mask for that bit is 0, this will cause the cog to hang.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • potatoheadpotatohead Posts: 10,261
    edited 2008-08-28 19:14
    The bits are associated with the pins, one for one. So, pin 10 (assuming that's decimal and not binary) would be the 10 bit!

    10_0000_0000 = 512 = 2^9.

    A series of masks for the pins 0 through 3 would be:

    0001 = 1 = 2^0
    0010 = 2 = 2^1
    0100 = 4 = 2^2
    1000 = 8 = 2^3


    What Paul is doing is using SPIN shortcuts to shift a single bit over X times, and OR'ing that with other single bits shifted X times.

    That's the "<" operator above, followed by the number of shifts.

    Set a bit to a 1 and you've impacted the pin associated with that particular bit, one bit per pin, for a total of 32 bits and 32 pins!

    If you want pins 1 and 2, then it's this:

    0110 = 2 + 4 = 6.

    The addition is like an OR, in that adding single bit values (powers of two) together sets those bits in the mask.

    0100
    or
    0010
    equals
    0110

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!

    Chat in real time with other Propellerheads on IRC #propeller @ freenode.net

    Post Edited (potatohead) : 8/28/2008 10:22:25 PM GMT
Sign In or Register to comment.