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

Overview

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

Data Structures

struct  cmp_comparator_config_t
 Defines a structure for configuring the comparator in the CMP module. More...
 
struct  cmp_sample_filter_config_t
 Defines a structure to configure the window/filter in CMP module. More...
 
struct  cmp_dac_config_t
 Defines a structure to configure the internal DAC in the CMP module. More...
 

Enumerations

enum  cmp_status_t {
  kStatus_CMP_Success = 0U,
  kStatus_CMP_InvalidArgument = 1U,
  kStatus_CMP_Failed = 2U
}
 CMP status return codes. More...
 
enum  cmp_hystersis_mode_t {
  kCmpHystersisOfLevel0 = 0U,
  kCmpHystersisOfLevel1 = 1U,
  kCmpHystersisOfLevel2 = 2U,
  kCmpHystersisOfLevel3 = 3U
}
 Defines the selections of the hard block hysteresis control level. More...
 
enum  cmp_filter_counter_mode_t {
  kCmpFilterCountSampleOf0 = 0U,
  kCmpFilterCountSampleOf1 = 1U,
  kCmpFilterCountSampleOf2 = 2U,
  kCmpFilterCountSampleOf3 = 3U,
  kCmpFilterCountSampleOf4 = 4U,
  kCmpFilterCountSampleOf5 = 5U,
  kCmpFilterCountSampleOf6 = 6U,
  kCmpFilterCountSampleOf7 = 7U
}
 Defines the selections of the filter sample counter. More...
 
enum  cmp_dac_ref_volt_src_mode_t {
  kCmpDacRefVoltSrcOf1 = 0U,
  kCmpDacRefVoltSrcOf2 = 1U
}
 Defines the selections of reference voltage source for the internal DAC. More...
 
enum  cmp_chn_mux_mode_t {
  kCmpInputChn0 = 0U,
  kCmpInputChn1 = 1U,
  kCmpInputChn2 = 2U,
  kCmpInputChn3 = 3U,
  kCmpInputChn4 = 4U,
  kCmpInputChn5 = 5U,
  kCmpInputChn6 = 6U,
  kCmpInputChn7 = 7U,
  kCmpInputChnDac = kCmpInputChn7
}
 Define the selection of the CMP channel mux. More...
 
enum  cmp_sample_filter_mode_t {
  kCmpContinuousMode = 0U,
  kCmpSampleWithNoFilteredMode = 1U,
  kCmpSampleWithFilteredMode = 2U,
  kCmpWindowedMode = 3U,
  kCmpWindowedFilteredMode = 4U
}
 Definition selections of the sample and filter modes in the CMP module. More...
 

Functions

void CMP_HAL_Init (CMP_Type *base)
 Resets the CMP registers to a known state. More...
 
void CMP_HAL_ConfigComparator (CMP_Type *base, const cmp_comparator_config_t *configPtr)
 Configures the CMP comparator function. More...
 
void CMP_HAL_ConfigDacChn (CMP_Type *base, const cmp_dac_config_t *configPtr)
 Configures the CMP DAC function. More...
 
void CMP_HAL_ConfigSampleFilter (CMP_Type *base, const cmp_sample_filter_config_t *configPtr)
 Configures the CMP sample or the filter function. More...
 
static void CMP_HAL_Enable (CMP_Type *base)
 Enables the comparator in the CMP module. More...
 
static void CMP_HAL_Disable (CMP_Type *base)
 Disables the comparator in the CMP module. More...
 
static bool CMP_HAL_GetOutputLogic (CMP_Type *base)
 Gets the comparator logic output in the CMP module. More...
 
static bool CMP_HAL_GetOutputFallingFlag (CMP_Type *base)
 Gets the logic output falling edge event in the CMP module. More...
 
static void CMP_HAL_ClearOutputFallingFlag (CMP_Type *base)
 Clears the logic output falling edge event in the CMP module. More...
 
static bool CMP_HAL_GetOutputRisingFlag (CMP_Type *base)
 Gets the logic output rising edge event in the CMP module. More...
 
static void CMP_HAL_ClearOutputRisingFlag (CMP_Type *base)
 Clears the logic output rising edge event in the CMP module. More...
 

Data Structure Documentation

struct cmp_comparator_config_t

This structure holds the configuration for the comparator inside the CMP module. With the configuration, the CMP can be set as a basic comparator without additional features.

Data Fields

cmp_hystersis_mode_t hystersisMode
 Set the hysteresis level.
 
bool pinoutEnable
 Enable outputting the CMPO to pin.
 
bool pinoutUnfilteredEnable
 Enable outputting unfiltered result to CMPO.
 
bool invertEnable
 Enable inverting the comparator's result.
 
bool highSpeedEnable
 Enable working in speed mode.
 
bool risingIntEnable
 Enable using CMPO rising interrupt.
 
bool fallingIntEnable
 Enable using CMPO falling interrupt.
 
cmp_chn_mux_mode_t plusChnMux
 Set the Plus side input to comparator.
 
cmp_chn_mux_mode_t minusChnMux
 Set the Minus side input to comparator.
 
struct cmp_sample_filter_config_t

This structure holds the configuration for the window/filter inside the CMP module. With the configuration, the CMP module can operate in advanced mode.

Data Fields

cmp_sample_filter_mode_t workMode
 Sample/Filter's work mode.
 
bool useExtSampleOrWindow
 Switcher to use external WINDOW/SAMPLE signal.
 
uint8_t filterClkDiv
 Filter's prescaler which divides from the bus clock.
 
cmp_filter_counter_mode_t filterCount
 Sample count for filter. More...
 

Field Documentation

cmp_filter_counter_mode_t cmp_sample_filter_config_t::filterCount

See "cmp_filter_counter_mode_t".

struct cmp_dac_config_t

This structure holds the configuration for the DAC inside the CMP module. With the configuration, the internal DAC provides a reference voltage level and is chosen as the CMP input.

Data Fields

bool dacEnable
 Enable the internal 6-bit DAC.
 
cmp_dac_ref_volt_src_mode_t refVoltSrcMode
 Select the reference voltage source for internal DAC.
 
uint8_t dacValue
 Set the value for internal DAC.
 

Enumeration Type Documentation

Enumerator
kStatus_CMP_Success 

Success.

kStatus_CMP_InvalidArgument 

Invalid argument existed.

kStatus_CMP_Failed 

Execution failed.

The hysteresis control level indicates the smallest window between the two inputs when asserting the change of output. See the chip Data Sheet for detailed electrical characteristics. Generally, the lower level represents the smaller window.

Enumerator
kCmpHystersisOfLevel0 

Level 0.

kCmpHystersisOfLevel1 

Level 1.

kCmpHystersisOfLevel2 

Level 2.

kCmpHystersisOfLevel3 

Level 3.

The selection item represents the number of consecutive samples that must agree prior to the comparator output filter accepting a new output state.

Enumerator
kCmpFilterCountSampleOf0 

Disable the filter.

kCmpFilterCountSampleOf1 

One sample must agree.

kCmpFilterCountSampleOf2 

2 consecutive samples must agree

kCmpFilterCountSampleOf3 

3 consecutive samples must agree

kCmpFilterCountSampleOf4 

4 consecutive samples must agree

kCmpFilterCountSampleOf5 

5 consecutive samples must agree

kCmpFilterCountSampleOf6 

6 consecutive samples must agree

kCmpFilterCountSampleOf7 

7 consecutive samples must agree

Enumerator
kCmpDacRefVoltSrcOf1 

Vin1 - Vref_out.

kCmpDacRefVoltSrcOf2 

Vin2 - Vdd.

Enumerator
kCmpInputChn0 

Comparator input channel 0.

kCmpInputChn1 

Comparator input channel 1.

kCmpInputChn2 

Comparator input channel 2.

kCmpInputChn3 

Comparator input channel 3.

kCmpInputChn4 

Comparator input channel 4.

kCmpInputChn5 

Comparator input channel 5.

kCmpInputChn6 

Comparator input channel 6.

kCmpInputChn7 

Comparator input channel 7.

kCmpInputChnDac 

Comparator input channel 7.

Comparator sample/filter is available in several modes. Use the enumeration to identify the comparator's status:

kCmpContinuousMode - Continuous Mode: Both window control and filter blocks are completely bypassed. The comparator output is updated continuously. kCmpSampleWithNoFilteredMode - Sample, Non-Filtered Mode: Window control is completely bypassed. The comparator output is sampled whenever a rising-edge is detected on the filter block clock input. The filter clock prescaler can be configured as a divider from the bus clock. kCmpSampleWithFilteredMode - Sample, Filtered Mode: Similar to "Sample, Non-Filtered Mode", but the filter is active in this mode. The filter counter value also becomes configurable. kCmpWindowedMode - Windowed Mode: In Windowed Mode, only output of analog comparator is passed when the WINDOW signal is high. The last latched value is held when the WINDOW signal is low. kCmpWindowedFilteredMode - Window/Filtered Mode: This is a complex mode because it uses both window and filtering features. It also has the highest latency of all modes. This can be approximated to up to 1 bus clock synchronization in the window function

  • ( ( filter counter * filter prescaler ) + 1) bus clock for the filter function.
Enumerator
kCmpContinuousMode 

Continuous Mode.

kCmpSampleWithNoFilteredMode 

Sample, Non-Filtered Mode.

kCmpSampleWithFilteredMode 

Sample, Filtered Mode.

kCmpWindowedMode 

Window Mode.

kCmpWindowedFilteredMode 

Window/Filtered Mode.

Function Documentation

void CMP_HAL_Init ( CMP_Type *  base)

This function resets the CMP registers to a known state. This state is defined in the chip Reference Manual, which is power on reset value.

Parameters
baseRegister base address for the module.
void CMP_HAL_ConfigComparator ( CMP_Type *  base,
const cmp_comparator_config_t configPtr 
)

This function configures the CMP comparator function.

Parameters
baseRegister base address for the module.
configPtrPointer to configuration structure. See to "cmp_comparator_config_t".
void CMP_HAL_ConfigDacChn ( CMP_Type *  base,
const cmp_dac_config_t configPtr 
)

This function configures the CMP DAC function.

Parameters
baseRegister base address for the module.
configPtrPointer to configuration structure. See to "cmp_dac_config_t".
void CMP_HAL_ConfigSampleFilter ( CMP_Type *  base,
const cmp_sample_filter_config_t configPtr 
)

This function configures the CMP sample or filter function.

Parameters
baseRegister base address for the module.
configPtrPointer to configuration structure. See to "cmp_sample_filter_config_t".
static void CMP_HAL_Enable ( CMP_Type *  base)
inlinestatic

This function enables the comparator in the CMP module. The analog comparator is the core component in the CMP module. Only when it is enabled, all other functions for advanced features are meaningful.

Parameters
baseRegister base address for the module.
static void CMP_HAL_Disable ( CMP_Type *  base)
inlinestatic

This function disables the comparator in the CMP module. The analog comparator is the core component in the CMP module. When it is disabled, it remains in the off state and consumes no power.

Parameters
baseRegister base address for the module.
static bool CMP_HAL_GetOutputLogic ( CMP_Type *  base)
inlinestatic

This function gets the comparator logic output in the CMP module. It returns the current value of the analog comparator output. The value is reset to 0 and read as de-asserted value when the CMP module is disabled. When setting to invert mode, the comparator logic output is inverted as well.

Parameters
baseRegister base address for the module.
Returns
The logic output is assert or not.
static bool CMP_HAL_GetOutputFallingFlag ( CMP_Type *  base)
inlinestatic

This function gets the logic output falling edge event in the CMP module. It detects a falling-edge on COUT and returns the asserted state when the falling-edge on COUT has occurred.

Parameters
baseRegister base address for the module.
Returns
The falling-edge on COUT has occurred or not.
static void CMP_HAL_ClearOutputFallingFlag ( CMP_Type *  base)
inlinestatic

This function clears the logic output falling edge event in the CMP module.

Parameters
baseRegister base address for the module.
static bool CMP_HAL_GetOutputRisingFlag ( CMP_Type *  base)
inlinestatic

This function gets the logic output rising edge event in the CMP module. It detects a rising-edge on COUT and returns the asserted state when the rising-edge on COUT has occurred.

Parameters
baseRegister base address for the module.
Returns
The rising-edge on COUT has occurred or not.
static void CMP_HAL_ClearOutputRisingFlag ( CMP_Type *  base)
inlinestatic

This function clears the logic output rising edge event in the CMP module.

Parameters
baseRegister base address for the module.