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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8285
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Accurate Temperature Thermometer using LM35

Postby medelec35 » Thu Jul 31, 2014 3:34 pm

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
LM35 Connections.png (30.3 KiB) Viewed 15405 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
Res 1mV.png (49.14 KiB) Viewed 15405 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 942 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.
These users thanked the author medelec35 for the post (total 8):
kersing (Thu Jul 31, 2014 5:08 pm) • JohnCrow (Thu Jul 31, 2014 6:59 pm) • Kenrix2 (Thu Jul 31, 2014 7:27 pm) • dazz (Thu Jul 31, 2014 8:44 pm) • Steve001 (Fri Aug 01, 2014 7:14 am) • jgu1 (Sat Aug 02, 2014 7:03 pm) • Benj (Wed Aug 27, 2014 11:27 am) • skquah (Fri Aug 05, 2016 4:18 am)
Rating: 44.44%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8285
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Re: Accurate Temperature Thermometer using LM35

Postby medelec35 » Fri Aug 08, 2014 10:10 am

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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Postby fairy » Wed Aug 27, 2014 8:39 am

is it possible to use this method on 16f877a?

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8285
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Re: Accurate Temperature Thermometer using LM35

Postby medelec35 » Wed Aug 27, 2014 10:29 am

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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Re: Accurate Temperature Thermometer using LM35

Postby Sanjay Singh » Tue Dec 01, 2015 7:11 pm

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: 514 times
Been thanked: 467 times
Contact:

Re: Accurate Temperature Thermometer using LM35

Postby dazz » Wed Dec 02, 2015 11:34 am

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
These users thanked the author dazz for the post (total 2):
Benj (Wed Dec 02, 2015 11:41 am) • medelec35 (Wed Dec 02, 2015 2:14 pm)
Rating: 11.11%
 
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8285
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Re: Accurate Temperature Thermometer using LM35

Postby medelec35 » Wed Dec 02, 2015 2:09 pm

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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8285
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2371 times
Been thanked: 3378 times
Contact:

Re: Accurate Temperature Thermometer using LM35

Postby medelec35 » Wed Dec 02, 2015 8:23 pm

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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Re: Accurate Temperature Thermometer using LM35

Postby alikimiafar » Tue Jul 04, 2017 9:07 am

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