Shop OBEX P1 Docs P2 Docs Learn Events
Capturing Accelerometer Output — Parallax Forums

Capturing Accelerometer Output

CumQuaTCumQuaT Posts: 156
edited 2009-06-15 23:27 in BASIC Stamp
Hello all!

I have a question with most likely a simple answer, but mental blanks are stopping me from seeing it.

I'm constructing a small-scale impact sensor, not just to detect impact but to measure it. Using the basic stamp 2 (or BS2px) I can't seem to capture the impact's G force quickly enough to detect the impact. Is there a way to make it react fast enough to capture this input?

I have the dual and tri-axis accelerometers from Parallax that I'm prototyping this with, however, the final piece will use an ADXL321 +/-18g accelerometer which uses analogue output to measure the impacts.

If the impacts lasted for one second I'd be fine, but they are often quite sharp and quick, and thus just seem to be too quick to be captured with any degree of accuracy.

Thanks!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who are you, and why are you reading my signature?

Comments

  • sylvie369sylvie369 Posts: 1,622
    edited 2009-06-10 10:36
    I think that if your "impacts" are really impacts, you're going to max out a +/-18G accelerometer, and not get accurate readings. I know, that's the biggest range you can easily get, but it's not going to be enough, I'm afraid.
  • CumQuaTCumQuaT Posts: 156
    edited 2009-06-10 11:31
    Suggestions? I've tried using a top-weighted piezofilm sensor without much luck...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who are you, and why are you reading my signature?
  • sylvie369sylvie369 Posts: 1,622
    edited 2009-06-10 13:04
    CumQuaT said...
    Suggestions? I've tried using a top-weighted piezofilm sensor without much luck...

    Read this thread:

    http://forums.parallax.com/showthread.php?p=771713

    Lots of discussion of just the kind of thing you're working on, with a nice parts list from a guy who got it to work.
    ·
  • CumQuaTCumQuaT Posts: 156
    edited 2009-06-10 22:56
    Awesome! Thanks heaps for the help!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who are you, and why are you reading my signature?
  • achilles03achilles03 Posts: 247
    edited 2009-06-11 15:55
    Can you post your code? I've done some quick accelerometer sampling with a BS2p, and managed to get it well over 200Hz (had to actually slow the code down, as the eeprom write time became the limiting factor). There may be a lot of code you can eliminate to increase your sample rate. How are you recording it? Or are you just looking for peaks?

    Also, do you have any filter on the accelerometer input? (i.e. a resistor/cap low pass filter)

    Dave
  • CumQuaTCumQuaT Posts: 156
    edited 2009-06-12 00:55
    The accelerometer I'm using for the final version (The ADXL321) outputs an analogue voltage in proportion to the amount of G's being experienced, so to do a basic test of the device, here's the code I'm using:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    Adc0831 PIN 0 ' ADC0831 Chip Select (The ADC0831 is an Analogue to Digital converter I am using)
    AdcClock PIN 1 ' ADC0831 Clock
    AdcData PIN 2 ' ADC0831 Data

    result VAR Byte ' ADC8031 Result
    volts VAR Word ' Volts (0.01 Increments)

    HIGH Adc0831

    DO
    GOSUB Read_Sensor
    DEBUG HOME, DEC5 volts, " volts "
    PAUSE 100
    LOOP
    END

    Read_Sensor:
    volts = 0
    LOW Adc0831
    SHIFTIN AdcData, AdcClock, MSBPOST, [noparse][[/noparse]result\9]
    HIGH Adc0831
    volts = result
    RETURN


    I'm actually only looking for peaks, as you say. I have no filters on my output from the accelerometer.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who are you, and why are you reading my signature?
  • achilles03achilles03 Posts: 247
    edited 2009-06-15 15:33
    Ok, there's a lot you can do to increase the sample rate. Here's a few suggestions:

    First, if you want it to go as fast as you can get it, take out that PAUSE 100 command. That's by far the biggest time killer. I know, it'll make you parse through a lot more data, but that's what you'll need to do in order to spot a peak using this programming setup.

    The second biggest time hog is that "debug" command. Each bit you transmit a bit, it takes about 1.04167e-4 seconds (1/9600 baud). And each time you export data, you're sending out at least 5 ascii characters (DEC5) for the "volts" variable, and 6 ascii variables for the " volts" descriptor, so that's 11 characters * 8 bits * 1.04167e-4 seconds = about 9 milliseconds for that command alone. That means the fastest you could sample is about 100 Hz, once you remove the pause command. And that's ignoring the start and stop bits.

    Additionally, the 'result' variable is a byte (8 bits), while your 'volts' variable is a word (16 bits), yet you're recording the ADC output in the 8-bit 'result' variable and then transfering it the 16-bit 'volts' variable. You don't need 16 bits to hold 8 bits of data. I would eliminate the 'volts' variable entirely, and just get everything in the 'results' variable. That's one less command the BS2 needs to process, and less data to debug.

    You can probably also eliminate some time with the gosub command... you don't need to split it out in a separate routine and give the BS2 extra jumping to do: why not just have everything in one loop?

    Here's my suggestion for your main loop:

    DO
    results = 0
    LOW Adc0831
    SHIFTIN AdcData, AdcClock, MSBPOST, [noparse][[/noparse]result\9]
    HIGH Adc0831
    DEBUG DEC result, CR
    LOOP
    END

    A better format might be to put a debug criteria, so that it only debugs once a certain threshold is reached... that way you're sampling even faster, and it doesn't debug EVERYTHING, but only the peaks that are beyond a certain criteria... something like:

    DO
    results = 0
    LOW Adc0831
    SHIFTIN AdcData, AdcClock, MSBPOST, [noparse][[/noparse]result\9]
    HIGH Adc0831
    if results > xxx
    DEBUG DEC result, CR
    end
    LOOP
    END

    When it does debug using the IF command, it will insert an extra pause in your sampling, but it won't be significantly longer than it would be if you debugged everything. Just something to keep in mind.


    Hope that helps!
    Dave

    Post Edited (achilles03) : 6/15/2009 5:48:09 PM GMT
  • CumQuaTCumQuaT Posts: 156
    edited 2009-06-15 23:27
    Wow, some solid tips there. Thank you very much! I'll implement these ideas tonight and see how I go!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who are you, and why are you reading my signature?
Sign In or Register to comment.