Run-time Configuration Functions

group group_sar_functions_config

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

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.

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.

    
    /* 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_SetConvertMode(SAR, CY_SAR_TRIGGER_MODE_FW_AND_HWEDGE);
    
Return

None

Function Usage

Parameters

__STATIC_INLINE void Cy_SAR_SetChanMask (SAR_Type *base, uint32_t enableMask)

Set the enable/disable mask for the channels.

    /* 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(SAR, 1UL);
    
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • enableMask: 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.

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.

    
    /* 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(SAR, 0x300UL);
    Cy_SAR_SetHighLimit(SAR, 0xC00UL);
    
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • lowLimit: The low threshold for range detection

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.

    
    /* 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(SAR, 0x300UL);
    Cy_SAR_SetHighLimit(SAR, 0xC00UL);
    
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • highLimit: The high threshold for range detection

__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.

    
    /* 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_SetRangeCond(SAR, CY_SAR_RANGE_COND_OUTSIDE);
    
Return

None

Function Usage

Parameters