Shop OBEX P1 Docs P2 Docs Learn Events
input register (INA) to variable — Parallax Forums

input register (INA) to variable

PJAllenPJAllen BannedPosts: 5,065
edited 2011-05-17 08:45 in Propeller 1
I think I'm not understanding the Propeller Manual.
If I have a pushbutton to P8...
dira[8] = 0

byte  btnstatus

btnstatus := ina[8]

If ina[8] is HI then btnstatus = %0000 0001 ?
Or do I have to make btnstatus a long and then btnstatus would be %...0000_0001 0000_0000 ?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-16 10:54
    INA[ 8 ] extracts bit #8 to yield a single bit value (0 or 1), so btnstatus is 1 when I/O pin #8 is high.

    In general, INA[ x..y ] extracts a bit field whose high order bit is x and whose low order bit is y. If y > x, then the bits are in reversed order from how they're represented as I/O pins. In all cases, this bit field is right justified in a 32 bit value.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-05-16 11:32
    OK.

    I have:
    dira[15..0] := $00FF (So 15..8 are INs, 7..0 are OUTs)

    Going the btnstatus/alias route resulted in anxiety.
    When I test ina[8] directly, it's as I expect, 0/1, and things move along.

    I should grab a shovel and move everything closer to the computer instead of going back and forth across "the office" as I am.
  • AribaAriba Posts: 2,690
    edited 2011-05-16 13:09
    PJ Allen wrote: »
    ...Or do I have to make btnstatus a long and then btnstatus would be %...0000_0001 0000_0000 ?

    Yes, this is also possible:
    long  btnstatus
    
    btnstatus := ina
    
    now every bit in btnstatus represents the corresponding input pin.

    Andy
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-05-16 14:20
    OK.
    The objective is for a pushbutton (Jog) to advance a stepper position.
    In buttonchecking2.spin, I test ina[8].
    In buttonchecking3.spin, I test 'btnstatus'.
    PUB buttoncheck
      repeat until ina[8] == 1
      position := position + 1
    
    versus
    PUB buttoncheck
      repeat until btnstatus == 1
        btnstatus := ina[8]       ' stays stuck w/o
      userpause                   ' dbl-clicks w/o
      btnstatus := ina[8]         ' goes automatic w/o
      position := position + 1
    
    Both work, but the second version (buttonchecking3) takes more lines of code or it'll double-pulse.
    Where am I going wrong?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-05-17 08:13
    Some D/L'ers, I see, but no replies.
    That's OK. It's only about Spin and things Propeller, not some supercilious ancillary pretense at association with one.
    Oh well.
    Such is the Propeller Forum Echo Chamber.

    I still found what I was looking for, within me, applying the gray matter, as ever. If anyone's interested, see #9 over here.
  • schillschill Posts: 741
    edited 2011-05-17 08:45
    This is not exactly an answer to your problem, but rather a question about your code. By the way, I'm not sure exactly what's happening, but the problem sounds like a debounce issue (but the delays you've thrown in should be minimizing that, I think).

    Anyway, I was wondering why you didn't write the second version like this:
    PUB buttoncheck
      btnstatus := ina[8]
      repeat until btnstatus == 1
        btnstatus := ina[8]     
      userpause                   
      position := position + 1
    

    The basic structure should be the same as your first version. If you use the following, does it work?
    PUB buttoncheck
      btnstatus := ina[8]
      repeat until btnstatus == 1
        btnstatus := ina[8]     
      position := position + 1
    

    I know you say you've already solved your problem (by changing the overall structure of the code) but I'm curious about what the issue here is.
Sign In or Register to comment.