Hi Guys,
Thanks for your responses. Here's some more info:
robtillart: uncommenting that line yields the same results. The voltage on the AREF pin also remains the same.
MarkT: The input to the analog reference comes from an op amp, in voltage follower mode. (I'm just using it as a buffer). I've checked the voltage into the analog input while varying in the input voltage, and everything is linear there. The original graph I posted actually has the voltage into the analog input in the x-axis. All of my logic is 5V, however I would have to agree with you that something is suspicious with the 3.3V - nothing is ringing a bell for me.
Below is the code. I'm going to break it into two sections to make it easier to understand. This first part contains all of the configuration of the Arduino. Note there are a few lines "pinMode(AXX, INPUT);" which are commented out. I've tried with and without them with no success.
void setup(){
// === PIN CONFIGURATION ===
// PWM setup (leaving CS bits at zero means timer is off)
pinMode(13, OUTPUT);
pinMode(13, OUTPUT);
TCCR0A = (1 << COM0A1) | (1 << WGM01) | (1 << WGM00);
TCCR0B = (1 << CS00);
OCR0A = 50;
digitalWrite(13,LOW);
pinMode(12, OUTPUT);
pinMode(12, OUTPUT);
TCCR1A = (1 << COM1B1) | (1 << WGM10);
TCCR1B = (1 << WGM12) | (1 << CS10);
OCR1B = 50;
digitalWrite(12,LOW);
// Shutdown signal for charging chip (low = off)
pinMode(42, OUTPUT);
// Charging indicator
pinMode(46, INPUT);
// LEDs
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
// Fault indicator
pinMode(54, INPUT);
// Current sensors
//pinMode(A15, INPUT);
//pinMode(A14, INPUT);
//pinMode(A12, INPUT);
// Auxiliary analog sensors
//pinMode(A11, INPUT);
//pinMode(A13, INPUT);
// Voltage sensors
//pinMode(A10, INPUT); // Output: 1/3 of actual
//pinMode(A9, INPUT); // 7.2 V on battery: 1/2 of actual
//pinMode(A8, INPUT); // 3.6 V on battery: 1/2 of actual
// Initial pin settings
//digitalWrite(42,LOW);
digitalWrite(42,HIGH);
Serial.begin(9600);
analogReference(DEFAULT);
// Determine current sensor zero values
i1Offset = 0;
i2Offset = 0;
i3Offset = 0;
for (int i = 0; i < 10; i++){
i1Offset += (1/0.185)*5.0*(float)analogRead(A12)/1023.0;
i2Offset += (1/0.185)*5.0*(float)analogRead(A15)/1023.0;
i3Offset += (1/0.185)*5.0*(float)analogRead(A14)/1023.0;
}
i1Offset = i1Offset/10;
i2Offset = i2Offset/10;
i3Offset = i3Offset/10;
}
This next part actually reads the sensors. I removed the code which outputs the data to the serial terminal.
void loop(){
// === CHECK FOR A FAULT ===
/*if (!faultOccurred && digitalRead(54) == LOW){
digitalWrite(42,LOW); // Turn off charging chip
faultOccurred = true;
}*/
// === READ CELL VOLTAGES ===
float vCellBoth = 2.0843*5.0*(float)analogRead(A9)/1023.0 + offsetVCellBoth; // 7.2 V sensor (both cells of the battery)
float vCellMid = 2.0843*5.0*(float)analogRead(A8)/1023.0 + offsetVCellMid; // 3.6 V sensor (between the cells)
float vOutput = 3.0*5.0*(float)analogRead(A10)/1023.0; // Output voltage sensor
}
I'm going to try the Arduino itself WITHOUT the op-amp circuit this weekend. I'll let you know how I get on. Perhaps my op-amp circuit is doing something strange - although I have no idea what....
Thanks,
defrost