PDA

View Full Version : Memsic 2125 Dual Axis Accelerometer



noobmuncher
12-16-2009, 11:05 AM
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/ (http://obex.parallax.com/objects/140/)

Thanks for the help!

Post Edited (noobmuncher) : 12/18/2009 3:54:24 AM GMT

Leon
12-16-2009, 11:46 AM
It's very easy to incorporate a different object for that. What do you want the output on?

Leon

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM

noobmuncher
12-16-2009, 01:48 PM
I would just like to output onto my computer screen, i have't done this before but if I can do it through the equivilent of a debug window or something that would be great.

Beau Schwabe
12-16-2009, 03:18 PM
noobmuncher,

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.




CON ''General Constants for Propeller Setup
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000

MMx = 0
MMy = 1

OBJ ''Setup Object references that make this demo work
Ser : "FullDuplexSerial"
MM2125 : "memsic2125"

PUB Main_Program | a,b

Ser.start(31, 30, 0, 9600) '' Initialize serial communication to the PC

MM2125.start(MMx, MMy) '' Initialize Mx2125

repeat
a := MM2125.Mx
b := MM2125.My

ser.dec(a)
ser.tx(9)
ser.dec(b)
ser.tx(13)



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

Post Edited (Beau Schwabe (Parallax)) : 12/16/2009 7:07:28 PM GMT

Roy Eltham
12-17-2009, 01:52 AM
Beau, I wired up my M2125 on my Stingray's breadboard and tested your code. It works fine.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out the Propeller Wiki (http://propeller.wikispaces.com/)·and contribute if you can.

Beau Schwabe
12-17-2009, 03:05 AM
Roy Eltham,

Thanks! - I appreciate that.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

noobmuncher
12-17-2009, 08:45 AM
I haven't been able to test this yet (been stuck in the library studying for exams), but I am sure it will work fine and will test it later tonight. Thanks!

noobmuncher
12-17-2009, 08:47 AM
Sorry I just realized something and I realize this is a noob question, but since I am new to the propeller bare with me please ha ha.
Which pins am I inputting the accelerometer too? Is it 13 and 9?

Beau Schwabe
12-17-2009, 10:31 AM
noobmuncher,

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 (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

noobmuncher
12-17-2009, 10:33 AM
oh okay great thank you very much

noobmuncher
12-17-2009, 11:27 AM
How could i modify this in order to output degrees on each axis?

Beau Schwabe
12-17-2009, 02:39 PM
noobmuncher,

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.




CON ''General Constants for Propeller Setup
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000

MMx = 1
MMy = 0

OBJ ''Setup Object references that make this demo work
Ser : "FullDuplexSerial"
MM2125 : "memsic2125"

PUB 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
waitcnt(clkfreq/10 + cnt) '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


repeat
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 and y values should be at about 400_000 if 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 (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

noobmuncher
12-18-2009, 02:40 AM
Thank you! All of that is very good to know and the code is appreciated.

noobmuncher
12-18-2009, 05:25 AM
Hello,

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 (http://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 :)

Beau Schwabe
12-19-2009, 12:16 AM
noobmuncher,

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 (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

noobmuncher
12-19-2009, 01:36 AM
Would you mind linking to the object just so I don't end up with the wrong one or something, then also I will know when it's updated. Plus this will be good for anyone in the future who is reading this.

Thanks alot Beau!

Beau Schwabe
12-19-2009, 07:48 AM
noobmuncher,

Try this code and see if that works for you and I will update the OBEX.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

noobmuncher
12-20-2009, 02:22 AM
What am I doing wrong? When I open this in Propeller tool it just says PK at the top and that's it. It won't let me compile or anything. Is it in an odd format or something?

hover1
12-20-2009, 02:50 AM
@ noob
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

hover1
12-20-2009, 02:59 AM
I guess I won't be trying it out. I only have Hitachi Tri-Axis modules.

Beau Schwabe
12-20-2009, 04:36 AM
hover1,

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 (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

Post Edited (Beau Schwabe (Parallax)) : 12/19/2009 8:43:56 PM GMT

Beau Schwabe
12-20-2009, 04:39 AM
noobmuncher,

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 (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

Beau Schwabe
12-21-2009, 09:00 AM
noobmuncher,

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 (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

noobmuncher
12-21-2009, 01:11 PM
Hello,

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!