Shop OBEX P1 Docs P2 Docs Learn Events
AnyVar.[bitfield] Syntax Question — Parallax Forums

AnyVar.[bitfield] Syntax Question

BitField = BF[9:0] = AddPins above Base (Size) = Bs[9:5] BasePin = Bp[4:0]
BF[9:0] = Bs[9:5] + Bp[4:0] = S4S3S2S1S0_ P4P3P2P1P0 = BF9BF8BF7BF6BF5BF4BF3BF2BF1BF0
A bitfield is a 10-bit value which contains a base-bit number in bits 4..0 and an additional-bits number in bits 9..5.

Not really sure what the signifigance of BitField has in the variable index ? Bitfield ends up being a binary number losing it's relation to BaseBits and AddBitSize.
Regards
Bob (WRD)

Comments

  • evanhevanh Posts: 15,126

    These are features of certain Prop2 instructions. So it's hardwired. In Pasm2 there is two types of bitfields: One is for 32-bit general register indexing, the other one is for the 64 I/O pin indexing. The difference being the size the bitfields. For 32-bit registers it's 5+5=10 bits. For the 64 pins it's 6+5=11 bits.

    I'm not sure if it applies to Spin2 or not ...

  • evanhevanh Posts: 15,126

    Cool, in Spin it can be tacked onto an array index too. eg: AnyVar[index].[bitfield]
    So the key syntax detail is the "." preceding the bitfield.

  • PinField has instructions such as PINLOW(PinField) which has a function of setting the basePin and the addpins to low . But what spin instruction uses BitField in a similar prescribed manner?
    AnyVar.[BitField] what does it do? BF[9:0] = BS[9:5] + BP[4:0] = S4S3S2S1S0_ P4P3P2P1P0 The following program seems to imply individual bits can be returned for status using the BaseBit
    Bs[9:5] = 0 and Bp[4:0] = 0-31 for each bit position in HubVar[0].[BitField] but the use of AddBits Bs[9:5] with BaseBit =0 does not seem to return calculated bit number. For example
    when Addbits Bs[9:5] =32 and BaseBit Bp[4:0] = 0 Y := HubVar[0].[%100000] = 2 where HubVar[0] is %1010_1010_1010_1010_1010_1010_1010_1010 there is something I am missing.
    Regards and Thanks
    Bob (WRD)

    CON
       _clkfreq = 200_000_000                                       
    VAR  
    Long HubVar[16]
    Long BitField    
    
    PUB main()|x,y,z
    
        debug("---------------------------------------------------")
        HubVar[0] := %1010_1010_1010_1010_1010_1010_1010_1010
        HubVar[1] := %0101_0101_0101_0101_0101_0101_0101_0101
        repeat x from 0 to 31
    
           BitField := x     'BaseBit = 30  AddBits = 0
           y := HubVar[0].[BitField]
           z := HubVar[1].[BitField]
           debug(udec(BitField,y,z))
        waitms(5000)
        debug("---------------------------------------------------")
        HubVar[0] := %1111_1111_1111_1111_0000_0000_0000_0000
        HubVar[1] := %0000_0000_0000_0000_1111_1111_1111_1111
        repeat x from 0 to 31
    
           BitField := x     'BaseBit = 30  AddBits = 0
           y := HubVar[0].[BitField]
           z := HubVar[1].[BitField]
           debug(udec(BitField,y,z))
        waitms(5000)
        debug("---------------------------------------------------")
        HubVar[0] := %1010_1010_1010_1010_1010_1010_1010_1010
        HubVar[1] := %0101_0101_0101_0101_0101_0101_0101_0101
        repeat x from 31 to 0
    
           x <<= 5
           BitField := x     'BaseBit = 0  AddBits = x<<5-1
           y := HubVar[0].[BitField]
           z := HubVar[1].[BitField]
           debug(udec(BitField,y,z))
        waitms(5000)
        repeat
    
  • evanhevanh Posts: 15,126

    @"Bob Drury" said:
    ...
    when Addbits Bs[9:5] =32 and BaseBit Bp[4:0] = 0 Y := HubVar[0].[%100000] = 2 where HubVar[0] is %1010_1010_1010_1010_1010_1010_1010_1010 there is something I am missing.

    Since 32 is out of range I'll assume you mean Addbits = 1. A value of one means two bits of the variable. Given the hubvar = %1010_1010_1010_1010_1010_1010_1010_1010 and you're extracting two bits it's not surprising the result is %10 or 2.

  • Cluso99Cluso99 Posts: 18,066

    An example of what I have used

      addr := pinread(zAddr ADDPINS 16-1)                           ' read 16 pins from and including zAddr
    
  • Yes "Addbits" should be 1 not 32. Y := HubVar[0].[%100000] so the penny just dropped. The "AddBits" is the request of how many bits to return plus the BaseBit, will try out thanks.
    Regards
    Bob (WRD)

Sign In or Register to comment.