Subtotal: 0
View Cart

Angle of Incline from the Memsic 2125

Appeared in the 2003 Product Catalog.

Applying the BASIC Stamp® microcontroller’s Arc Tangent Command to a Datasheet Formula

Accelerometers are used to convert tilt, inertial acceleration, or shock and vibration from gravity or motion into an electrical signal. The Memsic 2125 (www.memsic.com) provides an easy-to-read pulse-width signal which can be used to calculate two-axis values for acceleration or incline. Some industry applications of accelerometers include airbag deployment, farm equipment incline monitors and robotics.

Reading an accelerometer in its simplest form can be done by measuring the pulse width values in PBASIC without any math, but it’s often better planning to work with degrees, brads or g’s. In this mini-application we will demonstrate how to apply the BASIC Stamp microcontroller’s arc tangent (ATN) command to a datasheet formula to obtain degrees for using this sensor on its side.

For this project you need the following parts:

Memsic 2125 to BASIC Stamp Schematic


 

The datasheet provides a relationship between duty cycle and acceleration for each axis:



The datasheet provides another formula for calculating incline when the sensor is rotated:


Developing code to use the formula is a three-step process using two formulas. First, use the PULSIN command to measure pulse widths on P8 and P10 which are connected to the x and y outputs, respectively. Next, calculate milligrams (mg) for each axis using Formula #1 multiplied by 1000. Then, put these two acceleration components into Formula #2 to calculate incline on a single axis.

The BASIC Stamp microcontroller performs integer math. This means that any decimal points are removed through multiplication before doing any PBASIC math. Because the ATN command works with 8-bit values it was necessary to divide the xmg and ymg values by 16 to keep them under 255 before doing any calculations. Aside from that, it’s a straight adaptation of the datasheet formula. The ATN command gives an angle in binary radians (brads). Just as a circle is 360°, it is also 256 brads. This being the case, you can multiply a measurement in brads by 360, then divide by 256 to get degrees. This is exactly what */360 does.

Home    |    Contact Us    |    Job Opportunities    |    About Parallax    |    Privacy Statement    |    Terms Of Use    |    Copyright 2008 by Parallax, Inc.