3.6 DAC - Digital-to-Analog Converter

3.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.

3.6.2 Supported Device Families

AVR® DxAVR® ExATtiny

3.6.3 Required header files:

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

3.6.4 Module Documentation

3.6.4.1 DAC0

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

3.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 DAC0_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 DAC0_Enable (void)

    Enables the DAC0 module.

  • void DAC0_Disable (void)

    Disables the DAC0 module.

  • void DAC0_SetOutput (dac_resolution_t value)

    Starts a digital-to-analog conversion.

  • uint8_t DAC0_GetResolution (void)

    Returns the DAC0 resolution in number of bits.

3.6.4.1.2 Function Documentation

DAC0_Disable()

void DAC0_Disable (void )

Disables the DAC0 module.

Parameters:
None.
Returns:

None.

DAC0_Enable()

void DAC0_Enable (void )

Enables the DAC0 module.

Parameters:
None.
Returns:

None.

DAC0_GetResolution()

uint8_t DAC0_GetResolution (void )

Returns the DAC0 resolution in number of bits.

Parameters:
None.
Returns:

Resolution of the DAC.

DAC0_Initialize()

int8_t DAC0_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.

DAC0_SetOutput()

void DAC0_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.

3.6.5 File Documentation

3.6.5.1 source/dac0.c File Reference

Contains the API implementations for the DAC0 driver.

#include "../dac0.h"

3.6.5.1.1 Functions

  • int8_t DAC0_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 DAC0_Enable (void)

    Enables the DAC0 module.

  • void DAC0_Disable (void)

    Disables the DAC0 module.

  • void DAC0_SetOutput (dac_resolution_t value)

    Starts a digital-to-analog conversion.

  • uint8_t DAC0_GetResolution (void)

    Returns the DAC0 resolution in number of bits.

3.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

3.6.5.2 source/dac0.h File Reference

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

3.6.5.2.1 Functions

  • int8_t DAC0_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 DAC0_Enable (void)

    Enables the DAC0 module.

  • void DAC0_Disable (void)

    Disables the DAC0 module.

  • void DAC0_SetOutput (dac_resolution_t value)

    Starts a digital-to-analog conversion.

  • uint8_t DAC0_GetResolution (void)

    Returns the DAC0 resolution in number of bits.

3.6.5.2.3 Detailed Description

DAC0 Generated Driver API Header File

3.6.5.2.4 Typedef Documentation

dac_resolution_t

typedef uint16_t dac_resolution_t

Datatype for the resolution of the DAC