Shop OBEX P1 Docs P2 Docs Learn Events
memsic 2125 dual axis accelerometer — Parallax Forums

memsic 2125 dual axis accelerometer

n.borreron.borrero Posts: 16
edited 2008-08-27 03:40 in Propeller 1
i am trying to use the memsic 2125 accelerometer and the code that's written for the object converts the x and y values into cartesian coordinates. i'm not too familiar with assembly so i'm having some trouble working with this. i want to be able to get the x and y values from the object as well as everything else it already does. can anyone help me with this code? the object itself is at: http://obex.parallax.com/objects/140/

i know i can write a code to convert from cartesian back to x and y, but that wouldn't be efficient. i'd rather just have it basically intercept the x and y values and store them into another variable so that i can read those variables.

thanks.

turn.gif

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2008-08-18 00:08
    n.borrero,

    Check the obex again... I modified the code so that you can read raw X and Y values. I'm surprised that I didn't have it that way to begin with. Thanks!

    http://obex.parallax.com/objects/140/

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

    IC Layout Engineer
    Parallax, Inc.
  • n.borreron.borrero Posts: 16
    edited 2008-08-18 00:15
    thank you!

    cool, now i can compare the two codes n figure out how it's done to aid in my assembly learning.
  • n.borreron.borrero Posts: 16
    edited 2008-08-27 01:25
    a couple questions for anyone who might know...

    how does this write to all the different variables?

    
    VAR
    
      long  cog
    
      long  calflag                 '5 contiguous longs
      long  _ro
      long  _theta
      long  _xraw
      long  _yraw
    
    PUB start(xpin, ypin) : okay
    
    '' Start driver - starts a cog
    '' returns false if no cog available
    ''
    ''   xpin  = x input signal
    ''   ypin  = y input signal
    ''
    
      stop
      ctra_value := $6800_0000 + xpin
      ctrb_value := $6800_0000 + ypin
      mask_value := |<xpin + |<ypin
      okay := cog := cognew(@entry, @calflag) + 1
    
    
    ....some other code...then in the DAT section...
    
    
                            mov     t1,par                  'write result
                            add     t1,#4
                            wrlong  cx,t1
                            add     t1,#4
                            wrlong  ca,t1
                            add     t1,#4
                            wrlong  rawx,t1
                            add     t1,#4
                            wrlong  rawy,t1
    
    



    i understand it has something to do with the fact that the longs are defined in order and the "par" is pointed to "calflag" but i'm still not completely catching on...




    also, what is this doing?

      ctra_value := $6800_0000 + xpin
      ctrb_value := $6800_0000 + ypin
    
    



    it's telling the ctra and ctrb to look at the correct pins to check the duty cycle, but why is it defined this way?




    and lastly...in this section, do the phsa and phsb counters automatically just count the amount of time that the pins are high?

    :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
    
    






    if anyone knows any of these answers i would greatly appreciate the help. i am in the middle of reading desilva's assembly guide (which is awsome btw). i think i understand a decent amount of what's going on in the assembly code, but there's still some things that are hazy.
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2008-08-27 03:01
    n.borrero,

    I can answer your questions....

    "how does this write to all the different variables?"

    When you initially call the assembly program you define the "start" of the variable table as the address of 'calflag' with the line that reads....

    okay := cog := cognew(@entry, @calflag) + 1

    ... In the Propeller assembly language par also holds the "start" address of the variable table. The section below is able to write results back using a series of wrlong commands indexed from the par address. An offset of 4 is used ( add t1, #4 ) representing the 4-bytes that make up each long variable definition we are writing back..

                            mov     t1,par                  'write result
                            add     t1,#4
                            wrlong  cx,t1
                            add     t1,#4
                            wrlong  ca,t1
                            add     t1,#4
                            wrlong  rawx,t1
                            add     t1,#4
                            wrlong  rawy,t1
    
    




    also, what is this doing?
      ctra_value := $6800_0000 + xpin
      ctrb_value := $6800_0000 + ypin
    
    




    This is just a short-hand way of setting the counters to read the X and Y values from the memsic.

    Another way of looking at it is as follows...
    %x_CTRMode_PLL_xxxxxxxx_ BPIN _xxx_ APIN
    %0_ 11010 _000_00000000_000000_000_000000

    As you can see, the Counter Mode is set to 11010 ... This mode is 'LOGIC A' mode which simply increments the PHS counter if the pin of interest is a logic "1"
    The APIN is intentionally left blank, so that the assembly program can modify it to point to the correct pin by simply adding the pin value to 'ctra_value' or 'ctrb_value'.


    and lastly...in this section, do the phsa and phsb counters automatically just count the amount of time that the pins are high?

    Yes, based on the counter mode we have selected.

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

    IC Layout Engineer
    Parallax, Inc.
  • n.borreron.borrero Posts: 16
    edited 2008-08-27 03:13
    ok, i get that last two parts. but i'm still having trouble with part of the "write result" thing...


    "An offset of 4 is used ( add t1, #4 ) representing the 4-bytes that make up each long variable definition we are writing back."

    so #4 in binary is 100. is that just how the ram sets up longs? it puts "100" between them? i get the fact that #4 is putting the necessary spacing between the longs, but why is it that value?


    also...it begins with

    "mov t1, par"
    so that copies the value of par to t1.
    then you're using
    "wrlong cx, t1"
    isn't t1 just an uninitialized variable? how is t1 linked to the other 5 variables from the VAR section? is it because par is linked to the address of calflag so then t1 also becomes linked to the same address?
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2008-08-27 03:26
    n.borrero,

    See the added coments... see if that makes more sense

                            mov     t1,par                  'move the address of par into 't1'  ; this points to the address of calflag 
                            add     t1,#4                    'since were not writing back to calflag, we skip it by adding 4 to the address pointer so t1 now points to the address of _ro 
                            wrlong  cx,t1                   'write the contents of 'cx' into the address location referenced in t1 
                            add     t1,#4                    'add 4 to the address pointer so t1 now points to the address of _theta
                            wrlong  ca,t1                   'write the contents of 'ca' into the address location referenced in t1
                            add     t1,#4                    'add 4 to the address pointer so t1 now points to the address of _xraw
                            wrlong  rawx,t1                'write the contents of 'rawx' into the address location referenced in t1 
                            add     t1,#4                    'add 4 to the address pointer so t1 now points to the address of _yraw
                            wrlong  rawy,t1                'write the contents of 'rawy' into the address location referenced in t1
    
    

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

    IC Layout Engineer
    Parallax, Inc.
  • n.borreron.borrero Posts: 16
    edited 2008-08-27 03:29
    ohhh. so then you're changing the address pointer by adding 4 to it? so addresses are numbered by 4?
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2008-08-27 03:35
    "so addresses are numbered by 4"

    Defined as long's, yes, the addresses are numbered by 4.... if they were defined as words, then you would add 2 to jump to the next one. ...defined as bytes, you jump one at a time.
    be sure you use the corresponding wrlong,wrword, or wrbyte

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

    IC Layout Engineer
    Parallax, Inc.
  • n.borreron.borrero Posts: 16
    edited 2008-08-27 03:40
    awesome, thank you so much for time and patience with my n00bness! i'm pretty sure i get how the object works now! so this can be used with pretty much anything that outputs a value as a duty cycle right?
Sign In or Register to comment.