Netherlands
Offline
Tesla Member
Karma: 86
Posts: 9355
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #15 on: March 27, 2011, 02:34:01 pm » |
why 0x28 ?
|
|
|
|
|
Logged
|
|
|
|
|
Worcester, MA
Offline
God Member
Karma: 2
Posts: 619
Arduino rocks
|
 |
« Reply #16 on: March 27, 2011, 02:46:58 pm » |
The datasheet says the 4 MSB are 0101 followed by 3 address select bits and a final R/W bit. Assuming the 3 address bits are set to 0 and the R/W is 0 yields an 8 bit address of 0x50. That should yield a 7 bit address of 0x28.
|
|
|
|
|
Logged
|
|
|
|
|
Deep south of Italy
Offline
Faraday Member
Karma: 6
Posts: 2953
The quieter you become, the more you can hear
|
 |
« Reply #17 on: March 28, 2011, 11:45:02 am » |
tested with 0x28 and it always yelds: end:0 req:2 16
|
|
|
|
« Last Edit: March 28, 2011, 11:47:45 am by BrainBooster »
|
Logged
|
|
|
|
|
Worcester, MA
Offline
God Member
Karma: 2
Posts: 619
Arduino rocks
|
 |
« Reply #18 on: March 28, 2011, 11:51:11 am » |
I just went back and looked at the posts because I was going to recommend Todbots I2C buss scanner, but it looks like you already ran that. Just so you know, it returned back a value of 40 as the address. The address of 40 is decimal 40, which converts to 0x28 hex so I would continue to use 0x28 as the address.
|
|
|
|
|
Logged
|
|
|
|
|
Worcester, MA
Offline
God Member
Karma: 2
Posts: 619
Arduino rocks
|
 |
« Reply #19 on: March 28, 2011, 11:54:14 am » |
tested with 0x28 and it always yelds: end:0 req:2 16
This means it's working!
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 86
Posts: 9355
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #20 on: March 28, 2011, 11:55:27 am » |
tested with 0x28 and it always yelds: end:0 req:2 end: 0 ==> succes so the number 0x28 is OK req: 2 lets look in the library int8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity) { // clamp to buffer length if(quantity > BUFFER_LENGTH){ quantity = BUFFER_LENGTH; } // perform blocking read into buffer uint8_t read = twi_readFrom(address, rxBuffer, quantity); // set rx buffer iterator vars rxBufferIndex = 0; rxBufferLength = read;
return read; } So this indicate you have read 2 bytes from the device, just as requested Does the value 16 make sense? Now make a nice library out of it 
|
|
|
|
« Last Edit: March 28, 2011, 11:57:41 am by robtillaart »
|
Logged
|
|
|
|
|
Deep south of Italy
Offline
Faraday Member
Karma: 6
Posts: 2953
The quieter you become, the more you can hear
|
 |
« Reply #21 on: March 28, 2011, 12:12:37 pm » |
Great! it works! now i can read a value on channel 0, even if it is strangely high... with the Vin pin connected to channel 0 i read 29744, but what that number mean? where it comes from? i'm using the following code: int deviceAddress = 0x28;
#include <Wire.h>
void setup() { Wire.begin(); Serial.begin(9600); }
void loop() {
Wire.beginTransmission(deviceAddress); Wire.send(0x88); Wire.endTransmission();
Wire.requestFrom(deviceAddress, 2); int result = 0; for (int c = 0; c < 2; c++ ) if (Wire.available()) result = result * 256 + Wire.receive(); delay(500); Serial.println(result,DEC); }
|
|
|
|
|
Logged
|
|
|
|
|
Worcester, MA
Offline
God Member
Karma: 2
Posts: 619
Arduino rocks
|
 |
« Reply #22 on: March 28, 2011, 12:53:32 pm » |
You need to divide that number by 16. It's a 12 bit A/D and the LSB is trailed by 4 zeroes.
|
|
|
|
|
Logged
|
|
|
|
|
Worcester, MA
Offline
God Member
Karma: 2
Posts: 619
Arduino rocks
|
 |
« Reply #23 on: March 28, 2011, 01:10:25 pm » |
with the Vin pin connected to channel 0 i read 29744, but what that number mean? where it comes from? Doing the math I translate that to about 4.53 volts.
|
|
|
|
|
Logged
|
|
|
|
|
Deep south of Italy
Offline
Faraday Member
Karma: 6
Posts: 2953
The quieter you become, the more you can hear
|
 |
« Reply #24 on: March 28, 2011, 01:52:47 pm » |
let me understand the procedure... how did you get to the final result in volts?
|
|
|
|
|
Logged
|
|
|
|
|
Worcester, MA
Offline
God Member
Karma: 2
Posts: 619
Arduino rocks
|
 |
« Reply #25 on: March 28, 2011, 02:06:22 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 86
Posts: 9355
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #26 on: March 28, 2011, 02:08:55 pm » |
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..
|
|
|
|
|
Logged
|
|
|
|
|
Deep south of Italy
Offline
Faraday Member
Karma: 6
Posts: 2953
The quieter you become, the more you can hear
|
 |
« Reply #27 on: March 28, 2011, 02:32:08 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 86
Posts: 9355
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #28 on: March 28, 2011, 04:40:09 pm » |
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 ... 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; }
|
|
|
|
|
Logged
|
|
|
|
|
NZ
Offline
Sr. Member
Karma: 0
Posts: 376
Turtle in a hard shell
|
 |
« Reply #29 on: May 06, 2011, 08:34:56 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
|