Kinetis SDK v.1.3 API Reference Manual
Rev. 0
Freescale Semiconductor, Inc.
|
This section describes the programming interface of the DAC Peripheral driver. The DAC peripheral driver configures the DAC (Digital-to-Analog Converter). It also handles the module initialization and configuration by converting attributes.
To initialize the DAC module, call the DAC_DRV_Init() function and pass the configuration data structure, which can be filled by the DAC_DRV_StructInitUserConfigNormal() function with the default settings for the converter. After it is initialized, the DAC module can function as a DAC converter.
The DAC module provides advanced features internally with the hardware buffer. To use the advanced features, the API of the DAC_DRV_ConfigBuffer() function should be called to initialize the buffer.
The DAC module provides advanced features with the hardware DAC buffer.
When the DAC is enabled and the buffer is not enabled, the DAC module always converts the data in DAT0, the first item in the buffer, to analog output voltage. If the buffer is enabled, the DAC converts the items in the data buffer to analog output voltage according to the buffer configuration. The data buffer read pointer advances to the next word whenever any hardware or software trigger event occurs. The data buffer can be configured to operate in Normal mode, Swing mode, One-Time Scan mode or FIFO mode:
There are four kinds of typical use cases:
These use cases function either on the software trigger or the hardware trigger. To use the hardware trigger, enable the hardware trigger setting in the DAC module. Then, configure the other module that can generate the trigger, such as the PDB.
These are examples to initialize and configure the DAC driver for typical use cases:
Normal converter mode:
Buffer Normal mode:
Buffer Swing mode:
Buffer One-time Scan mode:
Buffer FIFO mode:
Enumerations | |
enum | dac_flag_t { kDacBuffIndexStartFlag = 1U, kDacBuffIndexUpperFlag = 2U } |
Defines the type of event flags. More... | |
Functions | |
dac_status_t | DAC_DRV_StructInitUserConfigNormal (dac_converter_config_t *userConfigPtr) |
Populates the initial user configuration for the DAC module without interrupt and buffer features. More... | |
dac_status_t | DAC_DRV_Init (uint32_t instance, const dac_converter_config_t *userConfigPtr) |
Initializes the converter. More... | |
dac_status_t | DAC_DRV_Deinit (uint32_t instance) |
De-initializes the DAC module converter. More... | |
void | DAC_DRV_Output (uint32_t instance, uint16_t value) |
Drives the converter to output the DAC value. More... | |
dac_status_t | DAC_DRV_ConfigBuffer (uint32_t instance, const dac_buffer_config_t *configPtr) |
Configures the internal buffer. More... | |
dac_status_t | DAC_DRV_SetBuffValue (uint32_t instance, uint8_t start, uint8_t offset, uint16_t arr[]) |
Sets values into the DAC internal buffer. More... | |
void | DAC_DRV_SoftTriggerBuffCmd (uint32_t instance) |
Triggers the buffer by software and returns the current value. More... | |
void | DAC_DRV_ClearBuffFlag (uint32_t instance, dac_flag_t flag) |
Clears the flag for an indicated event causing an interrupt. More... | |
bool | DAC_DRV_GetBuffFlag (uint32_t instance, dac_flag_t flag) |
Gets the flag for an indicated event causing an interrupt. More... | |
void | DAC_DRV_SetBuffCurIdx (uint32_t instance, uint8_t idx) |
Sets the current read pointer in DAC buffer. More... | |
uint8_t | DAC_DRV_GetBuffCurIdx (uint32_t instance) |
Gets the current read pointer in the DAC buffer. More... | |
Variables | |
DAC_Type *const | g_dacBase [] |
Table of base addresses for DAC instances. More... | |
const IRQn_Type | g_dacIrqId [DAC_INSTANCE_COUNT] |
Table to save DAC IRQ enumeration numbers defined in the CMSIS header file. More... | |
enum dac_flag_t |
dac_status_t DAC_DRV_StructInitUserConfigNormal | ( | dac_converter_config_t * | userConfigPtr | ) |
This function populates the initial user configuration without interrupt and buffer features. Calling the initialization function with the populated parameter configures the DAC module to operate as a simple converter. The settings are:
userConfigPtr | Pointer to the user configuration structure. See the "dac_user_config_t". |
dac_status_t DAC_DRV_Init | ( | uint32_t | instance, |
const dac_converter_config_t * | userConfigPtr | ||
) |
This function initializes the converter.
instance | DAC instance ID. |
userConfigPtr | Pointer to the initialization structure. See the "dac_user_config_t". |
dac_status_t DAC_DRV_Deinit | ( | uint32_t | instance | ) |
This function de-initializes the converter. It disables the DAC module and shuts down the clock to reduce the power consumption.
instance | DAC instance ID. |
void DAC_DRV_Output | ( | uint32_t | instance, |
uint16_t | value | ||
) |
This function drives the converter to output the DAC value. It forces the buffer index to be the first one and load the setting value to this item. Then, the converter outputs the voltage indicated by the indicated value immediately.
instance | DAC instance ID. |
value | Setting value for DAC. |
dac_status_t DAC_DRV_ConfigBuffer | ( | uint32_t | instance, |
const dac_buffer_config_t * | configPtr | ||
) |
This function configures the feature of the internal buffer for the DAC module. By default, the buffer feature is disabled. Calling this API enables the buffer and configures it.
instance | DAC instance ID. |
configPtr | Pointer to the configuration structure. See the "dac_buff_config_t". |
dac_status_t DAC_DRV_SetBuffValue | ( | uint32_t | instance, |
uint8_t | start, | ||
uint8_t | offset, | ||
uint16_t | arr[] | ||
) |
This function sets values into the DAC internal buffer. Note that the buffer size is defined by the "FSL_FEATURE_DAC_BUFFER_SIZE" macro and the available value is 12 bits.
instance | DAC instance ID. |
start | Start index of setting values. |
offset | Length of setting values' array. |
arr | Setting values' array. |
void DAC_DRV_SoftTriggerBuffCmd | ( | uint32_t | instance | ) |
This function triggers the buffer by software and returns the current value. After it is triggered, the buffer index updates according to work mode. Then, the value kept inside the pointed item is immediately output.
instance | DAC instance ID. |
void DAC_DRV_ClearBuffFlag | ( | uint32_t | instance, |
dac_flag_t | flag | ||
) |
This function clears the flag for an indicated event causing an interrupt.
instance | DAC instance ID. |
flag | Indicated flag. See "dac_flag_t". |
bool DAC_DRV_GetBuffFlag | ( | uint32_t | instance, |
dac_flag_t | flag | ||
) |
This function gets the flag for an indicated event causing an interrupt. If the event occurs, the return value is asserted.
instance | DAC instance ID. |
flag | Indicated flag. See "dac_flag_t". |
void DAC_DRV_SetBuffCurIdx | ( | uint32_t | instance, |
uint8_t | idx | ||
) |
This function sets the current read pointer in DAC buffer.
instance | DAC instance ID. |
idx | Index for read pointer in buffer. |
uint8_t DAC_DRV_GetBuffCurIdx | ( | uint32_t | instance | ) |
This function gets the current read pointer in DAC buffer.
instance | DAC instance ID. |
DAC_Type* const g_dacBase[] |
const IRQn_Type g_dacIrqId[DAC_INSTANCE_COUNT] |