Shop OBEX P1 Docs P2 Docs Learn Events
Software problem with Hitachi H48C accelerometer — Parallax Forums

Software problem with Hitachi H48C accelerometer

fmurphyfmurphy Posts: 6
edited 2006-08-04 09:06 in BASIC Stamp
I used a do loop to get 3 sequential readings of the x,y,and z axis.I can display:
·X axis Y axis Z axis
2058··· 2053·· 2509
2059··· 2051·· 2509
2057··· 2063·· 2507

(The readings are similar because the accelerometer is stationary)
I can't figure out how to subtract the first x axis reading from the·second and then the second from the third.
I do not want to store (write) because it is too slow. I would also like to display the variables: (2058- 2059)= -1·· etc.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-08-03 20:42
    Are you sure you want to subtract the values or average them?· In the range they are in you could average them on the fly to correct for subtle differences when stationary.· Another option is to set a threshold offset which the value won't update unless it goes outside of that threshold.· For example, if the number is 2500 and the threshold is 2, then the number going to 2501 or 2499 won't affect the main variable but going to 2502 or 2498 will, which will cause an update.· You would set your threshold value based on how much fluctuation range is in your readings.· These are two possibilities.· I hope this helps, take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • fmurphyfmurphy Posts: 6
    edited 2006-08-03 21:12
    Chris, Yes, I want to see the difference. As an example I want to see what is happening in the Z axis with the device. I want to know if the device is moving up or down or maybe neutral and only moving in the x and y planes. The z axis experienceing the 1g from gravity reads 2508. When turned 90 degrees it reads 2050, and when turned 180 degrees it reads 1600. I need to do some experiments to better utilize the data but I do not know how to subtract data that is being overwriten.
  • Series8217Series8217 Posts: 16
    edited 2006-08-04 09:06
    fmurphy, keep in mind that an accelerometer is not going to tell you if the device is moving or not. It only measures acceleration.. once the device is moving at a constant velocity all the readings will be at neutral (which seems to be ~2,000 except for the z axis since it is measuring static gravitional acceleration). Measuring a difference in acceleration between readings is going to tell you the rate that the acceleration is increasing... I'm not sure that's what you want.

    If it is you'll have to store the previous value in memory. Use something like this:

    Xprev VAR Word
    Xnew VAR Word
    DEBUG DEC (Xnew-Xprev)

    every time you poll for the new data you first set Xprev=Xnew and then store the newest reading from the accelerometer in Xnew again
Sign In or Register to comment.