Shop OBEX P1 Docs P2 Docs Learn Events
ADXL335 + MCP3208 output G's question — Parallax Forums

ADXL335 + MCP3208 output G's question

Dwayne DibbleyDwayne Dibbley Posts: 63
edited 2012-07-03 12:57 in Accessories
I am using Mike Rector's MCP3208_DEMO. I have the sparkfun ADXL335 connected to 3 inputs on the MCP. This works fine in returning a number from 0 - 4096, how do i convert this to mV and G's. in the adxl doc i mentions this if running on 3.3v:

USE WITH OPERATING VOLTAGES OTHER THAN 3 V
The ADXL335 is tested and specified at VS = 3 V; however, it can be powered with VS as low as 1.8 V or as high as 3.6 V. Note that some performance parameters change as the supply voltage is varied.
The ADXL335 output is ratiometric, therefore, the output sensitivity (or scale factor) varies proportionally to the supply voltage. At VS = 3.6 V, the output sensitivity is typi- cally 360 mV/g. At VS = 2 V, the output sensitivity is typically 195 mV/g.
The zero g bias output is also ratiometric, thus the zero g output is nominally equal to VS/2 at all supply voltages.

am i correct the the ratiometric value when running at 3.3v would be 330 mV/g ? and therfore the g formula should be something like :

x,y or z reading [ 0-4096 ] - ( 4096 / 2 ) * 1000 / 330 [ ratiometric value calculated ? ] of do i need to convert eh MCP value to mV first?

Thanks

Comments

  • Dwayne DibbleyDwayne Dibbley Posts: 63
    edited 2012-07-02 11:35
    starting at the basics am i on the correct path regarding reading the MCP3208 to calculate the ref voltage from the adc reading (3.3v on adc 3 ) with
    CON
        _clkmode = xtal1 + pll16x                           
        _xinfreq = 5_000_000
    
    OBJ
    adc     : "MCP3208"
    pst     : "Parallax Serial Terminal"
    f32     : "Float32Full"
    fs      : "FloatString"
    
    CON
    dpin = 26       'both din and dout of the mcp3208 are connected to this pin on the prop demo board.
    cpin = 27       'the clock pin of the mcp3208 is connected to this pin on the prop demo board.
    spin = 25       'the chip select pin of the mcp 3208 is connected to this pin on the prop demo board.
    
    pub go
    pst.start(115200)   'Start the Parallax Serial Terminal object at 115200 baud
    adc.start(dpin, cpin, spin, 255)  'Start the MCP3208 object and enable all 8 channels as
                                      'single-ended inputs.
    
    
    
    repeat
      pst.Str(String(pst#cs, pst#NL, pst#HM, "vref = "))
      pst.Str(fs.FloatToString(f32.FMul(f32.FDiv(f32.FFloat(adc.in(3)), 4096.0), 3.3)))    ' read adc pin 3, convert to float, divide by 4096, multiply by 3.3 ( input voltage )
        waitcnt(clkfreq/10 + cnt)        '10Hz screen refresh
    

    however nothing is displayed on the serial terminal
  • John AbshierJohn Abshier Posts: 1,116
    edited 2012-07-02 12:39
    F32 has a start method. Using the object without calling start may cause it to hang.

    John Abshier
  • Dwayne DibbleyDwayne Dibbley Posts: 63
    edited 2012-07-02 12:56
    lol, correct needed to add f32.start :)

    also is the 4096 the correct divider or should it be 4095? adc value when feeding 3.3v is 4095? i only assumed 0-4095 is 4096 places

    Thanks
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-07-02 13:09
    You don't really need to use floating point if you're just doing basic math. You should look up pseudoreal numbers. It''s basically just multiplying your numbers by some constant like "1000" to make the numbers you want to use integers. You just keep in mind the values have been multiplied by this constant when display or using the numbers for other purposes.

    I think you are right about the 4,096 value. There are 4096 places. (I'm not sure about this.)
  • John AbshierJohn Abshier Posts: 1,116
    edited 2012-07-02 13:46
    Here is a short program that outputs voltage in millivolts.
    CON
            _clkmode = xtal1 + pll16x                                               'Standard clock mode * crystal frequency = 80 MHz
            _xinfreq = 5_000_000
    
    VAR
      long  adc
       
    OBJ
      SIO : "FullDuplexSerialPlus"
      
    PUB Main
      SIO.StartPST(115200)
      repeat
        adc := SIO.GetDEC
        adc := adc * 3300
        adc := adc >> 12
        SIO.Dec(adc)
        SIO.TX(13)
    

    I didn't have time to hook up and ADC chip so I simulated it with input from PST.
    John Abshier
  • Mark_TMark_T Posts: 1,981
    edited 2012-07-02 16:23
    am i correct the the ratiometric value when running at 3.3v would be 330 mV/g ? and therfore the g formula should be something like :

    x,y or z reading [ 0-4096 ] - ( 4096 / 2 ) * 1000 / 330 [ ratiometric value calculated ? ] of do i need to convert eh MCP value to mV first?

    Thanks

    If its ratiometric then you don't need to know the supply voltage, the same ADC output value will appear - that's what ratiometric means. Here the sensitivity is Vcc/10 per g. With a 12 bit ADC that means 409.6 counts = 1g, and the zero is at 2048. So you calculate (adc_value - 2048) * 10 / 4096
  • Dwayne DibbleyDwayne Dibbley Posts: 63
    edited 2012-07-03 12:57
    Duane Degn wrote: »
    You don't really need to use floating point if you're just doing basic math. You should look up pseudoreal numbers. It''s basically just multiplying your numbers by some constant like "1000" to make the numbers you want to use integers. You just keep in mind the values have been multiplied by this constant when display or using the numbers for other purposes.

    I think you are right about the 4,096 value. There are 4096 places. (I'm not sure about this.)

    Thanks Duane, true they are not floats so not really worth converting :)
    Here is a short program that outputs voltage in millivolts.
    CON
            _clkmode = xtal1 + pll16x                                               'Standard clock mode * crystal frequency = 80 MHz
            _xinfreq = 5_000_000
    
    VAR
      long  adc
       
    OBJ
      SIO : "FullDuplexSerialPlus"
      
    PUB Main
      SIO.StartPST(115200)
      repeat
        adc := SIO.GetDEC
        adc := adc * 3300
        adc := adc >> 12
        SIO.Dec(adc)
        SIO.TX(13)
    

    I didn't have time to hook up and ADC chip so I simulated it with input from PST.
    John Abshier

    Thanks works fine resulting in 3.299

    i just found jwoods 5dof obex (no point in reinventing the wheel) and although not using the gyro have hooked up the adxl335 x,y,z and when returning the axis i get 0ish on z, 0ish on y and 415ish on z, so pretty close to the 409.6 Mark_T formula uses.

    i think i need to average the readings now to get a smoother result.

    Thanks for the help so far
Sign In or Register to comment.