4.6 DAC - Digital-to-Analog Converter

4.6.1 Introduction

The MCC Melody DAC PLIB Driver (Peripheral Library) generates API to support DAC specific peripheral functionality on AVRxxxDx and ATtiny target MCU's.

The Digital-to-Analog Converter (DAC) converts a digital value written to the Data (DACn.DATA) register to an analog voltage. The conversion range is between GND and the selected voltage reference in the Voltage Reference (VREF) peripheral. The DAC has one continuous time output with high drive capabilities. The DAC conversion can be started from the application by writing to the Data (DACn.DATA) register.

4.6.2 Supported Device Families

AVR® DxAVR® ExATtiny

4.6.3 Required header files:

#include "mcc_generated_files/dac/dac[X].h"
Note: Replace [X] with selected instance of the DAC module.

4.6.4 Module Documentation

4.6.4.1 DAC0

Contains the API prototypes and other data types for the DAC0 driver.

4.6.4.1.1 Module description

Contains the API prototypes and other data types for the DAC0 driver.

Version: DAC0 Driver Version 1.0.0
Functions
  • int8_t DACx_Initialize (void)

    Initializes the DAC0 and must be called only once, before any other DAC0 routine is called. If the enable bit is set to 0, writing to the Data register will not trigger a conversion until the enable bit is set to 1.

  • void DACx_Enable (void)

    Enables the DAC0 module.

  • void DACx_Disable (void)

    Disables the DAC0 module.

  • void DACx_SetOutput (dac_resolution_t value)

    Starts a digital-to-analog conversion.

  • uint8_t DACx_GetResolution (void)

    Returns the DAC0 resolution in number of bits.

4.6.4.1.2 Function Documentation

DACx_Disable()

void DACx_Disable (void )

Disables the DAC0 module.

Parameters:
None.
Returns:

None.

DACx_Enable()

void DACx_Enable (void )

Enables the DAC0 module.

Parameters:
None.
Returns:

None.

DACx_GetResolution()

uint8_t DACx_GetResolution (void )

Returns the DAC0 resolution in number of bits.

Parameters:
None.
Returns:

Resolution of the DAC.

DACx_Initialize()

int8_t DACx_Initialize (void )

Initializes the DAC0 and must be called only once, before any other DAC0 routine is called. If the enable bit is set to 0, writing to the Data register will not trigger a conversion until the enable bit is set to 1.

Parameters:
None.
Returns:

Initialization status.

Return values:
1

- the DAC initialization was successful.

0

- the DAC initialization was not successful.

DACx_SetOutput()

void DACx_SetOutput (dac_resolution_t value)

Starts a digital-to-analog conversion.

Parameters:
value

- The digital value to be converted to analog voltage by the DAC.

Returns:

None.

4.6.5 File Documentation

4.6.5.1 source/dac0.c File Reference

Contains the API implementations for the DAC0 driver.

#include "../dac0.h"

4.6.5.1.1 Functions

  • int8_t DACx_Initialize (void)

    Initializes the DAC0 and must be called only once, before any other DAC0 routine is called. If the enable bit is set to 0, writing to the Data register will not trigger a conversion until the enable bit is set to 1.

  • void DACx_Enable (void)

    Enables the DAC0 module.

  • void DACx_Disable (void)

    Disables the DAC0 module.

  • void DACx_SetOutput (dac_resolution_t value)

    Starts a digital-to-analog conversion.

  • uint8_t DACx_GetResolution (void)

    Returns the DAC0 resolution in number of bits.

4.6.5.1.2 Detailed Description

Contains the API implementations for the DAC0 driver.

DAC0 Generated Driver File

Version: DAC0 Driver Version 1.0.0

4.6.5.2 source/dac0.h File Reference

#include "../system/utils/compiler.h"

4.6.5.2.1 Functions

  • int8_t DACx_Initialize (void)

    Initializes the DAC0 and must be called only once, before any other DAC0 routine is called. If the enable bit is set to 0, writing to the Data register will not trigger a conversion until the enable bit is set to 1.

  • void DACx_Enable (void)

    Enables the DAC0 module.

  • void DACx_Disable (void)

    Disables the DAC0 module.

  • void DACx_SetOutput (dac_resolution_t value)

    Starts a digital-to-analog conversion.

  • uint8_t DACx_GetResolution (void)

    Returns the DAC0 resolution in number of bits.

4.6.5.2.3 Detailed Description

DAC0 Generated Driver API Header File

4.6.5.2.4 Typedef Documentation

dac_resolution_t

typedef uint16_t dac_resolution_t

Datatype for the resolution of the DAC