PSOC E8XXGP Device Support Library
SAR ADC (Successive-Approximation Register Analog to Digital Converter)

General Description

This driver provides the API functions to configure the successive approximation register analog-to-digital converter (SAR ADC) subsystem of the Autonomous Analog.

The versatile SAR ADC is an analog-to-digital converter with a dual-core 12-bit successive approximation register. The SAR ADC (hereafter ADC) contains a High Speed (HS) Core that can operate in Active mode with the SRSS clock up to 80 MHz and a Low Power (LP) Core based on the 4.096 MHz LPOSC from the Autonomous Analog. The HS Core is not available in DeepSleep while the LP Core is available in all power modes.

Note
Only one core can be active at a time.

For more information on the ADC, refer to the device Architecture Technical Reference Manual (TRM).
For the exact location of the pins, see the device datasheet.

The key components of the ADC are:

Channel Configuration

The signal path to the ADC input is controlled by the logical channel (a high-level abstraction). The configuration of the ADC logical channel includes the following settings (common for HS//LP modes):

Also:

8 individually-configurable logical channels are available to the ADC in HS mode and 16 logical channels are available to the ADC in LP mode.

The logical channels configuration is a part of the ADC Static Configuration (refer to cy_stc_autanalog_sar_sta_hs_t::hsGpioChan for GPIO inputs and cy_stc_autanalog_sar_sta_t::intMuxChan for MUX inputs accordingly).

Static Configuration

The static configuration contains application-specific settings intended to remain static for any ADC application. The Autonomous Controller (AC) will NOT change the static configuration during operation.

The diagram below shows the static configuration for ADC in HS mode.

The diagram below shows the static configuration for ADC in LP mode.

The diagram below shows the static configuration for LP ADC in Single Ended mode.

The static configuration for the whole ADC consists of static configurations for the HS and LP parts (refer to cy_stc_autanalog_sar_sta_hs_t, cy_stc_autanalog_sar_sta_lp_t) and includes the following settings in total (refer to cy_stc_autanalog_sar_sta_t):

Also:

Sequencer and State Transition Table

The sequencer is used to control the ADC to perform an automatic scan on all enabled logical channels without MCU intervention. Each ADC Core has its own sequencer, refer to cy_stc_autanalog_sar_seq_tab_hs_t for HS mode and refer to cy_stc_autanalog_sar_seq_tab_lp_t for LP mode. Both sequencers contain up to 32 states. Each state of the sequencer defines a single step in the ADC scan.

The Autonomous Controller is able to trigger the ADC. It points to a particular step (Entry State) of the sequencer in runtime using the State Transition Table, refer to cy_stc_autanalog_stt_sar_t. The next step of the sequencer is defined in the nextAction field of the sequencer configuration structure (refer to e.g. cy_stc_autanalog_sar_seq_tab_hs_t::nextAction):

The remaining fields of the sequencer are (common for HS//LP modes):

Also, the HS sequencer allows you to configure the following:

Also, the LP sequencer allows you to configure the following:

The ADC scan can be started by the Autonomous Controller (AC) in runtime per settings provided in the sequencer (refer to cy_stc_autanalog_sar_seq_tab_hs_t, cy_stc_autanalog_sar_seq_tab_lp_t) and State Transition Table (refer to cy_stc_autanalog_stt_sar_t structure).

Note
When ADC is powered down, the ADC logic and FIRs are reset, ADC/FIR clocks are gated, and all ADC AC conditions are cleared. The ADC configuration and sequencer tables are retained. The FIFO status and content are not cleared, i.e. the FIFO contents can still be read if the ADC is disabled.

Clock and Throughput

The ADC in HS mode is clocked from the SRSS peripheral clock (Clk_HF9, up to 80MHz, refer to General Configuration Considerations) in chip Active mode using Peri 0 Clock Group 2 8-bit divider in the clock chain.
The ADC in LP mode is clocked from the local Low Power Oscillator (LPOSC, 4096kHz, refer to cy_en_autanalog_timer_clk_src_t) in chip Deep Sleep mode.

ADC mode Clock source Clock frequency, MHz Throughput, samples/s
High Speed Clk_HF9 80 5Msps
Low Power LPOSC 4.096 200ksps

Sample Time

The sample time can be set separately for each HS\LP ADC Cores.

For HS mode, enable this option in the corresponding ADC sequencer, refer to cy_stc_autanalog_sar_seq_tab_hs_t::sampleTimeEn, cy_stc_autanalog_sar_seq_tab_hs_t::sampleTime. And the selection of a particular value of the acquisition time is defined in the corresponding Static configuration, refer to cy_stc_autanalog_sar_sta_hs_t::hsSampleTime.

For LP mode, enable this option in the corresponding ADC sequencer, refer to cy_stc_autanalog_sar_seq_tab_lp_t::sampleTimeEn, cy_stc_autanalog_sar_seq_tab_lp_t::sampleTime. The selection of a particular value of the acquisition time is defined in the corresponding Static configuration, refer to cy_stc_autanalog_sar_sta_lp_t::lpSampleTime.

Note
15us is the recommended sampling time for Die temperature measurement in LP mode.
12us is the recommended sampling time for Die temperature measurement in HS mode.

Reference Voltage

The level of the reference voltage can be defined separately for each HS\LP ADC Cores in the corresponding parts of the Static configuration, refer to cy_stc_autanalog_sar_sta_hs_t::hsVref and cy_stc_autanalog_sar_sta_lp_t::lpVref.

For the PRB configuration settings, refer to cy_stc_autanalog_prb_t structure.

Note
Vdda is 1.8V and Vbgr is 0.9V

Buffer Input and Output Ranges

The input range of the buffer can be rail-to-rail if the charge pump is enabled. Without the charge pump, the input range is 0 V to VDDA - 1.5 V. The output range of the buffer is typically 0.2 V to VDDA - 1.0 V. See the device datasheet for more details.

Charge Pump Input Range Output Range
Enabled 0 V to VDDA 0.2 V to VDDA - 0.2 V
Disabled 0 V to VDDA - 1.5 V 0.2 V to VDDA - 1.0 V
Note
The charge pump nominal clock is 4MHz

For the configuration settings, see cy_en_autanalog_sar_buf_pwr_t.

Signed/Unsigned Output

The ADC conversion result and the FIR//FIFO output are represented as 32-bit width integer, (zero or sign extended) regardless of the actual resolution of the ADC.

For the configuration settings, refer to cy_stc_autanalog_sar_hs_chan_t::sign and cy_stc_autanalog_sar_mux_chan_t::sign.

Handling of the Result

The results of the ADC conversion or FIR filtering can be stored with further notification about update, or sent directly to the FIFO buffer. To save the result for a specific logical channel or FIR filter, use the following settings in the Static configuration:

Averaging

The ADC subsystem includes an accumulator and shift registers to support the averaging at the hardware level.

To configure the averaging for the ADC conversion result, use:

FIR Filter

Two instances of the 64-tap FIR filters are available for the ADC post-processing.

The FIR filter configuration (refer to cy_stc_autanalog_sar_fir_cfg_t) includes:

Interrupts, Triggers and STT Events

The following internal events of the ADC can be configured to generate an interrupt or trigger or used as the STT event in the Autonomous Analog (refer to cy_en_autanalog_ac_out_trigger_mask_t and cy_en_autanalog_stt_ac_condition_t):

Refer to Interrupts, Triggers and STT Events chapter for the FIFO events.

Sample use case: Die Temperature

/* Scenario 1:
* This example illustrates the use of the SAR ADC to measure the chip temperature in High speed mode.
*/
#include "autanalog_sar.h"
/* Define the index for the ADC0 instance within the Autonomous Analog */
#define ADC0IDX (0U)
/* The GPIO channels are NOT USED */
/* The MUX channels configuration structure */
static cy_stc_autanalog_sar_mux_chan_t intMuxChan0 =
{
.posPin = CY_AUTANALOG_SAR_PIN_MUX_TEMP_SENSOR, // The temperature sensor in differential connection
.sign = true, // Signed result is used for die temperature
.posCoeff = CY_AUTANALOG_SAR_CH_COEFF_DISABLED, // The correction coefficient is not used
.negPin = CY_AUTANALOG_SAR_PIN_MUX_TEMP_SENSOR, // The temperature sensor in differential connection
.buffBypass = true, // The output of the temperature sensor is bypassed
.accShift = false, // The averaging is not used
.negCoeff = CY_AUTANALOG_SAR_CH_COEFF_DISABLED, // The correction coefficient is not used
.muxLimit = CY_AUTANALOG_SAR_LIMIT_STATUS_DISABLED, // The range is not checked
.fifoSel = CY_AUTANALOG_FIFO_DISABLED, // FIFO is not used
};
@ CY_AUTANALOG_FIFO_DISABLED
DISABLED.
Definition: cy_autanalog_sar.h:954
cy_en_autanalog_sar_pin_mux_t posPin
Positive pin assignment.
Definition: cy_autanalog_sar.h:1067
The MUX channel configuration structure, refer to Channel Configuration chapter.
Definition: cy_autanalog_sar.h:1066
@ CY_AUTANALOG_SAR_LIMIT_STATUS_DISABLED
The limit status is not used.
Definition: cy_autanalog_sar.h:738
@ CY_AUTANALOG_SAR_CH_COEFF_DISABLED
The channel correction coefficient not used.
Definition: cy_autanalog_sar.h:768
@ CY_AUTANALOG_SAR_PIN_MUX_TEMP_SENSOR
Temperature sensor.
Definition: cy_autanalog_sar.h:717
/* The HS mode static configuration structure */
static cy_stc_autanalog_sar_sta_hs_t sarStaHsCfg =
{
.hsVref = CY_AUTANALOG_SAR_VREF_VBGR, // Vbgr is used as a reference voltage
.hsSampleTime = {1023U, 0U, 0U, 0U}, // Define recommended sample time: (1/80MHz) * 1024 = 12us
.hsGpioChan = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
.hsGpioResultMask = CY_AUTANALOG_SAR_CHAN_MASK_GPIO_DISABLED, // Not used
};
cy_en_autanalog_sar_vref_t hsVref
Select ADC voltage reference, refer to Reference Voltage chapter.
Definition: cy_autanalog_sar.h:1105
The part of the Static configuration for ADC HS mode, refer to Static Configuration chapter.
Definition: cy_autanalog_sar.h:1104
@ CY_AUTANALOG_SAR_VREF_VBGR
The ADC reference is VBGR.
Definition: cy_autanalog_sar.h:794
#define CY_AUTANALOG_SAR_CHAN_MASK_GPIO_DISABLED
The GPIO channels masks.
Definition: cy_autanalog_sar.h:465
/* Compleate static configuration structure */
static cy_stc_autanalog_sar_sta_t sarStaCfg =
{
.lpStaCfg = NULL,
.hsStaCfg = &sarStaHsCfg,
.posBufPwr = CY_AUTANALOG_SAR_BUF_PWR_OFF, // The temperature sensor output is unbuffered
.negBufPwr = CY_AUTANALOG_SAR_BUF_PWR_OFF, // The temperature sensor output is unbuffered
.accMode = CY_AUTANALOG_SAR_ACC_DISABLED, // The temperature sensor value is not averaged
.startupCal = CY_AUTANALOG_SAR_CAL_DISABLED, // Not used
.chanID = false, // Not used
.shiftMode = false, // The temperature sensor value is not averaged
.intMuxChan = {&intMuxChan0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
.limitCond = {NULL, NULL, NULL, NULL}, // The range is not checked
.muxResultMask = CY_AUTANALOG_SAR_CHAN_MASK_MUX0, // The conversion result is stored for MUX channel #0
.firResultMask = CY_AUTANALOG_SAR_MASK_FIR_DISABLED, // Not used
};
#define CY_AUTANALOG_SAR_MASK_FIR_DISABLED
The FIR channels masks.
Definition: cy_autanalog_sar.h:538
cy_stc_autanalog_sar_sta_lp_t * lpStaCfg
LP part of static configuration.
Definition: cy_autanalog_sar.h:1150
The ADC static configuration structure, refer to Static Configuration chapter.
Definition: cy_autanalog_sar.h:1149
@ CY_AUTANALOG_SAR_CAL_DISABLED
Calibration disabled.
Definition: cy_autanalog_sar.h:887
@ CY_AUTANALOG_SAR_ACC_DISABLED
Average disabled.
Definition: cy_autanalog_sar.h:846
@ CY_AUTANALOG_SAR_BUF_PWR_OFF
The power mode for the buffer is OFF, the buffer is disabled.
Definition: cy_autanalog_sar.h:810
#define CY_AUTANALOG_SAR_CHAN_MASK_MUX0
The MUX channel 0.
Definition: cy_autanalog_sar.h:509
/* The HS sequencer configuration structure */
static cy_stc_autanalog_sar_seq_tab_hs_t sarHsSeqTabCfg =
{
.muxMode = CY_AUTANALOG_SAR_CHAN_CFG_MUX0_PSEUDO_DIFF, // Enable MUX channel #0 in the pseudo differential configuration
.mux0Sel = CY_AUTANALOG_SAR_CHAN_CFG_MUX0, // Enable MUX channel #0
.mux1Sel = CY_AUTANALOG_SAR_CHAN_CFG_MUX0, // Enable MUX channel #0
.sampleTimeEn = true, // Enable the sample time for the temperature sensor
.sampleTime = CY_AUTANALOG_SAR_SAMPLE_TIME0, // Use the sample time from cy_stc_autanalog_sar_sta_hs_t::hsSampleTime
.accEn = false, // The temperature sensor value is not averaged
.accCount = CY_AUTANALOG_SAR_ACC_CNT2, // The temperature sensor value is not averaged
.calReq = CY_AUTANALOG_SAR_CAL_DISABLED, // Not used
.nextAction = CY_AUTANALOG_SAR_NEXT_ACTION_STATE_STOP, // The ADC mode of operation is single scan
};
uint8_t chanEn
GPIO channels enable mask, valid range 0x0...0xFF, see High Speed Channels and Masks macros.
Definition: cy_autanalog_sar.h:1198
The ADC Sequencer Table configuration structure for HS mode, refer to Sequencer and State Transition ...
Definition: cy_autanalog_sar.h:1197
@ CY_AUTANALOG_SAR_NEXT_ACTION_STATE_STOP
Stop, send SAR_EOS and SAR_DONE events and idle.
Definition: cy_autanalog_sar.h:900
@ CY_AUTANALOG_SAR_SAMPLE_TIME0
Sampling Timer 0.
Definition: cy_autanalog_sar.h:874
@ CY_AUTANALOG_SAR_ACC_CNT2
Set samples averaged to 2.
Definition: cy_autanalog_sar.h:857
#define CY_AUTANALOG_SAR_CHAN_CFG_MUX0_PSEUDO_DIFF
The MUX channel pseudo differential.
Definition: cy_autanalog_sar.h:480
#define CY_AUTANALOG_SAR_CHAN_CFG_MUX0
The MUX channels configurations.
Definition: cy_autanalog_sar.h:490
/* The ADC configuration structure */
{
.sarStaCfg = &sarStaCfg,
.hsSeqTabNum = 1U, // The ADC LP Core sequencer contains one state
.hsSeqTabArr = &sarHsSeqTabCfg,
.lpSeqTabNum = 0U, // The ADC LP Core sequencer is not used but is mandatory
.lpSeqTabArr = NULL,
.firNum = 0U, // The FIR filtering is not used
.firCfg = NULL,
.fifoCfg = NULL, // The FIFO buffer is not used
};
cy_stc_autanalog_sar_sta_t * sarStaCfg
The pointer to a static part of the ADC configuration.
Definition: cy_autanalog_sar.h:1299
The configuration structure to set up the entire ADC.
Definition: cy_autanalog_sar.h:1297
/* The ADC State Transition Table */
{
/* State#0, start-up/settling delay */
{
.unlock = true,
.enable = true,
.trigger = false,
.entryState = 0U,
},
/* State#1, wait for external trigger to start conversion */
{
.unlock = true,
.enable = true,
.trigger = false,
.entryState = 0U,
},
/* State#2, temperature measurement (ADC conversion) */
{
.unlock = true,
.enable = true,
.trigger = true, // Trigger is active
.entryState = 0U, // Sequencer Entry State value
},
/* State#3, return to state #1 */
{
.unlock = true,
.enable = true,
.trigger = false,
.entryState = 0U,
},
};
bool unlock
ADC Unlock:
Definition: cy_autanalog_sar.h:1328
The ADC section in the State Transition Table state.
Definition: cy_autanalog_sar.h:1327
cy_en_autanalog_status_t
Return the status for functions of the Autonomous Analog driver.
Definition: cy_autanalog_common.h:105
status = Cy_AutAnalog_SAR_LoadConfig(ADC0IDX, &sarCfg);
if (CY_AUTANALOG_SUCCESS != status)
{
/* Error handling */
}
@ CY_AUTANALOG_SUCCESS
Initialization completed successfully.
Definition: cy_autanalog_common.h:106
cy_en_autanalog_status_t Cy_AutAnalog_SAR_LoadConfig(uint8_t sarIdx, const cy_stc_autanalog_sar_t *sarCfg)
Configures the ADC per provided settings.
Definition: cy_autanalog_sar.c:116
Warning
The first reading of the die temperature in HS mode may be incorrect.

API Reference

 Macros
 
 Functions
 
 Data Structures
 
 Enumerated Types