# DAC

DAC means digital to analog converter. The DAC circuit produces a proportional analog voltage at the output from a binary number at the input. Here I explain three different ways of implementing a DAC.

## Weighted code technique using Op-amps. • Note that the two operational amplifiers are in inverting configuration.
• The first on the left is an inverting summing amplifier.
• The summing amplifier has binary number at the input.
• The least significant bit is amplified with least gain magnitude: i.e. – 1
• The most significant bit is amplified with greatest gain magnitude: i.e. -8
• Bit-1 and bit-2 are amplified with gain -2 and -4 respectively.
• All the currents produced by the input bits are added at the inverting input of the amp and finally flows through the 8R feed back resistor. Thus resulting in the addition of the four inputs. Remember, this output is negative.
• To make the output positive, we use another unity gain inverting amplifier. This output is proportional to the input binary number.

## PWM technique Another way of implementing DAC is to use the PWM technique. PWM stands for Pulse Width Modulation. Duty cycle is very important term to understand PWM. It is given by the relation: $Duty cycle=frac{On time}{Total time}$

• Consider the peak voltage of the square wave generated by arduino is 5V.
• When the duty cycle is 75%, the output voltage will be 3.75V
• When the duty cycle is 50%, the output voltage will be 2.5V
• When the duty cycle is 25%, the output voltage will be 1.25V

There is an easy way to produce an analog voltage proportional to a digital value using arduino or TINAH.

• Choose proper pin which supports PWM on the board (like digital pin 9)
• Use the command “analogWrite(number)” to put a square wave on this pin such that its duty cycle is adjusted proportional to the number. For example, if we want 50% duty cycle, we will write “analogWrite(127)” to produce a 50% duty cycle 490 Hz square wave on pin 9.
• To make the voltage purely continuous, use the RC filter as shown in the diagram. This will produce a pure analog voltage at the output of the filter. This voltage is proportional to the input number.
• Notice the limitation. Quickly changing voltages can be converted only up to 15Hz or so.