Measure cold

For questions and comments on programming in general. And for any items that don't fit into the forums below.

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:

Measure cold

Post by foppa »

Hello everyone,
I've fixed a small thermostat which I will measure cold.
lm335 which does the job.
But when I put it in the fridge so it does not indicate below zero.
The show +16, not sure what it showed but they were not below freezing.

tempratur true when measuring the room tempratur

pic16f690
crystal 4MHZ
Display 2 * 16
lm335
conversion formula "temp = temp * 5 * 100 / 1024"

Something I missed
Foppa
Last edited by foppa on Sun Apr 18, 2010 8:00 pm, edited 1 time in total.

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

Re: Measure cold

Post by medelec35 »

Hello foppa.
If I have worked this out correctly.
Since o/p = 10mV per deg K
then
Read_ADC = Read_ADC*10/102*5-273
So long as Read_ADC = int variable
E.g. at 0 deg C Read_ADC is approx 559.
So temperature=559*10/102*5-273 = 1
1 instead of 0 is due to rounding errors

Not sure if this will work but it it does will be a bit more accurate:
Read_ADC= Read_ADC*500/1024-273
Hope this helps.
Martin

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

Re: Measure cold

Post by foppa »

Ok will try this tonight
I will come back and talk about how it goes.
Thanks for your help
Foppa

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

Re: Measure cold

Post by foppa »

Ok have tried it now.
Did not that good.
The display shows the -297 C

What do
Foppa

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

Re: Measure cold

Post by medelec35 »

Hiya foppa

Sorry, I did not take into account with int you cannot go above 32767 or below -32768 at any time during calculations. The Flowcode simulator does not take that into account either :P .
Here is a revised formula, verified 100% working using a different real time simulator.
Temperature =((Read_ADC*10/(1023/100)*5)+5)/10-280

Note: using -280 and not -273 due to rounding errors.
Alos resolution accuracy will not be that good (but im working on that), unless floating point maths is used.

Will only work If sampled in 10bit mode (0-1023) = (0V to 5V).

If you still are having problems then measure your i/p voltage to port you have connected to LM335. At 0 deg you should be measuring 2.73V:

Expected Voltage = (Temperature in C + 273.15 )/100

Are you using Flowcode?
If so what version?
Martin

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

Re: Measure cold

Post by medelec35 »

The simplest formula that appears to work is:
Temperature = Read_ADC*5/10-280
It also appears to be fairly accurate (i would guess =/- 1 deg C)
Martin

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

Re: Measure cold

Post by foppa »

Hello medelec35 First thanks for all your help.

I tested the simple solution and then show the -54 in the room tempratur.
I attach the file to lm335.
The difficult solution I do not know how to get to because it requires them these symbols (()) and do not know how to incorporate them.
I copied the difficult solution and pasted into flowcode.
no dissatisfaction from flowcode about that.
tempraturen is wrong there too

but it may be due to paste it into the flowcode from your posts

I have plugged in a resistor of 4.7Kohm from - to output on lm335

can you make a hex file for me to file that I attached in this post.
curious if there is someone setting that is wrong.
running with pickit2
Foppa
Attachments
Analog 690.fcf
(8.5 KiB) Downloaded 382 times

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

Re: Measure cold

Post by medelec35 »

Your welcome.
Your flowcode file is fine including the formula, and must be working OK since you have got a temperature showing on the display.
The best thing to do is measure the real temperature where the sensor is, and post that along with the voltage measured going into pin 19 of 16F690.
I looked at the data sheet and at 25 deg C the o/p from LM335 should be 2.982V. (-54C = approx 2.19V ). So you can confirm if that is the case with your hardware. Don't for get if you have not calibrated your sensor there could be a temperature error between 1 and 5C depending on temperature measured and reverse current.
Perhaps you can post a circuit diagram. Have you checked the sensor is connected the right way round (although if you are getting -54C then thats not likely to be wrong way), this again can be confirmed by measuring the i/p to pin 19 as previously stated.

Edit: Also try changing your supply resistor to something like 2k2 - 2K7, if your using 5V to supply sensor.
With 4K7: At 25 deg C, current through sensor = (5 -2.98)/4700 = 429 uA = too close to minimum current limit.

Also you need to take two other things into account:
1) For every 1 deg C change, the voltage at the pin of uc is only changing by 10mV = two counts (using 10 bit)
2) The accuracy is also totally dependent on the reference supply accuracy, which is the 5V supply to uc (if not changed internal supply reference). So a small ripple on supply will cause the temperature reading to fluctuate.

Hope this helps.
Martin

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

Re: Measure cold

Post by foppa »

Hello
Ok've drawn a bit on my connection.
Not the best but I hope you understand.
And I have measure the output of the lm335 and the value 2.040 V and the display shows -69
And the formula for conversion is the "Temperature = ((Read_ADC * 10 / (1023/100) * 5) +5) / 10-280
"
if this fails to work you should replace the sensor against someone else.

I have made sure that +5 V is stable.
Has had problems with not having a stable +5 V before.
Which gave me many problems.
But now it's okay

in the coming days to obtain the right of resistance that you write
I saw that I have 4Mhz crystal instead of 8Mhz.

VDD goes to plus
Foppa
Ps I use google translate which may explain my English
Attachments
16F690.JPG
16F690.JPG (46.37 KiB) Viewed 10646 times

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

Re: Measure cold

Post by medelec35 »

foppa wrote:And I have measure the output of the lm335 and the value 2.040 V and the display shows -69
That is correct if o/p = 2.04V then temperature should be -69 deg C. Since the sensor won't be at that temperature, then the problem is the o/p is at the wrong voltage, not with the software.
Your diagram is not clear enough to check connections. To connect LM335 Adj is not used. + of lm335 goes to RA0 and to the supply resistor the other end of resistor goes to +5V supply. - of lm335 goes to 0V.
lm335.jpg
lm335.jpg (28.53 KiB) Viewed 10645 times
Just as a reminder:
The simplest formula that appears to work is:
Temperature = Read_ADC*5/10-280
Martin

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

Re: Measure cold

Post by medelec35 »

If you are going to change your sensor. I have used a AD22100 which works well. Instead of 10mV per deg C, resolution is 22.5 mV per deg C. It would be more accurate, since there is a built in constant current source.
Martin

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

Re: Measure cold

Post by foppa »

Hello medelec35
Well now it starts to work as I want.
Should tomorrow calibrate the sensor.
I will come and talk about how it goes.
Thanks for the help

Well I know that my drawing was not good.
Must do a better drawing next time
Curious about what you draw with

Foppa

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

Re: Measure cold

Post by medelec35 »

Great! Glad you got it working. What was the problem with your circuit ?
Unfortunately the drawing package is not mine, some kind person let me use it on their PC. It is called Proteus. Too expensive for me :-( I am looking around for a cheaper schematic package I can use.
Martin

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

Re: Measure cold

Post by foppa »

Hold the horses medelec35
I was wrong
Since I am a novice in this, I need a bit more assists
How do I know where I will connect ADJUST or should not be connected
And what is o / p.

crap and I thought that this was ok

Foppa
Attachments
lm335.jpg
lm335.jpg (33.12 KiB) Viewed 10620 times

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

Re: Measure cold

Post by medelec35 »

As stated in my previous post:
medelec35 wrote: To connect LM335 Adj is not used.
+ of lm335 goes to RA0 and to the supply resistor the other end of resistor goes to +5V supply. - of lm335 goes to 0V
You only connect AJD if you are calibrating the device, then a trimmer stays connected to ADJ. Otherwise Leave ADJ open circuit.

Take a look at the datasheet, it should help.
lm335.jpg
lm335.jpg (33.12 KiB) Viewed 10619 times
Martin

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

Re: Measure cold

Post by foppa »

Hello.
Now I understand what I have done wrong all the time.
I was sure that adj on lm335 was the outout to RA0.
So now it should be okay,.
Differ to some degree but I can fix it.
now that I know what it should be done.

Foppa
:oops:

Post Reply