Shop OBEX P1 Docs P2 Docs Learn Events
Can you bitshift 22 bytes at once — Parallax Forums

Can you bitshift 22 bytes at once

I have 22 bytes containing 16 packets of 11 bits packed end to end. I want to see if there is some bitshift manipulation that could allow a very simple loop to bitshift left the entire 22 bytes by 11 and AND that 11 bits into 16 Words with 16 loops in spin. I have never seen such a thing but what the heck.

Comments

  • RaymanRayman Posts: 15,849
    edited 2025-11-23 10:54

    Is this spin2? Think there is a new structure thing that can do that…. I mean automatically.

  • P1. I don’t know about a Spin2.

  • Sounds like an S.BUS packet. You can do this is Spin.

    pri unpack_sbus | i, j, bc, tmp
    
      i := 1
      longfill(@j, 0, 3)
    
      repeat while (j < 16)
        repeat while (bc < 11)
          tmp |= (SBusX[i++] << bc)
          bc += 8
        channel[j++] := tmp & $07FF
        tmp >>= 11
        bc -= 11
    
      if (SBus[23] & %0001)
        channel[16] := 2047
      else
        channel[16] := 0
    
      if (SBus[23] & %0010)
        channel[17] := 2047
      else
        channel[17] := 0
    

    In this case the SBus[] array is the entire packet from the radio.

    In a practical application, though, you'd want to do it in PASM so that you can RX and process every packet. I have a driver if you need it (my friend Rick uses it in the movie business to puppeteer props and robot from a standard RC transmitter).

  • Yes probably need an engine to get and parse into 16 values spin can use. The time to get a packet and let spin do work is likely slower than the packet rate but that’s ok to skip some. Pasm will just crank out parsed values and spin can grab them as it can. One set of data is Sbus. The other is telemetry from a different port which is more byte aligned but I have not studied those in detail. Sbus 100k baud Telemetry 115200. Spin has to do work with both sets of data in a single loop. Check Sbus. Check Tel. Do something if required else keep scanning data. I can see all the data in Saleae so the config is sorted out per port.

Sign In or Register to comment.