February 25, 2012 by carlhako I have been having trouble getting a accurate 5v for AREF for a while. Without buying high end precision 5v regulators. My latest project I wanted an accurate voltage reading. To acheive this I used a voltage shunt regulator. Their cheap cost me \$1 less for SMD. All that is required is a high resistance external resistor. I am using a 33k. Its basically an accurate zener diode. ascii wiring diagram `````` 33k(10%) `````` ----///------- vref + ^ | <-- shunt regulator ----------------- vref - I have a 12.71v input (going by my mutimeter) using a voltage divider network (1% accurate resistors) R1 = 27000 R2 = 5100 I am getting 413 from the ADC which going by my resistor network is 414 * (5000 / 1024) = 2.01v then using that to work out input voltage 2.016601563 / 5100 * (27000 + 5100) = 12.69 only off by .03 v. If i change the original adv reading to 414 its almost spot on. so I am only off by 1 of 1024 which is pretty good in my books. I found i could not run the ADC off the voltage shunt regulator. The input voltage dropped to 4v. I have AVCC connected to my cheap 30c 5v regulator, outputting 4.8v. Hope this info will help out someone else. My ascii wiring diagram did not come out taken from the datasheet of LM4040CIZ-5.0 This is a chicken and the egg problem. How accurate is the calibration of the device you are measuring AREF with? Because AREF doesn't require a great deal of current, I suggest a 0.5 gain charge pump feeding the output of a PWM oscillator. Vary the duty cycle and you have a variable voltage. Your first question. I am comparing voltage using my multimeter which is aparently 0.1% accurate from memory. The atmega as far as understand compares the voltage your reading to AREF I am not sure how this is achieved exactly. This is just simply a accurate 5v regulator. For example If i was using the cheap voltage regulator that I am powering the microcontroller from which is outputting 4.8v (by my multimeter) as a AREF also and i assume its 5v as its a 5v regulator right? e.g. ADC reading of 300 out of the 1024 max 300 * (5000 / 1024) = 1464 (1.464v) this will be incorrect as the input voltage to AREF is actually 4.8v 300 * (4800 / 1024) = 1406 (1.406v) this is out by .6v plug that into the voltage divider equation and its is multiplied by quite a bit. reading 1 will show: 1.46 / 5100 * (27000 + 5100) = 9.18v reading 2 will show: 1.40 / 5100 * (27000 + 5100) = 8.81v that is .37 volts off which for a lead acid battery may do some harm if i discharge it a further .37v. the second part of your question. I am not trying to modify any sort of PWM signal to modify an output voltage. I am simply trying to get an accurate voltage reading.