Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 1 > How to convert the signed ADC value into decimal value?

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



How to convert the signed ADC value into decimal value?
Moderator:
ARVI

Post Reply
Follow this topic



How to convert the signed ADC value into decimal value?

gnuhcyee posted on 23 Apr 2012 7:55 AM PST
Senior Member
16 Forum Posts

Hello!

 I am using PSoC CY8C29466's DelSig and Triple input incremental ADC. Both ADC is set to data format as signed. The data input into ADCs is from sensor which the sensor itself have output value between 1V to 4.9 V.

Delsig is set to 3 MHz clock frequency and Pulse width is 10. Triple input ADC is set to ADC resolution of 13 bit, Calc time 400, 3 MHz clock frequency.

I want to know what is the C code to change the ADCs value into decimal value ( base number of 10).

 

Thank you!
 




Re: How to convert the signed ADC value into decimal value?

Bob Marlowe posted on 23 Apr 2012 08:25 AM PST
Top Contributor
1768 Forum Posts

There are a couple of possibilities to do that:

Do it yourself: when you divide the number by 10, the remainder will give the last digit (0..9), repeat until nuber is zero

Use itoa macro

Use csprintf(Buffer,"%d',Number)

Use Print-function of LCD-module

 

Happy de-coding

Bob



Re: How to convert the signed ADC value into decimal value?

gnuhcyee posted on 24 Apr 2012 11:05 PM PST
Senior Member
16 Forum Posts

What is itoa macro? Can somebody elobrate?

Another addition thing is that the  ADCs output values which is converted to decimal values;this decimal values is used as data to calculate the measured value of the sensor. I have done the calibration, and acquired the equation to convert the measured voltage into measured pH value. For example, the pH sensor, when the output of the reading is 3V, it represent pH 12.

So, I am wondering do the codes below can get my measured voltage value from ADC? Since I am using the measured voltage of sensor to calculate the measured sensor value, I am wondering whether the codes can get back the measured voltage value.

The pH sensor can detect pH 0 to pH 14, sensor voltage output values is 1.04 V to 4.94 V with the lowest voltage represent pH 0 and highest pH represent the higherst voltage.

pH_adc = TRIADC_1_iGetData2(); // read data from ADC
pH_dec=(pH_adc)*0.001221001221; // convert the data from ADC to decimal values

pH = (3.683 * pH_dec)-4.403; // calculate the measured pH value from decimal values

 

Thank you!



Re: How to convert the signed ADC value into decimal value?

Bob Marlowe posted on 24 Apr 2012 12:43 AM PST
Top Contributor
1768 Forum Posts

I cannot test your calibration-numbers (although there might be some error) but you forgot to wait for a sample beeing ready. Depending on your ADC it will be something like ADC_fIsDataAvailable() and ADC_GetDataClearFlag(), contact the datasheet.

For the Math: you have got a linear function which is f(x) = ax +b. So you have to evolve a and b. One multiplication and one addition will give you the desired Ph. As far as I know the voltage is temperature-dependent which might bring in another term.

When later everything works, think of a calibration-routine and storing the parameters in EEProm.

Happy measuring

Bob

 



Re: How to convert the signed ADC value into decimal value?

Bob Marlowe posted on 24 Apr 2012 12:49 AM PST
Top Contributor
1768 Forum Posts

Sorry, forgot itoa.

Contact your C-compiler handbook (Help -> Documentation... -> Compiler and Programming Documents -> C Language Com...

In the PDF search (CTRL-F) for "atoi"

 

Bob



Re: How to convert the signed ADC value into decimal value?

graa posted on 24 Apr 2012 02:51 AM PST
Cypress Employee
275 Forum Posts

The article below has example code for itoa.

 

http://www.planetpsoc.com/programming-assembly-and-c/9-converting-an-integer-to-ascii.html

 

Best Regards,

Ganesh

The PSoC Hacker



Re: How to convert the signed ADC value into decimal value?

gnuhcyee posted on 25 Apr 2012 05:10 AM PST
Senior Member
16 Forum Posts

Thanks anyone!






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20