Shop OBEX P1 Docs P2 Docs Learn Events
Memsic 2125 object — Parallax Forums

Memsic 2125 object

SSteveSSteve Posts: 808
edited 2006-12-28 18:38 in Propeller 1
I have a question about the Memsic 2125 accelerometer object from the Propeller Object Library. This is the beginning of the assembly routine:
entry                   mov     ctra,ctra_value         'Setup both counters to simultaniously 
                        mov     ctrb,ctrb_value         'read the X-axis and Y-axis from the accelerometer 

                        mov     frqa,#1
                        mov     frqb,#1

:loop                   mov     phsa,#0                 'Reset phase A and phase B on each counter
                        mov     phsb,#0

                        waitpeq mask_value,mask_value   'Wait until both the X-axis and Y-axis pins go HIGH  
                        waitpeq zero,mask_value         'Wait until both the X-axis and Y-axis pins go LOW

                        mov     rawx,phsa               'move raw phase A and raw phase B values into their 
                        mov     rawy,phsb               'coresponding variables

                        rdlong  t1,par          wz      'check calibration flag
        if_nz           mov     levelx,rawx             'If the calibration flag is set, initialize
        if_nz           mov     levely,rawy             'offset variables to compensate level tilt error.
        if_nz           wrlong  zero,par                'reset calibration flag to zero


What if the X-axis and Y-axis pins are already high the first time through the loop? Won't "levelx" and "levely" be initialized with values that are too small? It seems like there should be a "waitpeq zero,mask_value" before the ":loop" label. Or maybe even as the first line of the loop in case the pins go high again before the loop can complete.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows

links:
My band's website
Our album on the iTunes Music Store

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,547
    edited 2006-12-25 08:21
    SSteve,

    The calibration is just a "Zero-ing" routine based on what you are calling level. (Note: It may not actually be level to the Memsic sensor)
    From the Spin code you could/can always re-issue a calibrate or leveling command at any time that you wish.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Beau SchwabeBeau Schwabe Posts: 6,547
    edited 2006-12-27 06:10
    SSteve,

    I thought about this some more, and I don't think it·is a problem if you are using that object from Spin the way it was presented.

    When you 'start' the Memsic object from Spin, the object has already gone through several iterations before you initiate the 'calibrate'
    command. Because of this the object is already in sync with the Memsic accelerometer and there is no need to use a "waitpeq zero,mask_value".
    You could I guess, but I think it would be redundant.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 12/27/2006 7:23:44 AM GMT
  • SSteveSSteve Posts: 808
    edited 2006-12-28 18:38
    Thanks, Beau. I was only looking at the assembly code and didn't think to go up a level and see how it was being called from Spin. Now it seems very obvious.

    Please tell me if my understanding of cog usage is correct. The spin code in 'memsic_demo.spin' and 'memsic2125.spin' is all running in the same cog. The assembly code in 'memsic2125.spin' is running in its own cog. Right?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
Sign In or Register to comment.