PDA

View Full Version : Help!! Integer Math?



scottl
- 28th June 2006, 23:02
I have been racking my brain for the past two weeks with the following!

I have a PIC12F675 reading an AD595 thermocouple IC. The AD595 provides 10mV/C. In order to read the temp below 0 I have added a voltage divider to the ground pin of the AD595. I have also power the AD595 via a -5V to +5V power supply. I read the output of the AD595 on GPIO.0 and the Virtual Ground voltage via GPIO.1.

To read the temperature above 0C I basically subtract GPIO.1 from GPIO.0. I cannot get the math correct for any thing below 0C or 32F.

Here is some of the code:
'celsius
'farenheit
'adval = GPIO.0
'adval1 = GPIO.1

if adval > adval1 then
celsius = adval - adval1
farenheit = (celsius * 18) / 10
farenheit = farenheit + 32
else
adval_C = adval1 - adval
adval_F_18 = (adval_C * 18)/10
adval_F_32 = (adval_F_18 + 32)
check = 0
endif

psdayama
- 29th June 2006, 13:47
Hi,
U don't need racking Ur brain! As U have connected AD595 to +/- supplies
the output below 0 degrees Celesius is -ve. There is no problem in Basic
program. PIC A/D inputs cant read below 0V or GND of +5V supply. U just connect AD595 to only +5V and let 0degree celesius be at 2.5V and modify
program for offset and it will work.Or u take one OPAMP and shift output of
AD595 to some suitable value.
Let me know if u have any other problem.
psdayama