MCUXpresso SDK API Reference Manual  Rev 2.16.000
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
DAC: 12-bit Digital-to-Analog Converter Driver

Overview

This document consists of sections titled with Driver Overview, Data Structures, Enumerations, Functions, etc., each with an overview list and detailed documentation. It is recommended to read the Driver Overview first for it includes a comprehensive description of the peripheral, driver and driver changes. Other sections give detailed information for APIs, enums, macros, etc., for your further reference.

Modules

 DAC Peripheral and Driver Overview
 Content including 1) peripheral features, work logic and work method; 2) driver design logic and use method; 3) typical use case.
 
 The Driver Change Log
 The current DAC driver version is 2.0.1.
 

Data Structures

struct  dac_normal_mode_config_t
 The structure of configuration when the operation mode is selected are normal operation mode. More...
 
struct  dac_automatic_mode_config_t
 The structure of configuration when the operation mode is selected as automatic operation mode. More...
 
union  dac_operation_config_u
 The union of operation modes' configuration. More...
 
struct  dac_config_t
 The structure for configuring the DAC. More...
 

Enumerations

enum  _dac_fifo_status_flags {
  kDAC_FIFOFullStatusFlag = DAC_STATUS_FULL_MASK,
  kDAC_FIFOEmptyStatusFlag = DAC_STATUS_EMPTY_MASK
}
 The enumeration of DAC status flags, including FIFO full status flag and FIFO empty status flag. More...
 
enum  dac_operation_mode_t {
  kDAC_NormalOperationMode = 0U,
  kDAC_AutomaticOperationMode = 1U
}
 The enumeration of DAC operation mode, including normal operation mode and automatic operation mode. More...
 
enum  dac_sync_signal_selection_t {
  kDAC_InternalClockSignal = 0U,
  kDAC_ExternalSyncInSignal = 1U
}
 The enumeration of DAC sync signal mode, including internal clock signal and external SYNC_IN signal. More...
 
enum  dac_waveform_type_t {
  kDAC_RepeatSawtoothWaveform0 = 0U,
  kDAC_RepeatSawtoothWaveform1 = 1U,
  kDAC_RepeatTriangleWaveform0 = 2U,
  kDAC_RepeatTriangleWaveform1 = 3U,
  kDAC_OneShotSawtoothWaveform0 = 4U,
  kDAC_OneShotSawtoothWaveform1 = 5U
}
 The enumeration of waveform type, such as square waveform, triangle waveform, etc. More...
 
enum  dac_speed_mode_t {
  kDAC_HighSpeedMode = 0U,
  kDAC_LowSpeedMode = 1U
}
 The enumeration of DAC speed mode, including high speed mode and low speed mode. More...
 
enum  dac_watermark_level_t {
  kDAC_WatermarkValue0 = 0U,
  kDAC_WatermarkValue2 = 1U,
  kDAC_WatermarkValue4 = 2U,
  kDAC_WatermarkValue6 = 3U
}
 The enumeration of FIFO watermark level. More...
 
enum  dac_data_format_t {
  kDAC_DataWordRightJustified = 0U,
  kDAC_DataWordLeftJustified = 1U
}
 The enumeration of DAC data format, inclding right right-justified and left-justified. More...
 

Driver version

#define FSL_DAC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 1))
 DAC driver version. More...
 

Initialization And De-initialization Interfaces

void DAC_Init (DAC_Type *base, const dac_config_t *psConfig)
 Initializes the DAC resource, including data format, sync signal, operation mode, etc. More...
 
void DAC_Deinit (DAC_Type *base)
 De-initializes the DAC resource, the clock and power will be gated off. More...
 
void DAC_GetDefaultConfig (dac_config_t *psConfig)
 Gets the default DAC configs, such as operation mode, watermark level, sync signal, etc. More...
 

Operation Modes Related Interfaces

static void DAC_WriteDataFIFO (DAC_Type *base, uint16_t u16Data)
 Writes DAC buffered data value based on the data format when the DAC is in normal operation mode. More...
 
static void DAC_WriteStepSize (DAC_Type *base, uint16_t u16StepSize)
 Writes Step size based on the data format when the DAC is in automatic operation mode. More...
 
static void DAC_WriteMinValue (DAC_Type *base, uint16_t u16MinValue)
 Writes the minium value based on the data format when the DAC is in automatic operation mode. More...
 
static void DAC_WriteMaxValue (DAC_Type *base, uint16_t u16MaxValue)
 Writes the maximum value based on the data format when the DAC is in automatic operation mode. More...
 

DMA Control Related Interfaces

static void DAC_EnableDMA (DAC_Type *base, bool bEnable)
 Enables/Disables DMA request that to be generated when the FIFO is below the watermark level. More...
 
static void DAC_SetWatermarkLevel (DAC_Type *base, dac_watermark_level_t eWatermarkLevel)
 Sets watermark level which is used for asserting a DMA request. More...
 

Glitch Filter Related Interfaces

static void DAC_EnableGlitchFilter (DAC_Type *base, bool bEnable)
 Enables/Disables Glitch filter. More...
 
static void DAC_SetGlitchFilterCount (DAC_Type *base, uint8_t u8FilterCount)
 Sets glitch filter count value(ranges from 0 to 63) that represents the number of clock cycles for which the DAC output is held unchanged after new data is presented to the analog DAC's inputs. More...
 

Power And Speed Related Interface

static void DAC_SetSpeedMode (DAC_Type *base, dac_speed_mode_t eSpeedMode)
 Selects speed mode, high speed mode uses more power and low speed mode saves power. More...
 
static void DAC_EnableAnalogPortion (DAC_Type *base, bool bEnable)
 Enables/Disables the operation of the analog portion of the DAC. More...
 

Status Flags Interface

static uint16_t DAC_GetFIFOStatusFlags (DAC_Type *base)
 Gets the fifo status flag of selected DAC instance. More...
 

Data Structure Documentation

struct dac_normal_mode_config_t

Data Fields

bool bEnableDMA
 Enable/Disable DMA support. More...
 
uint16_t u16DataFIFO
 The FIFO watermark level, if the level of FIFO is less than or equal to the watermark level field, a DMA request should be sent. More...
 

Field Documentation

bool dac_normal_mode_config_t::bEnableDMA
  • true Enable DMA support.
  • false Disable DMA support.
uint16_t dac_normal_mode_config_t::u16DataFIFO

The DAC data to be converted to analog. If the data format is set as kDAC_DataWordRightJustified then u16DataFIFO should range from 0 to 4095, which means the higher 4 bits is useless. If the data format is set as kDAC_DataWordLeftJustified, then the u16DataFIFO should range from 16 to 65520, which means the lower 4 bits is useless.

struct dac_automatic_mode_config_t

Data Fields

dac_waveform_type_t eWaveformType
 The type of waveform to be generated. More...
 
uint16_t u16MinValue
 The step size to be added to or subtracted from the current value. More...
 
uint16_t u16MaxValue
 The maximum value is the upper range limit during automatic waveform generation. More...
 
uint16_t u16StartValue
 
The start value of the wavefrom, should larger than the minium value and

smaller than the maximum value. More...

 

Field Documentation

dac_waveform_type_t dac_automatic_mode_config_t::eWaveformType
uint16_t dac_automatic_mode_config_t::u16MinValue

If the data format is set as kDAC_DataWordRightJustified then u16StepSize should range from 0 to 4095, which means the higher 4 bits is useless. If the data format is set as kDAC_DataWordLeftJustified, then the u16StepSize should range from 16 to 65520, which means the lower 4 bits is useless. The minimum value is the lower range limit during automatic waveform generation. If the data format is set as kDAC_DataWordRightJustified then u16MinValue should range from 0 to 4095, which means the higher 4 bits is useless. If the data format is set as kDAC_DataWordLeftJustified, then the u16MinValue should range from 16 to 65520, which means the lower 4 bits is useless.

uint16_t dac_automatic_mode_config_t::u16MaxValue

If the data format is set as kDAC_DataWordRightJustified then u16MaxValue should range from 0 to 4095, which means the higher 4 bits is useless. If the data format is set as kDAC_DataWordLeftJustified, then the u16MaxValue should range from 16 to 65520, which means the lower 4 bits is useless.

uint16_t dac_automatic_mode_config_t::u16StartValue
union dac_operation_config_u

Data Fields

dac_normal_mode_config_t sNormalModeConfig
 The configuration of normal operation mode, such as buffered data, watermark level, etc. More...
 
dac_automatic_mode_config_t sAutomaticModeConfig
 The configuration of automatic operation mode, such as step size, minimum value, maximum value, etc. More...
 

Field Documentation

dac_normal_mode_config_t dac_operation_config_u::sNormalModeConfig
dac_automatic_mode_config_t dac_operation_config_u::sAutomaticModeConfig
struct dac_config_t

This structure is used to config the DAC module, to initialize the DAC module, user must set the member of this structure. This structure will cost 20 Byte memory space.

Data Fields

dac_operation_mode_t eOperationMode
 The operation mode. More...
 
dac_sync_signal_selection_t eSyncSignal
 The selected sync signal that used to update buffered data, the available selections are kDAC_InternalClockSignal and kDAC_ExternalSyncInSignal.
 
dac_data_format_t eDataFormat
 The data format of DAC instance. More...
 
dac_operation_config_u uOperationConfig
 The configuration of operation mode. More...
 
bool bEnableGlitchFilter
 Enable/Disable glitch suppression filter. More...
 
uint8_t u8GlitchFilterCount
 The count(ranges from 0 to 63) represents the number of clock cycles for which the DAC output is held unchanged after new data is presented to the analog DAC's inputs. More...
 
dac_speed_mode_t eSpeedMode
 The speed mode of DAC instance. More...
 
bool bEnableAnalogPortion
 Power up/down the analog portion. More...
 

Field Documentation

dac_operation_mode_t dac_config_t::eOperationMode

The available selections are kDAC_NormalOperationMode and kDAC_AutomaticOperationMode.

dac_data_format_t dac_config_t::eDataFormat

The available selections are kDAC_DataWordRightJustified and kDAC_DataWordLeftJustified

dac_operation_config_u dac_config_t::uOperationConfig
bool dac_config_t::bEnableGlitchFilter
  • true Enable glitch filter.
  • false Disable glitch filter.
uint8_t dac_config_t::u8GlitchFilterCount
dac_speed_mode_t dac_config_t::eSpeedMode

The available selections are kDAC_HighSpeedMode and kDAC_LowSpeedMode.

bool dac_config_t::bEnableAnalogPortion
  • true Power up the analog portion of the DAC, and the DAC will output the value currently presented to its inputs.
  • false Power down the analog portion of the DAC, and its output will be pulled down.

Macro Definition Documentation

#define FSL_DAC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 1))

Enumeration Type Documentation

Enumerator
kDAC_FIFOFullStatusFlag 

Indicate the FIFO is full.

kDAC_FIFOEmptyStatusFlag 

Indicate the FIFO is empty.

Enumerator
kDAC_NormalOperationMode 

Normal Mode to generate an analog representation of digital words.

kDAC_AutomaticOperationMode 

Automatic Mode to generate waveform without requiring CPU or core assistance.

Enumerator
kDAC_InternalClockSignal 

Internal Clock signal is selected as SYNC signal, data written to the buffered registers is used on the next clock cycle.

kDAC_ExternalSyncInSignal 

Peripheral external signal is selected as SYNC signal, the update occurs on the active edge of SYNC_IN signal.

Enumerator
kDAC_RepeatSawtoothWaveform0 

DAC generates repeated sawtooth waveform0.

The automatic waveform generation logic will create a repeated sawtooth waveform0 upon receiving an active SYNC edge, and the waveform repeats when it reaches its minimum and maximum value. The waveform increases from starting value to max value firstly. Like this following shown:

                                          /|   /|   /|   /|
                                         / |  / |  / |  / |
                                           | /  | /  | /  |
                                           |/   |/   |/   |
kDAC_RepeatSawtoothWaveform1 

DAC generates sawtooth waveform1.

The automatic waveform generation logic will create a repeated sawtooth waveform1 upon receiving an active SYNC edge, and the waveform repeats when it reaches its minimum and maximum value. The waveform decreases from starting value to min value firstly. Like this following shown:

                                                |\   |\   |\   |\
                                                | \  | \  | \  | \
                                              \ |  \ |  \ |  \ |  \
                                               \|   \|   \|   \|   \
kDAC_RepeatTriangleWaveform0 

The automatic waveform generation logic will create a repeated triangle waveform0 upon receiving an active SYNC edge, and the waveform repeats when it reaches its minimum and maximum value.

In this type the generated triangle waveform rises from the starting value. Like this following shown:

                                           /\      /\      /\
                                          /  \    /  \    /  \    /
                                         /    \  /    \  /    \  /
                                               \/      \/      \/
kDAC_RepeatTriangleWaveform1 

The automatic waveform generation logic will create a repeated triangle waveform1 upon receiving an active SYNC edge, and the waveform repeats when it reaches its minimum and maximum value.

In this type the generated triangle waveform drops from the starting value. Like this following shown:

                                             /\      /\      /\
                                       \    /  \    /  \    /  \
                                        \  /    \  /    \  /
                                         \/      \/      \/
kDAC_OneShotSawtoothWaveform0 

Automatic waveform generation logic will create a single pattern and stop at the final value.

It will remain at the finial value until a new active edge occurs on the SYNC input, and then the waveform will be repeated. Like this following shown:

                                                       /|       /|
                                                      / |      / |
                                                     /  |     /  |
                                                ____/   |____/   |___
kDAC_OneShotSawtoothWaveform1 

Automatic waveform generation logic will create a single pattern and stop at the final value.

It will remain at the finial value until a new active edge occurs on the SYNC input, and then the waveform will be repeated. Like this following shown:

:
                                             |\      |\
                                             | \     | \
                                             |  \    |  \
                                         ____|   \___|   \__
Enumerator
kDAC_HighSpeedMode 

In High Speed Mode, the setting time of the DAC module is 1us, but the DAC module uses more power.

kDAC_LowSpeedMode 

In Low Speed Mode, the DAC module uses less power but takes more time to settle.

Enumerator
kDAC_WatermarkValue0 

Watermark value is 0.

kDAC_WatermarkValue2 

Watermark value is 2.

kDAC_WatermarkValue4 

Watermark value is 4.

kDAC_WatermarkValue6 

Watermark value is 6.

Enumerator
kDAC_DataWordRightJustified 

The 12 bits data is right-justified.

kDAC_DataWordLeftJustified 

The 12 bits data iss left-justified.

Function Documentation

void DAC_Init ( DAC_Type *  base,
const dac_config_t psConfig 
)
Parameters
baseDAC peripheral base address.
psConfigThe pointer to dac_config_t.
void DAC_Deinit ( DAC_Type *  base)

Invoking this function to power down the analog portion of DAC and disable the DAC clock.

Parameters
baseDAC peripheral base address.
void DAC_GetDefaultConfig ( dac_config_t psConfig)
psConfig->eOperationMode = kDAC_NormalOperationMode;
psConfig->uOperationConfig.sNormalModeConfig.u16DataFIFO = 0U;
psConfig->bEnableDMA = false;
psConfig->eWatermarkLevel = kDAC_WatermarkValue2;
psConfig->eSyncInputEdge = kDAC_RisingEdge;
psConfig->eSpeedMode = kDAC_HighSpeedMode;
psConfig->eDataFormat = kDAC_DataWordRightJustified;
psConfig->eSyncSignal = kDAC_InternalClockSignal;
psConfig->bEnableAnalogPortion = false;
psConfig->bEnableGlitchFilter = true;
psConfig->u8GlitchFilterCount = 29U;
Parameters
psConfigThe pointer to dac_config_t.
static void DAC_WriteDataFIFO ( DAC_Type *  base,
uint16_t  u16Data 
)
inlinestatic
Parameters
baseDAC peripheral base address.
u16DataThe DAC data to be converted to analog. If the data format is set as kDAC_DataWordRightJustified then u16Data should range from 0 to 4095, which means the higher 4 bits is useless. If the data format is set as kDAC_DataWordLeftJustified, then the u16Data should range from 16 to 65520, which means the lower 4 bits is useless.
static void DAC_WriteStepSize ( DAC_Type *  base,
uint16_t  u16StepSize 
)
inlinestatic
Note
This function only useful when the operation mode is selected as automatic operation mode.
Parameters
baseDAC peripheral base address.
u16StepSizeThe step value to be added to or subtracted from the current value. If the data format is set as kDAC_DataWordRightJustified then u16StepSize should range from 0 to 4095, which means the higher 4 bits is useless. If the data format is set as kDAC_DataWordLeftJustified, then the u16StepSize should range from 16 to 65520, which means the lower 4 bits is useless.
static void DAC_WriteMinValue ( DAC_Type *  base,
uint16_t  u16MinValue 
)
inlinestatic
Note
This function only useful when the operation mode is selected as automatic operation mode. If DAC input data is less than the minium value, output is limited to the minium value during automatic waveform generation.
Parameters
baseDAC peripheral base address.
u16MinValueThe lower range limit during automatic waveform generation. If the data format is set as kDAC_DataWordRightJustified then u16MinValue should range from 0 to 4095, which means the higher 4 bits is useless. If the data format is set as kDAC_DataWordLeftJustified, then the u16MinValue should range from 16 to 65520, which means the lower 4 bits is useless.
static void DAC_WriteMaxValue ( DAC_Type *  base,
uint16_t  u16MaxValue 
)
inlinestatic
Note
This function only useful when the operation mode is selected as automatic operation mode. If DAC input data is greater than maximum value, output is limited to maximum value during automatic waveform generation.
Parameters
baseDAC peripheral base address.
u16MaxValueThe upper range limit during automatic waveform generation. If the data format is set as kDAC_DataWordRightJustified then u16MaxValue should range from 0 to 4095, which means the higher 4 bits is useless. If the data format is set as kDAC_DataWordLeftJustified, then the u16MaxValue should range from 16 to 65520, which means the lower 4 bits is useless.
static void DAC_EnableDMA ( DAC_Type *  base,
bool  bEnable 
)
inlinestatic
Note
This function is only useful when the operation mode is selected as Normal mode.
Parameters
baseDAC peripheral base address.
bEnableEnable/Disable DMA support.
  • true Enable DMA support.
  • false Disable DMA support.
static void DAC_SetWatermarkLevel ( DAC_Type *  base,
dac_watermark_level_t  eWatermarkLevel 
)
inlinestatic
Note
When the level of FIFO is less than or equal to the Watermark level, a DMA request will be sent. This function is only useful when the operation mode is selected as Normal mode.
Parameters
baseDAC peripheral base address.
eWatermarkLevelThe watermark level of FIFO, please refer to dac_watermark_level_t for details.
static void DAC_EnableGlitchFilter ( DAC_Type *  base,
bool  bEnable 
)
inlinestatic
Parameters
baseDAC peripheral base address.
bEnableEnable/Disable Glitch filter.
  • true Enable glitch filter.
  • false Disable glitch filter.
static void DAC_SetGlitchFilterCount ( DAC_Type *  base,
uint8_t  u8FilterCount 
)
inlinestatic
Parameters
baseDAC peripheral base address.
u8FilterCountThe count of glitch filter. This count represents the number of clock cycles for which the DAC output is held unchanged after new data is presented to the analog DAC's inputs.
static void DAC_SetSpeedMode ( DAC_Type *  base,
dac_speed_mode_t  eSpeedMode 
)
inlinestatic
Parameters
baseDAC peripheral base address.
eSpeedModeThe speedMode to be set, please refer to dac_speed_mode_t for details.
static void DAC_EnableAnalogPortion ( DAC_Type *  base,
bool  bEnable 
)
inlinestatic

The function controls the power-up of the analog portion of the DAC. If powered up the analog portion, the DAC module will output the value currently presented to the Data register. The analog portion should be powered up when the DAC is in use. If power down the analog portion, the output of the DAC module will be pulled low. The analog portion should be powered down when the DAC is not in use.

Parameters
baseDAC peripheral base address.
bEnablePower up/down the analog portion of the DAC.
  • true Power up the analog portion of the DAC, and the DAC will output the value currently presented to its inputs.
  • false Power down the analog portion of the DAC, and its output will be pulled down.
static uint16_t DAC_GetFIFOStatusFlags ( DAC_Type *  base)
inlinestatic
Parameters
baseDAC peripheral base address.
Returns
The status flags of DAC module, should be the OR'ed value of _dac_fifo_status_flags.