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,867
    edited 2025-11-23 10:54

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

  • T ChapT Chap Posts: 4,254

    P1. I don’t know about a Spin2.

  • JonnyMacJonnyMac Posts: 9,529

    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).

  • T ChapT Chap Posts: 4,254

    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.

  • JonnyMacJonnyMac Posts: 9,529

    Here's my S.BUS receiver for the P1. I have never experimented with telemetry so I don't know anything about that.

  • T ChapT Chap Posts: 4,254

    Awesome I’ll open it sometime Monday. Thanks

  • T ChapT Chap Posts: 4,254

    I connected that up and it was working immediately! Fantastic object for reading a controller data

  • JonnyMacJonnyMac Posts: 9,529

    Glad you got it working. I did a lot of testing before handing it off to my friend who went on to use it to control the head motion and lighting in the robot called "4" in the latest Superman movie. Yes, that robot has a P1 inside. I'm trying to get my friend to adopt the P2, but until we have a smaller form factor than the Edge, he can't do it.

Sign In or Register to comment.