Go Down

Topic: ATMega328 ADC Temperature compensation? (Read 1 time) previous topic - next topic

SXRguyinMA

Hi all! I created a benchtop power supply with an ATMega328 as the voltage monitor that outputs to a LCD panel. The worklog can be found here:

http://www.thebestcasescenario.com/forum/showthread.php?t=25018

I've been sing it more and more lately and I've noticed that the readings on the LCD drop when the temp goes up, and vice-versa. Currently the 3.3V is reading the same, the 5V is reading ~4.4 and the 12V is reading ~10. When the weather cools off the readings go back up to near normal. Is there some kind of temperature compensation I can work into the code to correct this? Here's the code I'm running:

Code: [Select]
/*Arduino Controlled Voltage Monitor
Code by Will Lyon 2/28/2011
Code for project Power House on TBCS
http://www.thebestcasescenario.com*/

#include <LiquidCrystal.h>

//Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup()
{
  lcd.begin(16, 2);                      //Set up the LCD's number of columns and rows
  lcd.print("  POWER  HOUSE");           //First line opening message
  lcd.setCursor(0, 1);
  lcd.print("Desktop Pwr Unit");         //Second line opening message
  delay(5000);
  lcd.setCursor(0, 1);                   //Clear bottom line
  lcd.print("                ");
  lcd.setCursor(0,0);
  lcd.print(" 3v    5v   12v");          //Update top line readout
}

void loop()
{
  lcd.setCursor(0, 1);
  float f = analogRead(0) * 4.92 / 1023;   // 3.3 => 9.9
  lcd.print(f, 2);                        // print float with two decimals


  lcd.setCursor(6, 1);
  float g = analogRead(5) * 8.05 / 1023;   // 5.0 => 9.9
  lcd.print(g, 2);

 
  lcd.setCursor(11, 1);
  float h = analogRead(4) * 20.88 / 1023;  // 12.0 => 25.0
  lcd.print(h, 2);

  delay(1000);
}
http://www.computersandcircuits.com

Bobnova

Might be worth taking a few reading from each pin and averaging them together.  I've found that I seem to have the best accuracy if I put a 1ms delay between readings as well.  Generally I read a pin once, chuck the data, then read it three more times with 1ms between each read.  Then average 'em together and move on.

Whether that would help your issue or not I have no idea.
Are you sure it's the Arduino and not the power supply itself?  Might be worth checking it with a multimeter.

SXRguyinMA

Yea I've checked the outputs with a multimeter and they're reading correctly on the meter, so it's something to do with the temp of the aTMega328 itself thats affecting the readings
http://www.computersandcircuits.com

dc42

If your voltage readings are going down, that implies that your adc reference voltage is going up. Consider using a different reference voltage, such as the 3.3v supply or a bandgap reference ic.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

SXRguyinMA

The readings are taken directly from the 3.3V, 5V and 12V lines straight off the PSU. They're then fed through a voltage divider setup (except the 3.3V) to the ATMega's inputs. These are the same 3.3V, 5V and 12V lines that go to the binding posts on the front that do read the correct voltage.
http://www.computersandcircuits.com

retrolefty

But how are you powering the arduino? The default reference voltage used by the analog input pins is whatever voltage is wired to the Avcc pin, normally +5vdc from either the USB connection or the on-board +5vdc voltage. Any variation in Vcc will show up as variation in your analog read values.

Lefty


winner10920

Ive founf out in my setup that my measured vin is accurate to 1% -20mv
I used the same thing with a voltage divider,
If you need to keep the vref at 5, you can temporarily change it to 3.3, then measure your 5v out, then adjust back to vref

SXRguyinMA

I've got the ATMega by itself on a board. The VCC, AVCC and AREF all hooked to the same 5V line, and both grounds hooked together to ground.

http://www.computersandcircuits.com

retrolefty

Aref should have no voltage applied to it. The default reference is the voltage applied to the Avcc pin. Only if you plan on using the external reference command do you apply a different voltage to that pin. Most just wire a .1ufd cap from Aref to ground for a little additional noise filtering. Note the caution about using external voltages on the Aref pin in the reference here.

http://arduino.cc/en/Reference/AnalogReference

SXRguyinMA

So I should remove the 5V to AREF and just put a cap to ground then?
http://www.computersandcircuits.com

Go Up