Pages: [1]   Go Down
Author Topic: ATMega328 ADC Temperature compensation?  (Read 1432 times)
0 Members and 1 Guest are viewing this topic.
Leicester, MA USA
Offline Offline
Jr. Member
**
Karma: 1
Posts: 88
Arduino newbie
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/*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);
}
Logged


Humboldt, CA
Offline Offline
Full Member
***
Karma: 2
Posts: 223
Arduino BBB
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Leicester, MA USA
Offline Offline
Jr. Member
**
Karma: 1
Posts: 88
Arduino newbie
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Leicester, MA USA
Offline Offline
Jr. Member
**
Karma: 1
Posts: 88
Arduino newbie
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17263
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Offline Offline
Edison Member
*
Karma: 5
Posts: 1730
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Leicester, MA USA
Offline Offline
Jr. Member
**
Karma: 1
Posts: 88
Arduino newbie
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged


Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17263
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Leicester, MA USA
Offline Offline
Jr. Member
**
Karma: 1
Posts: 88
Arduino newbie
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So I should remove the 5V to AREF and just put a cap to ground then?
Logged


Pages: [1]   Go Up
Jump to: