Help with interfacing Accelerometer
Silicon Sandman
Posts: 4
Hello all,
I'm hoping someone can help me with interfacing a Dimension Engineering Accelerometer to the Basic Stamp.· Here is the accelerometer I am using: http://www.robotshop.ca/dimension-engineering-de-accm.html
I'm connecting it to a ADC0831 A/D Converter 1 for X axis and one for Y axis.· The clock is connected to a pin on the BS2 and the Vref is connected to +5v.· I'm getting signal, but I'm only getting a range of about 32 steps.· With 128 as the median, It spans 112 to 144 depending on the angle of the unit.· So my questions are as follows:
1.· Can anyone give me a circuit that will allow the range of the accelerometer to span the entire 8 bit range (256 steps)?
2.· Once I have the data, I'm using it to control a servo.· I'm having trouble converting the input range to an output range to match the servo (500-1000us).· Can anyone show me some code that can perform this algorithm?· Unfortunately, I should have paid more attention in math class than I did.· Of course, high school was over 20 years ago... I've forgotten more than some people know.·
Any help is greatly appreciated!
Thank you,
Ryan
·
I'm hoping someone can help me with interfacing a Dimension Engineering Accelerometer to the Basic Stamp.· Here is the accelerometer I am using: http://www.robotshop.ca/dimension-engineering-de-accm.html
I'm connecting it to a ADC0831 A/D Converter 1 for X axis and one for Y axis.· The clock is connected to a pin on the BS2 and the Vref is connected to +5v.· I'm getting signal, but I'm only getting a range of about 32 steps.· With 128 as the median, It spans 112 to 144 depending on the angle of the unit.· So my questions are as follows:
1.· Can anyone give me a circuit that will allow the range of the accelerometer to span the entire 8 bit range (256 steps)?
2.· Once I have the data, I'm using it to control a servo.· I'm having trouble converting the input range to an output range to match the servo (500-1000us).· Can anyone show me some code that can perform this algorithm?· Unfortunately, I should have paid more attention in math class than I did.· Of course, high school was over 20 years ago... I've forgotten more than some people know.·
Any help is greatly appreciated!
Thank you,
Ryan
·
Comments
If the output range of voltage from the module is less than 5V, then using 5V for VREF will limit your resolution relative to the difference. What you want ideally is a VREF that is the maximum voltage you expect to see on the output. That is the only way you’ll get the full 256 steps. So if your output voltage never goes above 2.5V and your VREF is 5V then 127 is the maximum you will see. But if you set VREF to 2.5V then it would be 255.
As for your second question…you need to scale the values…I will leave the exact math to you, but if you have a reading of 0 – 100 and you need to output a proportional pulse that requires a value of 1000 – 2000 then you could do something like this…
sensorVal is the input value from the ADC…
pulseVal is the output value to the servo…
pulseVal = (sensorVal * 10) + 1000
I hope this helps. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
The spec sheet lists a sensitivity of 312 mV per g. So a 2g swing (from -1g to +1g) would give a count on an 8bit adc of:
(0.312v/5vref)*2*256 = 32 - again this is exactly what you measured.
The only way you can get the accelerometer to get to the ends of the 8 bit range is to subject it to a 5g acceleration - what it was designed to measure.
To get more sensitivity, you would need an ADC with a higher resolution. A 12bit ADC would give you a swing of approximately 511 counts, assuming the sensitivity and output of the accellerometer will support that. But you will still only be using 20% of the range of the sensor.
What range of accellerations will you be operating this device in? If you are only using it to measure tilt, you might want to look at an accellerometer with a narrower range like the Memsic 2125 Dual-axis Accelerometer Item code 28017. It doesn't require an ADC, you get a reading using the Basic Stamp's PULSIN command.
Is there a way I can amplify the +1g to -1G range to get better resolution with the ADC? Would running the ACC. through an OpAmp like the 741 work?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
Teaches me to go back and read the data sheet for the chip in question.
Ryan
By adding a resister between +5v and Vref, then tying that to V-, I now have readings that make sense.
Was that explanation clear as mud?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
__________________________________________________________
Silicon <^> Sandman