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
|
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...
|
|
struct dac12_hardware_info_t |
Actually, the most fields are for FIFO buffer.
uint32_t dac12_config_t::fifoWatermarkLevel |
Select the reference current source.
bool dac12_config_t::enableAnalogBuffer |
#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) |
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.
|
- Parameters
-
base | DAC12 peripheral base address. |
config | Pointer to configuration structure, see to dac12_config_t. |
This function initializes the user configuration structure to a default value. The default values are:
* config->fifoWatermarkLevel = 0U;
* config->speedMode = false;
* config->currentReferenceInternalTrimValue = 0x4;
*
- Parameters
-
config | Pointer to the configuration structure. See "dac12_config_t". |
void DAC12_Deinit |
( |
DAC_Type * |
base | ) |
|
- Parameters
-
base | DAC12 peripheral base address. |
static void DAC12_Enable |
( |
DAC_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DAC12 peripheral base address. |
enable | Enable the DAC12's converter or not. |
static void DAC12_ResetConfig |
( |
DAC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | DAC12 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
-
base | DAC12 peripheral base address. |
static uint32_t DAC12_GetStatusFlags |
( |
DAC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | DAC12 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
-
base | DAC12 peripheral base address. |
flags | Mask of status flags to be cleared. See to _dac12_status_flags. |
static void DAC12_EnableInterrupts |
( |
DAC_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
static void DAC12_DisableInterrupts |
( |
DAC_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
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
-
base | DAC12 peripheral base address. |
value | Setting 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
-
base | DAC12 peripheral base address. |
static uint32_t DAC12_GetFIFOReadPointer |
( |
DAC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | DAC12 peripheral base address. |
- Returns
- Read pointer index of FIFO buffer.
static uint32_t DAC12_GetFIFOWritePointer |
( |
DAC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | DAC12 peripheral base address. |
- Returns
- Write pointer index of FIFO buffer