# Board index » cppbuilder » C Formula

## C Formula

2008-04-19 06:05:47 AM
cppbuilder55
I'm reading a temp sensor with a 10 bit ADC. The Reference voltage is 5.00
volts.
I display the temp in Deg.C and in Deg F
There is a 0.500 vdc reading at 0 Deg. C and the output is 10 mv per Deg. C
So the formula below gets the voltage per step - 5.00f / 1023 then
Then I subtract my 0.500 volt offset then divide by 0.010f to get Degrees C.
DegC = ((((5.00f / 1023) * ADCSteps) - 0.500f) / 0.010f); //MCP9700
DegF = (((DegC * 9.0f) / 5.0f) + 32);
Anyone see anything wrong with the way I have this formula?
The mfg specifies the formula as:
Vout = Tc * Ta + Vo
Tc = Temp Coeff = 0.010
Ta = Ambient Temp
Vo = Output at 0 Deg. C = 0.500 v
So... 25 DegC * 0.010 = 0.25 + 0.500 = 0.750 Voltage Output

## Re:C Formula

DegC degF are float and ADCSteps is unsigned Int.
"Richard" < XXXX@XXXXX.COM >wrote in message
##### Quote
I'm reading a temp sensor with a 10 bit ADC. The Reference voltage is
5.00 volts.
I display the temp in Deg.C and in Deg F
There is a 0.500 vdc reading at 0 Deg. C and the output is 10 mv per Deg.
C

So the formula below gets the voltage per step - 5.00f / 1023 then
Then I subtract my 0.500 volt offset then divide by 0.010f to get Degrees
C.

DegC = ((((5.00f / 1023) * ADCSteps) - 0.500f) / 0.010f); //MCP9700
DegF = (((DegC * 9.0f) / 5.0f) + 32);

Anyone see anything wrong with the way I have this formula?

The mfg specifies the formula as:
Vout = Tc * Ta + Vo

Tc = Temp Coeff = 0.010
Ta = Ambient Temp
Vo = Output at 0 Deg. C = 0.500 v

So... 25 DegC * 0.010 = 0.25 + 0.500 = 0.750 Voltage Output

## Re:C Formula

Il Fri, 18 Apr 2008 17:05:47 -0500, "Richard" < XXXX@XXXXX.COM >ha scritto:
##### Quote
I'm reading a temp sensor with a 10 bit ADC. The Reference voltage is 5.00
volts.
I display the temp in Deg.C and in Deg F
There is a 0.500 vdc reading at 0 Deg. C and the output is 10 mv per Deg. C

So the formula below gets the voltage per step - 5.00f / 1023 then
Then I subtract my 0.500 volt offset then divide by 0.010f to get Degrees C.

DegC = ((((5.00f / 1023) * ADCSteps) - 0.500f) / 0.010f); //MCP9700
DegF = (((DegC * 9.0f) / 5.0f) + 32);

Anyone see anything wrong with the way I have this formula?

The mfg specifies the formula as:
Vout = Tc * Ta + Vo

Tc = Temp Coeff = 0.010
Ta = Ambient Temp
Vo = Output at 0 Deg. C = 0.500 v

So... 25 DegC * 0.010 = 0.25 + 0.500 = 0.750 Voltage Output

Generally speaking, if the system is linear, you can use the following
equation:
( x - x1 ) / ( x2 - x1 ) = ( y - y1 ) / ( y2 - y1 )
Now, let 'x' be the AD value and 'y' the temperature (in °C).
If so, the equation is rewritten in such fashion:
( AD - AD@t1 ) / ( AD@t2 - AD@t1 ) = ( t - t1 ) / ( t2 - t1 )
where AD is the AD value (0-1023), t1 is the reference temperature 1 (e.g. 0 °C),
t2 is the reference temperature 2 (e.g. 100 °C), AD@t1 is the AD value at reference
Manipulating the equation you can obtain the following formula:
t = ( ( AD - AD@t1 ) * ( t2 - t1 ) ) / ( AD@t2 - AD@t1 ) + t1
for t in Celsius.
For example, if we have the AD value of 100 @ 10 °C and 923 @ 90 °C,
the formula is:
t = ( ( AD - 100 ) * ( 90 - 10 ) ) / ( 923 - 100 ) + 10
t = ( ( AD - 100 ) * 80 ) / 823 + 10;
If AD is, for example, 512 the resulting value, in Celsius degrees, is:
t = ( ( 512 - 100 ) * 80 ) / 823 + 10
t = ( 412 * 80 ) / 823 + 10
t = 50.04 °C
Hope this helps.
Guliano

{smallsort}

## Re:C Formula

Richard wrote:
##### Quote
I'm reading a temp sensor with a 10 bit ADC. The Reference voltage is 5.00
volts.
I display the temp in Deg.C and in Deg F
There is a 0.500 vdc reading at 0 Deg. C and the output is 10 mv per Deg. C

So the formula below gets the voltage per step - 5.00f / 1023 then
Then I subtract my 0.500 volt offset then divide by 0.010f to get Degrees C.
From Gnd to +5v in 1024 steps, or 4.88mv per step.
Let's call it 5mv or 2 steps per DegC.
Zero is then 100ADC (500mv, 0.5v).
If you want to make it a bit more acurate,
you could notice that .5 is 1/10 the 5v max.