## PSoC4 CapSense ADC raw to mV formula

Level 1
Level 1

Hello,

I am using CY8C4124AZI-S413 (supplied with 5V) to read a voltage value using CapSense_ADC (release 5.0) block.

I need the formula to calculate raw to mV and viceversa.

Thanks

Regards

Mauro Berioli

1 Solution

## Re: PSoC4 CapSense ADC raw to mV formula

Moderator
Moderator

/*******************************************************************************************/

{

{

/* Select the polarity bit */

/* Select the result value */

/* ADC could have been converting or calibrating; handle each differently. */

{

/*

* After the converting will calculate an ADC result in mV depending on

* sourcing or sinking mode. Checks for a saturation in all modes.

*/

/* HSCMP polarity is 0:sink, 1:source */

if(0uL != polarity) /* Sourcing */

{

/* Saturate result at tVssa2Vref */

tmpResult = (tmpResult > (uint32)tVssa2Vref) ? (uint32)tVssa2Vref : tmpResult;

/* Scale result to Resolution range with rounding*/

((uint32)tFull >> 1uL)) / (uint32)tFull;

}

else /* Sinking */

{

/* Scale result with sink/source mismatch with rounding */

tmpResult = (((uint32)((uint32)tRecover << 1u) * tmpResult) + ((uint32)tVssa2Vref >> 1u)) / (uint32)tVssa2Vref;

/* Saturate result at t_Vdda2Vref*/

tmpResult = (tmpResult > (uint32)tVdda2Vref) ? (uint32)tVdda2Vref : tmpResult;

/* Scale result to Resolution range with rounding */

((uint32)tFull >> 1uL)) / (uint32)tFull;

/* In vref mode, we are not supposed to be sinking. Saturate */

}

/* Store ADC result code */

/* Scale result to mV with rounding and store it */

break;

.......

......

/*******************************************************************************************/

Please note that the formula include some static variables (tFull, tVssa2Vref, etc.), these variables store the calibration values measure by API CapSense_ADC_AdcCalibrate() which be called in CapSense_ADC_Start() once.

## Re: PSoC4 CapSense ADC raw to mV formula

Moderator
Moderator

/*******************************************************************************************/

{

{

/* Select the polarity bit */

/* Select the result value */

/* ADC could have been converting or calibrating; handle each differently. */

{

/*

* After the converting will calculate an ADC result in mV depending on

* sourcing or sinking mode. Checks for a saturation in all modes.

*/

/* HSCMP polarity is 0:sink, 1:source */

if(0uL != polarity) /* Sourcing */

{

/* Saturate result at tVssa2Vref */

tmpResult = (tmpResult > (uint32)tVssa2Vref) ? (uint32)tVssa2Vref : tmpResult;

/* Scale result to Resolution range with rounding*/

((uint32)tFull >> 1uL)) / (uint32)tFull;

}

else /* Sinking */

{

/* Scale result with sink/source mismatch with rounding */

tmpResult = (((uint32)((uint32)tRecover << 1u) * tmpResult) + ((uint32)tVssa2Vref >> 1u)) / (uint32)tVssa2Vref;

/* Saturate result at t_Vdda2Vref*/

tmpResult = (tmpResult > (uint32)tVdda2Vref) ? (uint32)tVdda2Vref : tmpResult;

/* Scale result to Resolution range with rounding */

((uint32)tFull >> 1uL)) / (uint32)tFull;

/* In vref mode, we are not supposed to be sinking. Saturate */

}

/* Store ADC result code */

/* Scale result to mV with rounding and store it */