Shop OBEX P1 Docs P2 Docs Learn Events
Accelerometer PBASIC Help — Parallax Forums

Accelerometer PBASIC Help

Greg SGreg S Posts: 3
edited 2008-03-11 03:15 in BASIC Stamp
Hello-· Working on my first program using PBASIC with BS2.· I have a Hitachi H48C 3-Axis accelerometer attached to the stamp and it is responding based on a simple program I created, but cannot figure out how to do the following which is much more difficult for me:

For a·defined time (30 seconds, 60 seconds, etc.)
Count the number of times the accelerometer sensed a strike during that time
For each strike store in an array the gforce

i need to eventually find the max force and average force - thus the reason I need to store each strike's force and the total number of strikes.· I have sub routines for this math, but getting the strike force into an array for a specific length of time is my problem.

Any suggestions would be appreciated.

Thanks,

GS

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-09 15:03
    There's no good way to do this since the Stamp doesn't have a real-time clock and, in your case, you have to spend most of your time looking at the accelerometer to catch a "strike". Normally, you would use a PAUSE statement to set a clock "tick". You might have a loop with a PAUSE 1000 at the beginning and every time the PAUSE would finish, you'd increment a variable which would count the seconds, then maybe do a very short operation, then go back to the PAUSE. You could adjust the PAUSE count to account for the execution time of the "short operation" and the resulting timing would be fairly accurate. In your case, you need to spend most of your time looking at the accelerometer and it's harder to figure out how much time you spent doing that. You will probably need some kind of external timer like a DS1302 or DS1307 real time clock. There are several Nuts and Volts columns on using a real time clock with a Stamp. Look under the Resources tab on the main Parallax website page.

    The Stamp has a very limited amount of storage. If you have more than a few strikes, you won't have room to store the information. It would be better to compute the average and maximum force with each additional strike so you don't have to store all of them.
  • Greg SGreg S Posts: 3
    edited 2008-03-09 19:44
    Mike-

    Thanks for the information.· That certainly does help.· It sounds like I need to rearrange my code for avg and max as well as look into the external clock.· I appreciate your response.

    GS
  • achilles03achilles03 Posts: 247
    edited 2008-03-09 23:51
    A few quick questions... what is the acceleration profile from the strikes? (Duration, magnitude in g's, etc) One option might be split the program into two parts: a datalogging loop, then a sorting loop. In the datalogging loop, just record all the data that comes into the accelerometer and record it to an eeprom. After you've gotten the data, the next loop filters through the data, identifies strikes based on whatever criteria you define, and stores the relevant in your array. This is assuming that you don't need to record strikes after the initial sample period.

    Hope that helps,
    Dave
  • MSDTechMSDTech Posts: 342
    edited 2008-03-10 00:31
    One other item you might consider if you add a real time clock. The DS1302 has 30 bytes of user ram. If you can store the estimated number of strikes over the period in this amount of RAM, it makes it a lot easier to keep them available.
  • Greg SGreg S Posts: 3
    edited 2008-03-11 00:15
    Thanks to all for your help.· For each strike I am determining the gforce.··Based on Mike's suggestion, I decided to determine the strike with the greatest force as I go.··I am using an if/then statement that compares the current strike gforce to the previous·gforce and·stores the larger value·so that·I am only storing one value rather than using an array.· I am also summing the total gforce·and the number of strikes as I go so that I can later figure out the average gforce.· It's pretty simplistic, but should work for a proof of concept.· Still have to·buy the external clock and integrate.· Thanks again for the feedback/help.

    GS
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2008-03-11 03:15
    Greg--

    All they said, plus this: The BS2 is the SLOWEST of the modern Stamp family. It executes 4,000 instructions per second. On the other hand, the BS2px is the fastest Stamp. I executes 19,000 instructions per second. I wonder if the increased speed would help in your application?

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
Sign In or Register to comment.