![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
triple_x
Joined: 01 Dec 2005 Posts: 10
|
LM335 reading value incorrect.. any help? |
Posted: Wed Mar 15, 2006 9:21 pm |
|
|
Hi all,
I try to implement this thread http://www.ccsinfo.com/forum/viewtopic.php?t=25665&highlight=lm335
as suggested by Thelmah, but I got invalid values when reading the temp sensor.
The LM335 pin connection as follows:
Code: |
to RA2/AN2
|
| 1uF
+-------|(--------GND
|
+5 |----[2.2k Res]---+----(2)|<|(1)----GND
LM335 (pin 3 not connected)
|
Here is the short code:
Code: |
#include <16F77.h>
#device adc=10
#fuses hs, nowdt, noprotect, noput, nobrownout
#use delay(clock=9830400)
// port A address
#byte porta = 5
// debug
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=COM1)
void main() {
int16 TempVal;
set_tris_a(0xFF); // inputs
// ADC SETUP
setup_adc_ports(A_ANALOG); // A0 A1 A2 A3 A5 Ref=Vdd
setup_adc(ADC_CLOCK_INTERNAL); // Internal 2-6us
set_adc_channel(2); // use AN2
while(1) {
delay_ms(1000);
TempVal = (read_adc() - 559L) / 2;
fprintf(COM1, "Temp is %2lu DegC.\r\n", TempVal);
}
}
|
The results:
Code: |
Temp is 88 DegC.
Temp is 88 DegC.
Temp is 88 DegC.
Temp is 88 DegC.
Temp is 88 DegC.
Temp is 88 DegC.
......
|
Using multimeter, I got constant reading of 4.88V at LM335 pin 2.
Any help is appreciated...
rgds, |
|
![](templates/subSilver/images/spacer.gif) |
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Wed Mar 15, 2006 10:44 pm |
|
|
My $0.02 guess is that you have a hardware problem. I have never used LM335 before, but I have skimmed through the datasheet and found that the output is 10mV/K. I assume that your sensor is at room temperature T~300K. Your voltmeter reading should be V(T)~3V, and your actual volmeter reading seems too high. Also V(T)=4.88V is suspiciously close to the Vcc=+5V, and it hints that you resistor value is too low. Try a higher value of, say, 10k.
By the way, thatnks for asking such a detailed question! |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Thu Mar 16, 2006 5:11 am |
|
|
One comment. Check the pinout.
The normal connection, is:
Vadj
V+
V-
Along the chip, requiring GND to pin 1, and reading the output from pin 2, so if you are connecting to the outer two pins (which your pin 1&3 comment suggests), it is no wonder it is not working.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
languer
Joined: 09 Jan 2004 Posts: 144 Location: USA
|
|
![](templates/subSilver/images/spacer.gif) |
triple_x
Joined: 01 Dec 2005 Posts: 10
|
|
Posted: Thu Mar 16, 2006 7:06 pm |
|
|
thanks for the reply. After changing to 10K resistor and triple check the pins, value now is ~2.7V. unfortunately, no change at output
Code: |
Temp is 88 DegC.
Temp is 88 DegC.
Temp is 88 DegC.
Temp is 88 DegC.
Temp is 88 DegC.
Temp is 88 DegC.
......
|
is there something wrong with the adc setup or AN2 pins?
rgds, |
|
![](templates/subSilver/images/spacer.gif) |
Les Scott
Joined: 18 Feb 2006 Posts: 2 Location: Cheyenne, WY
|
|
Posted: Thu Mar 16, 2006 10:54 pm |
|
|
Hi,
I am pretty new to CCS C but am successfully using the LM355Z in my project. The 355 wants a minimum of 450uA to work so that means that the series resistor should be something less than 4k ohms (if your supply voltage is 5V). In your last post you said that you were reading something like 2.7V. That would be a temperature of about 0 degrees C. I think you may still have a wiring problem. Make the series resistor somewhere between 2.2 and 3.9k. At room temp you should have a sensor voltage of about 2.9V. If this is not what you are reading at the output pin of the 355 you either have it wired up wrong or the 355 is fried.
You do not need the 1uf cap on the output of the 355. It is a pretty low impedance device and the cap isn't going to do much for you.
This is an amazing source of information. I hope I haven't offended any of the experts here because there are many that post here that are way more knowledgeable than I.
Let me know what more I can do to help. |
|
![](templates/subSilver/images/spacer.gif) |
kel
Joined: 17 Oct 2005 Posts: 68 Location: Brisbane
|
Right! |
Posted: Thu Mar 16, 2006 11:08 pm |
|
|
He is right,you don't need the capacitor.I worked on lm335 too a few weeks ago and you should be able to get what i posted.I didn't connect any capacitor and i through many helps from this forum was able to get the right temperature readings if the Vcc is constant.However lm335 is voltage depended and the temperature droops with the dripping of the VCC.Note that very well!
I had trouble with back light LCD that cause a drift in the Vcc and my temperatures were very much affected.
Looking at your code, there is nothing wrong with it!!
Quote: | #include <16F77.h>
#device adc=10
#fuses hs, nowdt, noprotect, noput, nobrownout
#use delay(clock=9830400)
// port A address
#byte porta = 5
// debug
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=COM1)
void main() {
int16 TempVal;
set_tris_a(0xFF); // inputs
// ADC SETUP
setup_adc_ports(A_ANALOG); // A0 A1 A2 A3 A5 Ref=Vdd
setup_adc(ADC_CLOCK_INTERNAL); // Internal 2-6us
set_adc_channel(2); // use AN2
while(1) {
delay_ms(1000);
TempVal = (read_adc() - 559L) / 2;
fprintf(COM1, "Temp is %2lu DegC.\r\n", TempVal);
}
} |
Remove the capacitor and let us know how it goes...
![Very Happy](images/smiles/icon_biggrin.gif) |
|
![](templates/subSilver/images/spacer.gif) |
triple_x
Joined: 01 Dec 2005 Posts: 10
|
|
Posted: Fri Mar 17, 2006 12:26 am |
|
|
Thanks for the info kel & Les Scott. resistor changed to 2.2k and 1uf cap is removed (already removed before read the posting :-) ), got value around 3.04V at the output. but what suspicious me is that result echoed to terminal is the same!
Code: |
Temp is 88 DegC.
...
|
I bet there is something wrong here.... |
|
![](templates/subSilver/images/spacer.gif) |
triple_x
Joined: 01 Dec 2005 Posts: 10
|
|
Posted: Fri Mar 17, 2006 12:46 am |
|
|
success!
I add one more variable:
Code: |
void main() {
int16 degC; // this one...
int16 TempVal;
set_tris_a(0xFF); // inputs
// ADC SETUP
setup_adc_ports(A_ANALOG); // A0 A1 A2 A3 A5 Ref=Vdd
setup_adc(ADC_CLOCK_INTERNAL); // Internal 2-6us
set_adc_channel(2); // use AN2
while(1) {
delay_ms(1000);
degC = read_adc(); // *****
TempVal = (degC - 559L) / 2;
fprintf(COM1, "Temp is %2lu DegC.\r\n", TempVal);
}
}
|
I'm not really sure what does effect the result, but it seems OK. |
|
![](templates/subSilver/images/spacer.gif) |
Les Scott
Joined: 18 Feb 2006 Posts: 2 Location: Cheyenne, WY
|
|
Posted: Fri Mar 17, 2006 12:49 am |
|
|
Cool!
Glad it is working!
Take care,
Les |
|
![](templates/subSilver/images/spacer.gif) |
sonicdeejay
Joined: 20 Dec 2005 Posts: 112
|
|
Posted: Mon Jun 04, 2007 6:21 am |
|
|
Code: |
TempVal = (degC - 559L) / 2;
fprintf(COM1, "Temp is %2lu DegC.\r\n", TempVal);
|
Brothers...
what is 559L means?? |
|
![](templates/subSilver/images/spacer.gif) |
sonicdeejay
Joined: 20 Dec 2005 Posts: 112
|
|
Posted: Mon Jun 04, 2007 6:35 am |
|
|
Guy...
my connection as followed..
Code: | to multimeter
|
| 1uF
|
+5 |----[1k Res]---+----(2)|<|(3)----GND
LM335 (pin 1 not connected)
|
The Room Temp is about 25 C and from multimeter I am getting 2.525 Volt.
what equation can I use to calculate from 2.525 V to 25 C? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Mon Jun 04, 2007 8:02 am |
|
|
559L, is 559. The 'L', ensures the compiler treats a value as a 'long', and is a good way of making sure that 16bit arithmetic is used, rather than the default 8bit.
1KR, is a bit low for the resistor on the chip. Shouldn't matter for 'normal' temperatures, but implies 2.5mA is being drawn at 0C, which is closer to the upper end of the chip's range, than is perhaps 'ideal'. Keeping the current lower, also helps to reduce error from the 'self heating' of the chip.
Your voltage is rather lower than I'd expect. In a typical room, you should see close to 3v, and even uncalibrated, the 'worst' chip from the maker, should not give as low a value as 2.525v. The specification from the manufacturer, is 2.98v at 25C, when 1mA is drawn, +/- 0.03v. Now, to draw 1mA, at this voltage, would require a resistor of:
(5-2.98)/0.001 = 2K02
So I'd suggest a 2K, or 2.2K resistor, as putting you 'on' the manufacturers recommended operating current.
You really need to find out why your reading is this low?..
The point about '559', is that with a normal chip, using an ADC operating off 5v, this is the reading for 0C. 0C, corresponds to 2.73v from the chip. The PIC ADC, has a 'step' size, of:
Vref/1024 (see my previous posts for why this is 1024, not the 1023, of many other ADC designs).
With Vref=5v, this gives a step size of:
0.0048828125v
Then 2.73v/0.00488 = 559 counts on the ADC.
So, you need to solve why your hardware is giving 2.525v. This is blatantly a 'wrong' value, and implies something is not right.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|