Go Down

Topic: interfacing to max127 and i2c (Read 3 times) previous topic - next topic

wayneft

Without seeing how you have the IC wired I made some assumptions and figured you were using the standard internal reference.  Taking the number you get from the A/D, 29744, and dividing that by 16 yields 1859.  Based off the control code you are sending 0x88, you have the A/D converter set to a range of 0 - 10 volts.  Each count should correspond to 2.44 mV ( 10volts/4096 counts).  2.44mV * 1859 counts = 4.53 volts.  Again this all assumes you are using a 10 volt reference.  What is the actual reference you are using and what is Vin measuring?
I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

robtillaart

The math

float Vref = 10.0;                               // see datasheet !! depends on control byte
float volts = Vref * value /16 /4096;   // 12 bits = max 4096
or shorter
float volts = Vref * value / 65536;     // 16 * 4096= 65536

10.0 * 29744 / 16 / 4096 = 4.53..


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

BrainBooster

i would like to use the 0 5v range and the schematic i'm using is the one you can see on the max127 datasheet (so, yes i'm using internal reference).
...so ( if got the point) to have a 0 5v range i should send 0x80 and then get the replay , divide it for 16 and multiplay for  0.001?
is it correct?

robtillaart

Quote
i would like to use the 0 5v range and the schematic i'm using is the one you can see on the max127 datasheet (so, yes i'm using internal reference).
...so ( if got the point) to have a 0 5v range i should send 0x80 and then get the replay , divide it for 16 and multiplay for  0.001?
is it correct?

Look at Table 1 the control byte format and Table 3 the Range and polarity.

You want 0..5 Volt => RNG = 0 , BIP = 0  (assume rest equal,  Channel 0) => control byte becomes 1000 0000 ==> 0x80   (right)

code: stays same except for the Vref.

float Vref = 5.0;                             
float volts = Vref * value / 65536;

Note you should make the variable result unsigned as it will become larger ...

Code: [Select]

int deviceAddress = 0x28;

#include <Wire.h>

void setup()
{
  Wire.begin();       
  Serial.begin(9600); 
}

void loop()
{
  // REQUEST SAMPLE
  Wire.beginTransmission(deviceAddress);
  Wire.send(0x80);   
  Wire.endTransmission();
  Wire.requestFrom(deviceAddress, 2);
  unsigned int result = 0;
  for (int c = 0; c < 2; c++ )
    if (Wire.available()) result = result * 256 + Wire.receive();

  // DISPLAY RAW RESULT
  Serial.println(result,DEC);

  // CONVERT TO VOLTS
  float Vref = 5.0;
  float voltage = Vref * result / 65535;
  Serial.print("voltage: ");
  Serial.println(voltage, 2);

  // ...
  delay(1000);
}


now to rewrite to something like

unsigned int max127(int deviceAddress, int Channel, ...)
{
  ...
  return result;
}
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

WanaGo

Hello

How did you get on with this, did you manage to read the correct result in etc?

I am about to start using one of these chips in the next few days.

Cheers
James

Go Up