ADC0831 - LM34 - Low Temperatures
french_mark
Posts: 6
Hi everyone,
I have been reading a lot on this forum and I always managed to find the solution of my problems. Until now... hopefully it's a quick fix.
I am trying to read the temperature from the LM34 temperature sensor and the ADC0831 ADC.
I have the Basic Stamp HomeWork Board and I just need to capture the temperature in the range -50F to 100F.
I (over?)simplified the code DataMonitoring.bs2 script and it works fairly well.
I tried it with the sensor in my freezer and it did not go under 19.6F
From what I read, I may need to recalibrate it by changing VREF to a lower voltage. Is it correct?
If not .. What should I do?
If it is, I don't know how to do it. By default mine is set to 5V I suppose.
I don't know if this change is done on the code (I have not seen any VRef as reference in any scripts I have seen) or If I need to to add a new resistor.
Does anyone have any guidelines or documentation?
Thank you in advance and Merry Christmas.
Best,
Marc
[HTML]'
[ Title ]
' Process Control - DataMonitoring.bs2 Modified
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ Declarations ]
DigDataIn VAR Bit ' Digital input data
ADC_DataIn VAR Byte ' Analog to Digital Converter data
ADC_CS PIN 3 ' ADC Chip Select pin
ADC_Clk PIN 4 ' ADC Clock pin
ADC_Dout PIN 5 ' ADC Data output
'
[ Initialize ]
PAUSE 1000 ' Allow connection to stabilize
DEBUG CLS 'Start display.
'
[ Main Routine ]
DO
GOSUB ReadData
GOSUB Display_Data
PAUSE 500
LOOP
'
[ Subroutines ]
ReadData: ' Read ADC 0831
LOW ADC_CS ' Enable chip
SHIFTIN ADC_Dout, ADC_Clk, MSBPOST,[ADC_DataIn\9] ' Clock in data from ADC
HIGH ADC_CS ' Disable ADC
RETURN
Display_Data:
DEBUG "INC:",DEC ADC_DataIn, CR
DEBUG "Temperature:", DEC (ADC_DataIn *196)/100, ".", DEC2 ABS(ADC_DataIn *196)," F", CR
RETURN[/HTML]
I have been reading a lot on this forum and I always managed to find the solution of my problems. Until now... hopefully it's a quick fix.
I am trying to read the temperature from the LM34 temperature sensor and the ADC0831 ADC.
I have the Basic Stamp HomeWork Board and I just need to capture the temperature in the range -50F to 100F.
I (over?)simplified the code DataMonitoring.bs2 script and it works fairly well.
I tried it with the sensor in my freezer and it did not go under 19.6F
From what I read, I may need to recalibrate it by changing VREF to a lower voltage. Is it correct?
If not .. What should I do?
If it is, I don't know how to do it. By default mine is set to 5V I suppose.
I don't know if this change is done on the code (I have not seen any VRef as reference in any scripts I have seen) or If I need to to add a new resistor.
Does anyone have any guidelines or documentation?
Thank you in advance and Merry Christmas.
Best,
Marc
[HTML]'
[ Title ]
' Process Control - DataMonitoring.bs2 Modified
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ Declarations ]
DigDataIn VAR Bit ' Digital input data
ADC_DataIn VAR Byte ' Analog to Digital Converter data
ADC_CS PIN 3 ' ADC Chip Select pin
ADC_Clk PIN 4 ' ADC Clock pin
ADC_Dout PIN 5 ' ADC Data output
'
[ Initialize ]
PAUSE 1000 ' Allow connection to stabilize
DEBUG CLS 'Start display.
'
[ Main Routine ]
DO
GOSUB ReadData
GOSUB Display_Data
PAUSE 500
LOOP
'
[ Subroutines ]
ReadData: ' Read ADC 0831
LOW ADC_CS ' Enable chip
SHIFTIN ADC_Dout, ADC_Clk, MSBPOST,[ADC_DataIn\9] ' Clock in data from ADC
HIGH ADC_CS ' Disable ADC
RETURN
Display_Data:
DEBUG "INC:",DEC ADC_DataIn, CR
DEBUG "Temperature:", DEC (ADC_DataIn *196)/100, ".", DEC2 ABS(ADC_DataIn *196)," F", CR
RETURN[/HTML]
Comments
It will take a change to the circuit and a small change in you code to get to negative temperatures. If you can use the differential inputs on the ADC0831, you will be able to run it without a negative power supply.
I have been looking at the LM34 specs and your responses and I think I just realized how much I don't know about all this!
I put the sensor in my freezer to test how it would react with cold temperatures. For my little project, I ultimately would need to be able to read negative temperatures.
I tried everything again after a good night's sleep. I think I had made a mistake with the conversion code to Deg F. I tried again and it actually works up for lower temperatures.
My freezer is apparently at a little less than 10 degrees F From my understanding the lowest temperature I can read should be 1.96F (1v = 100F = 51 increments out of 255 so 1 inc = 1.96F)
It may be a stupid question but how do create a negative power supply? According to the LM34 specs it looks like the easiest way. But That wouldn't solve my issue.
Kwinn's explanation with the ADC makes sense. Even if I had a negative voltage, the ADC wouldn't be able to translate it, correct?.
To amplify the output voltage, I guess I can play with the resistor's value (I currently have a 220ohm resistor)
However I do not how to shift the voltage output of the LM34 nor do I know how to use an op amp. Maybe I should get another ADC with a wider voltage input?
I really looking for the simplest solution. Accuracy would be nice but is not a must have.
Do you know a specific component or piece of documentation I could look at?
Thanks again!
If you use option A (0 - 5V range) this will result in an output from the ADC0831 of about 10 at -50F and about 137 at 200F
If you use option B (0 - 2.5V range) you will get an output from the ADC0831 of about 20 at -50F and 255 at about 180FAttachment not found.
I really appreciate it.
The issue with the LM75 is that I don't believe it can be mounted on a cable.
I am going to try with LM34 and the diagram you sent me. But I first need to go to radioshack because I don't have any of those resistors and capacitors.
Thanks again for your help!
Another analog sensor you might try is the AD590 or AD592. It is a two-wire sensor, so it is easy to mount on a cable, and it produces 1 µA per Kelvin. At the ADC, a resistor can convert the current to a voltage and with good choice of reference and offset, you could have the result in either Celsius or Fahrenheit.
I got curious and googled temperature sensors and found several that were complete with 9-12 bit serial data output. The Dallas Semiconductor/Maxim DS18B20 1 wire serial in a TO92 package looked like the ideal choice for this application. It is also available in SO-8 and uSOP-8 packages. This unit requires only 3 wires (gnd, Vcc, and data)
There were also the I2C 2 wire serial units listed below. Although these are all from TI there are similar units available from other manufacturers. These units require 4 wire connections and come in small packages with 6 or 8 pins. They are small enough to mount on the end of the wires, however soldering the wires to the package may be a bit of a challenge.
TMP75/TMP175 - SO-8 & MSOP-8
TMP100/TMP101/TMP121/TMP123/TMP125 - SOT23-6
TMP122/TMP124 - SOT23-6 & SO8
So I went to radioshack and bought the capacitors and resistors necessary to build the simplest diagram.
I went with Kwinn's option A.
I understand that there are some approximations but I am going with what seems to be the simplest to me. Both in terms of realization and understanding.
I built the option A diagram and it was pretty hard, on my little homework board. (I also have a datalogger installed).
I have not been able to find a correct ratio between the ADC output the temperature in degrees Fahrenheit.
I used another thermometer to build a mapping table.
ADC output = 83 -> Temperature = 71F
ADC output = 60 -> Temperature = 36F
Is it supposed to be non linear? Then I guess my script should be more sophisticated and I would need maybe additional reference values?
Or is something obviously wrong?
At this point, I am (of course) running out of time for my little project.
I am thinking about using the DS1620. I have used it before and It was pretty simple to implement. (I have not tested it with negative temperatures though).
What do you guys think?
Thanks again.
Degrees F = (ADCout + A) x M where A is approx -36 and M is approx 1.96.
Back to the LM34/ADC0831: The quiescent current out of the LM34 GND terminal is typically less than 100 µA,and varies slightly with temperature. The diode forward voltage might be lower on its curve, more like 0.55 V measured at point "A". That could be increased with a little additional forward bias of about 4 mA provided by a 1kΩ resistor from Vdd to point "A", and that also might make the bias point a little more stable. However, that does not change the basic idea.
If you measured as you say,
ADC output = 83 -> Temperature = 71F
ADC output = 60 -> Temperature = 36F
that is a slope of 0.657 ADC per degF, or the inverse, 1.522 degF per ADC. That is different from the expected value of 1.953 degF per ADC output count. (19.53 counts per milliVolt) To calculate the intercept at zero degF:
83 = 0.657 * 71 + Co where Co is the ADC count at 0 degrees F
solving makes Co = 36,
and
36 * 15.22 mV = 548 mV as the extrapolated diode forward voltage at 0 °F
or possibly 36 * 19.6 mV = 706 mV if you use the expected sensitivity.
But extrapolation might not mean much. Need more points.
The question is that there should not be that discrepancy in the slope, 19.53 vs 15.22--How to resolve it? Maybe it is in the circuit, or maybe in the pbasic math.
If you were to hook the (-) terminal on the ADC to point "A" instead of to the main circuit ground, that might help in a way, because then the ADC would be measuring the output of the LM34 directly. The trouble is, that would work as is only for positive temperatures. To measure negative temperatures, you would have to swap the ADC inputs, now (-) to LM34 output and (+) to point "A". Some ADCs such as the ADC0832 take a command from the microprocessor to do that swap of the differential inputs, and some ADCs actually produce a twos complement output when the (+) input goes below the (-) input.
Sooo indeed, I checked my formula for 6 sets of values and if Degrees F = (ADCout + A) x M . My A is 36.7 and M is 1.55
I reviewed my circuit and realized that I bought a 4.7Kohm instead of a 3.9Kohm resistor in series with a 10K one to create R1. That seems to be my obvious mistake.
Now that I know it and can "appropriately" get the voltage and associated temperature per ADC bit ... does it matter that it is 1.55 instead of 1.92?
I don't think I am getting the consequences of it.
Thanks a million to both of you for the incredible level of details of your explanations!
As long as the calculated temperature agrees with the actual measured ones for at least 3 different temperatures (approx -50, 0, and 200 would be good choices), I would not be too concerned about the actual value of the factors.
When I calibrate any kind of instrument I try to take a measurement as close as possible to the top and bottom of the range, and 3 readings in between.
My circuit and calculated temperatures seem to be correct so far.
Thank you very much for all your help.