Shop OBEX P1 Docs P2 Docs Learn Events
reading a 24Bit word with SX28 and SX/B — Parallax Forums

reading a 24Bit word with SX28 and SX/B

$WMc%$WMc% Posts: 1,884
edited 2009-02-11 01:23 in General Discussion
Hello all

I'm tring to read a 24Bit word with a SX28.

The word is LSB frist

I have seen this done with a PIC16F876A but it is·in ASM, and I really don't like the PIC Editor, The SX/B is far better in My opion and is in Basic.

I would like to stay with the SX/B and SX28. I'm A newbee to the SX, But I like it.

If Any has some code for this or a link, I would Appt. it.

Thanks in Advance for any help.

______________$WMc%___________

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there············································ BoogerWoods, FL. USA

Comments

  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-02-08 07:02
    Read from what? I use 24-bit values in a camera control program that will be in the March issue of Nuts & Volts; in my case, though, I'm simply incrementing and decrementing a value; I'm not converting to any sort of output.

    BTW, if you have something in PIC Assembly it shouldn't be too difficult to convert to SX/B.
  • $WMc%$WMc% Posts: 1,884
    edited 2009-02-08 22:05
    JonnyMac

    I'm trying to read a postion on a digital caliper ( 0" to 24" )

    I have a 4 pin header on the caliper

    pin1 = VSS
    pin2 = clock clock speed is 77kHz~ This is measured with a Parallax Oscope
    pin3 = DATA
    pin4 = VDD

    The word starts out with a 55uS pause then the 24 bit word and a 55uS stop

    I think My real ? is about the 16 bit REG. and a 24bit value.

    How do I get the first 16 bits and then catch the last 8 bits in a REG. without them going by the way side.? And how to read this in to differnt REG.?

    I'M confused

    The Assembly I have converts this 24bit word to Quadrature and involes a lot of hardware.

    Anyhelp or links would be great.

    I also look forward to Your artc.s in Nut&Volts


    ____________$WMc%__________

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············································ BoogerWoods, FL. USA
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-02-09 02:32
    You'll could synthesize a 24-bit value from a byte and a Word. Let's say you do this:

    calHigh         VAR     Byte                    ' bits 16 - 23
    calLow          VAR     Word                    ' bits  0 - 15
    


    The trick is shifting a bit from one element to the other -- this is problematic in high-level SX/B because the >> and << operators clear the Carry bit which is what the SX uses to get a bit from one byte to the next. Let's assume the values are arriving MSB-first after the clock line goes high. You might have a loop like this:

    Get_Cal_Bits:
      FOR idx = 0 TO 23
        DO WHILE ClockPin = 0
        LOOP
        calHigh = calHigh << 1
        calHigh.0 = calLow.15
        calLow = calLow << 1
        calLow.0 = DataPin
        DO WHILE ClockPin = 1
        LOOP    
      NEXT
    


    If you look at the compiler output for the shift operators you'll see that the Carry gets cleared first (this is why we get a 0 in the LSBit for << or the MSBit for >>). The "shifty" lines above compile to the equivalent of this:

    ASM
      CLC
      RL    calHigh
      MOVB  calHigh.0, calLow_MSB.7
      CLC 
      RL    calLow_LSB
      RL    calLow_MSB
      MOVB  calLow_LSB.0, DataPin
    ENDASM
    


    The CLC instruction means CLear Carry. This is why -- with high-level SX/B -- we have to shift and then copy a bit from one element to the other. If we code this "shifty" stuff in Assembly we can use the Carry to our advantage:

    Get_Cal_Bits:
      FOR idx = 0 TO 23
        ASM
          JNB   ClockPin, @$
          MOVB  C, DataPin
          RL    calLow_LSB
          RL    calLow_MSB
          RL    calHigh
          JB    ClockPin, @$
        ENDASM 
      NEXT
    


    As you can see, we copy the Data pin into the Carry bit and the the left shift (RL) instructions move everything through (right to left). Think of the movement of the data bit like this:

    calHigh.7 -- calHigh.0 <-- C <-- calLow_MSB.7 -- calLow_MSB.0 <-- C <-- calLow_LSB.7 -- calLow_LSB.0 <-- C <-- DataPin



    I don't know if this will help you but, perhaps, it will give you some insight into getting 24 bits from the caliper.

    Post Edited (JonnyMac) : 2/9/2009 2:39:27 AM GMT
  • David BaylissDavid Bayliss Posts: 58
    edited 2009-02-09 13:35
    I haven't tested the code but is it not possible to use an array to avoid the whole carry-shifting problem?

    cals VAR Byte(3) ' bits 0-23 
    CalsIdx var byte 
    BitsIdx var byte 
    
     
    program get_cal_bits 
    Get_Cal_Bits: 
    FOR CalsIdx = 0 TO 2 
      FOR Bitsidx = 0 TO 7 
        DO WHILE ClockPin = 0 
        LOOP 
        cals(CalsIdx) = cals(CalsIdx) << 1 
        cals(CalsIdx).0 = DataPin 
        DO WHILE ClockPin = 1 
        LOOP 
      NEXT 
    NEXT
    


    David
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-02-09 15:17
    Yep, David, that will work -- but it puts the values into an array which adds its own layer of complexity in SX/B (vis-a-vis treating the bits as one 24-bit value).
  • $WMc%$WMc% Posts: 1,884
    edited 2009-02-10 01:37
    Hello All

    I have tried the ASM code posted. I can see how it works and its very clever. However I keep getting a error from the compiler "Line 68,Error 5,Pass 1:BYTE PARAMETER EXPECTED " idx " "

    I'm new to the SXB v3.2.92h BETA and the templates so please for give Me if its something stupid that I have over looked

    I don't want to Bugg anybody, But If· You have a minute or two I would App. it a lot.

    Thanks in Advance for any help!

    __________$WMc%______


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············································ BoogerWoods, FL. USA

    Post Edited ($WMc%) : 2/10/2009 1:46:15 AM GMT
  • David BaylissDavid Bayliss Posts: 58
    edited 2009-02-10 02:57
    The variable IDX needs to be declared before it is used.
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-02-10 03:57
    WMc: Do you have link to that caliper and how others were interfacing to it? The code examples posted above are just for theory explanation; you to know actual clock polarity and the bit order to write a working function.
  • $WMc%$WMc% Posts: 1,884
    edited 2009-02-11 01:23
    JonnyMac

    Thanks for the reply...Here's the link

    http://www.shumatech.com/support/chinese_scales.htm#Chinese Scale Protocol

    If above doesn't work Try www.ShumaTech.com

    This link shows the protocol, and I have veryfied this with the Parallax Oscope.

    *Note this site no longer has the ASM program that converted Chinese to Digimatic or Quadrature, Or the Hardware schematics, But I have these in print. I will try to scan it tomarrow and send it out to this Post.

    David Bayliss:Thanks, I knew I was doing something stupid,.........I like to complie/snyntax check code as I go to check for errors.


    _____Thanks for the help_____$WMc%_____________

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············································ BoogerWoods, FL. USA
Sign In or Register to comment.