PDA

View Full Version : Floating point expression looking for integer math solution



Castor
- 27th May 2008, 11:43
This is for a temperature mesurement aplication. The expression I'm trying to figure out using integer math is R2=R1/[(Vcc/V2)-1]. R2 is a thermistor. It changes it's internal resistence with temperature so i need to calculate it's resistence to figure out the temperature.

R1=10K
Vcc=5V
V2 is 0 to 4096 (quantisized output from a a/d converter); where 456=0.456V and 2345=2.345V
so the actual expression comes to:

R2=10.000/[(5000/ad_res)-1]



ad_res var word
temp0 var word
temp1 var word
temp2 var word
final1 var word
final2 var word
final3 var word

temp0=5000/ad_res
temp1=5000//ad_res
temp2=temp0*100+temp1-1
final1=10000/temp2
final2=10000//temp2
final3=final1*100+final2

overflow and imprecise result :(

VCC
o
|
# R1
#
|
|-------oV2
|
# R2
#
|
|
GND

Acetronics2
- 27th May 2008, 14:48
Hi, Castor

May be there would be a smart turnaround ...

if , instead of R1, you use a constant current generator ...

say a PNP trans, with a red led between VCC and base, a resistor between emitter and VCC to fix your current ...
and another resistor between base and GND to allow, say, 1 mA into the led + trans base.

good idea, no ???

Alain

paul borgmeier
- 27th May 2008, 15:02
Short on time but this might get you started

Rewrite this
R2=10.000/[(5000/ad_res)-1]
to look like this
R2=10.000*ad_res/[5000-ad_res]

calculate the denominator and keep (5000 - ad_res)
Calculate the numerator (10.000*ad_res)
Use Div32 to divide the numerator by the denominator

Use Darrel's method to get the remainder

http://www.picbasic.co.uk/forum/showthread.php?t=1942

skimask
- 27th May 2008, 15:04
Or even easier (I think) to use a DS1820 type sensor.
There has to be at least a dozen examples here on the forums.

Acetronics2
- 27th May 2008, 15:14
Hi, Ski

Good idea ...

and if being really time-short a LM 35/335 ... could also do it !

But what replacement for my .5 mm dia thermistors ( from aerospace industry ) ??? didn't find yet ...

Alain

Castor
- 28th May 2008, 10:20
I used Paul's sollution and it works great !