Propeller Object: Memsic2125 Accelerometer
Beau Schwabe
Posts: 6,566
An object to read a Memsic 2125 Dual axis accelerometer has been uploaded
to the Propeller object exchange library.
The Memsic 2125 Dual axis accelerometer object is written in Propeller Assembly
and uses a 'cordic' routine to convert x and y tilt information into polar coordinates.
Output is RAW data, but can easily be resolved into acceleration (ro) and degrees (theta).
Upon startup, the demo expects the accelerometer to be in a level position
for an initial calibration leveling routine.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 8/11/2006 10:54:23 PM GMT
to the Propeller object exchange library.
The Memsic 2125 Dual axis accelerometer object is written in Propeller Assembly
and uses a 'cordic' routine to convert x and y tilt information into polar coordinates.
Output is RAW data, but can easily be resolved into acceleration (ro) and degrees (theta).
Upon startup, the demo expects the accelerometer to be in a level position
for an initial calibration leveling routine.
[b]Edit[/b]: Updated the way the digits were displayed in the 'SimpleNum' routine and also changed the order in which the graphics text vs. other graphics were rendered so that now the graphics text is "on top" of any of the other graphics.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 8/11/2006 10:54:23 PM GMT
Comments
Can you make an .avi to show it graphing in real time?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chip Gracey
Parallax, Inc.
At the moment, my video cables are packed in a moving box (misplaced somewhere??).... and I don't have my camera
with me? ...Maybe we can figure out something tomorrow at work, I have a fire-wire port on my laptop. Perhaps we can
find a fire-wire cable and a video camera.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chip Gracey
Parallax, Inc.
-Parsko
PS- It's nice to see you guys are back from vacation.· How was it?· My vacation yielded a very very special surprise !
Post Edited (parsko) : 8/11/2006 6:57:57 AM GMT
You can thank Chip for most of the code... I had an earlier version that used the existing sine table within the Propeller to do a successive approximation reverse lookup
to function as an ArcSine routine. When I showed Chip, he said "Ohh!!... you can do that much better with this cordic routine I have been working on". I think I will have
to agree with his comment.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
James
What timing! I just bought a Memsic this week and started learning how to use it. It arrived this past Tuesday, and by yesterday I had a primitive spin program that would respond to the basic tilting of the board, but this code goes waaaay beyond what I had even thought of.
Earlier this year I bought my wife a big Dobsonian telescope with a very simple mount. I'm planning to see if this Memsic can sense the vertical position of the scope well enough to help locate celestial things. Earlier I'd explored the idea of using an SX to do this same thing but got bogged down in sine calculations, and the propeller seems much more suited for this sort of project.
I'm not sure I can level the Memsic for calibration very easily once mounted on the scope; that might need some work in my application.
By any chance, does anyone know whether the Memsic X and Y output pulses have a fixed phase relationship - do both go high together, then each drops according to its respective measurement, or something like that, or are they completely independent?
David
-Phil
Last night I built a test frame that will let my propeller board with the Memsic rotate about an axis like the telescope, so maybe this weekend I'll get a chance to see how good its positioning results are using this Memsic spin object.
The Dobsonian mount has a large flat base, and I was thinking of using a computer mouse on it to generate pulses related to azimuth changes. So that would definitely need an initial calibration. I have an analog hall effect sensor that might work to align the azimuth axis, but if it isn't reliable enough, I may have to use something like a North star shot, and then could use it to calibrate both axes.
David
I don't want to confuse the issue... this "calibration" is simply to null the device into thinking that it is level.
In software it simply takes an initial reading and uses that value in subsequent readings to subtract from.
The so called calibration is relative to the orientation of the device upon start up... perhaps I should have
called it "Zero Leveling scheme" or something else to make it more intuitive.
David B.
Yes, this is exactly what happens.... The Propeller Assembly takes advantage of this and looks a both inputs
at the same time with CTRA and CTRB rather than looking at each input one at a time.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
I've been trying to modify (well re-write) your memsic object to get Acceleration X and Y instead of tilt.
Im not sure i've got the math right.· I am basically using your ASM to get the X and Y us - so with the memsic still I get about 4900us (4.9ms)·ish - which corresponds to the 50% duty cycle for t1/t2 mentioned in Nuts and Volts no.92
The code I am using to convert this into is as follows - memsicPinXTime is generated by the ASM code and is the clock cycles for T1:
The values out I get are:
Which I take to be 0.0040g and 0.0088g (as the memic is still)
Does this sound right?
Thanks for your help,
James
Post Edited (Javalin) : 8/18/2006 8:17:31 PM GMT
40 and 88 seem correct, there's also going to be a nice amount of noise if you are holding the accelerometer.
·Here are a few Spin routines to derive Sin and Cosine...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Thanks for the help. The memsic is on a table - so showing minor noise I guess.
For the acceleration I dont need to sin/cosine do I?
James
The acceleration in any direction is given in 'ro'
You need 'theta' to determine which direction the vector is.
If you don't like the 'polar coordinates' (ro and theta) you can easily convert it into 'Cartesian coordinates' (x and y).
To do this I simply provided a formula that uses Sine and Cosine to help you get started.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Looking at Nuts and Volts 92 - Jon Williams has the formula for the acceleration from the Memsic 2125 as:
A (g) = (T1 / T2 -0.5) / 12.5%
Which I was taking to mean:
A (g) = acceleration in G
T1 / T2 = the high and low pulse time
So I am confused as to the trig?
James
Sorry just realized what you mean. Your ASM code generates the "ro" variable.
Dont worry - I think based on your first comment that its ok.
Cheers for the help,
James
In reference to my original code, the output is only provided in polar coordinates.
When I wrote the Memsic object, I looked very closely at Jon's BS2 code, and where I
saw that he was using a lookup table for ARCSIN calculations, I decided not to use a
lookup table simply because the Propeller has the overhead capability and bit-resolution
to do this properly.· Not that Jon's code is wrong, it has more to do with the
limitations of the BS2.
That said, Your correct ....
g = (T1 / T2 -0.5) / 12.5%
T2 is calibrated to 10mS @ at room temperature.
Converting this to BS2 code...
g = ( ( T1 / 10 ) - 500 ) * 8
So Basically 'g' becomes a scaling function of 'T1'.· Knowing that and looking at
the 'polar coordinate' function for angle, it does not matter what units we use for
X and Y as long as they are the same ... We still get the correct angle... therefore
there is really no reason to do any scaling within the assembly program.
polar coordinate:
angle = ATN( y / x )
...We do however want to scale 'ro' against the clkfrequency but we can do this at
the Spin level.
From Spin we want to calculate the number of clock ticks that are in 1uS
ticks = clkfreq / 1_000_000
...At 80MHz 'ticks' this value is equal to '80'
The Sensitivity of the Memsic2125 is 12.5%/g
Since our measurements are in mg· (1000mg = 1g) ; 12.5% of 1000 = 125
Sensitivity = 125
At 0g our accelerometer produces a 50% duty cycle and a pulsewidth equal to 5000uS
duty = .5··· or··· duty = Pulsewidth / ( ticks * Sensitivity )
PulseWidth = 5000
So now we have enough information to calculate the 'clk_scale' I used in the demo...
clk_scale = ticks * duty
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 8/19/2006 4:35:27 PM GMT
Thats excellent - makes it much more clear. Thanks,
James
I am running into an application wall so any help is appreciated - I am trying to use the memsic 2125 to point a tracking antenna, much like David B's telescope example above. I am having a bit of difficulty understanding how the accelerometer can give what appears to be an absolute angle value...
I only need to measure tilt as I am using a digital compass to determine the rotation position. Theta is the polar coordinate angle. If I am limiting myself to one axis, will theta be off if I rotate (compass based direction) then do a tilt measurement sequentially? I think the object reads both X and Y to calculate theta...
Thanks for any insights or examples,
Paul
Yes, the object does calculate theta from X and Y by way of Cartesian coordinate to Polar coordinate conversion. I'm sorry, I'm not clear on your other question.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.