# Cypress Developer CommunityTM

## How to convert the signed ADC value into decimal value?

Summary: 6 Replies, Latest post by gnuhcyee on 25 Apr 2012 07:10 AM PDT
User
4 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!

User
9241 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

User
4 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 = (3.683 * pH_dec)-4.403; // calculate the measured pH value from decimal values

Thank you!

User
9241 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

User
9241 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

Cypress Employee
223 posts

The article below has example code for itoa.

http://www.planetpsoc.com/programming-assembly-and-c/9-converting-an-int...

Best Regards,

Ganesh

The PSoC Hacker

User
4 posts

Thanks anyone!