7
\$\begingroup\$

With a uC, I can input analog voltage levels, how do I output them?

I have a simple Arduino Uno R3 I had picked up, which has a few of each pin types (analog input, digital output/pwm, serial) and require some sort of voltage output control.

For now it is to compare things in a hobby with a threshold (I have a few op-amps laying around for comparators) and just to use as a simple quick variable reference, or underpower devices and measure effects as a bonus.

What integrated circuits do I require to do this? I have not heard of it being within the Uno, unsure if it would need a DAC or something similar which may take some time to get in my situation.

I'd love this functionality to be built up, the less "1-step IC" and more "subcircuit" the better :)

\$\endgroup\$
  • 1
    \$\begingroup\$ Does the precision matter? If not, I'll write about a PWM based DAC, hold on. \$\endgroup\$ – Transient Mar 19 '12 at 8:54
  • 1
    \$\begingroup\$ Erm, not too precise, as long as it works as a good comparison voltage. \$\endgroup\$ – Hopeful Hobbyist Mar 19 '12 at 9:04
  • \$\begingroup\$ I am sorry, what does uC stands for? I was recommended to use uC in a forum but I don't know what it is, google search showed me your question. Please help me! \$\endgroup\$ – Nulik Mar 1 '17 at 22:55
  • \$\begingroup\$ @Nulik uC is microcontroller. (u is used to represent μ) But you're more likely to get answers by posting an actual question, rather than commenting on a question from five years ago! \$\endgroup\$ – Hearth Apr 25 '17 at 12:35
18
\$\begingroup\$

What is your required precision/accuracy?
I will cover the foundations of a simple method, and update if necessary.


Parts:
You may already have what is necessary ;)

Lets look at your PWM outputs. Depending on the duty cycle, or how long the pulse is "high" compared to "low", an average level can be achieved.

You can keep this chart in mind as you are following along:

PWM cycle comparisons

If at 50% duty cycle and you can somehow chop a 5V waveform to fill in the hole you will have roughly 2.5V. You can use a simple RC filter for this:

RC filter

This is just a quick taste. You can learn about RC filtering to your heart's content after reading this (or before continuing.)

http://en.wikipedia.org/wiki/RC_circuit
http://en.wikipedia.org/wiki/Low-pass_filter (what we are doing here!)

Simulation:

An LTspice (free) simulation assuming 100MHz PWM just for this example with 10% duty cycle, 15.8k resistor, and 1uF capacitor:

(cutoff = \$\frac{1}{2\pi RC} =\$ 10Hz)

LTspice simulation of RC filter for PWM

The graph will show:

  • It will take roughly 100ms to steady
  • The result is 10% of 5, or 500mV (as expected)
  • Noise appears to be at a minimum (~5mV peak-to-peak)

In practise you will have defects and more variables to worry about and will be worse than this somewhat, while following the general curve.

Cleaning up the signal:
You can add more filtering stages to decrease noise, sometimes at the expense of a longer time to stabilise as capacitance increases. You should get a steady reading on your multimeter at the very least, you can even parallel with an ADC to calibrate - however note that microcontroller voltage references may not be that accurate to begin with.

An opamp in non-inverting configuration (with or without gain) can follow to do what you wish such as source current if required, for your low power tests on devices.


A DAC may be suitable if you require less noise and faster response time. A good DAC may cost you $2-3 which may be justified if an RC filter is not effective enough. You can build your own, feel free to read up on many methods to get an understanding of how they are implemented.

\$\endgroup\$
  • 3
    \$\begingroup\$ +1 nice complete answer, with graphics! now, someone needs to do one for the DAC. \$\endgroup\$ – sybreon Mar 19 '12 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.