2-Axis Digital Level w/accelerometer

Status
Not open for further replies.

Fred.Amoson

New Member
Hello,

I am wanting to make a 2-axis digital level with a 2 axis (x,y) accelerometer. The level will give you the degree of tilt for the x plane (tilt left/right) and the y plane (tilt up/down). I know how to do most of it, except one small math problem.

If both planes are tilted at the same time, say both are at 45 degrees one way or the other in real life, my readings are actually lower because neither axis is perpendicular to gravity anymore. Is there some math I can apply to this problem to give me the correct, real angle for each axis? I am assuming the code will involve some sort of sine/cosine calls, is it possible to do those in a PIC16?

Thank You,
Fred
 
Well yes and no. If you know it's not accelerating, then the x^2 + y^2 + z^2 will equal 1 so you can know z without a z sensor. IF it's not accelerating.

With z known you can calculate the angle in all planes.

Yep you need sine/cosine, well actually inverse tangent is the important one. In some cases you can use a lookup table. There are algorithms to do a sine/cosine/tangent in 8-bit math with varying degrees of accuracy and taking varying amounts of processor time.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…