Wednesday, March 5, 2014

Gyrations with Temperature Sensors

Gyrations in this context means "going 'round and 'round.

or 

"Oh what a tangled web we weave, when we learn."


I tried using a thermistor for sensing the air temperature exiting the space heater. As mentioned before, it was salvaged from a color laserjet printer. 

Later I tried an RTD, which stands for Resistance Thermal Detector. This is the familiar 100 ohm
platinum RTD I have worked with for years in the plants. 

OK, what do these have in common? Yes they are active components that are used to measure temperature. What else?

They have a sensing element attached to some wires, so the measurement point (location) can
be at some distance from the display, and the electronics driving it.

They have a response curve that is more-or-less linear, in other words they respond to a given
change in temperature with the same amount of change in their electrical characteristics.

And they have a Temperature Coefficient

NTC (Negative Temperature Coefficient)

                                  In the case of the thermistor, this number has a negative sign.
                                  As the temperature increases, the resistance decreases.

PTC (Positive Temperature Coefficient)

                                 With the RTD, the number has a positive sign. 
                                 As the temperature decreases, the resistance increases..

Sensors are also designed to measure in certain ranges, and the extension wiring/insulation/protective covering ("da wirez")  is usually designed with that in  mind. For example if you want to measure 700 degrees C, you don't want your sensor or the wiring burning up. It must be protected somehow.

These sensors have ranges of other environmental factors too: Exposure to humidity, chemicals, radiation have to be considered. For lower temperature applications, such as a space heater, designed for use in a home or office environment, we don't usually think about chemicals or radiation.  

Finally the further your measurement has to travel, whether using wires or not, the harder it is to make it work right.

Thermistor


My basic challenge with using the thermistor for measuring temperature was to make the ADC output stable enough to use for measuring and control. 

The ADC  (Analog to Digital Converter) on the Arduino can theoretically read many thousands of times per second. You may know that ADCs  are used to convert analog audio to digital audio.  In order to get decent resolution (it still sounds good) an audio ADC would need a MINIMUM sampling rate twice the highest frequency you want to digitize. So (for the young pups anyway) 20,000 Hz x 2 or 40KHz sampling rate

I timed a loop() in some Arduino code and discovered that the loop execution time was about 50 milliseconds! With one analogRead() in the loop(), I was sampling the voltage from the thermistor at about 20 times per second, or 20 Hz--given as the lowest frequency audible to human ears. Also far faster than it could be read from the Serial Monitor, a 9600 baud.

The ADC converts whatever voltage that happens to be on the pin, mixed in with your theoretical voltage signal.  In a perfect world, that signal would be as stable as the excitation voltage applied, and only the change would be in response to changes in the temperature being measured.

I tried Vcc first, supplied through the USB cable from my desktop computer. I did some reading and learned that this Vcc is not well regulated. If you have some circuit connected to, and powered from your Arduino, and it needs more current, your Arduino's Vcc is going to drop under load. 

The USB controller as implemented in personal computers is supposed to supply up to 1500 mA 
There are almost always more than one controller in a desktop PC, and they may be different...USB 10., USB 2.0, or even USB 3.0.

While the higher numbers indicate faster data transmission speeds, it comes at a price...sensitivity to interference. The faster versions rely a lot on cabling and connectors being up to the job too. So many variables. I advise finding out what's under YOUR hood.

Another consideration is that the convenient front USB ports are connected internally to jacks on the back side of the motherboard, near where the rear USB ports are located on the back of the box. And the wires travel through a potentially extremely noisy electrical environment. If you have faster ports they are most likely going to be on the back.

I have a bench power supply made from an old ATX computer power supply. They are relatively inexpensive, easy to set up, and can supply some respectable current at several different voltage levels. 

My friend Gus reminded me that the regulation of these supply lines is not really comparable to a "lab grade" bench power supply. The power supply voltages are fed into a computer motherboard where they undergo extensive "additional regulation" before powering the electronics.  

So it seems that powering my breadboard with +5V or +3.3 Volts MIGHT be substituting relatively poorly regulated voltages to my circuits, even if it does take some load off the Arduino's power supply circuitry.

Someone suggested using a powered USB hub to supply the current needs of the Arduino's USB port, to avoid "brownouts" when uploading/reflashing the microcontroller, which I have done.

(provide attribution)

You could say that this exercise in design forces you to consider a lot of variables. I think we get spoiled consuming mass-produced stuff...which is designed to be as no-brainer as possible. How did they manage  that? By hammering out all sorts of questions like these. Hats off!

I tried using the analogReference() function in the sketch's setup() to compare the thermistor readings to the internal 2.5 Volt reference on the Arduino.   

(code) analogReference(INTERNAL2V5); (code)

That seemed to help, but the voltage still changed far faster than the thermistor itself could possibly be changing temperature!  This made a lot of "noise" being added to my temperature signal, feeding into the heater-controlling portions of the sketch. 

Shielding I thought, and jacketed the extension leads of the thermistor with braided copper sheathing, grounded to the 0 volt rail of the breadboard, which is supplied from the Vcc (+5V) on the Arduino

Maybe that helped a little, but I don't have any hard numbers to prove it. And in the course of pursuing temperature control, it MIGHT have been "cooked" a little. Being a salvaged part, I have very little environmental or other data on it. 

RTD


I gave the thermistor a break and tried connecting the Pt-100 RTD sensor to the Arduino. With the ADC being done over a range of volts (0-5 on the Arduino) you must have a device which either puts out its own DC voltage signal or you use something like a resistive voltage divider circuit. 

That has the virtue of being basic, easy to understand, easy to construct. The disadvantage is loss of resolution.  The voltage across whatever current limiting resistor (so you don't exceed current limitations on the pin you connect it to) will not change, and it takes a big bite out of the available voltage range applied to the input pin.

With the 100 ohm platinum RTD, you need at least 400 ohms or so in series to make the circuit draw less than about 9 mA (milliAmps).  Why am I worried about that? The reason is that my Arduino must supply that current, and the greater the current load, the more my Vcc will "droop".

I did actually get the RTD version of temperature control working. The analog voltage coming from the RTD was rather small, as the change of resistance of the RTD itself is relatively small...

For instance at 0C  (32 F) it has a resistance of 100 ohms. At 100 C (212 F) depending on what Standard was used to generate the table you look at, the resistance rises to somewhere close to 138.5 Ohms using  5 volts.

In my circuit that translates to a voltage input range of 1.00V to 2.909 V fed to  my ADC input pin

So I've lost 2 volts of my 0-5 volt ADC conversion range. In my setup I was seeing about a 4 degree C change for each integer change in the ACD's output ( a range of 0-1023). And then I cut that in half again using the internal 2.5V reference voltage

If you can't even see a change of 1 degree C, you find it difficult to control to within +/- 1 degree (which would be nice).

No, "further research" shows that some signal-conditioning circuitry for the RTD will increase its resolution dramatically. It took very little digging to find some useful Application Notes on this very subject, as many of the electronic component manufacturers want to make it easier for you to use the stuff they sell you.

Fortunately one of the first I found was a very good one, from Microchip


This will be the model for the circuit I intend to assemble.

First step is to provide a PRECISION excitation current for the RTD (and the thermistor too, come to think of it!) that is low enough to avoid "heating" my resistance based sensor, or at least keep it to a stable (and quantified) minimum.

I have a wonderful collection of DIP chips, again many thanks to my friend Gus. There  I just happened to find some LM358N  (single-supply dual Op Amp) 8 pin DIP chips. Googling for datasheets, I learned this one is designed specifically for embedded applications with a single voltage supply (many op amps require two, a plus rail and a minus rail).

All right, a precision current source is easy enough using op amps (circuit). This will insure the voltage dropped across the RTD is not influenced by uncontrolled variation in the current going through it.
And as mentioned avoid resistance heating of the sensor.

The document linked above sets the excitation current at 1 mA, which has the added benefit of taking current load off the Arduino. Oh, okay the precision current source needs power...if we take it from the Arduino, it's certainly less than the 8 or 9 mA my current setup uses.

Then we need a voltage gain amplifier to change this 1 - 2.99 Volt range to 0 - 5 Volts, which is  the FULL RANGE of input to our ADC. Again, Op Amps to the rescue.  And wouldn't it be nice to put some kind of low-pass filter in there, so we don't see fast changes?  

Why Reinvent The Wheel?

I've worked with RTDs in an industrial setting, where all of these circuits were "built in" to both the systems and the calibration tools  used to maintain them. It made for a modular approach, which I highly recommend when you design and build anything. Building blocks that once mastered can be re used.

While I understood something about the level of complexity involved in these devices, I took them for granted. Now I want to really understand the nuts and bolts of this stuff! Wiser heads have advised me that it's easy to get sidetracked with theory, pleasantly lost in the details, (and learning a LOT) when for "a few pennies more" you could just "git 'er done".  

I took a break from my approach, mainly because of the unexpected time and effort it took me to get this far. 

I see that many retail sources, like  SparkFun  will sell you temperature sensors well suited for embedded applications..


Temperature Sensor - Waterproof (DS18B20)
SEN-11050


If you're asking why I send you off to SparkFun to look,  here's why: it's local for me and they
stock & sell some very tempting geek toys.

As an alternative, maybe Grainger would have items, that while more targeted to industrial
customers, would appeal to hobbyists.  I'm going to check on that and I invite you to do the same.

Disclaimer:      No ads here folks, that's the way I like it.
                      I get nothing from SparkFun that I didn't pay for.
                      (But if that changes I'll let you know)

I can't describe the feelings I had when I looked at these product descriptions...elated that they are so inexpensive, available and potentially useful. I have to admit, I needed a moment alone.  They are now "on order"...

And I became a bit frustrated at all the "gyrations" I've been through chasing down this data and trying to use it. I sat down initially thinking "I have all this in my head! Let's go!" but the exercise of translating that stuff "in my head" to a working model teaches me just how much I know and how well I understand it. I'm still catching up with myself!   

This is a very good example of the complexity that is to be found when you look "under the hood". It makes sense (to me) to be aware of it at the very least.

Able to use it? Wonderful. Able to  keep it "working good and lasting a long time"? Better still. Able to design your own solutions? That's where I want to go...
















No comments:

Post a Comment