Memsic 2125 Dual Axis Accelerometer
Hello,
I am just starting with the propeller chip (coming from BS2's) and I am trying to find a object that I can use to show the ouput of the Accelerometer on my screen. I found one program, but it outputs to a TV and that won't work for my purposes.
The link for the one that outputs to video is
obex.parallax.com/objects/140/
Thanks for the help!
Post Edited (noobmuncher) : 12/18/2009 3:54:24 AM GMT
I am just starting with the propeller chip (coming from BS2's) and I am trying to find a object that I can use to show the ouput of the Accelerometer on my screen. I found one program, but it outputs to a TV and that won't work for my purposes.
The link for the one that outputs to video is
obex.parallax.com/objects/140/
Thanks for the help!
Post Edited (noobmuncher) : 12/18/2009 3:54:24 AM GMT
Comments
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Try this... I don't have a Memsic 2125 at the moment, so I couldn't test this code for sure, but it should return the RAW x and y values from a Memsic Accelerometer to a serial terminal set for 9600 Baud. Please let me know if this works for you.
[b]CON[/b] ''General Constants for Propeller Setup [b]_CLKMODE[/b] = [b]XTAL1[/b] + [b]PLL16X[/b] [b]_XINFREQ[/b] = 5_000_000 MMx = 0 MMy = 1 [b]OBJ[/b] ''Setup Object references that make this demo work Ser : "FullDuplexSerial" MM2125 : "memsic2125" [b]PUB[/b] Main_Program | a,b Ser.start(31, 30, 0, 9600) '' Initialize serial communication to the PC MM2125.start(MMx, MMy) '' Initialize Mx2125 [b]repeat[/b] a := MM2125.Mx b := MM2125.My ser.dec(a) ser.tx(9) ser.dec(b) ser.tx(13)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 12/16/2009 7:07:28 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out the Propeller Wiki·and contribute if you can.
Thanks! - I appreciate that.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Which pins am I inputting the accelerometer too? Is it 13 and 9?
Pins 0 and 1
MMx = 0 MMy = 1
The 9 and 13 are for the debug .... 9 indicates a TAB Space, while a 13 indicates a Return
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Since it takes at least two vectors to determine a degree, you can't really display a deg for each axis.
Only by combining the x and y axis can you determine a degree.
The memsic2125 object does this for you by using a routine to convert the Cartesian X and Y coordinates into Polar coordinates ro and theta.
In order to get these values so that they are 'human readable' there are a few conversions that you need to apply to the raw values.
[b]CON[/b] ''General Constants for Propeller Setup [b]_CLKMODE[/b] = [b]XTAL1[/b] + [b]PLL16X[/b] [b]_XINFREQ[/b] = 5_000_000 MMx = 1 MMy = 0 [b]OBJ[/b] ''Setup Object references that make this demo work Ser : "FullDuplexSerial" MM2125 : "memsic2125" [b]PUB[/b] Main_Program | a,b,c,d,clk_scale Ser.start(31, 30, 0, 9600) '' Initialize serial communication to the PC MM2125.start(MMx, MMy) '' Initialize Mx2125 [b]waitcnt[/b](clkfreq/10 + [b]cnt[/b]) 'wait for things to settle MM2125.setlevel 'assume at startup that the memsic2125 is level 'Note: This line is important for determining a deg clk_scale := clkfreq / 500_000 'set clk_scale based on system clock [b]repeat[/b] a := MM2125.Mx 'get RAW x value b := MM2125.My 'get RAW y value c := MM2125.ro 'Get raw value for acceleration c := c / clk_scale 'convert raw acceleration value to mg's d := MM2125.theta 'Get raw 32-bit deg d := d >> 24 'scale 32-bit value to an 8-bit Binary Radian d := (d * 45)/32 'Convert Binary radians into Degrees ser.dec(a) 'Display RAW x value ser.tx(9) ser.dec(b) 'Display RAW y value ser.tx(9) ser.tx(9) ser.dec(c) 'Display Acceleration value in mg's ser.tx(9) ser.dec(d) 'Display Deg ser.tx(13) {{ Note: At rest, normal RAW x [b]and[/b] y values should be at about 400_000 [b]if[/b] the Propeller is running at 80MHz. Since the frequency of the MM2125 is about 100Hz this means that the Period is 10ms... At rest this is a 50% duty cycle, the signal that we are measuring is only HIGH for 5ms. At 80MHz (12.5ns) this equates to a value of 400_000 representing a 5ms pulse width. }}
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
So I tested this program and I must say it is pretty cool, but is there any way that it can be outputted in a style similar to the BS2 program MEMSIC2125-Dual.BS2?
www.parallax.com/Portals/0/Downloads/src/prod/3rd/Memsic2125Demo.zip
It would just be nice to be able to see
x axis: (degree)
y axis: (degree)
Sorry for being a pain, thanks for the help though [noparse]:)[/noparse]
Ahhh, I see.... Tilt verses rotational Deg.
Tilt is basically the rotational deg with respect to the horizon (A fixed vector), where the way the Memsic2125 object returns a Deg now is the rotational deg with respect to the X vector and Y vector.
I'll update the current object, I can see how this would be very useful. I don't know why I didn't think to incorporate that into the Propeller Memsic2125 object before.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Thanks alot Beau!
Try this code and see if that works for you and I will update the OBEX.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Compiles fine here. Maybe download the .zip again. May have gotten corupted.
@ Beau
Are you running a 6MHz xtal? I'm going to try it with a 5 and 6.25
Jim
Ohh yeah... sorry, yes I am running on a 6MHz crystal. All of my demo boards are tied up at the moment, and I was using an older board with a different crystal....
Just change the header at the top of the Spin program to match your crystal setup.
Change this...
CON ''General Constants for Propeller Setup
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 6_000_000
...so that it reads...
CON ''General Constants for Propeller Setup
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
... I will update the OBEX early next week with the default 5MHz setup.
"I guess I won't be trying it out. I only have Hitachi Tri-Axis modules." - suppose the object for that should be updated as well, so that Tilt can also be displayed in addition to Rotational Deg.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 12/19/2009 8:43:56 PM GMT
The 'PK' indicates that it is a zipped file using the standard "PKzip" format... you need to unzip the file before loading it into the Propeller.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Here is an example of what I think might be more like what you are looking for...
http://forums.parallax.com/showthread.php?p=866419
...again, I'm not exactly sure why I didn't do something like that right off the bat.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Beau, just tried the code you wrote and it worked great, it was exactly what I needed so thank you very much. I think i will give this graphic one a whirl now too.
Thanks!