Introduction

Author: Victor Berzan, Microchip Technology Inc.

The Digital-to-Analog Converter (DAC) converts a digital value written to the Data (DAC.DATA) register to an analog voltage. The output can be connected to a physical pin or used internally. The conversion range is between GND and the selected internal voltage reference (VREF), provided by the Voltage Reference (VREF) peripheral module.

This technical brief describes how the DAC works on tinyAVR® 1-series and AVR® DA microcontrollers (MCUs). It covers the following use cases:
  • Generating Constant Analog Signal:

    Illustrates how to initialize the DAC, set the voltage reference, set the DAC to output a specific constant voltage

  • Generating Sine Wave Signal:

    Initializes the DAC, sets the voltage reference, updates the DAC output inside the infinite loop to generate sine wave samples.

  • Reading the DAC Internally with the ADC:

    Shows how to initialize the DAC and ADC, set the voltage reference, configure the ADC to read the DAC output values. The DAC output voltage is incremented each step, and then it is read using the ADC.

  • Using DAC as Negative Input for AC:

    Initializes the DAC and AC, configures the AC to use the negative input provided by the DAC, configures the DAC output value. The AC will compare the voltage on its positive input pin with the DAC voltage, and set the output pin to high or low, according to the compare result.

Note: For the first three use cases described in this document, there are two code examples: One bare metal developed on ATtiny817, and one generated with MPLAB® Code Configurator (MCC) developed on AVR128DA48. For the last use case, there is one bare metal code example developed on ATtiny817.