Strictly necessary cookies are on by default and cannot be turned off. Functional, Performance and Tracking/targeting/sharing cookies can be turned on below based on your preferences (this banner will remain available for you to accept cookies). You may change your cookie settings by deleting cookies from your browser. Then this banner will appear again. You can learn more details about cookies HERE.

Strictly necessary (always on)

Functional, Performance and Tracking/targeting/sharing (default off)

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- Products
- MCU & PSoC
- PSoC 4 MCU
- How to set Gain (ADC_SetGain) for PSoC4 ADC SAR Se...

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Not applicable

Aug 29, 2018
07:47 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

In an example application CE95272 there is code in this example that sets the gain of the API ADC_SetGain(). Below is a copy of the code from this example.

** /* Calculate gain for the first channel */**

** adcGain = (((int32)ADC_SAR_WRK_MAX_12BIT * ADC_10MV_COUNTS) +**

** ADC_DEFAULT_VREF_MV_VALUE) / (ADC_DEFAULT_VREF_MV_VALUE * 2);**

** adcGain *= GAIN;**

** ADC_SetGain(CHANNEL_1, adcGain);**

Does anyone know were I can find information as to the other API used so i can understand why its there. I am doing a similar application using a instrumentation amplifier with a gain of 10, but i don't understand this code and why its there. I don't know if its there for a voltage conversion or a calibration.

Thanks

Scott

Solved! Go to Solution.

1 Solution

Moderator

Sep 12, 2018
06:45 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Hello Scott,

I will try to answer your doubts. The adc_gain parameter is used by the voltage conversion functions in the ADC component. It will remove the effect of the gain from the final voltage value. So the count you have obtained will be according to the input you have given at the input of the ADC. But inside the ADC_CountsTo_mVolts( or any other count to volt API) the result is after removing the adc_gain factor. Which will give you the input value you have given.

Now to answer your questions,

Q1> What is value in this case for (int32)ADC_SAR_WRK_MAX_12BIT?

It 4096, the number of steps for 12 bit accuracy

Q2> What is value for ADC_10MV_COUNTS ?

10000

Q3> What is value for ADC_DEFAULT_VREF_MV_VALUE?

1024

Q4> The data sheet for the ADC_SAR_Seq ... says its sets the gain in counts per 10 volts. .... can this be explained by example?

adc_gain value is used in the voltage conversion APIs. If you see the internal code of these APIs, you will get a better idea.

Q5> Were does this equation come from?

I will try to answer this in detail. We are trying to find the ADC count value for 10V. This will give the slope of the curve.

**adc_gain = 10 V/ resolution**

now ,

**resolution = voltage range / maximum count value**

So the equation becomes

**adc_gain = 10V * maximum count value/ voltage range**

For SAR , the range is 2*Vref.

**adc_gain = 10V* maximum count value/ 2 * Vref**

Now there is rounding off in this equation ( half way rounding)

SO if you wan to find A/B, you will find the division (A+ (B/2))/B for rounding of the value to the rail or floor. You can search about the same. If you use the same principle in the above equation,

**adc_gain = (10V* maximum count value + Vref )/ 2 * Vref**

That is how the equation is created. I hope this answers your question.

Best Regards,

VRS

5 Replies

Moderator

Aug 30, 2018
05:06 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Hi,

**ADC_SetGain(uint32 chan, int32 adcGain)** API sets the ADC gain in counts per 10volt for the voltage conversion functions ADC_CountsTo_uVolts(), ADC_CountsTo_mVolts(), and ADC_CountsTo_Volts(). This value is set by default based on the reference and input range settings in the ADC component. It should only be used to further calibrate the ADC with a known input or if an external reference is used. It affects these functions by supplying the correct conversion between ADC counts and the applied input voltage.

Thanks,

P Yugandhar.

Not applicable

Aug 30, 2018
10:24 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Thank you for getting back to me on this but ... my question is what is all the other API doing and why is it structured in the code. What does it do and why?

Thanks

Scott

Moderator

Sep 04, 2018
04:34 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Hello,

In the above code, adcGain value is used to calibrate the gain. This value is rounding off to nearest integer and is used to give the correct conversion between ADC counts and the applied input voltage. The value will be calculated based on Maximum count value and Vref voltage given to the ADC.

In the above code, ADC_SAR_WRK_MAX_12BIT is the maximum count value and ADC_DEFAULT_VREF_MV_VALUE is the Vref voltage.

Thanks,

P Yugandhar.

Not applicable

Sep 04, 2018
12:09 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Thanks again for trying to help me understand, but I am just not seeing the reasoning for all the variables and the math in the ADC_SetGain() function. The problem for me is this, when you run this code it does not report a gain of 10 to the UART on the differential input (CHANNEL_1). When I run this code/application, and I apply just under 25mV or just over 75mV the LED is supposed to light and it does perfectly based on the Compare mode settings, then it should report that voltage with a gain of 10 applied to the UART, which it does not do! For example, when I apply 30mV to the input the LED should go off which it does and the UART should report 300mV which it does not do. I did the math which calculates the Compare Mode settings. I will attach my spread sheet that others my see, use and review. It was helpful for me to understand how those compare mode values were derived. In trying to understand the ADC_SetGain() function and how to make sure the gain is set properly for CHANNEL_1, i do not understand the values of the variables and the math used? Would it be possible to answer the questions below so i fully understand the calculations used.

Q1> What is value in this case for (int32)ADC_SAR_WRK_MAX_12BIT? ... is this 2^n-1 or 2048

Q2> What is value for **ADC_10MV_COUNTS ? ... is this number of counts for 10mV ?**

**Q3> What is value for ADC_DEFAULT_VREF_MV_VALUE? ... is this 1.024 volts? **

**Q4> The data sheet for the ADC_SAR_Seq ... says its sets the gain in counts per 10 volts. .... can this be explained by example?**

**Q5> Were does this equation come from?**

Moderator

Sep 12, 2018
06:45 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Hello Scott,

I will try to answer your doubts. The adc_gain parameter is used by the voltage conversion functions in the ADC component. It will remove the effect of the gain from the final voltage value. So the count you have obtained will be according to the input you have given at the input of the ADC. But inside the ADC_CountsTo_mVolts( or any other count to volt API) the result is after removing the adc_gain factor. Which will give you the input value you have given.

Now to answer your questions,

Q1> What is value in this case for (int32)ADC_SAR_WRK_MAX_12BIT?

It 4096, the number of steps for 12 bit accuracy

Q2> What is value for ADC_10MV_COUNTS ?

10000

Q3> What is value for ADC_DEFAULT_VREF_MV_VALUE?

1024

Q4> The data sheet for the ADC_SAR_Seq ... says its sets the gain in counts per 10 volts. .... can this be explained by example?

adc_gain value is used in the voltage conversion APIs. If you see the internal code of these APIs, you will get a better idea.

Q5> Were does this equation come from?

I will try to answer this in detail. We are trying to find the ADC count value for 10V. This will give the slope of the curve.

**adc_gain = 10 V/ resolution**

now ,

**resolution = voltage range / maximum count value**

So the equation becomes

**adc_gain = 10V * maximum count value/ voltage range**

For SAR , the range is 2*Vref.

**adc_gain = 10V* maximum count value/ 2 * Vref**

Now there is rounding off in this equation ( half way rounding)

SO if you wan to find A/B, you will find the division (A+ (B/2))/B for rounding of the value to the rail or floor. You can search about the same. If you use the same principle in the above equation,

**adc_gain = (10V* maximum count value + Vref )/ 2 * Vref**

That is how the equation is created. I hope this answers your question.

Best Regards,

VRS