SARMUX Switch Control Functions

group group_sar_functions_switches

This set of functions is for controlling/querying the SARMUX switches.

Functions

void Cy_SAR_SetAnalogSwitch(SAR_Type *base, cy_en_sar_switch_register_sel_t switchSelect, uint32_t switchMask, cy_en_sar_switch_state_t state)

Provide firmware control of the SARMUX switches for firmware sequencing.

Each call to this function can open or close a set of switches. Previously configured switches are untouched.

If the SARSEQ is enabled, there is no need to use this function.

    /* Scenario: 
     * - Channel 0 is configured as a differential pair between P10.0 and P10.1.
     * - Channel 1 is configured to sample the internal DieTemp sensor.
     * Close required switches to make these connections.
     * Make sure to also enable the SAR sequencer control of these same switches. */

    uint32_t chan0SwitchMask = CY_SAR_MUX_FW_P0_VPLUS | CY_SAR_MUX_FW_P1_VMINUS;
    uint32_t chan1SwitchMask = CY_SAR_MUX_FW_TEMP_VPLUS | CY_SAR_MUX_FW_VSSA_VMINUS;

    /* Close the switches for channel 0. */
    Cy_SAR_SetAnalogSwitch(SAR, CY_SAR_MUX_SWITCH0, chan0SwitchMask, CY_SAR_SWITCH_CLOSE);
    
    /* Close the switches for channel 1. */
    Cy_SAR_SetAnalogSwitch(SAR, CY_SAR_MUX_SWITCH0, chan1SwitchMask, CY_SAR_SWITCH_CLOSE);
    
Return

None

Function Usage

Parameters

uint32_t Cy_SAR_GetAnalogSwitch(const SAR_Type *base, cy_en_sar_switch_register_sel_t switchSelect)

Return the state (open or close) of SARMUX switches.

Return

Each bit corresponds to a single switch, where a bit value of 0 is open and 1 is closed. Compare this value to the switch masks in cy_en_sar_mux_switch_fw_ctrl_t.

Parameters
  • base: Pointer to structure describing registers

  • switchSelect: The switch register that contains the desired switches. Select a value from cy_en_sar_switch_register_sel_t.

__STATIC_INLINE void Cy_SAR_SetVssaVminusSwitch (SAR_Type *base, cy_en_sar_switch_state_t state)

Open or close the switch between VSSA and Vminus of the SARADC through firmware.

This function calls Cy_SAR_SetAnalogSwitch with switchSelect set to CY_SAR_MUX_SWITCH0 and switchMask set to SAR_MUX_SWITCH0_MUX_FW_VSSA_VMINUS_Msk.

    /* Scenario: Easily close the switch between Vminus of the SARADC and VSSA. */
    Cy_SAR_SetVssaVminusSwitch(SAR, CY_SAR_SWITCH_CLOSE);
    
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • state: Open or close the switch. Select a value from cy_en_sar_switch_state_t.

void Cy_SAR_SetSwitchSarSeqCtrl(SAR_Type *base, uint32_t switchMask, cy_en_sar_switch_sar_seq_ctrl_t ctrl)

Enable or disable SARSEQ control of one or more switches.

Previously configured switches are untouched.

    /* Scenario: The SAR sequencer needs control of all switches on the dedicated SARMUX port
     * so that the channels can by sampled in a round robin fashion without CPU intervention. */
    
    uint32_t switchMask     = CY_SAR_MUX_SQ_CTRL_P0 \
                            | CY_SAR_MUX_SQ_CTRL_P1 \
                            | CY_SAR_MUX_SQ_CTRL_P2 \
                            | CY_SAR_MUX_SQ_CTRL_P3 \
                            | CY_SAR_MUX_SQ_CTRL_P4 \
                            | CY_SAR_MUX_SQ_CTRL_P5 \
                            | CY_SAR_MUX_SQ_CTRL_P6 \
                            | CY_SAR_MUX_SQ_CTRL_P7;

    Cy_SAR_SetSwitchSarSeqCtrl(SAR, switchMask, CY_SAR_SWITCH_SEQ_CTRL_ENABLE);
Return

None

Function Usage

Parameters

__STATIC_INLINE void Cy_SAR_SetVssaSarSeqCtrl (SAR_Type *base, cy_en_sar_switch_sar_seq_ctrl_t ctrl)

Enable or disable SARSEQ control of the switch between VSSA and Vminus of the SARADC.

This function calls Cy_SAR_SetSwitchSarSeqCtrl with switchMask set to SAR_MUX_SWITCH_SQ_CTRL_MUX_SQ_CTRL_VSSA_Msk.

    /* Scenario: Easily enable SARSEQ control of the switch between Vminus of the SARADC and VSSA. */
    Cy_SAR_SetVssaSarSeqCtrl(SAR, CY_SAR_SWITCH_SEQ_CTRL_ENABLE);
    
Return

None

Function Usage

Parameters