CSEN - Capacitive Sense#
Capacitive Sense (CSEN) Peripheral API.
Provides functions to control the capacitive sense peripheral of Silicon Labs' 32-bit MCUs and SoCs. The CSEN includes a capacitance-to-digital circuit that measures capacitance on selected inputs. Measurements are performed using either a Successive Approximation Register (SAR) or a Delta Modulator (DM) analog to digital converter.
The CSEN can be configured to measure capacitance on a single port pin or to automatically measure multiple port pins in succession using scan mode. Also, several port pins can be shorted together to measure the combined capacitance.
The CSEN includes an accumulator, which can be configured to average multiple conversions on the selected input. Additionally, an Exponential Moving Average (EMA) calculator is included to provide data smoothing. A comparator is also included and can be used to terminate a continuous conversion when the configured threshold condition is met.
The following example shows how to initialize and start a single conversion on one input:
/* CSEN is a HFPERCLK peripheral. */
CMU_ClockEnable(cmuClock_HFPER, true);
CMU_ClockEnable(cmuClock_CSEN_HF, true);
/* Initialize with default settings. */
CSEN_Init_TypeDef csenInit = CSEN_INIT_DEFAULT;
CSEN_Init(CSEN, &csenInit);
/* Select the input pin and initialize the conversion mode. */
CSEN_InitMode_TypeDef csenInitMode = CSEN_INITMODE_DEFAULT;
csenInitMode.singleSel = csenSingleSelAPORT1XCH0;
CSEN_InitMode(CSEN, &csenInitMode);
/* Enable CSEN and manually start the conversion. */
CSEN_Enable(CSEN);
CSEN_Start(CSEN);
Modules#
Enumerations#
Comparator Mode.
Converter Select.
Sample Mode.
Starts Trigger Select.
Accumulator Mode Select.
Successive Approximation (SAR) Conversion Resolution.
Delta Modulator (DM) Conversion Resolution.
Period counter clock pre-scaler.
Exponential Moving Average sample weight.
Reset Phase Timing Select (units are microseconds).
Drive Strength Select.
Gain Select.
Peripheral Reflex System signal used to trigger conversion.
APORT channel to CSEN input selection.
APORT channel to CSEN single input selection.
Functions#
Get the last conversion result.
Get the last exponential moving average.
Set the exponential moving average initial value.
Disable CSEN.
Enable CSEN.
Set the DM integrator initial value.
Initialize CSEN.
Initialize a CSEN measurement mode.
Reset CSEN to same state that it was in after a hardware reset.
Clear one or more pending CSEN interrupts.
Disable one or more CSEN interrupts.
Enable one or more CSEN interrupts.
Get pending CSEN interrupt flags.
Get enabled and pending CSEN interrupt flags.
Set one or more pending CSEN interrupts from SW.
Return CSEN conversion busy status.
Start a scan sequence and/or a single conversion.
Macros#
CSEN default initialization.
CSEN default mode initialization.
Enumeration Documentation#
CSEN_CmpMode_TypeDef#
CSEN_CmpMode_TypeDef
Comparator Mode.
Selects the operation of the digital comparator.
Enumerator | |
---|---|
csenCmpModeDisabled | Comparator is disabled. |
csenCmpModeGreater | Comparator trips when the result is greater than the threshold. |
csenCmpModeLessOrEqual | Comparator trips when the result is less than or equal to the threshold. |
csenCmpModeEMAWindow | Comparator trips when the EMA is within the threshold window. |
CSEN_ConvSel_TypeDef#
CSEN_ConvSel_TypeDef
Converter Select.
Determines the converter operational mode.
Enumerator | |
---|---|
csenConvSelSAR | Successive Approximation (SAR) converter. |
csenConvSelSARChop | Successive Approximation (SAR) converter with low frequency attenuation. |
csenConvSelDM | Delta Modulation (DM) converter. |
csenConvSelDMChop | Delta Modulation (DM) converter with low frequency attenuation. |
CSEN_SampleMode_TypeDef#
CSEN_SampleMode_TypeDef
Sample Mode.
Determines how inputs are sampled for a conversion.
Enumerator | |
---|---|
csenSampleModeBonded | Converts multiple inputs shorted together and stop. |
csenSampleModeSingle | Converts one input and stop. |
csenSampleModeScan | Converts multiple inputs one at a time and stop. |
csenSampleModeContBonded | Continuously converts multiple inputs shorted together. |
csenSampleModeContSingle | Continuously converts one input. |
csenSampleModeContScan | Continuously converts multiple inputs one at a time. |
CSEN_TrigSel_TypeDef#
CSEN_TrigSel_TypeDef
Starts Trigger Select.
Enumerator | |
---|---|
csenTrigSelPRS | PRS system. |
csenTrigSelTimer | CSEN PC timer. |
csenTrigSelStart | Start bit. |
CSEN_AccMode_TypeDef#
CSEN_AccMode_TypeDef
Accumulator Mode Select.
Enumerator | |
---|---|
csenAccMode1 | Accumulate 1 sample. |
csenAccMode2 | Accumulate 2 samples. |
csenAccMode4 | Accumulate 4 samples. |
csenAccMode8 | Accumulate 8 samples. |
csenAccMode16 | Accumulate 16 samples. |
csenAccMode32 | Accumulate 32 samples. |
csenAccMode64 | Accumulate 64 samples. |
CSEN_SARRes_TypeDef#
CSEN_SARRes_TypeDef
Successive Approximation (SAR) Conversion Resolution.
Enumerator | |
---|---|
csenSARRes10 | 10-bit resolution. |
csenSARRes12 | 12-bit resolution. |
csenSARRes14 | 14-bit resolution. |
csenSARRes16 | 16-bit resolution. |
CSEN_DMRes_TypeDef#
CSEN_DMRes_TypeDef
Delta Modulator (DM) Conversion Resolution.
Enumerator | |
---|---|
csenDMRes10 | 10-bit resolution. |
csenDMRes12 | 12-bit resolution. |
csenDMRes14 | 14-bit resolution. |
csenDMRes16 | 16-bit resolution. |
CSEN_PCPrescale_TypeDef#
CSEN_PCPrescale_TypeDef
Period counter clock pre-scaler.
See the reference manual for source clock information.
Enumerator | |
---|---|
csenPCPrescaleDiv1 | Divide by 1. |
csenPCPrescaleDiv2 | Divide by 2. |
csenPCPrescaleDiv4 | Divide by 4. |
csenPCPrescaleDiv8 | Divide by 8. |
csenPCPrescaleDiv16 | Divide by 16. |
csenPCPrescaleDiv32 | Divide by 32. |
csenPCPrescaleDiv64 | Divide by 64. |
csenPCPrescaleDiv128 | Divide by 128. |
CSEN_EMASample_TypeDef#
CSEN_EMASample_TypeDef
Exponential Moving Average sample weight.
Enumerator | |
---|---|
csenEMASampleW1 | Weight 1. |
csenEMASampleW2 | Weight 2. |
csenEMASampleW4 | Weight 4. |
csenEMASampleW8 | Weight 8. |
csenEMASampleW16 | Weight 16. |
csenEMASampleW32 | Weight 32. |
csenEMASampleW64 | Weight 64. |
CSEN_ResetPhaseSel_TypeDef#
CSEN_ResetPhaseSel_TypeDef
Reset Phase Timing Select (units are microseconds).
Enumerator | |
---|---|
csenResetPhaseSel0 | Reset phase time = 0.75 usec. |
csenResetPhaseSel1 | Reset phase time = 1.00 usec. |
csenResetPhaseSel2 | Reset phase time = 1.20 usec. |
csenResetPhaseSel3 | Reset phase time = 1.50 usec. |
csenResetPhaseSel4 | Reset phase time = 2.00 usec. |
csenResetPhaseSel5 | Reset phase time = 3.00 usec. |
csenResetPhaseSel6 | Reset phase time = 6.00 usec. |
csenResetPhaseSel7 | Reset phase time = 12.0 usec. |
CSEN_DriveSel_TypeDef#
CSEN_DriveSel_TypeDef
Drive Strength Select.
Scales the output current.
Enumerator | |
---|---|
csenDriveSelFull | Drive strength = fully on. |
csenDriveSel1 | Drive strength = 1/8 full scale. |
csenDriveSel2 | Drive strength = 1/4 full scale. |
csenDriveSel3 | Drive strength = 3/8 full scale. |
csenDriveSel4 | Drive strength = 1/2 full scale. |
csenDriveSel5 | Drive strength = 5/8 full scale. |
csenDriveSel6 | Drive strength = 3/4 full scale. |
csenDriveSel7 | Drive strength = 7/8 full scale. |
CSEN_GainSel_TypeDef#
CSEN_GainSel_TypeDef
Gain Select.
See reference manual for information on each setting.
Enumerator | |
---|---|
csenGainSel1X | Gain = 1x. |
csenGainSel2X | Gain = 2x. |
csenGainSel3X | Gain = 3x. |
csenGainSel4X | Gain = 4x. |
csenGainSel5X | Gain = 5x. |
csenGainSel6X | Gain = 6x. |
csenGainSel7X | Gain = 7x. |
csenGainSel8X | Gain = 8x. |
CSEN_PRSSel_TypeDef#
CSEN_PRSSel_TypeDef
Peripheral Reflex System signal used to trigger conversion.
Enumerator | |
---|---|
csenPRSSELCh0 | PRS channel 0. |
csenPRSSELCh1 | PRS channel 1. |
csenPRSSELCh2 | PRS channel 2. |
csenPRSSELCh3 | PRS channel 3. |
csenPRSSELCh4 | PRS channel 4. |
csenPRSSELCh5 | PRS channel 5. |
csenPRSSELCh6 | PRS channel 6. |
csenPRSSELCh7 | PRS channel 7. |
csenPRSSELCh8 | PRS channel 8. |
csenPRSSELCh9 | PRS channel 9. |
csenPRSSELCh10 | PRS channel 10. |
csenPRSSELCh11 | PRS channel 11. |
CSEN_InputSel_TypeDef#
CSEN_InputSel_TypeDef
APORT channel to CSEN input selection.
Enumerator | |
---|---|
csenInputSelDefault | |
csenInputSelAPORT1CH0TO7 | |
csenInputSelAPORT1CH8TO15 | |
csenInputSelAPORT1CH16TO23 | |
csenInputSelAPORT1CH24TO31 | |
csenInputSelAPORT3CH0TO7 | |
csenInputSelAPORT3CH8TO15 | |
csenInputSelAPORT3CH16TO23 | |
csenInputSelAPORT3CH24TO31 |
CSEN_SingleSel_TypeDef#
CSEN_SingleSel_TypeDef
APORT channel to CSEN single input selection.
Enumerator | |
---|---|
csenSingleSelDefault | |
csenSingleSelAPORT1XCH0 | |
csenSingleSelAPORT1YCH1 | |
csenSingleSelAPORT1XCH2 | |
csenSingleSelAPORT1YCH3 | |
csenSingleSelAPORT1XCH4 | |
csenSingleSelAPORT1YCH5 | |
csenSingleSelAPORT1XCH6 | |
csenSingleSelAPORT1YCH7 | |
csenSingleSelAPORT1XCH8 | |
csenSingleSelAPORT1YCH9 | |
csenSingleSelAPORT1XCH10 | |
csenSingleSelAPORT1YCH11 | |
csenSingleSelAPORT1XCH12 | |
csenSingleSelAPORT1YCH13 | |
csenSingleSelAPORT1XCH14 | |
csenSingleSelAPORT1YCH15 | |
csenSingleSelAPORT1XCH16 | |
csenSingleSelAPORT1YCH17 | |
csenSingleSelAPORT1XCH18 | |
csenSingleSelAPORT1YCH19 | |
csenSingleSelAPORT1XCH20 | |
csenSingleSelAPORT1YCH21 | |
csenSingleSelAPORT1XCH22 | |
csenSingleSelAPORT1YCH23 | |
csenSingleSelAPORT1XCH24 | |
csenSingleSelAPORT1YCH25 | |
csenSingleSelAPORT1XCH26 | |
csenSingleSelAPORT1YCH27 | |
csenSingleSelAPORT1XCH28 | |
csenSingleSelAPORT1YCH29 | |
csenSingleSelAPORT1XCH30 | |
csenSingleSelAPORT1YCH31 | |
csenSingleSelAPORT3XCH0 | |
csenSingleSelAPORT3YCH1 | |
csenSingleSelAPORT3XCH2 | |
csenSingleSelAPORT3YCH3 | |
csenSingleSelAPORT3XCH4 | |
csenSingleSelAPORT3YCH5 | |
csenSingleSelAPORT3XCH6 | |
csenSingleSelAPORT3YCH7 | |
csenSingleSelAPORT3XCH8 | |
csenSingleSelAPORT3YCH9 | |
csenSingleSelAPORT3XCH10 | |
csenSingleSelAPORT3YCH11 | |
csenSingleSelAPORT3XCH12 | |
csenSingleSelAPORT3YCH13 | |
csenSingleSelAPORT3XCH14 | |
csenSingleSelAPORT3YCH15 | |
csenSingleSelAPORT3XCH16 | |
csenSingleSelAPORT3YCH17 | |
csenSingleSelAPORT3XCH18 | |
csenSingleSelAPORT3YCH19 | |
csenSingleSelAPORT3XCH20 | |
csenSingleSelAPORT3YCH21 | |
csenSingleSelAPORT3XCH22 | |
csenSingleSelAPORT3YCH23 | |
csenSingleSelAPORT3XCH24 | |
csenSingleSelAPORT3YCH25 | |
csenSingleSelAPORT3XCH26 | |
csenSingleSelAPORT3YCH27 | |
csenSingleSelAPORT3XCH28 | |
csenSingleSelAPORT3YCH29 | |
csenSingleSelAPORT3XCH30 | |
csenSingleSelAPORT3YCH31 |
Function Documentation#
CSEN_DataGet#
uint32_t CSEN_DataGet (CSEN_TypeDef * csen)
Get the last conversion result.
Type | Direction | Argument Name | Description |
---|---|---|---|
CSEN_TypeDef * | [in] | csen | Pointer to a CSEN peripheral register block. |
Note
Check the conversion busy flag before calling this function. In addition, the result width and format depend on the parameters passed to the CSEN_InitMode() function.
Returns
Result data from last conversion.
CSEN_EMAGet#
uint32_t CSEN_EMAGet (CSEN_TypeDef * csen)
Get the last exponential moving average.
Type | Direction | Argument Name | Description |
---|---|---|---|
CSEN_TypeDef * | [in] | csen | Pointer to a CSEN peripheral register block. |
Note
Confirm that CSEN is idle before calling this function.
Returns
Exponential moving average from last conversion.
CSEN_EMASet#
void CSEN_EMASet (CSEN_TypeDef * csen, uint32_t ema)
Set the exponential moving average initial value.
Type | Direction | Argument Name | Description |
---|---|---|---|
CSEN_TypeDef * | [in] | csen | Pointer to a CSEN peripheral register block. |
uint32_t | [in] | ema | Initial value for the exponential moving average. |
Note
Call this function before starting a conversion.
CSEN_Disable#
void CSEN_Disable (CSEN_TypeDef * csen)
Disable CSEN.
Type | Direction | Argument Name | Description |
---|---|---|---|
CSEN_TypeDef * | [in] | csen | Pointer to a CSEN peripheral register block. |
CSEN_Enable#
void CSEN_Enable (CSEN_TypeDef * csen)
Enable CSEN.
Type | Direction | Argument Name | Description |
---|---|---|---|
CSEN_TypeDef * | [in] | csen | Pointer to a CSEN peripheral register block. |
CSEN_DMBaselineSet#
void CSEN_DMBaselineSet (CSEN_TypeDef * csen, uint32_t up, uint32_t down)
Set the DM integrator initial value.
Type | Direction | Argument Name | Description |
---|---|---|---|
CSEN_TypeDef * | [in] | csen | A pointer to the CSEN peripheral register block. |
uint32_t | [in] | up | An initial value for the ramp-up integrator. |
uint32_t | [in] | down | An initial value for the ramp-down integrator. Has no effect if low-frequency attenuation is not configured. |
Sets the initial value of the integrator(s) for the Delta Modulation (DM) converter. The initial value for the ramp-down integrator has no effect if the low-frequency attenuation was not selected by the mode initialization function CSEN_InitMode().
Note
Confirm CSEN is idle before calling this function.
CSEN_Init#
void CSEN_Init (CSEN_TypeDef * csen, const CSEN_Init_TypeDef * init)
Initialize CSEN.
Type | Direction | Argument Name | Description |
---|---|---|---|
CSEN_TypeDef * | [in] | csen | A pointer to the CSEN peripheral register block. |
const CSEN_Init_TypeDef * | [in] | init | A pointer to the CSEN initialization structure. |
Initializes common functionality for all measurement types. In addition, measurement mode must be configured. See CSEN_InitMode().
Note
This function will stop any ongoing conversion and disable CSEN.
CSEN_InitMode#
void CSEN_InitMode (CSEN_TypeDef * csen, const CSEN_InitMode_TypeDef * init)
Initialize a CSEN measurement mode.
Type | Direction | Argument Name | Description |
---|---|---|---|
CSEN_TypeDef * | [in] | csen | A pointer to the CSEN peripheral register block. |
const CSEN_InitMode_TypeDef * | [in] | init | A pointer to the CSEN measurement mode initialization structure. |
Used to configure any type of measurement mode. After the measurement has been configured, calling CSEN_Enable() will enable CSEN and allow it to start a conversion from the selected trigger source. To manually start a conversion, use CSEN_Start(). To check if a conversion is in progress, use CSEN_IsBusy(), or alternatively use the interrupt flags returned by CSEN_IntGet() to detect when a conversion is completed.
Note
This function will stop any ongoing conversion and disable CSEN.
CSEN_Reset#
void CSEN_Reset (CSEN_TypeDef * csen)
Reset CSEN to same state that it was in after a hardware reset.
Type | Direction | Argument Name | Description |
---|---|---|---|
CSEN_TypeDef * | [in] | csen | A pointer to the CSEN peripheral register block. |
CSEN_IntClear#
void CSEN_IntClear (CSEN_TypeDef * csen, uint32_t flags)
Clear one or more pending CSEN interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
CSEN_TypeDef * | [in] | csen | Pointer to a CSEN peripheral register block. |
uint32_t | [in] | flags | Pending CSEN interrupt source to clear. Use a bitwise logic OR combination of valid interrupt flags for the CSEN module (CSEN_IF_nnn). |
CSEN_IntDisable#
void CSEN_IntDisable (CSEN_TypeDef * csen, uint32_t flags)
Disable one or more CSEN interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
CSEN_TypeDef * | [in] | csen | Pointer to a CSEN peripheral register block. |
uint32_t | [in] | flags | CSEN interrupt sources to disable. Use a bitwise logic OR combination of valid interrupt flags for the CSEN module (CSEN_IF_nnn). |
CSEN_IntEnable#
void CSEN_IntEnable (CSEN_TypeDef * csen, uint32_t flags)
Enable one or more CSEN interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
CSEN_TypeDef * | [in] | csen | Pointer to a CSEN peripheral register block. |
uint32_t | [in] | flags | CSEN interrupt sources to enable. Use a bitwise logic OR combination of valid interrupt flags for the CSEN module (CSEN_IF_nnn). |
Note
Depending on the use case, a pending interrupt may already be set prior to enabling the interrupt. Consider using CSEN_IntClear() prior to enabling if such a pending interrupt should be ignored.
CSEN_IntGet#
uint32_t CSEN_IntGet (CSEN_TypeDef * csen)
Get pending CSEN interrupt flags.
Type | Direction | Argument Name | Description |
---|---|---|---|
CSEN_TypeDef * | [in] | csen | Pointer to a CSEN peripheral register block. |
Note
The event bits are not cleared by the use of this function.
Returns
CSEN interrupt sources pending. A bitwise logic OR combination of valid interrupt flags for the CSEN module (CSEN_IF_nnn).
CSEN_IntGetEnabled#
uint32_t CSEN_IntGetEnabled (CSEN_TypeDef * csen)
Get enabled and pending CSEN interrupt flags.
Type | Direction | Argument Name | Description |
---|---|---|---|
CSEN_TypeDef * | [in] | csen | Pointer to a CSEN peripheral register block. |
Useful for handling more interrupt sources in the same interrupt handler.
Note
Interrupt flags are not cleared by the use of this function.
Returns
Pending and enabled CSEN interrupt sources. The return value is the bitwise AND combination of
the OR combination of enabled interrupt sources in CSENx_IEN_nnn register (CSENx_IEN_nnn) and
the OR combination of valid interrupt flags of the CSEN module (CSENx_IF_nnn).
CSEN_IntSet#
void CSEN_IntSet (CSEN_TypeDef * csen, uint32_t flags)
Set one or more pending CSEN interrupts from SW.
Type | Direction | Argument Name | Description |
---|---|---|---|
CSEN_TypeDef * | [in] | csen | Pointer to a CSEN peripheral register block. |
uint32_t | [in] | flags | CSEN interrupt sources to set to pending. Use a bitwise logic OR combination of valid interrupt flags for the CSEN module (CSEN_IF_nnn). |
CSEN_IsBusy#
bool CSEN_IsBusy (CSEN_TypeDef * csen)
Return CSEN conversion busy status.
Type | Direction | Argument Name | Description |
---|---|---|---|
CSEN_TypeDef * | [in] | csen | Pointer to a CSEN peripheral register block. |
Returns
True if CSEN conversion is in progress.
CSEN_Start#
void CSEN_Start (CSEN_TypeDef * csen)
Start a scan sequence and/or a single conversion.
Type | Direction | Argument Name | Description |
---|---|---|---|
CSEN_TypeDef * | [in] | csen | Pointer to a CSEN peripheral register block. |