memsic 2125 dual axis accelerometer
n.borrero
Posts: 16
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.
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.
Comments
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.
cool, now i can compare the two codes n figure out how it's done to aid in my assembly learning.
how does this write to all the different variables?
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?
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?
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.
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..
also, what is this doing?
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.
"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?
See the added coments... see if that makes more sense
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
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.