Shop OBEX P1 Docs P2 Docs Learn Events
H48C Oddness (SOLVED) — Parallax Forums

H48C Oddness (SOLVED)

tpw_mantpw_man Posts: 276
edited 2008-06-27 23:18 in Propeller 1
I am trying to make a self-keeping accelerometer package with the H48C Accelerometer Module. Everything is working fine, except the Z axis seems to be always reporting +1g. The other to axes are reporting more sane values. I have sat my Propeller on the ground, and with a 600 sample average, X= -0.018, Y= 0.033, and Z= 1. I am using V1.1 of the H48C Driver. Is there some calibration I need to do, or is my code messed up?

EDIT: I have left Zero-G unconnected, and left out the 220 Ohm resistors for the pins. I know this might damage the prop, but I do not have any on hand.

Code:

con
_clkmode = xtal1+pll16x
_xinfreq = 5_000_000

obj
accel : "H48C Tri-Axis Accelerometer"
lcd : "Debug_LCD"
math : "FloatMath"
str : "FloatString"

var
long x,y,z
long x2,y2,z2

pub main
str.setprecision(2)
accel.start(0,1,2)
lcd.init(15,19200,4)
lcd.cls
lcd.backlight(true)
average(600)

pub display(num)
lcd.str(string("X_Gforce= ",13,"Y_Gforce= ",13,"Z_Gforce"))
repeat num
  lcd.gotoxy(10,0)
  lcd.str(str.floattostring(math.fdiv(math.ffloat(accel.x),math.ffloat(455))))
  lcd.str(string("  "))
  lcd.gotoxy(10,1)
  lcd.str(str.floattostring(math.fdiv(math.ffloat(accel.y),math.ffloat(455))))
  lcd.str(string("  "))
  lcd.gotoxy(10,2)
  lcd.str(str.floattostring(math.fdiv(math.ffloat(accel.z),math.ffloat(455))))
  lcd.str(string("  "))
  'output(accel.x,accel.y,accel.z, 1)
  waitcnt(clkfreq/10+cnt)  

pub average(num)
lcd.str(string("Averaging..."))
lcd.home
repeat num
  x += accel.x
  y += accel.y
  z += accel.z
  waitcnt(clkfreq/10+cnt)
output(x/num,y/num,z/num, 0)
'repeat

pub output(x_,y_,z_, t)
if t == 0
  lcd.cls
  lcd.str(string("X_Gforce= ",13,"Y_Gforce= ",13,"Z_Gforce"))
lcd.gotoxy(10,0)
lcd.str(str.floattostring(math.fdiv(math.ffloat(x_),math.ffloat(455))))
lcd.gotoxy(10,1)
lcd.str(str.floattostring(math.fdiv(math.ffloat(y_),math.ffloat(455))))
lcd.gotoxy(10,2)
lcd.str(str.floattostring(math.fdiv(math.ffloat(z_),math.ffloat(455))))



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I am 1011, so be surprised!


Advertisement sponsored by dfletch:
Come and join us on the Propeller IRC channel for fast and easy help!
Channel: #propeller
Server: irc.freenode.net or freenode.net
If you don't want to bother installing an IRC client, use Mibbit. www.mibbit.com
tongue.gif

Post Edited (tpw_man) : 6/27/2008 11:20:46 PM GMT

Comments

  • Graham StablerGraham Stabler Posts: 2,507
    edited 2008-06-27 22:02
    Gravity is 1g, is it not that?
  • tpw_mantpw_man Posts: 276
    edited 2008-06-27 23:18
    Oh, duh. blush.gif I forgot Z is up and down. I haven't tried tilting it on its side. One would think that the driver should subtract that 1g. I guess you can use that to determine angle as well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I am 1011, so be surprised!


    Advertisement sponsored by dfletch:
    Come and join us on the Propeller IRC channel for fast and easy help!
    Channel: #propeller
    Server: irc.freenode.net or freenode.net
    If you don't want to bother installing an IRC client, use Mibbit. www.mibbit.com
    tongue.gif
Sign In or Register to comment.