MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
DAC Peripheral and Driver Overview

Peripheral features and how this peripheral works

The 12-bit digital-to-analog converter(DAC) provides a voltage reference to on-chip modules or a package pin. It can also be used as a waveform generator to generate triangle and sawtooth waveforms. The DAC module has two different operation modes, they are Normal Mode and Automatic mode. In the Normal mode, the DAC is used to convert the digital value to analog voltage, the input data is held in a data FIFO(8 words depth), the value in data FIFO is pushed to DAC analog portion for conversion on a selected edge of an input SYNC signal. In the Automatic mode, the DAC is used to generate different types of waveforms, data FIFO is disconnected from DAC analog portion in this mode, DAC output is determined by buffered STEP, MIN and MAX value registers. The SYNC signal is used to updated STEP, MIN and MAX registers from their buffers and reset the output wavefrom as well. A fast refresh signals(generated within DAC) is used to update DAC output based on STEP, MIN and MAX. The details of those operation modes will be provided in the following sections.

Features

Sawtooth waveform generation. To generate the sawtooth waveform which likes kDAC_RepeatSawtoothWaveform0, the CTRL0[UP] should be set with the CTRL0[DOWN] be cleared. To generate the sawtooth waveform which likes kDAC_RepeatSawtoothWaveform1, the CTRL0[DOWN] should be set with the CTRL0[UP] be cleared. To generate the sawtooth waveform which likes kDAC_OneShotSawtoothWaveform0, the CTRL0[UP] should be set with the CTRL0[DOWN] be cleared. CTRL0[ONESHOT] should be set. To generate the sawtooth waveform which likes kDAC_OneShotSawtoothWaveform1, the CTRL0[DOWN] should be set with the CTRL0[UP] be cleared. CTRL0[ONESHOT] should be set. Usually, SYNC signal defines the period of this waveform, while REFRESH signal defines the slope of the waveform. When oneshot is enabled, the output waveform holds the value when it reaches MAX or MIN value before the occurrence of the next SYNC signal.

  1. Triangle waveform generation. To generate the triangle waveform which likes kDAC_RepeatTriangleWaveform0, the CTRL0[DOWN] should be set firstly then the CTRL0[UP] should be set. In this way, the generated waveform will rise from the starting value firstly then drop down upon reaching the maximum value. To generate the triangle waveform which likes kDAC_RepeatTriangleWaveform1, the CTRL[UP] should be set firstly then the CTRL[DOWN] should be set. In this way, the generated waveform will drop down from the starting value firstly then rise up upon reaching the minimum value.
  2. Starting value The starting value of the generated waveform is programmable. Before entering Automatic operation mode, set the DAC module as Normal mode and set SYNC as clock signal, choose the active edge of SYNC signal, write the starting value to DATA register, then enter automatic mode. All the above options can be realized by invoking the DAC_Init() function.

LDOK feature STEP, MIN, and MAX registers are updated when LDOK bit equals to 1 upon the active edge of SYNC signal, and then LDOK bit is cleared automatically. This is to make sure these 3 registers are updated simultaneously.

How this peripheral works

How this driver is designed to make this peripheral works.

This driver is designed with one DAC_Init() function and multiple register access level APIs. DAC_Init() can realize all the possible DAC configurations. Users need to invoke DAC_Init() firstly and then use other functions such as DAC_WriteDataFIFO() in the runtime.

How to use this driver

For initialization:

For runtime DAC update:

Typical Use Case

  1. Normal operation mode + Clock selected as SYNC signal. In this type of use case, the DAC is used to generate voltage output, and when the data is written to the DAC's DATA FIFO, the data can be almost immediately presented to the DAC output. The template of this type of use case is shown below.
    dac_config_t sDacConfig;
    DAC_GetDefaultConfig(&sDacConfig);
    sDacConfig.eOperationMode = kDAC_NormalMode;
    sDacConfig.uOperationConfig.sNormalModeConfig.u16DataFIFO = 4095; (Each DAC LSB represent 0.806mV)
    sDacConfig.eSyncSignal = kDAC_InternalClockSignal;
    sDacConfig.bEnableAnalogPortion = true;
    DAC_Init(DACA, &sDacConfig);
    In this template, the 3.3V voltage will be generated on the DAC output pin. During runtime, invoke DAC_WriteDataFIFO() to change DAC output, such as DAC_WriteDataFIFO(DAC_BASE, 2048), where DAC outputs 1.65V.
  2. Automatic operation mode + External SYNC_IN signal selected as SYNC signal. In this type of use case, the DAC is used to generate a waveform, and the SYNC_IN signal controls when the values of the buffered registers are updated. The update occurs on the active edge of the SYNC_IN signal if DAC_SetLDOK() function is invoked. The active edge of SYNC_IN will also cause the automatic waveform to be reset to its start point as defined by the new minimum value and maximum value. The SYNC_IN signal can come from a timer, comparator, pins, or other sources through the crossbar. The template of this type of use case is shown below.
    1. Initialize the DAC module with automatic operation mode and SYNC_IN signal. After this initialization, a ramping down sawtooth waveform will be generated on the DAC output pin. Supposes SYNC_IN signal is 10kHz, because REFERSH signal is configured as 500kHz(bus clock is 100MHz), the sawtooth waveform will be similar as the one shown in kDAC_OneShotSawtoothWaveform1.
    2. Update waveform(maximum value/minimum value/step size)during runtime.
      DAC_WriteMinValue(DACA, 800);
      DAC_WriteMaxValue(DACA, 2000);
      When the active edge of SYNC_IN signal occurs, a new sawtooth waveform will be generated on the DAC output pin.