Help with Arduino DAC

So I am not very experienced with electronics, and I need a little help.

Basically, I am working on a research project where we require an Arduino UNO to do an analog read, some basic processing, and then an analog output. I know the Due has built-in DAC, but for this project we are sticking with the UNO.

Is there a DAC shield that is easy to use with the UNO, and, if so, how does it work code-wise? Or, how do those external DAC chips work?

I tried perusing the forums for this info, but I had a tough time understanding the info due to my inexperience in electronics (not programming).

Any help is appreciated!

You can connect a board like this

and send it bytes of data to create the output.

http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en020399

Datasheet

See figure 5.1
You will send it two bytes. The 4 upper bits define the configuration/usage (port, mode, etc), the other 12 will be the 10 bits from the Uno ADC with your processing.

analogValue = 0b00000011 & analogRead(A0); // result is 0b000000aa
upperByte = (highByte (analogValue)) | configBits; // configBits = xxxx0000, see 5.1
lowerByte = lowByte (analogValue);

digitalWrite(csPin, LOW);
SPI.transfer (upperByte); // 4 bits of configuration, 2 bits of 0, 2 bits of analogRead
SPI.transfer (lowerByte); // 8 bits of analogRead
digitalWrite (csPin, HIGH);

Connect LDAC to Gnd, connect Shutdown pin to +5V.

What will the DAC be driving, how much resolution you you need in the DAC output, and how fast does it need to change?

Depending on the answers, there are at least 3 solutions:

  1. Smooth one of the PWM outputs with an R-C network, or (better) an op amp 2nd order low pass filter. You get 8 bits resolution, but you can't change the output very quickly because of the low pass filter. You can get higher resolution by combining 2 PWM outputs.

  2. Build your own R-2R network attached to some of the digital outputs. You get relatively poor resolution, but fast response time.

  3. Use an external DAC such as the one Crossroads suggested.

BlackBelt2025:
Is there a DAC shield that is easy to use with the UNO, and, if so, how does it work code-wise? Or, how do those external DAC chips work?

How many bits? How accurate...?

As an aside, when providing a varying analogue voltage from an Arduino (as a signal, i.e. low current), when do you use an op-amp and when do you use a DAC?

Arduino in general does not provide a varying analogue voltage - only 0V or 5V.
It can provide a series of pulses of varying width and frequency that a filter can absorb & smooth out that may look DCish and which then likely needs an op-amp to buffer to provide any drive capability.
If you want a better analogue voltage, than a DAC is needed. Even that will have discrete steps between levels, but they can filtered out as well.

Thanks Crossroads. At the moment I am using an LM358 to provide a 0-10v input into speed controllers (VFD) to three phase motors.
This uses a capacitor to provide a 'smoothed' voltage from an Arduino PWM to the input of the op-amp.

I was wondering if there were any benefits in using a DAC over an op-amp as I am in the process of redoing the board with a rail to rail op-amp. Should I be looking at a DAC instead? If so why?

Your reference to ..."better analogue voltage... " I assume to mean a smoother voltage?

Better as in higher resolution than 8 bits, better as in higher frequency range available, better as in more control, better as in smoother waveform.
If you just need a DC level, smoothed PWM could be good enough. Your initial question asked about varying voltage without saying at what frequency.

The advantages of using a DAC over the smoothed PWM approach are:

  • You can get higher resolution easily (e.g. by using a 12-bit DAC)
  • You can change the output voltage much faster
  • Some DACs include precision voltage references, allowing you to generate more precise output voltages
  • If you need several analog outputs, you can get a multiple-output DAC that needs just 2 Arduino pins to interface it
  • If the output voltage you need is 0-5V or less, then the DAC can provide that directly, at low source impedance, without the need to use an op amp to buffer it

Given that you need 0-10V output, then even with a DAC you will need to use an op amp to amplify the DAC output. You are controlling the speed of a motor, so you don't need to vary the output voltage at high speed. Therefore, if 8-bit resolution is sufficient for you and you only need 1 or 2 outputs, I don't see any advantage to using a DAC over the smoothed PWM approach.

With 0-10V needed, you can use a DAC that runs from a 12V supply.
Examples:

http://www.digikey.com/product-search/en/integrated-circuits-ics/data-acquisition-digital-to-analog-converters-dac/2556292?k=ad5501

Or use a 5V supply DAC , and put its output thru an op-amp with a larger supply range for the 10V output.