Sometimes it’s necessary to add a D/ A converter to a microcontroller for a specific application. This can be fairly simply accomplished by interfacing an off-the-shelf D/A converter to the microcontroller’s bus. An even simpler and more cog-effective solution based on an application note from Microchip  is shown here. A microcontroller produces a PWM (pulse width modu-lated) digital output signal which is fil-tered by a low-pass RC filter. Although the PWM signal has a fixed repetition rate the on-to-off ratio is varied from 0 to 100 % which, after filtering gives an analogue output signal proportional to the ratio. A single digital output from a port pin (driven from an on-chip timer for example) can therefore form the basis of an analogue output signal.
Guidelines to calculate values for the RC low-pass filter are given in the application note. Using the values suggested (3.9 la and 10 nF) gives a —3 dB corner frequency of around 4 kHz. When driven by a PWM frequency of approximately 20 kHz the filter will be suitable for outputting audio tones and voice signals with a bandwidth of 4 kHz. This simple filter will attenuate the 20 kHz fundamental PWM frequency by 14 dB which may not sound like much but the human ear has its own high fre-quency roll-off (the characteristics of which change as we age) so frequen-cies this high will be barely audible. Any $andard operational amplifier, for example the TL071 can be used in this application. Lower frequency signals all the way down to DC can also be handled by this circuit and in this case the low-pass filter corner fre-quency can be reduced further which will give better attenuation of the PWM fundamental and reduce ripple on DC output signals. One typical application of the circuit is speed control of a DC motor in accordance with the industry standard ±10V. The circuit will connect to the motor via a suitable power Myer stage. In this case the electromechanical proper-ties of the motor itself will act as a low pass filter.