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

Overview

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

This DAC is the 12-bit resolution digital-to-analog converters with programmable reference generator output. Its output data items are loaded into a FIFO, so that various FIFO mode 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 software and hardware trigger are also included in the driver.

Typical use case

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

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

Working with the trigger

Once more than one data is filled into the FIFO, the output pointer moves into configured mode when a trigger comes. This trigger can be from software or hardware, and moves one item for each trigger. Also, the interrupt/DMA event can 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/dac12

Files

file  fsl_dac12.h
 

Data Structures

struct  dac12_hardware_info_t
 DAC12 hardware information. More...
 
struct  dac12_config_t
 DAC12 module configuration. More...
 

Macros

#define DAC12_CR_W1C_FLAGS_MASK   (DAC_CR_OVFF_MASK | DAC_CR_UDFF_MASK)
 Define "write 1 to clear" flags. More...
 
#define DAC12_CR_ALL_FLAGS_MASK   (DAC12_CR_W1C_FLAGS_MASK | DAC_CR_WMF_MASK | DAC_CR_NEMPTF_MASK | DAC_CR_FULLF_MASK)
 Define all the flag bits in DACx_CR register. More...
 

Enumerations

enum  _dac12_status_flags {
  kDAC12_OverflowFlag = DAC_CR_OVFF_MASK,
  kDAC12_UnderflowFlag = DAC_CR_UDFF_MASK,
  kDAC12_WatermarkFlag = DAC_CR_WMF_MASK,
  kDAC12_NearlyEmptyFlag = DAC_CR_NEMPTF_MASK,
  kDAC12_FullFlag = DAC_CR_FULLF_MASK
}
 DAC12 flags. More...
 
enum  _dac12_interrupt_enable {
  kDAC12_UnderOrOverflowInterruptEnable = DAC_CR_UVIE_MASK,
  kDAC12_WatermarkInterruptEnable = DAC_CR_WTMIE_MASK,
  kDAC12_NearlyEmptyInterruptEnable = DAC_CR_EMPTIE_MASK,
  kDAC12_FullInterruptEnable = DAC_CR_FULLIE_MASK
}
 DAC12 interrupts. More...
 
enum  dac12_fifo_size_info_t {
  kDAC12_FIFOSize2 = 0U,
  kDAC12_FIFOSize4 = 1U,
  kDAC12_FIFOSize8 = 2U,
  kDAC12_FIFOSize16 = 3U,
  kDAC12_FIFOSize32 = 4U,
  kDAC12_FIFOSize64 = 5U,
  kDAC12_FIFOSize128 = 6U,
  kDAC12_FIFOSize256 = 7U
}
 DAC12 FIFO size information provided by hardware. More...
 
enum  dac12_fifo_work_mode_t {
  kDAC12_FIFODisabled = 0U,
  kDAC12_FIFOWorkAsNormalMode = 1U,
  kDAC12_FIFOWorkAsSwingMode = 2U
}
 DAC12 FIFO work mode. More...
 
enum  dac12_reference_voltage_source_t {
  kDAC12_ReferenceVoltageSourceAlt1 = 0U,
  kDAC12_ReferenceVoltageSourceAlt2 = 1U
}
 DAC12 reference voltage source. More...
 
enum  dac12_fifo_trigger_mode_t {
  kDAC12_FIFOTriggerByHardwareMode = 0U,
  kDAC12_FIFOTriggerBySoftwareMode = 1U
}
 DAC12 FIFO trigger mode. More...
 
enum  dac12_reference_current_source_t {
  kDAC12_ReferenceCurrentSourceDisabled = 0U,
  kDAC12_ReferenceCurrentSourceAlt0 = 1U,
  kDAC12_ReferenceCurrentSourceAlt1 = 2U,
  kDAC12_ReferenceCurrentSourceAlt2 = 3U
}
 DAC internal reference current source. More...
 
enum  dac12_speed_mode_t {
  kDAC12_SpeedLowMode = 0U,
  kDAC12_SpeedMiddleMode = 1U,
  kDAC12_SpeedHighMode = 2U
}
 DAC analog buffer speed mode for conversion. More...
 

Driver version

#define FSL_DAC12_DRIVER_VERSION   (MAKE_VERSION(2, 0, 2))
 DAC12 driver version 2.0.2. More...
 

Initialization and de-initialization

void DAC12_GetHardwareInfo (DAC_Type *base, dac12_hardware_info_t *info)
 Get hardware information about this module. More...
 
void DAC12_Init (DAC_Type *base, const dac12_config_t *config)
 Initialize the DAC12 module. More...
 
void DAC12_GetDefaultConfig (dac12_config_t *config)
 Initializes the DAC12 user configuration structure. More...
 
void DAC12_Deinit (DAC_Type *base)
 De-initialize the DAC12 module. More...
 
static void DAC12_Enable (DAC_Type *base, bool enable)
 Enable the DAC12's converter or not. More...
 
static void DAC12_ResetConfig (DAC_Type *base)
 Reset all internal logic and registers. More...
 
static void DAC12_ResetFIFO (DAC_Type *base)
 Reset the FIFO pointers. More...
 

Status

static uint32_t DAC12_GetStatusFlags (DAC_Type *base)
 Get status flags. More...
 
static void DAC12_ClearStatusFlags (DAC_Type *base, uint32_t flags)
 Clear status flags. More...
 

Interrupts

static void DAC12_EnableInterrupts (DAC_Type *base, uint32_t mask)
 Enable interrupts. More...
 
static void DAC12_DisableInterrupts (DAC_Type *base, uint32_t mask)
 Disable interrupts. More...
 

DMA control

static void DAC12_EnableDMA (DAC_Type *base, bool enable)
 Enable DMA or not. More...
 

Functional feature

static void DAC12_SetData (DAC_Type *base, uint32_t value)
 Set data into the entry of FIFO buffer. More...
 
static void DAC12_DoSoftwareTrigger (DAC_Type *base)
 Do trigger the FIFO by software. More...
 
static uint32_t DAC12_GetFIFOReadPointer (DAC_Type *base)
 Get the current read pointer of FIFO. More...
 
static uint32_t DAC12_GetFIFOWritePointer (DAC_Type *base)
 Get the current write pointer of FIFO. More...
 

Data Structure Documentation

struct dac12_hardware_info_t

Data Fields

dac12_fifo_size_info_t fifoSizeInfo
 The number of words in this device's DAC buffer. More...
 

Field Documentation

dac12_fifo_size_info_t dac12_hardware_info_t::fifoSizeInfo
struct dac12_config_t

Actually, the most fields are for FIFO buffer.

Data Fields

uint32_t fifoWatermarkLevel
 FIFO's watermark, the max value can be the hardware FIFO size. More...
 
dac12_fifo_work_mode_t fifoWorkMode
 FIFI's work mode about pointers. More...
 
dac12_reference_voltage_source_t referenceVoltageSource
 Select the reference voltage source. More...
 
dac12_reference_current_source_t referenceCurrentSource
 Select the trigger mode for FIFO. More...
 
dac12_speed_mode_t speedMode
 Select the speed mode for conversion. More...
 
bool enableAnalogBuffer
 Enable analog buffer for high drive. More...
 

Field Documentation

uint32_t dac12_config_t::fifoWatermarkLevel
dac12_fifo_work_mode_t dac12_config_t::fifoWorkMode
dac12_reference_voltage_source_t dac12_config_t::referenceVoltageSource
dac12_reference_current_source_t dac12_config_t::referenceCurrentSource

Select the reference current source.

dac12_speed_mode_t dac12_config_t::speedMode
bool dac12_config_t::enableAnalogBuffer

Macro Definition Documentation

#define FSL_DAC12_DRIVER_VERSION   (MAKE_VERSION(2, 0, 2))
#define DAC12_CR_W1C_FLAGS_MASK   (DAC_CR_OVFF_MASK | DAC_CR_UDFF_MASK)
#define DAC12_CR_ALL_FLAGS_MASK   (DAC12_CR_W1C_FLAGS_MASK | DAC_CR_WMF_MASK | DAC_CR_NEMPTF_MASK | DAC_CR_FULLF_MASK)

Enumeration Type Documentation

Enumerator
kDAC12_OverflowFlag 

FIFO overflow status flag, which indicates that more data has been written into FIFO than it can hold.

kDAC12_UnderflowFlag 

FIFO underflow status flag, which means that there is a new trigger after the FIFO is nearly empty.

kDAC12_WatermarkFlag 

FIFO wartermark status flag, which indicates the remaining FIFO data is less than the watermark setting.

kDAC12_NearlyEmptyFlag 

FIFO nearly empty flag, which means there is only one data remaining in FIFO.

kDAC12_FullFlag 

FIFO full status flag, which means that the FIFO read pointer equals the write pointer, as the write pointer increase.

Enumerator
kDAC12_UnderOrOverflowInterruptEnable 

Underflow and overflow interrupt enable.

kDAC12_WatermarkInterruptEnable 

Watermark interrupt enable.

kDAC12_NearlyEmptyInterruptEnable 

Nearly empty interrupt enable.

kDAC12_FullInterruptEnable 

Full interrupt enable.

Enumerator
kDAC12_FIFOSize2 

FIFO depth is 2.

kDAC12_FIFOSize4 

FIFO depth is 4.

kDAC12_FIFOSize8 

FIFO depth is 8.

kDAC12_FIFOSize16 

FIFO depth is 16.

kDAC12_FIFOSize32 

FIFO depth is 32.

kDAC12_FIFOSize64 

FIFO depth is 64.

kDAC12_FIFOSize128 

FIFO depth is 128.

kDAC12_FIFOSize256 

FIFO depth is 256.

Enumerator
kDAC12_FIFODisabled 

FIFO disabled and only one level buffer is enabled.

Any data written from this buffer goes to conversion.

kDAC12_FIFOWorkAsNormalMode 

Data will first read from FIFO to buffer then go to conversion.

kDAC12_FIFOWorkAsSwingMode 

In Swing mode, the FIFO must be set up to be full.

In Swing back mode, a trigger changes the read pointer to make it swing between the FIFO Full and Nearly Empty state. That is, the trigger increases the read pointer till FIFO is nearly empty and decreases the read pointer till the FIFO is full.

Enumerator
kDAC12_ReferenceVoltageSourceAlt1 

The DAC selects DACREF_1 as the reference voltage.

kDAC12_ReferenceVoltageSourceAlt2 

The DAC selects DACREF_2 as the reference voltage.

Enumerator
kDAC12_FIFOTriggerByHardwareMode 

Buffer would be triggered by hardware.

kDAC12_FIFOTriggerBySoftwareMode 

Buffer would be triggered by software.

Analog module needs reference current to keep working . Such reference current can generated by IP itself, or by on-chip PMC's "reference part". If no current reference be selected, analog module can’t working normally ,even when other register can still be assigned, DAC would waste current but no function. To make the DAC work, either kDAC12_ReferenceCurrentSourceAltx should be selected.

Enumerator
kDAC12_ReferenceCurrentSourceDisabled 

None of reference current source is enabled.

kDAC12_ReferenceCurrentSourceAlt0 

Use the internal reference current generated by the module itself.

kDAC12_ReferenceCurrentSourceAlt1 

Use the ZTC(Zero Temperature Coefficient) reference current generated by on-chip power management module.

kDAC12_ReferenceCurrentSourceAlt2 

Use the PTAT(Proportional To Absolution Temperature) reference current generated by power management module.

Enumerator
kDAC12_SpeedLowMode 

Low speed mode.

kDAC12_SpeedMiddleMode 

Middle speed mode.

kDAC12_SpeedHighMode 

High speed mode.

Function Documentation

void DAC12_GetHardwareInfo ( DAC_Type *  base,
dac12_hardware_info_t info 
)
Parameters
baseDAC12 peripheral base address.
infoPointer to info structure, see to dac12_hardware_info_t.
void DAC12_Init ( DAC_Type *  base,
const dac12_config_t config 
)
Parameters
baseDAC12 peripheral base address.
configPointer to configuration structure, see to dac12_config_t.
void DAC12_GetDefaultConfig ( dac12_config_t config)

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

* config->fifoWatermarkLevel = 0U;
* config->fifoWorkMode = kDAC12_FIFODisabled;
* config->referenceVoltageSource = kDAC12_ReferenceVoltageSourceAlt1;
* config->fifoTriggerMode = kDAC12_FIFOTriggerByHardwareMode;
* config->referenceCurrentSource = kDAC12_ReferenceCurrentSourceAlt0;
* config->speedMode = kDAC12_SpeedLowMode;
* config->speedMode = false;
* config->currentReferenceInternalTrimValue = 0x4;
*
Parameters
configPointer to the configuration structure. See "dac12_config_t".
void DAC12_Deinit ( DAC_Type *  base)
Parameters
baseDAC12 peripheral base address.
static void DAC12_Enable ( DAC_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseDAC12 peripheral base address.
enableEnable the DAC12's converter or not.
static void DAC12_ResetConfig ( DAC_Type *  base)
inlinestatic
Parameters
baseDAC12 peripheral base address.
static void DAC12_ResetFIFO ( DAC_Type *  base)
inlinestatic

FIFO pointers should only be reset when the DAC12 is disabled. This function can be used to configure both pointers to the same address to reset the FIFO as empty.

Parameters
baseDAC12 peripheral base address.
static uint32_t DAC12_GetStatusFlags ( DAC_Type *  base)
inlinestatic
Parameters
baseDAC12 peripheral base address.
Returns
Mask of current status flags. See to _dac12_status_flags.
static void DAC12_ClearStatusFlags ( DAC_Type *  base,
uint32_t  flags 
)
inlinestatic

Note: Not all the flags can be cleared by this API. Several flags need special condition to clear them according to target chip's reference manual document.

Parameters
baseDAC12 peripheral base address.
flagsMask of status flags to be cleared. See to _dac12_status_flags.
static void DAC12_EnableInterrupts ( DAC_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseDAC12 peripheral base address.
maskMask value of interrupts to be enabled. See to _dac12_interrupt_enable.
static void DAC12_DisableInterrupts ( DAC_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseDAC12 peripheral base address.
maskMask value of interrupts to be disabled. See to _dac12_interrupt_enable.
static void DAC12_EnableDMA ( DAC_Type *  base,
bool  enable 
)
inlinestatic

When DMA is enabled, the DMA request will be generated by original interrupts. The interrupts will not be presented on this module at the same time.

static void DAC12_SetData ( DAC_Type *  base,
uint32_t  value 
)
inlinestatic

When the DAC FIFO is disabled, and the one entry buffer is enabled, the DAC converts the data in the buffer to analog output voltage. Any write to the DATA register will replace the data in the buffer and push data to analog conversion without trigger support. When the DAC FIFO is enabled. Writing data would increase the write pointer of FIFO. Also, the data would be restored into the FIFO buffer.

Parameters
baseDAC12 peripheral base address.
valueSetting value into FIFO buffer.
static void DAC12_DoSoftwareTrigger ( DAC_Type *  base)
inlinestatic

When the DAC FIFO is enabled, and software trigger is used. Doing trigger would increase the read pointer, and the data in the entry pointed by read pointer would be converted as new output.

Parameters
baseDAC12 peripheral base address.
static uint32_t DAC12_GetFIFOReadPointer ( DAC_Type *  base)
inlinestatic
Parameters
baseDAC12 peripheral base address.
Returns
Read pointer index of FIFO buffer.
static uint32_t DAC12_GetFIFOWritePointer ( DAC_Type *  base)
inlinestatic
Parameters
baseDAC12 peripheral base address.
Returns
Write pointer index of FIFO buffer