Kinetis SDK v.1.3 API Reference Manual
Rev. 0
Freescale Semiconductor, Inc.
|
This section describes the programming interface of the CADC Peripheral driver. The CADC peripheral driver configures the Cyclic ADC (12-bit Cyclic Analog-to-Digital Converter). It handles initialization, configuration and controlling the conversion of this module.
CADC driver has four objects:
The ADC operates either in a sequential scan mode or a parallel scan mode. In the sequential scan mode, the scan sequence is determined by defining the 16 sample slots that are processed in order, SAMPLE[0:15]. In the parallel scan mode, ConvA processes SAMPLE[0:7] in order and ConvB processes SAMPLE[8:15] in order.
The parallel scan mode is simultaneous or non-simultaneous:
The ADC can be configured to perform a single scan and halt, perform a scan whenever triggered, or perform the scan sequence repeatedly until manually stopped. The single scan (once mode) differs from the triggered mode only in that SYNC input signals must be re-armed after each use and subsequent SYNC inputs are ignored until the SYNC input is re-armed. Arming can occur any time after the SYNC pulse, including while the scan is still in process.
There are three categories of ADC interrupts:
When using the CADC module, all four objects should be configured according to the application requirements. This example illustrates how to use the CADC driver.
Enumerations | |
enum | cadc_conv_id_t { kCAdcConvA = 0U, kCAdcConvB = 1U } |
Defines the type of enumerating ADC converter ID. More... | |
enum | cadc_flag_t { kCAdcConvInProgress = 0U, kCAdcConvEndOfScanInt = 1U, kCAdcConvPowerDown = 2U, kCAdcZeroCrossingInt = 3U, kCAdcLowLimitInt = 4U, kCAdcHighLimitInt = 5U, kCAdcSlotReady = 6U, kCAdcSlotLowLimitEvent = 7U, kCAdcSlotHighLimitEvent = 8U, kCAdcSlotCrossingEvent = 9U } |
Defines types for an enumerating event. More... | |
Variables | |
ADC_Type * | g_cadcBaseAddr [] |
Table of base addresses for ADC instances. More... | |
IRQn_Type | g_cadcErrIrqId [ADC_INSTANCE_COUNT] |
Table to save ADC IRQ enumeration numbers defined in the CMSIS header file. More... | |
CADC Driver | |
cadc_status_t | CADC_DRV_StructInitUserConfigDefault (cadc_controller_config_t *userConfigPtr) |
Populates the user configuration structure for the CyclicADC common settings. More... | |
cadc_status_t | CADC_DRV_Init (uint32_t instance, const cadc_controller_config_t *userConfigPtr) |
Initializes the CyclicADC module for a global configuration. More... | |
cadc_status_t | CADC_DRV_Deinit (uint32_t instance) |
De-initializes the CyclicADC module. More... | |
cadc_status_t | CADC_DRV_StructInitConvConfigDefault (cadc_converter_config_t *configPtr) |
Populates the user configuration structure for each converter. More... | |
cadc_status_t | CADC_DRV_ConfigConverter (uint32_t instance, cadc_conv_id_t convId, const cadc_converter_config_t *configPtr) |
Configures each converter in the CyclicADC module. More... | |
cadc_status_t | CADC_DRV_ConfigSampleChn (uint32_t instance, const cadc_chn_config_t *configPtr) |
Configures the input channel for ADC conversion. More... | |
cadc_status_t | CADC_DRV_ConfigSeqSlot (uint32_t instance, uint32_t slotIdx, const cadc_slot_config_t *configPtr) |
Configures each slot for the ADC conversion sequence. More... | |
void | CADC_DRV_SoftTriggerConv (uint32_t instance, cadc_conv_id_t convId) |
Triggers the ADC conversion sequence by software. More... | |
uint16_t | CADC_DRV_GetSeqSlotConvValue (uint32_t instance, uint32_t slotIdx) |
Reads the conversion value and returns an absolute value. More... | |
bool | CADC_DRV_GetFlag (uint32_t instance, cadc_flag_t flag) |
Gets the global event flag. More... | |
void | CADC_DRV_ClearFlag (uint32_t instance, cadc_flag_t flag) |
Clears the global event flag. More... | |
bool | CADC_DRV_GetConvFlag (uint32_t instance, cadc_conv_id_t convId, cadc_flag_t flag) |
Gets the flag for each converter event. More... | |
void | CADC_DRV_ClearConvFlag (uint32_t instance, cadc_conv_id_t convId, cadc_flag_t flag) |
Clears the flag for each converter event. More... | |
uint16_t | CADC_DRV_GetSlotFlag (uint32_t instance, uint16_t slotIdxMask, cadc_flag_t flag) |
Gets the flag for each slot event. More... | |
void | CADC_DRV_ClearSlotFlag (uint32_t instance, uint16_t slotIdxMask, cadc_flag_t flag) |
Clears the flag for each slot event. More... | |
enum cadc_conv_id_t |
enum cadc_flag_t |
cadc_status_t CADC_DRV_StructInitUserConfigDefault | ( | cadc_controller_config_t * | userConfigPtr | ) |
This function populates the cadc_user_config_t structure with default settings, which are used in polling mode for ADC conversion. These settings are:
.zeroCrossingIntEnable = false; .lowLimitIntEnable = false; .highLimitIntEnable = false; .scanMode = kCAdcScanOnceSequential; .parallelSimultModeEnable = false; .dmaSrc = kCAdcDmaTriggeredByEndOfScan; .autoStandbyEnable = false; .powerUpDelayCount = 0x2AU; .autoPowerDownEnable = false;
userConfigPtr | Pointer to structure of "cadc_controller_config_t". |
cadc_status_t CADC_DRV_Init | ( | uint32_t | instance, |
const cadc_controller_config_t * | userConfigPtr | ||
) |
This function configures the CyclicADC module for the global configuration which is shared by all converters.
instance | Instance ID number. |
userConfigPtr | Pointer to structure of "cadc_controller_config_t". |
cadc_status_t CADC_DRV_Deinit | ( | uint32_t | instance | ) |
This function shuts down the CyclicADC module and disables related IRQs.
instance | Instance ID number. |
cadc_status_t CADC_DRV_StructInitConvConfigDefault | ( | cadc_converter_config_t * | configPtr | ) |
This function populates the cadc_conv_config_t structure with default settings, which are used in polling mode for ADC conversion. These settings are:
.dmaEnable = false; .stopEnable = false; .syncEnable = false; .endOfScanIntEnable = false; .clkDivValue = 0x3FU; .useChnInputAsVrefH = false; .useChnInputAsVrefL = false; .speedMode = kCAdcConvClkLimitBy25MHz; .sampleWindowCount = 0U;
configPtr | Pointer to structure of "cadc_converter_config_t". |
cadc_status_t CADC_DRV_ConfigConverter | ( | uint32_t | instance, |
cadc_conv_id_t | convId, | ||
const cadc_converter_config_t * | configPtr | ||
) |
This function configures each converter in the CyclicADC module. However, when the multiple converters are operating simultaneously, the converter settings are interrelated. For more information, see the appropriate device reference manual.
instance | Instance ID number. |
convId | Converter ID. See "cadc_conv_id_t". |
configPtr | Pointer to configure structure. See "cadc_converter_config_t". |
cadc_status_t CADC_DRV_ConfigSampleChn | ( | uint32_t | instance, |
const cadc_chn_config_t * | configPtr | ||
) |
This function configures the input channel for ADC conversion. The CyclicADC module input channels are organized in pairs. The configuration can be set for each channel in the pair.
instance | Instance ID number. |
configPtr | Pointer to configure structure. See "cadc_chn_config_t". |
cadc_status_t CADC_DRV_ConfigSeqSlot | ( | uint32_t | instance, |
uint32_t | slotIdx, | ||
const cadc_slot_config_t * | configPtr | ||
) |
This function configures each slot in the ADC conversion sequence. ADC conversion sequence is the basic execution unit in the CyclicADC module. However, the sequence should be configured slot-by-slot. The end of the sequence is a slot that is configured as disabled.
instance | Instance ID number. |
slotIdx | Indicated slot number, available in range of 0 - 15. |
configPtr | Pointer to configure structure. See "cadc_slot_config_t". |
void CADC_DRV_SoftTriggerConv | ( | uint32_t | instance, |
cadc_conv_id_t | convId | ||
) |
This function triggers the ADC conversion by executing a software command. It starts the conversion if no other SYNC input (hardware trigger) is needed.
instance | Instance ID number. |
convId | Indicated converter. See "cadc_conv_id_t". |
uint16_t CADC_DRV_GetSeqSlotConvValue | ( | uint32_t | instance, |
uint32_t | slotIdx | ||
) |
This function reads the conversion value from each slot in a conversion sequence. The return value is the absolute value without being signed.
instance | Instance ID number. |
slotIdx | Indicated slot number, available in range of 0 - 15. |
bool CADC_DRV_GetFlag | ( | uint32_t | instance, |
cadc_flag_t | flag | ||
) |
This function gets the global flag of the CyclicADC module.
instance | Instance ID number. |
flag | Indicated event. See "cadc_flag_t". |
void CADC_DRV_ClearFlag | ( | uint32_t | instance, |
cadc_flag_t | flag | ||
) |
This function clears the global event flag of the CyclicADC module.
instance | Instance ID number. |
flag | Indicated event. See "cadc_flag_t". |
bool CADC_DRV_GetConvFlag | ( | uint32_t | instance, |
cadc_conv_id_t | convId, | ||
cadc_flag_t | flag | ||
) |
This function gets the flag for each converter event.
instance | Instance ID number. |
convId | Indicated converter. |
flag | Indicated event. See "cadc_flag_t". |
void CADC_DRV_ClearConvFlag | ( | uint32_t | instance, |
cadc_conv_id_t | convId, | ||
cadc_flag_t | flag | ||
) |
This function clears the flag for each converter event.
instance | Instance ID number. |
convId | Indicated converter. |
flag | Indicated event. See "cadc_flag_t". |
uint16_t CADC_DRV_GetSlotFlag | ( | uint32_t | instance, |
uint16_t | slotIdxMask, | ||
cadc_flag_t | flag | ||
) |
This function gets the flag for each slot event in the conversion in sequence.
instance | Instance ID number. |
slotIdxMask | Indicated slot number's mask. |
flag | Indicated event. See "cadc_flag_t". |
void CADC_DRV_ClearSlotFlag | ( | uint32_t | instance, |
uint16_t | slotIdxMask, | ||
cadc_flag_t | flag | ||
) |
This function clears the flag for each slot event in the conversion in sequence.
instance | Instance ID number. |
slotIdxMask | Indicated slot number's mask. |
flag | Indicated event. See "cadc_flag_t". |
ADC_Type* g_cadcBaseAddr[] |
IRQn_Type g_cadcErrIrqId[ADC_INSTANCE_COUNT] |