Capturing Accelerometer Output
CumQuaT
Posts: 156
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?
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who are you, and why are you reading my signature?
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.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who are you, and why are you reading my signature?
Also, do you have any filter on the accelerometer input? (i.e. a resistor/cap low pass filter)
Dave
' {$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?
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who are you, and why are you reading my signature?