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

Overview

The MCUXpresso SDK provides a peripheral driver for the Digital-to-Analog Converter (DAC) module of MCUXpresso SDK devices.

This DAC is the 12-bit resolution digital-to-analog converters with a programmable reference generator output. Its output data items are loaded into a FIFO, so that various FIFO modes can be used to output the value for user-defined sequence.

The DAC driver provides a user-friendly interface to operate the DAC peripheral. The user can initialize/deinitialize the DAC driver, set data into FIFO, or enable the interrupt DMA for special events so that the hardware can process the DAC output data automatically. Also, the configuration for the software and hardware trigger are also included in the driver.

Typical use case

A simple use case to output the user-defined DAC value.

Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/dac

Working with the trigger

Once more than one data is filled into the FIFO, the output pointer would move in configured mode when a trigger come. This trigger can be from software or hardware, and move one item for each trigger. Also, the interrupt/DMA event could be activated when the output pointer hits to the configured position.

Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/dac

Files

file  fsl_dac.h
 

Data Structures

struct  _dac_config
 DAC configuration structure. More...
 

Typedefs

typedef enum _dac_fifo_trigger_mode dac_fifo_trigger_mode_t
 DAC FIFO trigger mode.
 
typedef enum _dac_fifo_work_mode dac_fifo_work_mode_t
 DAC FIFO work mode.
 
typedef enum
_dac_reference_voltage_source 
dac_reference_voltage_source_t
 DAC reference voltage source.
 
typedef struct _dac_config dac_config_t
 DAC configuration structure.
 

Enumerations

enum  {
  kDAC_ResetFIFO = LPDAC_RCR_FIFORST_MASK,
  kDAC_ResetLogic = LPDAC_RCR_SWRST_MASK
}
 DAC reset control. More...
 
enum  {
  kDAC_FIFOFullInterruptEnable = LPDAC_IER_FULL_IE_MASK,
  kDAC_FIFOEmptyInterruptEnable = LPDAC_IER_EMPTY_IE_MASK,
  kDAC_FIFOWatermarkInterruptEnable = LPDAC_IER_WM_IE_MASK,
  kDAC_SwingBackInterruptEnable = LPDAC_IER_SWBK_IE_MASK,
  kDAC_FIFOOverflowInterruptEnable = LPDAC_IER_OF_IE_MASK,
  kDAC_FIFOUnderflowInterruptEnable = LPDAC_IER_UF_IE_MASK
}
 DAC interrupts. More...
 
enum  {
  kDAC_FIFOEmptyDMAEnable = LPDAC_DER_EMPTY_DMAEN_MASK,
  kDAC_FIFOWatermarkDMAEnable = LPDAC_DER_WM_DMAEN_MASK
}
 DAC DMA switchers. More...
 
enum  {
  kDAC_FIFOUnderflowFlag = LPDAC_FSR_UF_MASK,
  kDAC_FIFOOverflowFlag,
  kDAC_FIFOSwingBackFlag = LPDAC_FSR_SWBK_MASK,
  kDAC_FIFOWatermarkFlag = LPDAC_FSR_WM_MASK,
  kDAC_FIFOEmptyFlag = LPDAC_FSR_EMPTY_MASK,
  kDAC_FIFOFullFlag = LPDAC_FSR_FULL_MASK
}
 DAC status flags. More...
 
enum  _dac_fifo_trigger_mode {
  kDAC_FIFOTriggerByHardwareMode = 0U,
  kDAC_FIFOTriggerBySoftwareMode = 1U
}
 DAC FIFO trigger mode. More...
 
enum  _dac_fifo_work_mode {
  kDAC_FIFODisabled = 0U,
  kDAC_FIFOWorkAsNormalMode = 1U,
  kDAC_FIFOWorkAsSwingMode = 2U
}
 DAC FIFO work mode. More...
 
enum  _dac_reference_voltage_source {
  kDAC_ReferenceVoltageSourceAlt1 = 0U,
  kDAC_ReferenceVoltageSourceAlt2 = 1U
}
 DAC reference voltage source. More...
 

Driver version

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

Initialization and de-initialization

void DAC_Init (LPDAC_Type *base, const dac_config_t *config)
 Initialize the DAC module with common configuartion. More...
 
void DAC_GetDefaultConfig (dac_config_t *config)
 Get the default settings for initialization's configuration. More...
 
void DAC_Deinit (LPDAC_Type *base)
 De-initialize the DAC module. More...
 
static void DAC_SetReset (LPDAC_Type *base, uint32_t mask)
 Assert the reset control to part hardware. More...
 
static void DAC_ClearReset (LPDAC_Type *base, uint32_t mask)
 Clear the reset control to part hardware. More...
 
static void DAC_Enable (LPDAC_Type *base, bool enable)
 Enable the DAC hardware system or not. More...
 

Interrupts

static void DAC_EnableInterrupts (LPDAC_Type *base, uint32_t mask)
 Enable the interrupts. More...
 
static void DAC_DisableInterrupts (LPDAC_Type *base, uint32_t mask)
 Disable the interrupts. More...
 

DMA control

static void DAC_EnableDMA (LPDAC_Type *base, uint32_t mask, bool enable)
 Enable the DMA switchers or not. More...
 

Status flags

static uint32_t DAC_GetStatusFlags (LPDAC_Type *base)
 Get status flags of DAC module. More...
 
static void DAC_ClearStatusFlags (LPDAC_Type *base, uint32_t flags)
 Clear status flags of DAC module. More...
 

Functional feature

static void DAC_SetData (LPDAC_Type *base, uint32_t value)
 Set data into the entry of FIFO buffer. More...
 
static uint32_t DAC_GetFIFOWritePointer (LPDAC_Type *base)
 Get the value of the FIFO write pointer. More...
 
static uint32_t DAC_GetFIFOReadPointer (LPDAC_Type *base)
 Get the value of the FIFO read pointer. More...
 
static void DAC_DoSoftwareTriggerFIFO (LPDAC_Type *base)
 Do software trigger to FIFO when in software mode. More...
 

Data Structure Documentation

struct _dac_config

Data Fields

uint32_t fifoWatermarkLevel
 FIFO's watermark, the max value can be the hardware FIFO size. More...
 
dac_fifo_trigger_mode_t fifoTriggerMode
 Select the trigger mode for FIFO. More...
 
dac_fifo_work_mode_t fifoWorkMode
 Select the work mode for FIFO. More...
 
bool enableLowPowerMode
 Enable the low power mode. More...
 
dac_reference_voltage_source_t referenceVoltageSource
 Select the reference voltage source. More...
 

Field Documentation

uint32_t _dac_config::fifoWatermarkLevel
dac_fifo_trigger_mode_t _dac_config::fifoTriggerMode
dac_fifo_work_mode_t _dac_config::fifoWorkMode
bool _dac_config::enableLowPowerMode
dac_reference_voltage_source_t _dac_config::referenceVoltageSource

Macro Definition Documentation

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

Enumeration Type Documentation

anonymous enum
Enumerator
kDAC_ResetFIFO 

Resets the FIFO pointers and flags.

kDAC_ResetLogic 

Resets all DAC registers and internal logic.

anonymous enum
Enumerator
kDAC_FIFOFullInterruptEnable 

FIFO full interrupt enable.

kDAC_FIFOEmptyInterruptEnable 

FIFO empty interrupt enable.

kDAC_FIFOWatermarkInterruptEnable 

FIFO watermark interrupt enable.

kDAC_SwingBackInterruptEnable 

Swing back one cycle complete interrupt enable.

kDAC_FIFOOverflowInterruptEnable 

FIFO overflow interrupt enable.

kDAC_FIFOUnderflowInterruptEnable 

FIFO underflow interrupt enable.

anonymous enum
Enumerator
kDAC_FIFOEmptyDMAEnable 

FIFO empty DMA enable.

kDAC_FIFOWatermarkDMAEnable 

FIFO watermark DMA enable.

anonymous enum
Enumerator
kDAC_FIFOUnderflowFlag 
   This flag means that there is a new trigger after the buffer is

empty.

The FIFO read pointer will not increase in this case and the data sent to DAC analog conversion will not changed. This flag is cleared by writing a 1 to it.

kDAC_FIFOOverflowFlag 
   This flag indicates that data is intended to write into FIFO after the

buffer is full.

The writer pointer will not increase in this case. The extra data will not be written into the FIFO. This flag is cleared by writing a 1 to it.

kDAC_FIFOSwingBackFlag 
   This flag indicates that the DAC has completed one period of

conversion in swing back mode.

It means that the read pointer has increased to the top (write pointer) once and then decreased to zero once. For example, after three data is written to FIFO, the writer pointer is now 3. Then, if continually triggered, the read pointer will swing like: 0-1-2-1-0-1-2-, and so on. After the fourth trigger, the flag is set. This flag is cleared by writing a 1 to it.

kDAC_FIFOWatermarkFlag 

This field is set if the remaining data in FIFO is less than or equal to the setting value of wartermark.

By writing data into FIFO by DMA or CPU, this flag is cleared automatically when the data in FIFO is more than the setting value of watermark.

kDAC_FIFOEmptyFlag 

FIFO empty flag.

kDAC_FIFOFullFlag 

FIFO full flag.

Enumerator
kDAC_FIFOTriggerByHardwareMode 

Buffer would be triggered by hardware.

kDAC_FIFOTriggerBySoftwareMode 

Buffer would be triggered by software.

Enumerator
kDAC_FIFODisabled 

FIFO mode is disabled and buffer mode is enabled.

Any data written to DATA[DATA] goes to buffer then goes to conversion.

kDAC_FIFOWorkAsNormalMode 

FIFO mode is enabled.

Data will be first read from FIFO to buffer then goes to conversion.

kDAC_FIFOWorkAsSwingMode 

In swing mode, the read pointer swings between the writer pointer and zero.

That is, the trigger increases the read pointer till reach the writer pointer and decreases the read pointer till zero, and so on. The FIFO empty/full/watermark flag will not update during swing back mode.

Enumerator
kDAC_ReferenceVoltageSourceAlt1 

The DAC selects VREFH_INT as the reference voltage.

kDAC_ReferenceVoltageSourceAlt2 

The DAC selects VREFH_EXT as the reference voltage.

Function Documentation

void DAC_Init ( LPDAC_Type *  base,
const dac_config_t config 
)

The clock will be enabled in this function.

Parameters
baseDAC peripheral base address.
configPointer to configuration structure.
void DAC_GetDefaultConfig ( dac_config_t config)

This function initializes the user configuration structure to a default value. The default values are:

* config->fifoWatermarkLevel = 0U;
* config->fifoTriggerMode = kDAC_FIFOTriggerByHardwareMode;
* config->fifoWorkMode = kDAC_FIFODisabled;
* config->enableLowPowerMode = false;
* config->referenceVoltageSource = kDAC_ReferenceVoltageSourceAlt1;
*
Parameters
configPointer to configuration structure.
void DAC_Deinit ( LPDAC_Type *  base)

The clock will be disabled in this function.

Parameters
baseDAC peripheral base address.
static void DAC_SetReset ( LPDAC_Type *  base,
uint32_t  mask 
)
inlinestatic

This function is to assert the reset control to part hardware. Responding part hardware would remain reset untill cleared by software.

Parameters
baseDAC peripheral base address.
maskThe reset control mask, see to _dac_reset_control_t.
static void DAC_ClearReset ( LPDAC_Type *  base,
uint32_t  mask 
)
inlinestatic

This function is to clear the reset control to part hardware. Responding part hardware would work after the reset control is cleared by software.

Parameters
baseDAC peripheral base address.
maskThe reset control mask, see to _dac_reset_control_t.
static void DAC_Enable ( LPDAC_Type *  base,
bool  enable 
)
inlinestatic

This function is to start the Programmable Reference Generator operation or not.

Parameters
baseDAC peripheral base address.
enableAssertion of indicated event.
static void DAC_EnableInterrupts ( LPDAC_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseDAC peripheral base address.
maskMask value of indicated interrupt events. See to _dac_interrupt_enable.
static void DAC_DisableInterrupts ( LPDAC_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseDAC peripheral base address.
maskMask value of indicated interrupt events. See to _dac_interrupt_enable.
static void DAC_EnableDMA ( LPDAC_Type *  base,
uint32_t  mask,
bool  enable 
)
inlinestatic
Parameters
baseDAC peripheral base address.
maskMask value of indicated DMA requeset. See to _dac_dma_enable.
enableEnable the DMA or not.
static uint32_t DAC_GetStatusFlags ( LPDAC_Type *  base)
inlinestatic
Parameters
baseDAC peripheral base address.
Returns
Mask value of status flags. See to _dac_status_flags.
static void DAC_ClearStatusFlags ( LPDAC_Type *  base,
uint32_t  flags 
)
inlinestatic
Parameters
baseDAC peripheral base address.
flagsMask value of status flags to be cleared. See to _dac_status_flags.
static void DAC_SetData ( LPDAC_Type *  base,
uint32_t  value 
)
inlinestatic
Parameters
baseDAC peripheral base address.
valueSetting value into FIFO buffer.
static uint32_t DAC_GetFIFOWritePointer ( LPDAC_Type *  base)
inlinestatic
Parameters
baseDAC peripheral base address.
Returns
Current value of the FIFO write pointer.
static uint32_t DAC_GetFIFOReadPointer ( LPDAC_Type *  base)
inlinestatic
Parameters
baseDAC peripheral base address.
Returns
Current value of the FIFO read pointer.
static void DAC_DoSoftwareTriggerFIFO ( LPDAC_Type *  base)
inlinestatic
Parameters
baseDAC peripheral base address.