Software problem using the Hitachi H48C accelerometer
I'm using the Hitachi H48C accelerometer with the BS2 basic stamp and s/w version 2.5
I want to compare the successive readings for each axis for 3 or 4 cycles.As an example I want to compare the initial y axis axcount with the second reading and compare the second with the third.
The values appear on the screen but each set overwrites the previous set, and I do not know how to capture them to make the comparison. When I set up the variables I used:
axcount VAR Word(3)
I tried changing the (3) to a (9) thinking I would get the three readings on the 3 axis but I got a syntax error for too many variables.
I thought about storing them with a WRITE command, but I understand each EEPROM write takes several milliseconds (slow), additionally I was not sure how to make a comparison of stored data.
Help would be appreciated.
I want to compare the successive readings for each axis for 3 or 4 cycles.As an example I want to compare the initial y axis axcount with the second reading and compare the second with the third.
The values appear on the screen but each set overwrites the previous set, and I do not know how to capture them to make the comparison. When I set up the variables I used:
axcount VAR Word(3)
I tried changing the (3) to a (9) thinking I would get the three readings on the 3 axis but I got a syntax error for too many variables.
I thought about storing them with a WRITE command, but I understand each EEPROM write takes several milliseconds (slow), additionally I was not sure how to make a comparison of stored data.
Help would be appreciated.
Comments
1. Variable space into which you read the accelerometer count values.
2. A way to display successive readings for you personally to compare them, or
2 alt: A way to keep successive readings in memory so you can compute the differences along each axis.
The first two are easy. Something like this:
axcount VAR Word(3)
DO
'·· [noparse][[/noparse]code to read data from the accelerometer into that array]
·· DEBUG DEC5 axcount(0)," ",DEC5 axcount(1)," ",DEC5 axcount(2),CR
LOOP
That will put the data for successive readings on separate lines of the display. If you also want the alternative version of step two, then you need to add another array. Something like this:
axcount VAR Word(3)
lastcount VAR Word(3)
ndx VAR Nib
DO
'·· [noparse][[/noparse]code TO READ DATA from the accelerometer into that array]
· FOR ndx=0 TO 2
· ·· DEBUG DEC5 axcount(ndx)
· ·· IF axcount(ndx)> lastcount(ndx)THEN
··· ···· DEBUG " up ", DEC5(axcount(ndx)-lastcount(ndx)),", "
· ·· ELSE
· ··· ·· DEBUG " dn ", DEC5(lastcount(ndx)-axcount(ndx)),", "
· ·· ENDIF
··· ·lastcount(ndx)=axcount(ndx)
· NEXT
DEBUG CR
LOOP
The second version saves the current reading into an array for the previous readings, and then displays the differences·after each new reading.·That's pretty off the cuff code, but it should do the job.
Good luck.