Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

pic16F877A based thermometer

Status
Not open for further replies.

georges

New Member
heyy folks
im building a pic microcontroler based thermometer interfaced with 2*16 LCD and im using a 10k thermistor as a sensor !
can anyone help me to write a simple source code on mikrobasic compiler ? cz im having some difficulties dealing with function !
thank u all
 
In general it does not work like that.

We will help you with your code but we will not hand you
a ready to run solution. Show us what you have that does
not work. Use the # icon on the toolbar to place CODE
tags prior to and after your code to make it readable.

Please post the schematic.
 
ok i will show u my code , this one is giving me 2 digits result on the LCD screen
but i want it to show the other 2 digits after a comma for precision ( for example
28.50 deg. )

and this is the source code:
---------------------------
program LCD_Temp1 ' thermometer with temp. range going
' from -9 deg. to + 55 deg.

dim rr as float
txt as char[5]
t as float

main:

ADCON0 = $55 ' %01010101
ADCON1 = $80
TRISD = $00
TRISA = $FF

LCD_INIT( PORTD)
LCD_CMD(LCD_CURSOR_OFF)
delay_ms(2000)
Lcd_cmd(Lcd_Clear)
Lcd_Out( 1,1,"temperature:")
Lcd_out( 2,10,"celsius")

while true

rr=ADC_read(2)

if (rr>250.0)and(rr<740.0)then ' the temp vs a2d curve is supposed lineaire

Lcd_Out(2,1,"+") ' when 250 < adc <740
t=(-0.108)*rr+80.0 ' +53 c --> 0 c
floattostr(t,txt)
lcd_out(2,2,txt)
delaY_ms(1000)

end if

if ( rr > 739.0) and ( rr < 800.0) then
Lcd_Out(2,1,"-")
t=(-0.138) *rr + 102.7 ' -0.1 c --> - 8.3 c
inttostr( t,txt)
lcd_out(2,2,txt)
delay_ms(1000)

end if
wend
end.
 
Hi,

I have source code in c that may be useful (you may be able to translate this into basic). In my case I am using the thermistor in a temperature data logger project but the code would be similar for a thermistor based temperature display.

The code is attached.

Regards,
Jeff Fedison
-----------------------------------------------
Micro Circuit Labs ~ Innovative electronic kits
**broken link removed**
 

Attachments

  • 10k_thermistor_code.txt
    2.1 KB · Views: 279
Hi,

I have source code in c that may be useful (you may be able to translate this into basic). In my case I am using the thermistor in a temperature data logger project but the code would be similar for a thermistor based temperature display.

The code is attached.

Hi there Jeff
is it possible to briefly explain how you calculated the a b c d coefficients for your calculations?

Thanks
 
Hello Demestav,

The a b c d coefficients are calculated using Excel by choosing a 3rd order polynomial fit to the plot of temperature versus code. More details are on page 5 of the manual (available at **broken link removed**) in the "Thermistor" section, repeated here:

--------------
Thermistor
Thermistor R4 is used as the temperature sensor in this circuit. It is a 10Kohm negative temperature coefficient type that is specified with an accuracy of ± 1.8F at 77F. Referring to the DTL schematic on page 6, the thermistor (R4) and the 10Kohm resistor (R3) form a voltage divider that feeds the analog input AN1 of the microcontroller. To take a temperature measurement, the A/D converter reads the voltage at the AN1 input and this voltage is represented by a 10-bit code that ranges from 0 to 1023. The code that is read is related to the values of R3 and R4 by the following relation:

Code = Maxcode × (R4 / (R4+R3))

Where R4 is the thermistor resistance, R3 equals 10Kohms and Maxcode equals 1023. An Excel spreadsheet was used to compute the resistance of the thermistor versus temperature from equations provided in the thermistor datasheet. The equation above was then used to relate the value of Code to temperature. A plot of temperature versus Code was made and the resulting curve was fitted to a third order polynomial. The end result is an equation that allows the computation of temperature for a given value of Code. The polynomial fit was done in three sections from -40F to 214F and was tweaked until the error was less 0.3F in each section.

--------------

Best Regards,
Jeff
 
Last edited:
Hi Jeff and thanks for the reply,

Where do you find the equation that corresponds to the resistance in relation to temperature? I looked around and I see various equations. Is there a different equation for each brand of thermistors or equation should be the same because they are made out of the same material?

Thanks!
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top