# Output voltage not exactly 5 V despite using external 12 V supply

I'm using the Arduino Mega 2560 R3 and having trouble with the 5 V output. I'm powering the board through the power jack by an external 12 V power supply, but I won't get an exact 5 V output.

My application requires a very exact output voltage: my output should be an analog voltage (realized by PWM) that is proportional to a linear encoder output (provided to the Arduino via SPI). The output will go to a PLC for further processing.

My idea is to make the sensor output (position) proportional to an Arduino output voltage of 1...5 V. I need at least 10 bits resolution, so I'm planning on using the 16-bit timer to create the PWM (as suggested here and here). However, my Arduino will only output around 4.0 V (as measured with Oscilloscope against GND), both on a HIGH pin (pin 13: 4.89 V) and the 5V pin (4.91 V).

Now, my question is, why do I get only around 4.9 V. I understand, that the Arduino uses a voltage regulator to output that voltage, so from my understanding it should always output 5 V as long as the input voltage is higher (here 12 V), right?

If it's not possible, I could of course also go for a range of 0.5 ... 4.5 V. Would you say the voltage regulator is stable enough to provide reproducible output voltages using a PWM, provided both the fast timer (I'm afraid the edges might not rise fast enough due to some low-pass or something) and a power supply greater than 4.5 V?

Best regards,
Hemanti

The voltage regulator has some tolerance. (I don't know what the actual specs are.) And of course, you're oscilloscope will have some tolerance/error too.

Also, output high isn't "exactly" 5V. A high is guaranteed to be 0.7Vcc (3.5V) or more. A low is guaranteed to be 0.3Vcc (1.5V) or less. (From the ATmega datasheet.)

4.91volt on the 5volt pin is well within the specs of a 5volt regulator (4.75-5.25volt).

A pin has internal resistance, so you "loose" some voltage if you put a load on the pin.
4.91 - 4.89 is a 0,02 drop, and is rather low.
What is the load on the pin, apart from your 1Megohm scope or 10Megohm DMM.

Don't see how you can't get a 16-bit resolution from that approach (VCC hash and residual PWM ripple).
I think you need an external DAC with buildin voltage reference.
Not into PLCs, but are you sure the resolution of a 16-bit analogue voltage (~76uV) can be processed?
Leo..

Thank you for your quick replies, both of you! I'm really impressed!

Don't see how you can't get a 16-bit resolution from that approach (VCC hash and residual PWM ripple).
I think you need an external DAC with buildin voltage reference.

I think, I really need to use an external DAC driver AC with regulated voltage. Sounds like a good option if the output reliability is still not high enough for me when using 0.5...4.5 V. What do you mean by "VCC hash and residual PWM ripple"?

4.91volt on the 5volt pin is well within the specs of a 5volt regulator (4.75-5.25volt)

A pin has internal resistance, so you "loose" some voltage if you put a load on the pin.
4.91 - 4.89 is a 0,02 drop, and is rather low.
What is the load on the pin, apart from your 1Megohm scope or 10Megohm DMM

Okay, thank you for those specifications! On the digital pin, there is only the oscilloscope for now to measure the voltage (do you mean, I should expect it to be lower with more load connected?) and later will be only PLC or the DAC you suggested. The 5 V pin also drives an iC evaluation board and my MR sensor.

Also, output high isn't "exactly" 5V. A high is guaranteed to be 0.7Vcc (3.5V) or more. A low is guaranteed to be 0.3Vcc (1.5V) or less. (From the ATmega datasheet.)

If the range for digital output is that big, how can I ever expect to get a reliable analog output by using the PWM timers?

Not into PLCs, but are you sure the resolution of a 16-bit analogue voltage (~76uV) can be processed?

Actually, I only need 10-bit analogue voltage (just on Arduino, I only have the choice between 8 and 16-bit timer), which is possible for a PLC to process. I don't care if the PLC makes my nice 16 bit value to 10 bit, because that's all I need.

If the range for digital output is that big, how can I ever expect to get a reliable analog output by using the PWM timers?

You can't. Period.

Buy a DAC chip/module with a precision voltage reference.

jremington:
You can't. Period.

Buy a DAC chip/module with a precision voltage reference.

Okay, I will do that anyway. I was just wondering because the function Name analogWrite() sounded like I can set a fixed voltage only using the Arduino itself. Thanks for your reply!

I was just wondering because the function Name analogWrite() sounded like I can set a fixed voltage only using the Arduino itself.

No it is a bad name. You can only set the PWM duty cycle with it.

See PWM

So should analogWrite be renamed to PWMWrite instead? As seeing it's not true analog out?

wilykat:
So should analogWrite be renamed to PWMWrite instead? As seeing it's not true analog out?

Yes, but the horse already out of the barn on that one. It's a bit too late to change it now without breaking a whole bunch of existing code. So folks are going to have to do more than look at the name of the function and assume. They're just going to have to read the documentation.

with regulated voltage.

Note that REALLY GOOD "voltage regulators" are usually 0.5 to 1% accurate - call it 8bits.
To get anything close to 16bit accuracy, you're going to need a really good (expensive!) "precision voltage reference" instead. The best I see at digikey looks like 0.01%, which is still only 13 or 14bits, and costs \$50.
Frankly, I have no idea how one achieves anything close to 16bits of precision, especially on an absolute scale. Usually you count on relative behavior, do a lo of calibration, and figure out how to compensate for inherent inaccuracies by modifying the rest of the design.

Note that REALLY GOOD "voltage regulators" are usually 0.5 to 1% accurate - call it 8bits.
To get anything close to 16bit accuracy, you're going to need a really good (expensive!) "precision voltage reference" instead. The best I see at digikey looks like 0.01%, which is still only 13 or 14bits, and costs \$50.
Frankly, I have no idea how one achieves anything close to 16bits of precision, especially on an absolute scale. Usually you count on relative behavior, do a lo of calibration, and figure out how to compensate for inherent inaccuracies by modifying the rest of the design.

The thing is, that I need only 10 bits accuracy. I've found this Texas Instruments DAC on Digikey, which is close to my requirements (internal reference of 5 V with intial accuracy of 0.004%). However, the temperature drift of the internal reference voltage is 2 ppm/°C.

Am I assuming correctly, that my 10-bit accuracy will already be spoiled after only a few degrees of temperature drift? I couldn't find DACs that perform a lot better, so I guess, I should add a temperature sensor, feed that back to the Arduino and then compensate the DAC input according to the DAC datasheet?

Thank you so much for all your replies!

So it'd come down to how important the accuracy is for you. Important enough to spend over \$50 for a precise VR and maybe additional hardware like very accurate temperature probe and voltmeter so the VR can be adjusted to compensate for drifting?

Yes, it’s really important for me to convert the value from my sensor (output by another IC in a resolution of 16-bit) to an analogue signal in at least 2000 steps.

After considering about the temperature drift again, another consideration came to my mind: am I actually wrong and the 2 ppm/°C do not mean an inaccuracy of 5 V * 2/1000 * <temperature difference in °C> to my analogue value at any given time, but only about 5 V / 2^16 * 2/1000 * <temperature difference in °C>? That would indeed be quite good.

The datasheet of this “Ultra-precision” voltage regulator talks about “Ultra-Low 3ppm/°C (max) Temperature Coefficient”. So I’m wondering what I can expect from Vref at all and how to get the desired accuracy if the reference source itself can’t supply that.

Hi,
Why can't you feed the sensor output directly to the PLC, what does the Arduino have to do.

What is the application?
What is the position sensor?

Thanks.. Tom...

2000 steps requires 11 bits. With 10 bits you come to no more than 1024 bits.

2 ppm is usually based on full scale, so at 5V you’d be up to 10 µV/°C off. A single step at 10 bits is 4.88 mV (or 76 µV for a 16-bit ADC over 5V full scale). So you’d need 50°C change in temperature to be 1 scale point off on your 10-bit scale, or about 8°C for one point on the 16-bit scale - and that’s assuming the chip is at it’s maximum rated drift. You’re three zeroes off in your calculation - ppm = parts per million, not per thousand.

Thank you so much, both of you! Finally I can work on the project again, so let me answer now.

TomGeorge:
Hi,
Why can’t you feed the sensor output directly to the PLC, what does the Arduino have to do.

What is the application?
What is the position sensor?

Thanks… Tom…

The sensor is a magneto-resistive sensor that I use to measure linear heat extension (which is really small → thus so high resolution). Its output signal is sin/cos, which I feed to an IC, which determines the displacement for me (which includes auto-calibration - neat!) and outputs it as SPI. The SPI is then fed to the Arduino, which processes the signal (especially, I’m thinking of only using 1…4 V so that the PLC can detect lead fracture). Using the DAC 8560 (and an extra low noise, high-stability voltage regulator beside it), I can convert this to an analog output, which then is fed to the PLC analog-in. Despite majoring in electrical engineering, it’s one of my first practical electronic projects (before I mainly did software), but I expect to learn a lot from that. So far, I’ve already learnt that digital communication seems a lot easier than clean analog.

wvmarle:
2000 steps requires 11 bits. With 10 bits you come to no more than 1024 bits.

2 ppm is usually based on full scale, so at 5V you’d be up to 10 µV/°C off. A single step at 10 bits is 4.88 mV (or 76 µV for a 16-bit ADC over 5V full scale). So you’d need 50°C change in temperature to be 1 scale point off on your 10-bit scale, or about 8°C for one point on the 16-bit scale - and that’s assuming the chip is at it’s maximum rated drift. You’re three zeroes off in your calculation - ppm = parts per million, not per thousand.

You point me at two errors I made. Thank you! Of course, you are right about 11 bits and also about parts per million (somehow, I was confusing that with per mil <‰>). In that case, my wish should be fulfilled by that set-up. In fact, I’m gonna order the DAC today (+ a low-noise voltage regulator for it, but I haven’t yet chosen which one) and just see what happens.

I really appreciate your help! Great forum!

Best regards,
Henrik