Home
Prox / RFID
Verichips
Ladder Logic
[interfacing] †
Tube Joints
Key Code From Photo
SolveSpace (3d CAD)
SketchFlat (2d CAD)
Photographs
Miscellany
Resume / Consulting
Contact Me

LDmicro Forum - Microcontroller temp sensor interfacing

(you are viewing a thread; or go back to list of threads)

Microcontroller temp sensor interfacing (by Matthew)
I'm using a PIC16F886 microcontroller and my ADC is set to 10 bits and am using 0-5v. I'm using a LM34 temp sensor which has a 10mv/degree F calibration. All power is connected to a +5volt regulator.

My problem that I have is when I want to increase or decrease the 'set' temperature by half of a degree, the temperature inside my wooden box always goes up by ONE degree no matter what.

I recently read somewhere on the net if I decrease the voltage range from 0-5v to say 0-3v I would then be able to have my half degree steps. The way I would do that is by using a pot going to the '+vref' pin on my chip. I did this and it now changes by half degree increments.

So now my question is, instead of adjusting the voltage, could I just use and op-amp in the middle of my temp sensor and micro controller? I'm trying to figure out how the op-amp would solve this problem.
Mon Nov 15 2010, 22:38:11
(no subject) (by Jonathan Westhues)
With a 10 bit A/D, and a 5 V reference, a single least significant bit corresponds to (5 V)/1023 ~ 5 mV. So in theory, you have barely enough resolution to resolve a half-degree change. In practice, other specifications of the A/D, like the INL, DNL, and noise, limit the useful resolution. You can improve the noise performance by averaging multiple readings, but you can't improve the static errors. (Although, you can actually improve the resolution to something better than 10 bits by averaging in the presence of noise.)

With a 3 V reference, a single LSb corresponds to roughly 3 mV. That's not really much better, but perhaps it's enough to make the difference in your system, between almost working and barely working.

In theory, you can always improve the A/D resolution by decreasing the voltage reference. (For example, with an 0.1 V reference, in theory, you could resolve a ~0.1 mV change.) In practice, this isn't true; the effective number of bits drops as the A/D reference voltage decreases. The datasheet will often specify this degradation, or at least specify a minimum voltage for Vref.

Instead, you can scale up your input voltage, to make best use of your available dynamic range. The LM34 is rated to work from -50 to +300 degrees F, which is a span of 350 degrees. So best case, you could achieve a resolution of 350/1023 = 0.34 degrees F. That's not much better than what you already have.

But, if you're interested in only a smaller temperature range, then you can do better. For example, if you're interested only in temperatures between 0 and 100 degrees F, then the output voltage of the LM34 goes from 0 V to 1.00 V. So to scale that to your A/D's 0 V to 5 V range, you want a gain of 5 V/V. You can get that with the textbook non-inverting opamp circuit, with gain (1 + Rf/Ri) = 5; for example, Rf = 40k and Ri = 10k.

If you're interested in temperatures between 50 and 150 degrees F, then things are a bit more complicated. You want to both scale and shift the voltage now. So your input voltage goes from 0.5 V to 1.5 V, and your desired output still goes from 0 V to 5 V. So the transfer characteristic of the amplifier should be Vout = (Vin - 0.5 V)*5, or Vout = (Vin - 0.625 V)*5 + 0.625 V.

So we want to amplify the voltage symmetrically about a voltage of 0.625 V (i.e., we want Vout = Vin when Vin = 0.625 V), instead of symmetrically about ground as before. So we'd like to replace the ground connection (the other end of Ri) on our non-inverting opamp with a connection to Vref = 0.625 V.

If we don't happen to have such a reference voltage, then we can replace that resistor with its Thevenin equivalent circuit. Assuming that we have a 5 V rail available, we might, for example, choose a 5k resistor to ground, and a 35k resistor to +5V. That generates the correct voltage of (5 V)*(5k/(35k + 5k)) = 0.625 V, but it has the wrong equivalent resistance, of 5k in parallel with 35k, or 4.375k. So we need to scale everything by 10k/4.365k, for 11.4k and 80k.

So the result is the attached circuit. Note that both the inputs and outputs get very close to the supply voltage, if you're running from a +5V single supply; so rail to rail in/out opamps, like the MCP601, are a good idea.

Of course, the accuracy of your circuit will be much less than 10 bits. For example, your voltage reference, if it's just the output of some regulator, is probably good to ~1 % at best. Your resistors are probably 5% or 1%, and there's some approximation when you translate the calculated Rx to a standard value. The opamp has input offset voltage typically around 1 mV. Better components are available (0.1% references and resistors, for example), but less common.

In any case, the sensor itself is accurate only to +/- 1.5 degrees F over its range. So if this kind of accuracy is required, then the LM34 is probably not appropriate in the first place.
Mon Nov 15 2010, 23:48:34, download attachment scale-shift-opamp.png
(no subject) (by Mukesh )
Is there any way to use Vref- & Vref+ pins to alter analog input reference voltage by using move instruction in LD micro. Please check if this program will change the reference voltage of analog input.
Thanks & Regards
Tue Apr 10 2018, 13:14:41, download attachment analogrefvoltage.ld
Post a reply to this comment:
Your Name:
Your Email:
Subject:
(no HTML tags; use plain text, and hit Enter for a line break)
Attached file (if you want, 5 MB max):