Shop OBEX P1 Docs P2 Docs Learn Events
Parallax Products' P2 code. {REQUEST P1 CONVERSION TO P2} — Parallax Forums

Parallax Products' P2 code. {REQUEST P1 CONVERSION TO P2}

Clock LoopClock Loop Posts: 2,069
edited 2021-12-29 21:12 in PASM2/Spin2 (P2)

I have some parallax products that I need P2 code for, I do not have the skills to covert p1 to p2, specifically if the p1 code contains PASM.

Is there already a place to request p2 objects for parallax products which already have p1 objects.
Clearly every P1 product will eventually get done, but until then, can I request?

Like the:

Memsic2125: https://raw.githubusercontent.com/parallaxinc/propeller/master/libraries/community/p1/All/Memsic 2125 Accelerometer DEMO - Serial Version/Memsic2125_v1.2.spin

Perhaps a designated thread to request conversions?

( I am converting the Model Railroad Controller and my WX module code and schematics to P2, and posting the updates in those threads, when its done, but small amounts of the code needs pasm conversion, the rest is just conversion work in spin ->spin2 which I can likely do myself)

I guess an alternative is the MPU 9DOF 27$ "click" chip since there is code for that in the parallax store, but the LSM6DSL is missing its code in the store/OBEX, so its useless to SELL IT, if you can't even use it as a customer, even the manufacturers page has no example P2 code.

So if you want movement sensor on the p2 you are limited to the MPU9DOF, the only one with available code.

Comments

  • Hi

    I have the same problem.
    It seems, that only new products and SW are supported :(

    BR Magneto

  • JonnyMacJonnyMac Posts: 9,104
    edited 2022-03-08 22:31

    The P2 doesn't have counters like the P1, but it does have smart pins that can measure pulses, and built in math functions that will do what Beau is doing in that code. I don't have a Memsic 2125 else I'd try it myself.

    One of the many neat things that the P2 allows is inline PASM. I wondered what it would take to measure high-going pulse in the P2 that mimics the use of the counter in the P1. It turns out to be very easy. This works, and follows what Beau is doing (wait for pin to be low, reset, wait for pulse to finish, return result).

    Edit: Upgraded from one pin to two pins -- you should be able to read the Memsic pulses with this.

    pub xy_ticks(xpin, ypin) : xtix, ytix
    
      org
                            wrpin     #P_NORMAL, xpin               ' clear smart mode
                            fltl      xpin
                            wrpin     #P_NORMAL, ypin
                            fltl      ypin
    
                            testp     xpin                  wc      ' sample pins
                            testp     ypin                  wz
        if_c_or_z           jmp       #$-2                          ' if either high, wait
    
                            wrpin     #P_HIGH_TICKS, xpin           ' set to count high ticks
                            drvl      xpin                          ' enable smart pin
                            wrpin     #P_HIGH_TICKS, ypin
                            drvl      ypin               
                            nop
    
                            testp     ypin                  wc      ' wait for pulses to finish
                            testp     ypin                  wz
        if_nc_and_nz        jmp       #$-2                   
    
                            rdpin     xtix, xpin                    ' get the results
                            rdpin     ytix, ypin                     
      end
    
  • JonnyMacJonnyMac Posts: 9,104
    edited 2022-03-09 16:57

    The Memsic PASM1 code takes the x/y readings and converts them to polar coordinates. Spin2 has a built-in command for this called xypol() -- but the angle is returned in a 32-bit angle unit ($1_0000_0000 = 360 degrees). Inline PASM2 comes to the rescue again. You should be able to take the raw ticks values measured by xy_ticks() and run them through this:

    pub cart_pol(x, y) : r, t
    
    '' Convert coordinate x,y to polar (length, angle)
    
      org
                            qvector   x, y                          ' cartesian to polar
                            getqx     r                             ' get radius (length)
                            getqy     t                             ' get theta (angle)
                            qdiv      t, ##1193046                  ' convert angle to 0.1 degree units
                            getqx     t
      end
    

    My test results match this online converter:
    -- https://keisan.casio.com/exec/system/1223526375#!

  • @JonnyMac said:
    The Memsic PASM1 code takes the x/y readings and converts them to polar coordinates. Spin2 has a built-in command for this called xypol() -- but the angle is returned in a 32-bit angle unit ($1_0000_0000 = 360 degrees). Inline PASM2 comes to the rescue again. You should be able to take the raw ticks values measured by xy_ticks() and run them through this:

    pub cart_pol(x, y) : r, t
    
    '' Convert coordinate x,y to polar (length, angle)
    
      org
                            qvector   x, y                          ' cartesian to polar
                            getqx     r                             ' get radius (length)
                            getqy     t                             ' get theta (angle)
                            qdiv      t, ##1193046                  ' convert angle to 0.1 degree units
                            getqx     t
      end
    

    My test results match this online converter:
    -- https://keisan.casio.com/exec/system/1223526375#!

    Great little routine! I just put it in my hex robot program to replace a SPIN version that I was using. Its faster and simpler.

Sign In or Register to comment.