CAT2 Peripheral Driver Library
Run-time Configuration Functions

This set of functions allows changes to the SAR configuration after initialization. More...

Functions

void Cy_SAR_SetConvertMode (SAR_Type *base, cy_en_sar_sample_ctrl_trigger_mode_t mode)
 Set the mode in which conversions are triggered. More...
 
__STATIC_INLINE void Cy_SAR_SetChanMask (SAR_Type *base, uint32_t enableMask)
 Set the enable/disable mask for the channels. More...
 
__STATIC_INLINE uint32_t Cy_SAR_GetChanMask (SAR_Type *base)
 Get the enable/disable mask for the channels. More...
 
void Cy_SAR_SetLowLimit (SAR_Type *base, uint32_t lowLimit)
 Set the low threshold for range detection. More...
 
void Cy_SAR_SetHighLimit (SAR_Type *base, uint32_t highLimit)
 Set the high threshold for range detection. More...
 
void Cy_SAR_SetVref (SAR_Type *base, cy_en_sar_ctrl_vref_sel_t vrefSel)
 Sets the Vref of the SAR ADC during runtime. More...
 
__STATIC_INLINE void Cy_SAR_SetRangeCond (SAR_Type *base, cy_en_sar_range_detect_condition_t cond)
 Set the condition in which range detection interrupts are triggered. More...
 
__STATIC_INLINE void Cy_SAR_EnableChannels (SAR_Type *base, uint32_t chanMask)
 Enable the specified channels. More...
 
__STATIC_INLINE void Cy_SAR_DisableChannels (SAR_Type *base, uint32_t chanMask)
 Disable the specified channels. More...
 

Detailed Description

This set of functions allows changes to the SAR configuration after initialization.

Function Documentation

◆ Cy_SAR_SetConvertMode()

void Cy_SAR_SetConvertMode ( SAR_Type base,
cy_en_sar_sample_ctrl_trigger_mode_t  mode 
)

Set the mode in which conversions are triggered.

This function does not start any conversions; it only configures the mode for subsequent conversions.

There are three modes:

  • firmware only; hardware triggering is disabled
  • firmware and edge sensitive hardware triggering
  • firmware and level sensitive hardware triggering

Note that firmware triggering is always enabled.

Parameters
basePointer to structure describing registers
modeA value of the enum cy_en_sar_sample_ctrl_trigger_mode_t
Function Usage
/* Scenario: Allow a rising edge on a hardware trigger signal to initiate
* a single conversion. FW triggering is still supported. The trigger signal
* can come from a device pin or an internal block. Make sure route the hardware signal
* to the SAR trigger input. */

◆ Cy_SAR_SetChanMask()

__STATIC_INLINE void Cy_SAR_SetChanMask ( SAR_Type base,
uint32_t  enableMask 
)

Set the enable/disable mask for the channels.

Parameters
basePointer to structure describing registers
enableMaskChannel enable/disable mask. Each bit corresponds to a channel.
  • 0: the corresponding channel is disabled.
  • 1: the corresponding channel is enabled; it will be included in the next scan.
Function Usage
/* Scenario: Channels 0 and 1 have been configured during initialization.
* Channel 1 only needs to be scanned periodically. Disable it and only scan channel 0. */
Cy_SAR_SetChanMask(SAR0, 1UL);

◆ Cy_SAR_GetChanMask()

__STATIC_INLINE uint32_t Cy_SAR_GetChanMask ( SAR_Type base)

Get the enable/disable mask for the channels.

Parameters
baseThe pointer to the structure, which describes registers.
Returns
Channel enable/disable mask. Each bit corresponds to a channel.
  • 0: the corresponding channel is disabled.
  • 1: the corresponding channel is enabled; it will be included in the next scan.

◆ Cy_SAR_SetLowLimit()

void Cy_SAR_SetLowLimit ( SAR_Type base,
uint32_t  lowLimit 
)

Set the low threshold for range detection.

The values are interpreted as signed or unsigned according to the channel configuration. Range detection is done on the value stored in the result register. That is, after averaging, shifting sign extension, and left/right alignment.

Parameters
basePointer to structure describing registers
lowLimitThe low threshold for range detection
Returns
None
Function Usage
/* Scenario: Range detection interrupts have been enabled for all unsigned channels.
* Adjust the the low limit of the range detection to 0x300 and the high limit to 0xC00. */
Cy_SAR_SetLowLimit(SAR0, 0x300UL);
Cy_SAR_SetHighLimit(SAR0, 0xC00UL);

◆ Cy_SAR_SetHighLimit()

void Cy_SAR_SetHighLimit ( SAR_Type base,
uint32_t  highLimit 
)

Set the high threshold for range detection.

The values are interpreted as signed or unsigned according to the channel configuration. Range detection is done on the value stored in the result register. That is, after averaging, shifting sign extension, and left/right alignment.

Parameters
basePointer to structure describing registers
highLimitThe high threshold for range detection
Returns
None
Function Usage
/* Scenario: Range detection interrupts have been enabled for all unsigned channels.
* Adjust the the low limit of the range detection to 0x300 and the high limit to 0xC00. */
Cy_SAR_SetLowLimit(SAR0, 0x300UL);
Cy_SAR_SetHighLimit(SAR0, 0xC00UL);

◆ Cy_SAR_SetVref()

void Cy_SAR_SetVref ( SAR_Type base,
cy_en_sar_ctrl_vref_sel_t  vrefSel 
)

Sets the Vref of the SAR ADC during runtime.

If Vref = BGR or VDDA/2, API enables the Vref buffer, otherwise, disable the Vref buffer. When using this API, the user must:

  • Stop the ADC before running this function.
  • Configure the correct gain of channels using Cy_SAR_SetChannelGain for raw count conversations APIs to work properly while using a different Vref.
  • Allow sufficient time for Vref to settle change when using a bypass cap or the Vref buffer.
Parameters
baseThe pointer to the structure, which describes registers.
vrefSelThe enumerated type of possible Vref settings cy_en_sar_ctrl_vref_sel_t.

◆ Cy_SAR_SetRangeCond()

__STATIC_INLINE void Cy_SAR_SetRangeCond ( SAR_Type base,
cy_en_sar_range_detect_condition_t  cond 
)

Set the condition in which range detection interrupts are triggered.

Parameters
basePointer to structure describing registers
condA value of the enum cy_en_sar_range_detect_condition_t.
Function Usage
/* Scenario: Range detection interrupts have been enabled for all unsigned channels.
* Set the range condition to be outside; a range interrupt is detected
* when (result < lowLimit) || (highLimit <= result). */

◆ Cy_SAR_EnableChannels()

__STATIC_INLINE void Cy_SAR_EnableChannels ( SAR_Type base,
uint32_t  chanMask 
)

Enable the specified channels.

Parameters
basePointer to structure describing registers
chanMaskCombined mask of all channels to be enabled.
Function Usage
/* Scenario: Channels 0 and 1 have been configured during initialization.
* Channel 1 only needs to be scanned periodically. Disable it and only scan channel 0.
*/
/* Scenario: Now channels 1 is needed again. */

◆ Cy_SAR_DisableChannels()

__STATIC_INLINE void Cy_SAR_DisableChannels ( SAR_Type base,
uint32_t  chanMask 
)

Disable the specified channels.

Parameters
basePointer to structure describing registers
chanMaskCombined mask of all channels to be disabled.
Function Usage
/* Scenario: Channels 0 and 1 have been configured during initialization.
* Channel 1 only needs to be scanned periodically. Disable it and only scan channel 0.
*/
/* Scenario: Now channels 1 is needed again. */