Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

Using 8-bit SAR ADC with PMG1 USB PD functionality – KBA238312

Using 8-bit SAR ADC with PMG1 USB PD functionality – KBA238312

Infineon_Team
Employee
Employee
50 replies posted 25 likes received 25 replies posted

The USB PD block of all EZ-PD™ PMG1 devices includes an 8-bit Successive Approximation Register (SAR) ADC, which can be used independently outside PD purposes.

This knowledge base article guides you with the steps to use the 8-bit SAR ADC block.

1. Initiate the PD ADC block

API: cy_en_usbpd_status_t Cy_USBPD_Adc_Init(cy_stc_usbpd_context_t *context, cy_en_usbpd_adc_id_t adcId)

Example: Cy_USBPD_Adc_Init(context, CY_USBPD_ADC_ID_0)

Use API Cy_USBPD_Adc_Init to initiate the PD ADC block. This function enables the PD block and the registers required for ADC operation.

The adcId must be specified in the function parameter (refer to Table 1 for available adcIds based on your device). When using the 8-bit SAR ADC alongside USBPD functionality, use only ADC_ID_0. The same ADC is also used to measure VBUS voltages by the USB PD.

Note that some devices have access to more than one PD ADC block. All PMG1 devices have access to ADC_ID_0. Only
PMG1-S0 and PMG1-S2 have two ADCs per PD block and, therefore, have access to ADC_ID_0 and ADC_ID_1 (refer to Table 1).

Table 1 ADC Ids for various EZ-PD™ PMG1 devices

ADC Ids (cy_en_usbpd_adc_id_t)

PMG1-S0

PMG1-S1

PMG1-S2

PMG1-S3

CY_USBPD_ADC_ID_0

Supported

Supported

Supported

Supported

CY_USBPD_ADC_ID_1

Supported

Not Supported

Supported

Not Supported

 

2Select the VREF

API: cy_en_usbpd_status_t Cy_USBPD_Adc_SelectVref(cy_stc_usbpd_context_t *context, cy_en_usbpd_adc_id_t adcId, cy_en_usbpd_adc_vref_t vrefSel)

Example: Cy_USBPD_Adc_SelectVref(context, CY_USBPD_ADC_ID_0, CY_USBPD_ADC_VREF_VDDD)

Use API Cy_USBPD_Adc_SelectVref to select the voltage reference used by the ADC block. The following  options are available for ADC VREF, as shown in Table 2:

  • CY_USBPD_ADC_VREF_PROG is a programmable reference voltage from the RefGen block. RefGen produces 2 V by default for this VREF (PMG1-S2 does not have this VREF option)
  • CY_USBPD_ADC_VREF_VDDD is a reference voltage based on VDDD voltage.

Note that PMG1-S2 has only VDDD as the reference voltage option, as the RefGen block is absent in PMG1-S2.

Table 2 ADC VREF options

ADC Vref (cy_en_usbpd_adc_vref_t)

Voltage

CY_USBPD_ADC_VREF_PROG

Default – 2.0V

CY_USBPD_ADC_VREF_VDDD

VDDD

 

3Connect GPIO to AMUX

API: void Cy_GPIO_SetHSIOM(const GPIO_PRT_Type* base, uint32_t pinNum, en_hsiom_sel_t value)

Example: Cy_GPIO_SetHSIOM(GPIO_PRT1, 1, HSIOM_SEL_AMUXA)

Use API Cy_GPIO_SetHSIOM to connect the GPIO of choice to AMUXA. The first argument takes the GPIO_PRT_Type, the second argument takes the pin number, and last is the HSIOM selection. To get the ADC sample of the specified GPIO, use AMUXA as HSIOM selection.

4Calibrate the ADC

API: uint16_t Cy_USBPD_Adc_Calibrate(cy_stc_usbpd_context_t *context, cy_en_usbpd_adc_id_t adcId)

Example: Cy_USBPD_Adc_Calibrate(context, CY_USBPD_ADC_ID_0)

Use API Cy_USBPD_Adc_Calibrate to calibrate the ADC volts per division value before taking any ADC readings. This is because VDDD (our VREF) supply level can vary over time.

5Get ADC sample and convert to voltage

API: uint8_t Cy_USBPD_Adc_Sample(cy_stc_usbpd_context_t *context, cy_en_usbpd_adc_id_t adcId, cy_en_usbpd_adc_input_t input)

Example: Cy_USBPD_Adc_Sample(context, CY_USBPD_ADC_ID_0, CY_USBPD_ADC_INPUT_AMUX_A)

Use API Cy_USBPD_Adc_Sample to return the sample value in ADC units. The final parameter cy_en_usbpd_adc_input_t specifies the ADC input source. Since the GPIO was previously connected to AMUXA through HSIOM, specify AMUXA in this parameter. Refer to Table 3.

Table 3 ADC Input selection options

ADC Input (cy_en_usbpd_adc_input_t)

Description

CY_USBPD_ADC_INPUT_AMUX_A

AMUX_A bus

CY_USBPD_ADC_INPUT_AMUX_B

AMUX_B bus

CY_USBPD_ADC_INPUT_BANDGAP

BANDGAP input

CY_USBPD_ADC_INPUT_BJT

BJT


The obtained ADC sample is based on the VREF chosen as well as the GPIO voltage.

The following example equation can be used to convert ADC sample to GPIO voltage in mV:

Equation.png

 

6. Revert GPIO to normal GPIO functionality

API: void Cy_GPIO_SetHSIOM(const GPIO_PRT_Type* base, uint32_t pinNum, en_hsiom_sel_t value)

Example: Cy_GPIO_SetHSIOM(GPIO_PRT1, 1, HSIOM_SEL_GPIO)

After completing ADC sampling, ensure to revert GPIO to normal functionality using the API Cy_GPIO_SetHSIOM.

7. Code example for 8-bit SAR ADC

Refer to the 8-bit SAR ADC code example, which demonstrates the method of using the 8-bit SAR ADC in the USBPD block on EZ-PD™ PMG1 devices.

0 Likes
220 Views