Shop OBEX P1 Docs P2 Docs Learn Events
Measuring the duration/time of an event using BS2px — Parallax Forums

Measuring the duration/time of an event using BS2px

Leo.KLeo.K Posts: 21
edited 2008-03-21 14:21 in BASIC Stamp
Hi there,

I'm trying to calculate the amount of time the BS2px is performing a task. In this case reading the voltage value from an accelerometer axis then outputting it over serial to a USB stick before returning to repeat the process for the next axis.

I require the time for the constant acceleration equation v = u + at.

I've researched a lot·but have only found a solution for the propeller chip using the system's clock·- CNT.

Is there a method/s that exist for the BS2px? I'm not sure if it will make a difference but the axis values are read on one EEProm then I use "run 2" to run the next EEProm that writes the value to the USB drive.

Any pointers would be much appreciated

Thank you

Leo··

Comments

  • Tracy AllenTracy Allen Posts: 6,666
    edited 2008-03-21 04:15
    The Stamps do not have an internal clock tick that you can read independent of program execution. It is possible to make loops of program code that take a fixed amount of time to execute, and to take readings within that loop. But it is brittle, because changes to the program change the timing. The best solution may be to use an external clock. There are real time clock chips and oscillator chips that toggle a pin every 1/2 second, and you could sync execution to that.

    You could perhaps use the 60 Hz ac line frequency to get a time reference, high for 8 1/3 ms and low for 8 1/3 ms. The BS2px cannot execute a lot of code in that short time, particularly if it involves serial writing the the USB stick. In the Stamps, everything has to be done by polling.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Leo.KLeo.K Posts: 21
    edited 2008-03-21 12:48
    Thanks very much Tracy, it's much appreciated.

    As I mentioned, I am trying to read the X and Y axis voltage and write them to the USB Drive. Then loop this many times until the user stops the process. Is this a particularly bad idea as you say the serial comms are slow? and I would be assuming acceleration was constant during this writing stage. I could datalog them first but I believe I would be limited to something like 1000 readings in total before the eeprom became full. Is that right? Could you maybe suggest an alternative·method if that is the case? I'd like it to record maybe at least 30 seconds of activity. And ideally 10-15 minutes worth.

    Thanks again

    Leo

    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-21 14:21
    The BS2px has about 16K of EEPROM of which some needs to be for the program. If you use 4 bytes for a reading, that's 3500-4000 sets of data.

    Tracy's concern is about the time it takes to communicate with the datalogger. There's a bit of overhead in writing and time is tight. You might consider adding a pair of 24C1024 Atmel EEPROMs which would give you 256K of data storage with only 2 I/O lines needed. That would be room enough for 100 readings a second for 10 minutes and the BS2px has the I2CIN / I2COUT statements for quick and easy access.
Sign In or Register to comment.