Analog Output with the Arduino

The Arduino implements an analog output via pulse-width modulation (PWM) with analogWrite(). This creates a train of 5 V pulses of a duty cycle determined by the argument of analogWrite().  

In order to obtain an analog voltage the output is low pass filtered with a resistor and capacitor in series. Unfortunately the preset frequency of the PWM output of the Arduino is relatively low (490 Hz), which means that for a standard combination of resistor and capacitor (10 kΩ and 1 µF) a ripple with a peak-to-peak amplitude of about 250 mV (!!!) is still present. 

An on-line simulation tool can be found here:  http://sim.okawa-denshi.jp/en/PWMtool.php

This is fine for many applications, but if the analog voltage is used to control a precision circuitry this is not acceptable. In principle, the ripple can be reduced by using a higher frequency. This is possible with the Arduino, but changing of the internal timers affects other functions requiring a time base, and one would have to delve relatively deeply into the details of its internals to master this. 

Two alternative options are proposed: 

1) PWM-Vout-DAC

Linear Technology has just released two series of novel PWM-to-voltage convertors as integrated circuits (LTC2644 and LTC2645), which essentially measure the timing of the pulse train and produce an appropriate output voltage. 

The oscilloscope picture shows the PWM train fed to the LTC2644 and its output when toggling between two values. 

LTC2644toggling

 

2) I2C-DAC

Alternatively a conventional digital-to-analog convertor (DAC) is used, which is connected to the Arduino via its I2C bus. 

I2C-DAC

Many different I2C-DACs are available and a simple example is the MAX517 from Maxim Integrated Products. 

An I2C device is not controlled by analogWrite(), but the required Arduino code is very simple:

Wire.begin(); // to join the I2C bus
Wire.beginTransmission(44); // transmit to device #44
Wire.write(0); // send a command byte to the MAX517 (usually a zero)  
Wire.write(125); // send the DAC value
Wire.endTransmission(); // stop transmitting


Several I2C devices can be placed onto the bus and be addressed individually. 


The choice between the two options is probably dictated by hardware considerations. The MAX517 is available in conventional through hole technology, while the LTC2644/45 series are only available in tiny surface mount packages which are difficult to solder by conventional means.