Shop OBEX P1 Docs P2 Docs Learn Events
Getting 'ina' value in PASM — Parallax Forums

Getting 'ina' value in PASM

PhilldapillPhilldapill Posts: 1,283
edited 2009-04-17 17:03 in Propeller 1
I am new to PASM and I'm trying to write a very simple driver for an ADC. Right now, I need to be able to see if a pin is high/low, and shift that value into a variable.

How is this done?

Comments

  • AleAle Posts: 2,363
    edited 2009-04-17 05:24
    The INA register is like any other register but do not use it as destination:

      mov  temp, INA
      test   temp, my_pin   wc   ' sets carry if odd number of bits are set, 1 is odd [img]http://forums.parallax.com/images/smilies/wink.gif[/img]
    
    if_c  jmp  #lbl_pin_set
    
    ... ' When pin is not set it goes here
    
    lbl_pin_set
    
    it ends here when the pin is set
    
    temp   long 0
    my_pin   long %0000_1000
    
    




    You can also use the value of INA directly :

      test   my_pin, INA   wc   ' sets carry if odd number of bits are set, 1 is odd [img]http://forums.parallax.com/images/smilies/wink.gif[/img]
    
    if_c  jmp  #lbl_pin_set
    
    ... ' When pin is not set it goes here
    
    lbl_pin_set
    
    it ends here when the pin is set
    
    temp   long 0
    my_pin   long %0000_1000
    
    
  • PhilldapillPhilldapill Posts: 1,283
    edited 2009-04-17 06:32
    Got it working. Thanks Ale!
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-04-17 09:27
    Why jump? You can directly rotate the C- flag into a register.

    test INA, my_pin WC
    rcl result, #1
    or
    rcr result, #1

    rcl or rcr depends on the word order you have - for MSB first you need rcl, for LSB first you need rcr and if the result is smaller than 32 bit, you have to shift for 32-number_of_bits.

    By the way ... as long as you don't write back (which test does not do) the order of the INA and my_pin is not relevant. The difference is, if you do it like I showed, you can use immediate value if your pin is one of the first nine pins.

    test INA, #000100000 WC

    This saves one long of memory (only for the case you get short with memory ;o)


    Post Edited (MagIO2) : 4/17/2009 9:34:26 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-17 10:31
    You won't get the result you expect using "test INA,my_pin WC" because you can't have INA in the destination field of an instruction. In that position, it references a "shadow RAM" location rather than the input register. Use "test my_pin,INA WC" instead.
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-04-17 10:52
    Got that from another actual thread. And now you want to tell me that Beau is lying on us?

    http://forums.parallax.com/showthread.php?p=800398
    ·
  • AleAle Posts: 2,363
    edited 2009-04-17 11:18
    I think Beau forgot about that smile.gif
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-04-17 14:54
    Ok, I got it backwards.... I was thinking since the test function basically "and" ed the two values together and didn't write anything back to the destination register, that it didn't matter what order they were in.· Next time I'll test the code and make sure.


    CON     ''General Constants for Propeller Setup
      _CLKMODE = XTAL1 + PLL16X
      _XINFREQ = 5_000_000
    
    PUB Main_Program
        cognew(@ASM_SpinTest,0)
    DAT
    ASM_SpinTest
            mov   dira,     OutputMask
            test  InputPinMask{<-- pin-mask}, ina  wc
            rcr   DataIn,   #1
            mov   outa,     DataIn
            jmp   #ASM_SpinTest                  
     
    InputPinMask  long      %00000000_00000000_00000000_00000001
    OutputMask    long      %00000000_11111111_00000000_00000000
    DataIn        res       1
    

    BTW)
    If your data is comming in as inverted logic, you can rotate the "true" logic into "DataIn" this way...
            andn  InputPinMask{<-- pin-mask}, ina  wc,nr
            rcr   DataIn,   #1
    
    

    ·


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 4/17/2009 3:03:28 PM GMT
  • PhilldapillPhilldapill Posts: 1,283
    edited 2009-04-17 17:03
    Yep, this works great. I've now completed my first PASM object for a chip that isn't in the OBEX! I'm going to start a new thread strictly about optimizing the program, rather than asking silly questions that could be read in the Propeller Manual(oops...).
Sign In or Register to comment.