PDA

View Full Version : NTC thermistor temperature monitering



Divinci
- 26th November 2012, 03:48
Hello I am very green when it comes to programming and need some help. I am trying to write a program so that a voltage divider is created by a thermistor and a resistor and that value is sent into my PIC16F690. I wanted to just calculate the value but the equation requires using ln. so my plan now is to make a lookup table but I'm lost. Then after I want to convert the number to BCD and output it to 7 segment decoders and displayed it on 2 7 segment displays. Then I want take in from two input on a count up and one a count down, then compare the measured value to the counter value and output on one of three outputs more than 2 less than, equal to and more than 2 greater than (which I haven't even gotten to yet). I might be doing most or all of this completely wrong any help would be greatly appreciated. Also i only need it to work for values 0-39 in BCD to save outputs on the chip. As you will notice a lot is cut and paste.
Thank you Anthony
'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 11/25/2012 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
p16F690.Inc
TRISA = 011111 'set most to input but leave three bits for output
TRISB = 000000
TRISC = 000000
ADCON1 = 000010


define OSC 20
DEFINE ADC_BITS 8 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 10 ' Set sampling time in microseconds


adcVar VAR WORD
adcVoltage VAR WORD
temp VAR WORD
tempa var word
ba var word
k1 var word
ya var word
yb var word
yc var word
yd var word
ye var byte
yf var byte
Myvar var word




main:


ADCIN 1,adcVar


ADCVoltage=(adcVar/1024)*5
ba = (100000/((5/ADCVoltage)-1))
k = ln(ba/100000)
ya = 0.003354016
yb = 0.000256985
yc = 0.00000262213
yd = 0.0000000638309
tempa = (ya+yb*(k*k)+yc*(k*k*k)+yd*(k*k*k*k)
temp = 1/tempa


if temp=< 0 then
temp=0
endif


if temp => 39 then
temp=39
endif


if temp > 9 then 'Convert to bcd
temp = temp +6
endif


For MyVar = 8 to 15 'highest 8 to go to one 7 segment
yf = temp.0(MyVar)
Next MyVar


ye = portb 'lowest 8 to go to other 7 segment
yf = portc


GoTo main

wdmagic
- 13th December 2012, 17:09
first i notice "TRISA = 011111" you should use all 8 so "TRISA = 00011111"

also your using 8 bit processors that dont use floating point math, so all those ya = 0.0000203123 numbers, your going to have to convert to whole numbers and the max is going to be somewhere near 65353 as a max number, all math cannot excede this numberso you cant do a 35000 + 35000, wont work
go ahead and set your adbits to 10, when you get to the read/store use something like this
ADCIN 0, Res1 ' Read Channel 0 data
res1 = res1 / 64 ' 0-1024 (/256 = 0-255) etc...
Ive got to do this too, i need to use a NTC for a temp guage, I'm sure i can do it with about 5 lines of code, so you should be able to clean this up a bit.
try to get your math down, it looks way to complicated.

Normnet
- 14th December 2012, 03:31
A bit easier is the MCP9700A. (http://ww1.microchip.com/downloads/en/DeviceDoc/21942e.pdf)
It's linear and runs about 34 cents.

Norm

wdmagic
- 15th December 2012, 00:54
great idea, I didnt know about that chip, just order a bunch.