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

Help with interfacing Accelerometer

Silicon SandmanSilicon Sandman Posts: 4
edited 2008-12-11 03:41 in Robotics
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
·

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-12-09 23:54
    Ryan,

    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
  • MSDTechMSDTech Posts: 342
    edited 2008-12-10 00:05
    You are getting the correct values for the g load range you are testing at. When you tilt the unit from side to side, it should register from -1g on one side to +1g on the other side, with 0 g in the middle. 0 g will be 1/2 of the supply voltage or 2.5v.··On an 8bit adc, this should be close to 128, which is what you measure.

    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.
  • Silicon SandmanSilicon Sandman Posts: 4
    edited 2008-12-10 15:18
    I doubt I will be going much over 1g. The end result will be to measure tilt on a hexapod robot, having the servos adjust their center points based on the angle the robot will be standing on.

    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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-12-10 17:05
    As I mentioned above…if you simply set the VREF for the maximum output you expect from the module, you will get the maximum resolution from the ADC.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • MSDTechMSDTech Posts: 342
    edited 2008-12-10 22:54
    I agree with Chris. I was thinking of the ltc1298, which uses the 5v Vdd for its Vref. The ADC0831 has a seperate input for Vref, so you can set that to the max value that you expect the voltage to swing over the g range you will be measuring.

    Teaches me to go back and read the data sheet for the chip in question.
  • Silicon SandmanSilicon Sandman Posts: 4
    edited 2008-12-11 00:18
    I'll go back and try this again.· I hooked up a 10k pot between Vref and +5 volts, hoping I would be able to "Tune" it.·· But this didn't work.· As soon as I moved the pot the number jumped to 255 and stayed there.· ??· Maybe I'll read a bit closer and see if I can figure out what I'm missing.· Thank you for the advice, I'll post my results.



    Ryan
  • Silicon SandmanSilicon Sandman Posts: 4
    edited 2008-12-11 03:41
    I found my mistake in the circuit. I was adding a resister to Vref, but living V- tied to ground. Since the conversion is the difference in voltage from Vref to V-, I would get stuck at 255 with any voltage under 5v.
    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
Sign In or Register to comment.