Shop OBEX P1 Docs P2 Docs Learn Events
ADC0831 - LM34 - Low Temperatures — Parallax Forums

ADC0831 - LM34 - Low Temperatures

french_markfrench_mark Posts: 6
edited 2010-12-29 14:54 in Accessories
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]

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-12-26 13:42
    You need a negative supply to read negative temperatures or a circuit that will replicate that. An option is the <edit> TMP36.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2010-12-26 14:17
    What temperature are you expecting in your freezer? It should probably be closer to zero Fahrenheit (-17 Celsius). The circuit as you have it should be able to go lower than the 19.6 that you are seeing, at least down to 2 or 3 degrees Fahrenheit. You probably have the sensor mounted on a cable, right? These sensors are subject to oscillations when mounted on a cable and that usually appears as an offset. Put a 3kΩ resistor and a 1µF capacitor in series at the sensor output (see the LM34 data sheet).
    [FONT=Courier New]            3k
    TF output----/\/\/\------o-------- ADC input
                          [/FONT][FONT=Courier New]   |     
                          ====== 1µF
                             |
                           Vss[/FONT]
    
    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.
  • kwinnkwinn Posts: 8,697
    edited 2010-12-26 14:28
    As Franklin says, you need a negative supply to measure the negative temperatures. You also need to be aware that the output from the LM34 goes from -500mV at -50F to +3,000mV at +300F while the ADC0831 is expecting an input of 0 - 5V with a 5V reference. For proper operation and maximum accuracy the simplest solution would be to shift and amplify the output voltage from the LM34 with an op amp. For your range an op amp gain of 2 would give maximum resolution.
  • french_markfrench_mark Posts: 6
    edited 2010-12-26 19:40
    First of all, thank you all for replies.

    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!
  • kwinnkwinn Posts: 8,697
    edited 2010-12-27 11:59
    If you want the simplest solution you may want to look at the LM75. It provides an I2C protocol digital output. As far as I know it is only in Celsius though. Easy enough to convert to Farenheit with a micro. If you want to continue with the LM34 the attached diagram should get you started. The LM34 will output approximately +200mV at -50F, and + 2700mV at +200F.
    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.
  • french_markfrench_mark Posts: 6
    edited 2010-12-27 12:34
    Thanks for your reply and the great level of details!
    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!
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2010-12-27 13:24
    Kwinn beat me to it, but I was going to suggest something similar. The diode lifts the GND terminal of the LM34 about 0.6 V above Vss, but that is very approximate. It would be better either 1) if that were a definite reference of say 0.5 V, or, 2) if your ADC had a second channel or a more capable differential input that would allow you to measure or offset the voltage across the diode (for example, the ADC0802 or the 12-bit LT1298).

    LM34_ADC.png


    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.
    758 x 415 - 19K
  • kwinnkwinn Posts: 8,697
    edited 2010-12-28 08:19
    Tracy is correct about the 1n914 diode drop being somewhat of an approximation. The diode and R1 should be mounted on the PCB with the rest of the circuitry, not on the end of the cable with the sensor for maximum accuracy. You should also do a one point calibration by immersing the probe (suitably waterproofed) in a glass of water and ice. That reading will be the required correction for 0C or 32F.

    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
  • french_markfrench_mark Posts: 6
    edited 2010-12-28 18:30
    Thanks again for your replies.

    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.
  • kwinnkwinn Posts: 8,697
    edited 2010-12-28 18:48
    Two points will not tell you if the response is non linear or not. You need at least 3 points. You also need to have 2 correction factors to convert the binary value from the ADC to degrees F. First you need to subtract any offset, and then you need to multiply that by a constant to convert the ADC reading to degrees F.
  • kwinnkwinn Posts: 8,697
    edited 2010-12-28 21:03
    I have updated the diagram with some additional information. You will also need to convert the reading from the ADC0831 using the following formula:

    Degrees F = (ADCout + A) x M where A is approx -36 and M is approx 1.96.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2010-12-28 22:53
    If you already have a DS1620, and limited time to get it working, it is not a bad option. It does take 5 fine wires for power and the three signal lines. The DS1620 does work at negative temperatures (rated -67 to +257 degrees F).

    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.
  • french_markfrench_mark Posts: 6
    edited 2010-12-28 23:05
    Hi again,

    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!
  • kwinnkwinn Posts: 8,697
    edited 2010-12-29 06:20
    I have attached the diagram from page 2 of the National LM34 data sheet to show how I came up with the circuit I sent you. As you can see from the formula for R1 the actual value is dependent on the actual forward voltage drop of the 1n914 diode. That may account for the difference between your correction factors and the theoretical ones I sent.

    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.
  • french_markfrench_mark Posts: 6
    edited 2010-12-29 14:54
    Understood. It make sense. I will try to make more tests shortly.
    My circuit and calculated temperatures seem to be correct so far.

    Thank you very much for all your help.
Sign In or Register to comment.