Accurate Temperature Thermometer using LM35

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Accurate Temperature Thermometer using LM35

Post by medelec35 »

Equipment used and files required:
EB006 Programmer with 16F1824 fitted.
Note: Only designed to work with the following microcontrollers:
12F1822, 16F1823, 16F1824,16F1825, 16F1828 & 16F1829
Also External Vref will no be available unless original PIC_CAL_ADC.c is restored.

EB005 LCD.
LM35 Temperature sensor (10mv per deg C) connnected to An0 (pin 13)
Connections:
LM35 Connections.png
(30.3 KiB) Downloaded 17087 times
If readings fluctuate, then a basic RC filter (see Datasheet)
Attached Thermometer LM35 V1.fcfx
Description:
The 16F1824 (and all shown devices above) have many new features including 3 different internal stabled Fixed Voltage References (FVR)
These are:
1.024V which changes 10 Bit ADC resolution to 1.024/1024 = 1mV
2.048V which changes 10 Bit ADC resolution to 2.048/1024 = 2mV
& 4.096V which changes 10 Bit ADC resolution to 4.096/1024 = 4mV
Now you can see the reasoning behind this since without FVR and supply =5V
10 Bit ADC resolution = 5/1024 = 4.88mV
The down side is since each ADC variable increment of 1 = 1mV then maximum i/p voltage for ADC = 1023 = 1.023V = 102.3 deg C

PIC_CAL_ADC.c has been modified to enable internal Fixed Voltage reference of 1.024V as this makes the thermometer much more sensitive!
But only when Vref+ has been selected from Vref options (ADC component properties)
If not, then the default resolution will be 4.88mV:
Res 1mV.png
(49.14 KiB) Downloaded 17087 times
This means when FVR is enabled the resolution of 10bit ADC is 1.024/1024 = 1mV
Since output voltage from LM35 is 10mV per deg C that means that the resolution of temperature Thermometer is 0.1 deg C
Floats are not required to display temperature to an accuracy of 0.1 deg C

How the flowchart works is:
10Bit ADC is read.
Since voltage out from LM35 is 10mV per C and resolution of ADC is 1mV then ADC = temperature x 10
So if ADC= 151 then actual temperature is 15.1 deg C.
The 151 is converted to a string.
All numbers except from the last number on the right is printed so in this case 15
Then decimal point is printed. Finally the last digit on the right is printed.
The result printed will be 15.1

At the time of writing this, being in a warm room, calibrated Ktype thermometer displayed 27.0 deg C and LCD connected to EB006 programmer with LM35 connected displayed 26.9 deg C

Hope you find this useful.

Martin
Attachments
Themometer LM35 V1.fcfx
(8.02 KiB) Downloaded 1276 times
Last edited by medelec35 on Wed Dec 02, 2015 8:27 pm, edited 2 times in total.
Reason: Removed PIC_CAL_ADC.c. See post below (Dated Wed Dec 02, 2015 7:23 pm) for further details.
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Accurate Temperature Thermometer using LM35

Post by medelec35 »

If anyone wants to use the above method on a different target device (with internal fixed voltage reference), then let me know and I will see what I can do.

Martin
Martin

fairy
Posts: 14
Joined: Wed Jan 22, 2014 9:20 pm
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Accurate Temperature Thermometer using LM35

Post by fairy »

is it possible to use this method on 16f877a?

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Accurate Temperature Thermometer using LM35

Post by medelec35 »

No sorry.
This method will only work on devices with:

Code: Select all

 Fixed Voltage Reference (FVR) with 1.024V
so it's for the newer devices e.g xxF18xx
If you're not sure if it will work or not with a target device, then the simplest way would be to go to Microchip website
Enter your microcontroller in the Search for Data Sheets box
Then load data sheet.
When loaded hold Ctrl then press F
Enter

Code: Select all

1.024v
If there are instances of 1.024v and FVR then your target device is probably compatible.

Martin
Martin

Sanjay Singh
Posts: 23
Joined: Fri Jun 08, 2012 10:54 am
Location: India
Has thanked: 10 times
Been thanked: 3 times
Contact:

Re: Accurate Temperature Thermometer using LM35

Post by Sanjay Singh »

Dear Medelec,

I wanna use 16F1938 & 16F1939, which has FVR of 1.024V on it. The ADC input will be AN0 or AN1
Please help me out in this matter.

Sanjay

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: Accurate Temperature Thermometer using LM35

Post by dazz »

Hi Sanjay
Please help us to help you, follow the steps in martins post above yours, once done let us know if you still need help, also let us know what you have done and specifically what you need help with

Regards
Dazz
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Accurate Temperature Thermometer using LM35

Post by medelec35 »

It's best not to use PIC_CAL_ADC.c as it could be replacing an updated version.
I will post some additional steps to modify PIC_CAL_ADC.c with correct values as soon as i get the time.
Hopefully will be tonight but no promises.

Martin
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Accurate Temperature Thermometer using LM35

Post by medelec35 »

Not got LM35 anymore so cant test on hardware but as promised here are some details.

Run text editing software like notepad or notepad++ in admin mode.
Use text editing software to load C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_ADC.c
If 64 bit windows
or
C:\Program Files\Flowcode 6\CAL\PIC\PIC_CAL_ADC.c
If 32 bit windows

Search for your target device then look for if (Vref != 0) just below all the #ifdef MX_ADC_CHANNEL_
Then immediately after

Code: Select all

if (Vref != 0)
place

Code: Select all

{
There will be a statement below e.g:

Code: Select all

adcon1 = adcon1 | (Vref & 0x03);
on the next line down place the following:

Code: Select all

fvrcon=fvrcon | 0xC1; }
so for:
// ADC Type 18 Supported Devices ***********************************************************
// 16F722, 16F723, 16F724, 16F726, 16F727, 16F1933, 16F1934, 16F1936, 16F1937, 16F1939
// *****************************************************************************************/
For example you should have:

Code: Select all

if (Vref != 0){ 											
adcon1 = adcon1 | (Vref & 0x03);
fvrcon=fvrcon | 0xC1; }
Not sure if that is how Ben intended FVR to be implemented or not as I believe PIC_CAL_ADC.c was to be modified for such a purpose?
Martin

alikimiafar
Posts: 7
Joined: Tue May 23, 2017 10:26 am
Has thanked: 1 time
Contact:

Re: Accurate Temperature Thermometer using LM35

Post by alikimiafar »

hi
what I can do ? to chose internal fixed voltage reference , fvr 2.048 for 18f26k22 in flowcode6
?

Post Reply