Kinetis SDK v.1.3 API Reference Manual
Rev. 0
Freescale Semiconductor, Inc.
|
This section describes the programming interface of the AFE Peripheral driver. The AFE peripheral driver provides functions to initialize AFE module and channels, conversion triggering, and result reading.
The driver uses instances of the channel configuration structures to configuration and initialization AFE channel. This structure holds the settings of the AFE measurement channel. The settings include AFE hardware/software triggering, AFE continuous/Single conversion mode, AFE phase delay compensation, AFE channel mode, AFE channel analog gain, AFE channel oversampling ration, and AFE channel interrupt or DMA function. The AFE channel mode selects whether the bypass mode is enabled or disabled and the external clock selection.
The AFE driver uses instances of the user configuration structure afe_user_config_t for the AFE driver configuration. This structure holds the configuration which is common for all AFE channels. The settings include AFE low power mode, AFE result format, AFE clock divider mode, AFE clock source mode, and AFE start up delay of modulators.
This is an example of a typical AFE configuration. The afe_user_config_t instantiation is configured in the normal mode (low power mode disabled), result format is justified to the right, clock divider is selected 2 and a first clock source is selected (see the microcontroller documentation for information about these selections). The afe_chn_config_t instantiation is configured in the normal mode (no bypass), a continuous conversion, a zero delay, no interrupt or DMA request, the software trigger enabled, and the PGA disabled and the OSR is 2048.
This is an example code to set up a user and a channel AFE configuration instantiation:
This example shows how to call the AFE_DRV_Init() given the user configuration structure and the AFE instance 0.
This example shows how to call the AFE_DRV_ChnInit() given the channel configuration structure and the AFE channel 0 and 1.
The last part of the initialization contains the start up count setting, delay values confirmation, and the AFE module enabling.
The driver contains functions for software triggering, a channel delay after trigger setting, a result (raw or converted to right justified), reading and waiting functions.
If the software triggering is enabled (hwTriggerEnable parameter in afe_chn_config is a false value), call the AFE_DRV_SoftTriggerConv() function to start conversion. In this example, the channel 0 and channel 1 are triggered simultaneously. After the conversion is completed, the results are read.
If the hardware triggering is enabled (hwTriggerEnable parameter in afe_chn_config is a true value), the AFE_DRV_SoftTriggerConv() function isn't called. The rest of the code is the same.
If the continuous conversion isn't allowed (continuousConvEnable parameter in afe_chn_config is a false value), call the AFE_DRV_SoftTriggerConv() function (in the software trigger case) in the main loop to trigger the next conversion.
Data Structures | |
struct | afe_chn_config_t |
Defines the structure to initialize the AFE channel. More... | |
struct | afe_user_config_t |
Defines the structure to initialize the AFE module. More... | |
struct | afe_delay_config_t |
Defines the structure to configure phase delay of each AFE channel. More... | |
Enumerations | |
enum | afe_pga_state_t { kAfePgaDisable = 0U, kAfePgaGain1 = 1U, kAfePgaGain2 = 2U, kAfePgaGain4 = 3U, kAfePgaGain8 = 4U, kAfePgaGain16 = 5U, kAfePgaGain32 = 6U } |
Defines the PGA's values. More... | |
enum | afe_chn_mode_t { kAfeNormal = 0, kAfeBypassExternCltPosEdge = 1, kAfeBypassExternClkNegEdge = 2, kAfeBypassInternClkPosEdge = 3, kAfeBypassInternClkNegEdge = 4 } |
Defines the channel's modes. More... | |
enum | afe_chn_event_t { kAfeNoneReq = 0, kAfeIntReq = 1, kAfeDmaReq = 2 } |
Defines the channel's event requests. More... | |
enum | afe_flag_t { kAfeOverflowFlag = 0U, kAfeReadyFlag = 1U, kAfeConvCompleteFlag = 2U } |
Defines the type of event flags. More... | |
Functions | |
afe_status_t | AFE_DRV_StructInitUserConfigDefault (afe_user_config_t *userConfigPtr) |
Fills the user configure structure. More... | |
afe_status_t | AFE_DRV_StructInitChnConfigDefault (afe_chn_config_t *chnConfigPtr) |
Fills the channel configuration structure. More... | |
afe_status_t | AFE_DRV_Init (uint32_t instance, afe_user_config_t *userConfigPtr) |
Initializes the AFE module. More... | |
afe_status_t | AFE_DRV_ChnInit (uint32_t instance, uint32_t chn, afe_chn_config_t *chnConfigPtr) |
Initializes the selected AFE channel. More... | |
void | AFE_DRV_Enable (uint32_t instance, bool enable) |
Enables/disables all configured AFE channels. More... | |
void | AFE_DRV_WaitConvDone (uint32_t instance, uint32_t chn) |
Waits until the last conversion is complete. More... | |
void | AFE_DRV_WaitChnReady (uint32_t instance, uint32_t chn) |
Waits until the channel is ready for conversion. More... | |
void | AFE_DRV_SoftTriggerConv (uint32_t instance, uint32_t chnMask) |
Triggers the AFE conversion by software. More... | |
bool | AFE_DRV_GetChnFlag (uint32_t instance, uint32_t chn, afe_flag_t flag) |
Gets the flag for channel's events. More... | |
uint32_t | AFE_DRV_GetChnConvValRaw (uint32_t instance, uint32_t chn) |
Reads the conversion value in a raw form. More... | |
int32_t | AFE_DRV_GetChnConvVal (uint32_t instance, uint32_t chn) |
Reads the conversion value in 2's complement form. More... | |
void | AFE_DRV_Deinit (uint32_t instance) |
De-initializes the AFE module. More... | |
void | AFE_DRV_ChnDeinit (uint32_t instance, uint32_t chn) |
De-initializes the selected AFE channel. More... | |
void | AFE_DRV_AssertDelayOk (uint32_t instance) |
Asserts the phase delay setting. More... | |
void | AFE_DRV_SetPhaseDelays (uint32_t instance, afe_delay_config_t *delayConfigPtr) |
Sets phase delays. More... | |
Variables | |
AFE_Type *const | g_afeBase [] |
Table of base addresses for AFE instances. More... | |
const IRQn_Type | g_afeIrqId [] |
Table to save AFE IRQ enumeration numbers defined in CMSIS header file. More... | |
struct afe_chn_config_t |
This structure keeps the configuration for the AFE channel.
Data Fields | |
bool | hwTriggerEnable |
Enable triggering by hardware. | |
bool | continuousConvEnable |
Enable continuous conversion mode. | |
uint32_t | delay |
Set the phase compensation. | |
afe_chn_mode_t | chnMode |
Select if channel is in bypassed mode. | |
afe_pga_state_t | pgaGainSel |
Select the analog gain applied to the input signal. | |
afe_chn_osr_mode_t | decimOSR |
Select the over sampling ration. | |
afe_chn_event_t | chnEvent |
Select DMA or interrupt function. | |
struct afe_user_config_t |
This structure keeps the configuration for the AFE module.
Data Fields | |
bool | lowPowerEnable |
Enable low power mode. | |
afe_result_format_mode_t | resultFormat |
Select the result format. | |
afe_clk_divider_mode_t | clkDividerMode |
Select the clock divider ration for the modulator clock. | |
afe_clk_src_mode_t | clkSrcMode |
Select clock source for modulator clock. | |
uint8_t | startupCnt |
Select the start up delay of modulators. | |
struct afe_delay_config_t |
This structure keeps the phase delay of each AFE channel.
Data Fields | |
uint32_t | delayChn0 |
Phase compensation of channel0. More... | |
uint32_t | delayChn1 |
Phase compensation of channel1. More... | |
uint32_t | delayChn2 |
Phase compensation of channel2. More... | |
uint32_t afe_delay_config_t::delayChn0 |
uint32_t afe_delay_config_t::delayChn1 |
uint32_t afe_delay_config_t::delayChn2 |
enum afe_pga_state_t |
enum afe_chn_mode_t |
enum afe_chn_event_t |
enum afe_flag_t |
afe_status_t AFE_DRV_StructInitUserConfigDefault | ( | afe_user_config_t * | userConfigPtr | ) |
This function fills the afe_user_config_t structure with default settings. These setting are:
userConfigPtr | Pointer to structure of "afe_user_config_t". |
afe_status_t AFE_DRV_StructInitChnConfigDefault | ( | afe_chn_config_t * | chnConfigPtr | ) |
This function fills the afe_chn_config_t structure with default settings. These setting are:
chnConfigPtr | Pointer to structure of "afe_chn_config_t". |
afe_status_t AFE_DRV_Init | ( | uint32_t | instance, |
afe_user_config_t * | userConfigPtr | ||
) |
This function configures the AFE module for the configuration which are shared by all channels.
instance | The AFE instance number. |
userConfigPtr | Pointer to structure of "afe_user_config_t". If startupCnt parameter is less than two, this value is calculated according to equation Statup_cnt = (clk_freq/clk_div)*20e-6. |
afe_status_t AFE_DRV_ChnInit | ( | uint32_t | instance, |
uint32_t | chn, | ||
afe_chn_config_t * | chnConfigPtr | ||
) |
This function configures the selected AFE channel.
instance | The AFE instance number. |
chn | Channel which will be triggered. |
chnConfigPtr | Pointer to structure of "afe_chn_config_t". |
void AFE_DRV_Enable | ( | uint32_t | instance, |
bool | enable | ||
) |
This function enables or disables all channels whose SD_MOD_EN and DEC_EN bits are asserted.
instance | The AFE instance number. |
enable | Enable (true) or disable (false) all ADCs and filters. |
void AFE_DRV_WaitConvDone | ( | uint32_t | instance, |
uint32_t | chn | ||
) |
This function holds the program until the last conversion is complete.
instance | The AFE instance number. |
chn | Channel which is triggered. |
void AFE_DRV_WaitChnReady | ( | uint32_t | instance, |
uint32_t | chn | ||
) |
This function holds the program until the channel is ready for conversion.
instance | The AFE instance number. |
chn | Channel which is triggered. |
void AFE_DRV_SoftTriggerConv | ( | uint32_t | instance, |
uint32_t | chnMask | ||
) |
This function triggers the AFE conversion by executing a software command. It starts the conversion on selected channels if the software trigger option is selected for the channels.
instance | The AFE instance number. |
chnMask | Channel(s) mask which is triggered. |
bool AFE_DRV_GetChnFlag | ( | uint32_t | instance, |
uint32_t | chn, | ||
afe_flag_t | flag | ||
) |
This function returns the selected flag of the desired channel.
instance | The AFE instance number. |
chn | The AFE Channel. |
flag | Indicated event, see to "afe_flag_t". |
uint32_t AFE_DRV_GetChnConvValRaw | ( | uint32_t | instance, |
uint32_t | chn | ||
) |
This function returns the conversion value of the selected channel. The returned value could be left or right adjusted according to the AFE module configuration.
instance | The AFE instance number. |
chn | The AFE Channel. |
int32_t AFE_DRV_GetChnConvVal | ( | uint32_t | instance, |
uint32_t | chn | ||
) |
This function returns the conversion value of the selected channel. The returned value is in the twos complement (right adjusted) format.
instance | The AFE instance number. |
chn | The AFE Channel. |
void AFE_DRV_Deinit | ( | uint32_t | instance | ) |
When the AFE is no longer used, calling this function shuts down the device to reduce power consumption.
instance | The AFE instance number. |
void AFE_DRV_ChnDeinit | ( | uint32_t | instance, |
uint32_t | chn | ||
) |
De-initializes the selected AFE channel configuration and interrupt.
instance | The AFE instance number. |
chn | The AFE Channel. |
void AFE_DRV_AssertDelayOk | ( | uint32_t | instance | ) |
This function should be called after all desired channel's delay registers are loaded. Values in channel's delay registers are active after calling this function and after the conversation starts.
instance | The AFE instance number. |
void AFE_DRV_SetPhaseDelays | ( | uint32_t | instance, |
afe_delay_config_t * | delayConfigPtr | ||
) |
This function sets the phase delays for channels. This delay is inserted before the trigger response of the decimation filters. The delay is used to provide a phase compensation between AFE channels in step of prescaled modulator clock periods. The DelayOk bit is asserted in this function and the 'AFE_DRV_AssertDelayOk()' function doesn't have to be called. The delays for each channel are stored in a 'afe_delay_config_t' structure.
instance | The AFE instance number. |
delayConfigPtr | Pointer to structure of "afe_delay_config_t". |
AFE_Type* const g_afeBase[] |
const IRQn_Type g_afeIrqId[] |