Sensor LM50BIM3 in Celsius

Any general or miscellaneous queries that do not fit into the other forum catagories

Moderators: Benj, Mods

Post Reply
foppa
Posts: 45
Joined: Sat Dec 20, 2008 1:55 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Sensor LM50BIM3 in Celsius

Post by foppa »

I'm about to fix temp gauge.
I wonder what to do in order to display in Celsius.
instead of the value is 0 to 1023
the ADC is working with

PIC16F690
Kristal 4MHz
temp sensor LM50BIM3
John

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Sensor LM50BIM3 in Celsius

Post by Benj »

Hello

The 0-1023 ADC result is representive of Voltage on the analogue input pin. There should be a calculation that you can follow that will specify how to convert the voltage supplied from the sensor to a temperature reading in degrees C.

foppa
Posts: 45
Joined: Sat Dec 20, 2008 1:55 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Sensor LM50BIM3 in Celsius

Post by foppa »

you have some formula for this.
As I can take advantage of
John

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Sensor LM50BIM3 in Celsius

Post by Benj »

Hello John

Your in luck, this one looks quite simple.

According to the datasheet.

The LM50's output voltage is linearly proportional to Celsius (Centigrade) temperature (10 mV/DegreeC) and has a DC offset of a 500 mV.

So heres what to do in Flowcode.

Temp Result = INT Variable

Comp macro: Sample ADC
Comp macro: Temp Result = Read Value as INT
Calculation: Temp Result = Temp Result - 102
Calculation: Temp Result = Temp Result / 5

Hope this helps.

foppa
Posts: 45
Joined: Sat Dec 20, 2008 1:55 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Sensor LM50BIM3 in Celsius

Post by foppa »

Thanks to be fun to test.
John

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: Sensor LM50BIM3 in Celsius

Post by medelec35 »

I'm not that good with maths... You can ask Steve :p
What about:
Comp macro: Sample ADC
Comp macro: Temp Result = Read Value as INT
Calculation: Temp Result = Temp Result *50
Calculation: Temp Result = Temp Result / 102
Calculation: Temp Result = Temp Result - 50

Or

Temperature = ADC value as int * 50 / 102 - 50

So if ADC value as int = 153 = 0.75V then
Temperature = (153 *50)/102 - 50
= 25

Using another sample if ADC value as int = 358 = 1.75V then
Temperature = (358 *50)/102 - 50
= 125

Ben, bit odd my results don't agree. with yours:

(153 - 102)/5 = 10
Perhaps I'm missing something?
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: Sensor LM50BIM3 in Celsius

Post by medelec35 »

Ben, not sure if I am correct or not. Please let me know If I have gone wrong in the calculations.
Thank you.
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: Sensor LM50BIM3 in Celsius

Post by medelec35 »

foppa
Just curios if you hardware is displaying correct temperature now?
Martin

foppa
Posts: 45
Joined: Sat Dec 20, 2008 1:55 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Sensor LM50BIM3 in Celsius

Post by foppa »

No, it shows about 10 when the current temperature is 18.
Have not had time to test this further.
'll Try to do it tonight.
I have also another problem, it is that value is not fixed / stationary on my screen.
Oscillate up and down.
Do not know what to invent to this problem.

But I'm going and try your solution

Foppa

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: Sensor LM50BIM3 in Celsius

Post by medelec35 »

You can place a delay that will slow down the rapid change, so you can read display. This may seem a daft question but. If change is too rapid, then is o/p connected to pin you have set up to read? If pin is floating then you will get allsorts of rapidly changing figures. Measure the o/p from your sensor, and see how much that changes. Does the LCD change at the same rate?
Also check your formula. If there is an error with formula, then a small change to i/p could cause a large change to calculated value.
When I created a flowchart with a temperature sensor, I measured the voltage on pin that's connected to sensor o/p, then did the maths to make sure correct temperature would be displayed.

If fomula used is: Temperature = ADC value as int * 50 / 102 - 50
What you could do is measure room temperature. Then transpose for ADC so you have:
ADC value as int = 51*(Temperature + 50)/25
So if room is 21 deg C then ADC value = 51 * (21+50)/25 = 144
Just confirm if all agrees.
Martin

foppa
Posts: 45
Joined: Sat Dec 20, 2008 1:55 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Sensor LM50BIM3 in Celsius

Post by foppa »

hello medelec35

I tried this and it seems to show the right
"Temperature = ADC value as int * 50 / 102 - 50"

But the value of the display goes up and down.
It goes from 25 down to 17 and up to 25 again.
all the time.
I have insert the 4.7kohm for pullup.
I enclose my small test program.
Perhaps you have someone the idea of what I'm doing wrong.
Foppa
Attachments
Analog 690.fcf
(7 KiB) Downloaded 316 times

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: Sensor LM50BIM3 in Celsius

Post by medelec35 »

Formula looks OK. Only thing I can think of is lack of supply decoupling capacitor can cause instability, whether you are using a voltage regulator or batteries. Just remembered. When I made my temperature sensor, I was using batteries for a power source. The instability threw me. Was sorted by using placing a 4u7F Electrolytic Cap between VDD and VSS. You should not require a pull-resistor.
When you measure voltage on pin 19 which you have got sensor connected to, is it stable at correct voltage for current temperature being measured?
Improved your Flowcode slightly.
Depending on LCD you have used, can also place a suitable degrees symbol next to the C
Attachments
Analog 690_1.fcf
(7.5 KiB) Downloaded 327 times
Martin

foppa
Posts: 45
Joined: Sat Dec 20, 2008 1:55 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Sensor LM50BIM3 in Celsius

Post by foppa »

What type of capacitor should I have.
And what value will it have.
Should it be connected in series with LM50BIM3.

I see that you have changed a bit in Coden.
Should be fun to try this tonight
Many questions now.

I thank you for all the help.
Foppa.
:mrgreen:

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: Sensor LM50BIM3 in Celsius

Post by medelec35 »

What I have posted won’t stop the instability, that’s caused by your hardware. The program I posted just formats display slightly better and gives less of a flicker. It’s as broad as is long. Supply decoupling capacitors are just low value non-polarised capacitors connected across power supply e.g. 100nF Mica or cermic (RS 653-0210. for example). I have not seen your circuit, but take a look at 78L05 datasheet for capacitor values.
The 4u7F Capacitor I used is RS stock number 116-852P This is polarised, so connect +ve of cap to +5V of chip and –ve of cap to 0V of chip.

It would help if you posted your circuit diagram.
Martin

Post Reply