Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Overview

This section describes the programming interface of the CADC HAL driver.

Data Structures

struct  cadc_controller_config_t
 Defines a structure to configure the CyclicADC module during initialization. More...
 
struct  cadc_converter_config_t
 Defines a structure to configure each converter in the CyclicADC module. More...
 
struct  cadc_chn_config_t
 Defines a structure to configure each input channel. More...
 
struct  cadc_slot_config_t
 Defines a structure to configure each slot. More...
 

Enumerations

enum  cadc_status_t {
  kStatus_CADC_Success = 0U,
  kStatus_CADC_InvalidArgument = 1U,
  kStatus_CADC_Failed = 2U
}
 CADC status return codes. More...
 
enum  cadc_diff_chn_t {
  kCAdcDiffChnANA0_1 = 0U,
  kCAdcDiffChnANA2_3 = 1U,
  kCAdcDiffChnANA4_5 = 2U,
  kCAdcDiffChnANA6_7 = 3U,
  kCAdcDiffChnANB0_1 = 4U,
  kCAdcDiffChnANB2_3 = 5U,
  kCAdcDiffChnANB4_5 = 6U,
  kCAdcDiffChnANB6_7 = 7U
}
 Defines the type of enumerating ADC differential channel pair. More...
 
enum  cadc_chn_sel_mode_t {
  kCAdcChnSelN = 0U,
  kCAdcChnSelP = 1U,
  kCAdcChnSelBoth = 2U
}
 Defines the type of enumerating ADC channel in a differential pair. More...
 
enum  cadc_scan_mode_t {
  kCAdcScanOnceSequential = 0U,
  kCAdcScanOnceParallel = 1U,
  kCAdcScanLoopSequential = 2U,
  kCAdcScanLoopParallel = 3U,
  kCAdcScanTriggeredSequential = 4U,
  kCAdcScanTriggeredParalled = 5U
}
 Defines the type of enumerating ADC converter's scan mode. More...
 
enum  cadc_zero_crossing_mode_t {
  kCAdcZeroCrossingDisable = 0U,
  kCAdcZeroCrossingAtRisingEdge = 1U,
  kCAdcZeroCrossingAtFallingEdge = 2U,
  kCAdcZeroCrossingAtBothEdge = 3U
}
 Defines the type to enumerate the zero crossing detection mode for each slot. More...
 
enum  cadc_gain_mode_t {
  kCAdcSGainBy1 = 0U,
  kCAdcSGainBy2 = 1U,
  kCAdcSGainBy4 = 2U
}
 Defines the type to enumerate the amplification mode for each slot. More...
 
enum  cadc_conv_speed_mode_t {
  kCAdcConvClkLimitBy6_25MHz = 0U,
  kCAdcConvClkLimitBy12_5MHz = 1U,
  kCAdcConvClkLimitBy18_75MHz = 2U,
  kCAdcConvClkLimitBy25MHz = 3U
}
 Defines the type to enumerate the speed mode for each converter. More...
 
enum  cadc_dma_trigger_src_t {
  kCAdcDmaTriggeredByEndOfScan = 0U,
  kCAdcDmaTriggeredByConvReady = 1U
}
 Defines the type of DMA trigger source for each converter. More...
 

Functions

void CADC_HAL_Init (ADC_Type *base)
 Initializes all ADC registers to a known state. More...
 
void CADC_HAL_ConfigController (ADC_Type *base, const cadc_controller_config_t *configPtr)
 Configures the common features in cyclic ADC module. More...
 
void CADC_HAL_ConfigConvA (ADC_Type *base, const cadc_converter_config_t *configPtr)
 Configures the features for the converter A. More...
 
void CADC_HAL_ConfigConvB (ADC_Type *base, const cadc_converter_config_t *configPtr)
 Configures the features for the conversion B. More...
 
void CADC_HAL_ConfigChn (ADC_Type *base, const cadc_chn_config_t *configPtr)
 Configures the feature for the sample channel. More...
 
void CADC_HAL_ConfigSeqSlot (ADC_Type *base, uint32_t slotIdx, const cadc_slot_config_t *configPtr)
 Configures the features for the sample sequence slot. More...
 
static void CADC_HAL_SetConvAStartCmd (ADC_Type *base)
 Executes the command that starts conversion of the converter A. More...
 
static void CADC_HAL_SetConvBStartCmd (ADC_Type *base)
 Executes the command that start conversion of the converter B. More...
 
static void CADC_HAL_SetConvAPowerDownCmd (ADC_Type *base, bool enable)
 Shuts down the conversion power manually for the converter A. More...
 
static void CADC_HAL_SetConvBPowerDownCmd (ADC_Type *base, bool enable)
 Shuts down the conversion power manually for the converter B. More...
 
static bool CADC_HAL_GetConvAInProgressFlag (ADC_Type *base)
 Gets the flag whether the converter A is in process. More...
 
static bool CADC_HAL_GetConvBInProgressFlag (ADC_Type *base)
 Gets the flag whether the converter B is in process. More...
 
static bool CADC_HAL_GetConvAEndOfScanIntFlag (ADC_Type *base)
 Gets the flag whether the converter A has finished the conversion. More...
 
static bool CADC_HAL_GetConvBEndOfScanIntFlag (ADC_Type *base)
 Gets the flag whether the converter B has finished the conversion. More...
 
static void CADC_HAL_ClearConvAEndOfScanIntFlag (ADC_Type *base)
 Clears the flag that finishes the conversion of the converter A. More...
 
static void CADC_HAL_ClearConvBEndOfScanIntFlag (ADC_Type *base)
 Clears the flag that finishes the conversion of the converter B. More...
 
static bool CADC_HAL_GetZeroCrossingIntFlag (ADC_Type *base)
 Gets the flag whether a sample zero-crossing event has happened. More...
 
static uint16_t CADC_HAL_GetSlotZeroCrossingFlag (ADC_Type *base, uint16_t slotIdxMask)
 Gets the flag whether a sample zero-crossing event has happened. More...
 
static void CADC_HAL_ClearSlotZeroCrossingFlag (ADC_Type *base, uint16_t slotIdxMask)
 Clears the flags of a sample zero-crossing events. More...
 
static bool CADC_HAL_GetLowLimitIntFlag (ADC_Type *base)
 Gets the flag whether any sample value is lower than the low limit value. More...
 
static uint16_t CADC_HAL_GetSlotLowLimitFlag (ADC_Type *base, uint16_t slotIdxMask)
 Gets the flags whether a sample value is lower than the low limit value. More...
 
static void CADC_HAL_ClearSlotLowLimitFlag (ADC_Type *base, uint16_t slotIdxMask)
 Clears the flags of the sample low limit event. More...
 
static bool CADC_HAL_GetHighLimitIntFlag (ADC_Type *base)
 Gets the flag whether any sample value is higher than the high limit value. More...
 
static uint16_t CADC_HAL_GetSlotHighLimitFlag (ADC_Type *base, uint16_t slotIdxMask)
 Gets the flags whether a sample value is higher than the high limit value. More...
 
static void CADC_HAL_ClearSlotHighLimitFlag (ADC_Type *base, uint16_t slotIdxMask)
 Clears the flags of the sample high limit event. More...
 
static uint16_t CADC_HAL_GetSlotReadyFlag (ADC_Type *base, uint16_t slotIdxMask)
 Gets the flags whether a sample value is ready. More...
 
static bool CADC_HAL_GetConvAPowerDownFlag (ADC_Type *base)
 Gets the flag whether the converter A is powered down. More...
 
static bool CADC_HAL_GetConvBPowerDownFlag (ADC_Type *base)
 Gets the flag whether the converter B is powered down. More...
 
static uint16_t CADC_HAL_GetSampleValue (ADC_Type *base, uint16_t slotIdx)
 Gets the sample value. More...
 

Data Structure Documentation

struct cadc_controller_config_t

This structure holds the configuration when initializing the CyclicADC module.

Data Fields

bool zeroCrossingIntEnable
 Global zero crossing interrupt enable.
 
bool lowLimitIntEnable
 Global low limit interrupt enable.
 
bool highLimitIntEnable
 Global high limit interrupt enable.
 
cadc_scan_mode_t scanMode
 ADC scan mode control.
 
bool parallelSimultModeEnable
 Parallel scans done simultaneously enable.
 
cadc_dma_trigger_src_t dmaSrc
 DMA trigger source.
 
bool autoStandbyEnable
 Auto standby mode enable.
 
uint16_t powerUpDelayCount
 Power up delay.
 
bool autoPowerDownEnable
 Auto power down mode enable.
 
struct cadc_converter_config_t

This structure holds the configuration for each converter in the CyclicADC module. Normally, there are two converters, ConvA and ConvB in the cyclic ADC module. However, each converter can be configured separately for some features.

Data Fields

bool dmaEnable
 DMA enable.
 
bool stopEnable
 Stop mode enable.
 
bool syncEnable
 Enable external sync input to trigger conversion.
 
bool endOfScanIntEnable
 End of scan interrupt enable.
 
uint16_t clkDivValue
 ADC clock divider from the bus clock.
 
bool useChnInputAsVrefH
 Use input channel as high reference voltage, such as AN2.
 
bool useChnInputAsVrefL
 Use input channel as low reference voltage, such as AN3.
 
cadc_conv_speed_mode_t speedMode
 ADC speed control mode.
 
uint16_t sampleWindowCount
 Sample window count.
 
struct cadc_chn_config_t

This structure holds the configuration for each input channel. In CylicADC module, the input channels are handled by a differential sample. However, the user can still configure the function for each channel when set to operate as a single end sample.

Data Fields

cadc_diff_chn_t diffChns
 Select the differential channel pair.
 
cadc_chn_sel_mode_t diffSelMode
 Select which channel is indicated in a pair.
 
cadc_gain_mode_t gainMode
 Gain mode for each channel.
 
struct cadc_slot_config_t

This structure holds the configuration for each slot in a conversion sequence.

Data Fields

bool slotDisable
 Keep the slot unavailable.
 
bool syncPointEnable
 Sample waits for an enabled SYNC input to occur.
 
bool syncIntEnable
 Scan interrupt enable.
 
cadc_diff_chn_t diffChns
 Select the differential pair.
 
cadc_chn_sel_mode_t diffSel
 Positive or negative channel in differential pair.
 
cadc_zero_crossing_mode_t zeroCrossingMode
 Select zero crossing detection mode.
 
uint16_t lowLimitValue
 Select low limit for hardware compare.
 
uint16_t highLimitValue
 Select high limit for hardware compare.
 
uint16_t offsetValue
 Select sign change limit for hardware compare.
 

Enumeration Type Documentation

Enumerator
kStatus_CADC_Success 

Success.

kStatus_CADC_InvalidArgument 

Invalid argument existed.

kStatus_CADC_Failed 

Execution failed.

Note, "cadc_diff_chn_t" and "cadc_chn_sel_mode_t" can determine to select the single ADC sample channel.

Enumerator
kCAdcDiffChnANA0_1 

ConvA's Chn 0 & 1.

kCAdcDiffChnANA2_3 

ConvA's Chn 2 & 3.

kCAdcDiffChnANA4_5 

ConvA's Chn 4 & 5.

kCAdcDiffChnANA6_7 

ConvA's Chn 6 & 7.

kCAdcDiffChnANB0_1 

ConvB's Chn 0 & 1.

kCAdcDiffChnANB2_3 

ConvB's Chn 2 & 3.

kCAdcDiffChnANB4_5 

ConvB's Chn 4 & 5.

kCAdcDiffChnANB6_7 

ConvB's Chn 6 & 7.

Note, "cadc_diff_chn_t" and "cadc_chn_sel_mode_t" can determine selecting the single ADC sample channel.

Enumerator
kCAdcChnSelN 

Selects a negative side channel.

kCAdcChnSelP 

Selects a positive side channel.

kCAdcChnSelBoth 

Selects both channels in differential modes.

See the ADC_CTRL1[SMODE] in the chip Reference Manual for detailed information about the ADC converter scan mode.

Enumerator
kCAdcScanOnceSequential 

Once (single) sequential.

kCAdcScanOnceParallel 

Once parallel.

kCAdcScanLoopSequential 

Loop sequential.

kCAdcScanLoopParallel 

Loop parallel.

kCAdcScanTriggeredSequential 

Triggered sequential.

kCAdcScanTriggeredParalled 

Triggered parallel (default).

Enumerator
kCAdcZeroCrossingDisable 

Zero crossing detection disabled.

kCAdcZeroCrossingAtRisingEdge 

Enable for positive to negative sign change.

kCAdcZeroCrossingAtFallingEdge 

Enable for negative to positive sign change.

kCAdcZeroCrossingAtBothEdge 

Enable for any sign change.

Enumerator
kCAdcSGainBy1 

x1 amplification.

kCAdcSGainBy2 

x2 amplification.

kCAdcSGainBy4 

x4 amplification.

These items represent the clock speed at which the ADC converter can operate. Faster conversion speeds require greater current consumption.

Enumerator
kCAdcConvClkLimitBy6_25MHz 

Conversion clock frequency <= 6.25 MHz; current consumption per converter = 6 mA.

kCAdcConvClkLimitBy12_5MHz 

Conversion clock frequency <= 12.5 MHz; current consumption per converter = 10.8 mA.

kCAdcConvClkLimitBy18_75MHz 

Conversion clock frequency <= 18.75 MHz; current consumption per converter = 18 mA.

kCAdcConvClkLimitBy25MHz 

Conversion clock frequency <= 25 MHz; current consumption per converter = 25.2 mA.

During sequential and simultaneous parallel scan modes, it selects between end of scan for ConvA's scan and RDY status as the DMA source. During non-simultaneous parallel scan mode it selects between end of scan for converters A and B, and the RDY status as the DMA source.

Enumerator
kCAdcDmaTriggeredByEndOfScan 

DMA trigger source is end of scan interrupt.

kCAdcDmaTriggeredByConvReady 

DMA trigger source is RDY status.

Function Documentation

void CADC_HAL_Init ( ADC_Type *  base)

The initial states of ADC registers are set as specified in the chip Reference Manual.

Parameters
baseRegister base address for the module.
void CADC_HAL_ConfigController ( ADC_Type *  base,
const cadc_controller_config_t configPtr 
)

This function configures the common features in cyclic ADC module. For detailed items, see the "cadc_controller_config_t".

Parameters
baseRegister base address for the module.
configPtrPointer to configuration structure.
void CADC_HAL_ConfigConvA ( ADC_Type *  base,
const cadc_converter_config_t configPtr 
)

This function configures the features for the converter A. For detailed items, see the "cadc_converter_config_t".

Parameters
baseRegister base address for the module.
configPtrPointer to configuration structure.
void CADC_HAL_ConfigConvB ( ADC_Type *  base,
const cadc_converter_config_t configPtr 
)

This function configures the features for the conversion B. For detailed items, see the "cadc_converter_config_t".

Parameters
baseRegister base address for the module.
configPtrPointer to configuration structure.
void CADC_HAL_ConfigChn ( ADC_Type *  base,
const cadc_chn_config_t configPtr 
)

This function configures the features for the sample channel. For detailed items, see the "cadc_chn_config_t".

Parameters
baseRegister base address for the module.
configPtrPointer to configuration structure.
void CADC_HAL_ConfigSeqSlot ( ADC_Type *  base,
uint32_t  slotIdx,
const cadc_slot_config_t configPtr 
)

This function configures the features for the sample sequence slot. For detailed items, see the "cadc_slot_config_t".

Parameters
baseRegister base address for the module.
slotIdxSample slot index.
configPtrPointer to configuration structure.
static void CADC_HAL_SetConvAStartCmd ( ADC_Type *  base)
inlinestatic

This function executes the command that start the conversion of the converter A when using the software trigger.

Parameters
baseRegister base address for the module.
static void CADC_HAL_SetConvBStartCmd ( ADC_Type *  base)
inlinestatic

This function executes the command that start the conversion of the converter B when using the software trigger.

Parameters
baseRegister base address for the module.
static void CADC_HAL_SetConvAPowerDownCmd ( ADC_Type *  base,
bool  enable 
)
inlinestatic

This function shuts down the conversion power manually for the conversion A. The conversion stops immediately after calling this function.

Parameters
baseRegister base address for the module.
enableSwitcher to enable the feature or not.
static void CADC_HAL_SetConvBPowerDownCmd ( ADC_Type *  base,
bool  enable 
)
inlinestatic

This function shots downs the conversion power manually for the conversion B. The conversion stops immediately after calling this function.

Parameters
baseRegister base address for the module.
enableSwitcher to enable the feature or not.
static bool CADC_HAL_GetConvAInProgressFlag ( ADC_Type *  base)
inlinestatic

This function gets the flag whether the converter A is in process.

Parameters
baseRegister base address for the module.
Returns
The event is asserted or not.
static bool CADC_HAL_GetConvBInProgressFlag ( ADC_Type *  base)
inlinestatic

This function gets the flag whether the converter B is in process.

Parameters
baseRegister base address for the module.
Returns
The event is asserted or not.
static bool CADC_HAL_GetConvAEndOfScanIntFlag ( ADC_Type *  base)
inlinestatic

This function gets the flag whether the converter A has finished the conversion.

Parameters
baseRegister base address for the module.
Returns
The event is asserted or not.
static bool CADC_HAL_GetConvBEndOfScanIntFlag ( ADC_Type *  base)
inlinestatic

This function gets the flag whether the converter B has finished the conversion.

Parameters
baseRegister base address for the module.
Returns
The event is asserted or not.
static void CADC_HAL_ClearConvAEndOfScanIntFlag ( ADC_Type *  base)
inlinestatic

This function clears the flag that finishes the conversion of the converter A.

Parameters
baseRegister base address for the module.
static void CADC_HAL_ClearConvBEndOfScanIntFlag ( ADC_Type *  base)
inlinestatic

This function clears the flag that finishes the conversion of the converter B.

Parameters
baseRegister base address for the module.
static bool CADC_HAL_GetZeroCrossingIntFlag ( ADC_Type *  base)
inlinestatic

This function gets the flag whether any sample zero-crossing event has happened.

Parameters
baseRegister base address for the module.
Returns
The event is asserted or not.
static uint16_t CADC_HAL_GetSlotZeroCrossingFlag ( ADC_Type *  base,
uint16_t  slotIdxMask 
)
inlinestatic

This function gets the flags whether a sample zero-crossing event has happened.

Parameters
baseRegister base address for the module.
slotIdxMaskMask for indicated slots.
Returns
flags whether the event are happened for indicated slots.
static void CADC_HAL_ClearSlotZeroCrossingFlag ( ADC_Type *  base,
uint16_t  slotIdxMask 
)
inlinestatic

This function clears the flags of the sample zero-crossing events.

Parameters
baseRegister base address for the module.
slotIdxMaskMask for indicated slots.
static bool CADC_HAL_GetLowLimitIntFlag ( ADC_Type *  base)
inlinestatic

This function gets the flag whether any sample value is lower than the low limit value.

Parameters
baseRegister base address for the module.
Returns
The event is asserted or not.
static uint16_t CADC_HAL_GetSlotLowLimitFlag ( ADC_Type *  base,
uint16_t  slotIdxMask 
)
inlinestatic

This function gets the flags whether a samples value is lower than the low limit value.

Parameters
baseRegister base address for the module.
slotIdxMaskMask for indicated slots.
Returns
flags whether the event are happened for indicated slots.
static void CADC_HAL_ClearSlotLowLimitFlag ( ADC_Type *  base,
uint16_t  slotIdxMask 
)
inlinestatic

This function clears the flags of the sample low limit event.

Parameters
baseRegister base address for the module.
slotIdxMaskMask for indicated slots.
static bool CADC_HAL_GetHighLimitIntFlag ( ADC_Type *  base)
inlinestatic

This function gets the flag whether any sample value is higher than the high limit value.

Parameters
baseRegister base address for the module.
Returns
The event is asserted or not.
static uint16_t CADC_HAL_GetSlotHighLimitFlag ( ADC_Type *  base,
uint16_t  slotIdxMask 
)
inlinestatic

This function gets the flags whether a sample value is higher than the high limit value.

Parameters
baseRegister base address for the module.
slotIdxMaskMask for indicated slots.
Returns
flags whether the event are happened for indicated slots.
static void CADC_HAL_ClearSlotHighLimitFlag ( ADC_Type *  base,
uint16_t  slotIdxMask 
)
inlinestatic

This function clears the flags of the sample high limit event.

Parameters
baseRegister base address for the module.
slotIdxMaskMask for indicated slots.
static uint16_t CADC_HAL_GetSlotReadyFlag ( ADC_Type *  base,
uint16_t  slotIdxMask 
)
inlinestatic

This function gets the flags whether a sample value is ready.

Parameters
baseRegister base address for the module.
slotIdxMaskMask for indicated slots.
Returns
flags whether the event are happened for indicated slots.
static bool CADC_HAL_GetConvAPowerDownFlag ( ADC_Type *  base)
inlinestatic

This function gets the flag whether the converter A is powered down.

Parameters
baseRegister base address for the module.
Returns
The event is asserted or not.
static bool CADC_HAL_GetConvBPowerDownFlag ( ADC_Type *  base)
inlinestatic

This function gets the flag whether the converter B is powered down.

Parameters
baseRegister base address for the module.
Returns
The event is asserted or not.
static uint16_t CADC_HAL_GetSampleValue ( ADC_Type *  base,
uint16_t  slotIdx 
)
inlinestatic

This function gets the sample value. Note that the 3 LSBs are not available. When the differential conversion is executed, the MSB is the sign bit.

Parameters
baseRegister base address for the module.
slotIdxIndex of slot in conversion sequence.
Returns
sample value with sign bit in MSB.