Floating point expression looking for integer math solution
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]
Code:
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
a good hard ... allows easy soft !!!
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