help, conversion of raw to Gs on H48C Tri-Axis Accelerometer.
grins73
Posts: 17
·hi there!
········· I would like to know the spin code to convert the raw numbers coming out of the H48C
·in to G force so its shown in the "debug" in the same way it dose on the stamp2.
· as in...
·········································
··································· G. x = 0.00
····································G. y =·0.00
····································G. z = 1.00
ive tryed using the "floatmath" and "floatstring" objects·and·dividing the raw data with 455
(Beau Schwabe) says to do this in his demo
and I get readings like this......
····································G. x = -3.829107e+38
··································· G. y = 0.02417583
··································· G. z = 1.096703
Now the Y and Z may be right but whats going on with X? its sitting flat on the·tabe and there are no earth quakes going on in my town· I only want 2 decimal·places anyway·what am I doing wrong and how do I fix it.
········································ THANKS!!
········· I would like to know the spin code to convert the raw numbers coming out of the H48C
·in to G force so its shown in the "debug" in the same way it dose on the stamp2.
· as in...
·········································
··································· G. x = 0.00
····································G. y =·0.00
····································G. z = 1.00
ive tryed using the "floatmath" and "floatstring" objects·and·dividing the raw data with 455
(Beau Schwabe) says to do this in his demo
and I get readings like this......
····································G. x = -3.829107e+38
··································· G. y = 0.02417583
··································· G. z = 1.096703
Now the Y and Z may be right but whats going on with X? its sitting flat on the·tabe and there are no earth quakes going on in my town· I only want 2 decimal·places anyway·what am I doing wrong and how do I fix it.
········································ THANKS!!
Comments
If you look at page #2 of this document ...
www.parallax.com/Portals/0/Downloads/docs/prod/acc/HitachiH48C3AxisAccelerometer.pdf
... you will see the formula...
G = ((axis-vRef)/4095)x(3.3/0.3663)
... which is simplified down to ...
G = (axis-vRef)x0.0022
... and instead of multiplying by .0022 you divide by 455, you get...
G = (axis-vRef)/ 455
... the reciprocal of 0.0022 is 454.54_
To answer your question any further however, we need to see the code that you are using.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
·thanks for answering so quickly, unfortunately math strong point of mine (one of the resons I thought·it would be good to take this sort of thing up, it may make me better at it)·I read that page, I can get it to work with the·BS2 no probs cos the code is all there. But·now im trying to get the same thing·out of the prop I fall down! lol
part of the problem might be I dont know what this symbol realy means·· ** as in
··· gForce = (axCount - rvCount) ** GfCnv ' positive g-force
··· (I even ploughed though all my old stamp books trying to figger it)
ok so here is the spin code you will know it well, after writing my own and not being able to get the G reading the same as the stamp code dose I murdered yours too, LOL sorry about that
·····
·····CON
· _CLKMODE = XTAL1 + PLL16X
· _XINFREQ = 5_000_000
······· CS = 3
······ DIO = 4
······ CLK = 5
······ grav = 455
VAR
··· long vref,x,y,z,ThetaA,ThetaB,ThetaC
OBJ
· H48C··· : "H48C Tri-Axis Accelerometer"
· VGA···· : "FullDuplexSerialPlus"
· Fmath·· : "FloatMath"
· Fstring : "FloatString"
PUB DEMO_TEST
· 'start VGA terminal
· VGA.start(31, 30, 0,115200)
· 'start and setup Accelerometer
· H48C.start(CS,DIO,CLK)
·
· waitcnt· (clkfreq/10 + cnt)
· repeat
···· 'vref := (H48C.vref*825)/1024·· '<-- Here's how to get vref in mV
···· vref := H48C.vref·············· '<-- Here's how to get vref in RAW
·········
'Note: The returned value for X, Y, and Z is equal to the axis - Vref
······· x := (Fmath.FDiv( H48C.x,grav)) '<-- Here's how to get x
······· y := (Fmath.FDiv( H48C.y,grav)) '<-- Here's how to get y
······· z := (Fmath.FDiv( H48C.z,grav)) '<-- Here's how to get z
······· 'z := (Fmath.FDiv(z,0.022))
'Note: The returned value is in Deg (0-359)
'····· remove the '*45)/1024' to return the 13-Bit Angle
·· ThetaA := (H48C.ThetaA*45)/1024·· '<-- ThetaA is the angle relationship between X and Y
·· ThetaB := (H48C.ThetaB*45)/1024·· '<-- ThetaB is the angle relationship between X and Z
·· ThetaC := (H48C.ThetaC*45)/1024·· '<-- ThetaC is the angle relationship between Y and Z
··· VGA.str (string(16))
····
··· VGA.str(string("H48C Tri-Axis Accelerometer",13))
··· VGA.str(string("Vref ="))·
··· VGA.dec(Vref)
··· VGA.str(string(13))
·
·
··· VGA.str(string("X ="))
··· VGA.str(Fstring.FloatToString (x))
··· VGA.str(string(13))·
··· VGA.str(string("Y ="))
··· VGA.str(Fstring.FloatToString (y))
··· VGA.str(string(13))·
··· VGA.str(string("Z ="))
··· VGA.str(Fstring.FloatToString (z))
··· VGA.str(string(13))·
··· VGA.str(string("Theta A ="))·
··· VGA.dec(ThetaA)
··· VGA.str(string(13))·
··· VGA.str(string("Theta B ="))
··· VGA.dec(ThetaB)
··· VGA.str(string(13))·
··· VGA.str(string("Theta C ="))
··· VGA.dec(ThetaC)
··· VGA.str(string(13))
··· VGA.str (string(1))
·· waitcnt· (clkfreq/80 + cnt)
·