Experience connecting the temperature sensor LM335 with ATMega16
LM335 datasheet
How to connect
LEFT pin is GND, MIDDLE is Vout, RIGHT is adjust
Datasheet has a 'bottom view' of the pinout that can confuse!
MIDDLE (Vout) is connected to the AVR-ADC pin & is also pulled-up with a resistor
RIGHT (adjust) – it is not necessary to connect this with a POT. We can adjust in software
Referred to the TI datasheet, however the piece we have is from ST. Could find ST datasheet later – pinout was same – also assuming no other difference
Electrical characteristics
the sensor 'acts like a zener diode' but actually has a complex circuitry inside
No matter what is the voltage supplied, as long as valid current supplied, it's output voltage should be fixed - a reflection of the temperature around
valid current to be supplied: 400uA – 5mA. For optimum accuracy, 1 mA
At 25*C, with 1mA current, it should give 2.98v at output pin
Every 10mV change = 1*C change
Overall range of the sensor is -40*C to 100*C
PCB guide
thermal isolation from other elements on pcb
specially high speed switching digital tracks
using 'thermal well'
ADC basics (Paul's book – page 811)
Successive approximation
ATMega16 datasheet
Things to consider:
Single conversion / Differential
Auto trigger
resolution
Prescalar for ADC clock
Interrupt / check direct flag
registers
read ADSL first & then ADSH. If you want <=8-bit precision, 'left-adjust' & read ADSH only
channel select before conversion
voltage reference: Vcc/2.56V internal/Aref (capacitor b/w aref & gnd), discard 1st reading after change
if using interrupt, you may get avr to sleep
Ideal sensor should have low impedance with slowly varying signals: sample and hold capacitor should charge fast & hold the charge for a good enough duration. Lm335's dynamic impedance is 1 ohm
Noise reduction
LC (100nF, 10uH) network b/w Vcc & Avcc [Not tried]
analog paths away from high speed digital switching paths
adc noise canceler function [Not tried]
don't use same port pins for other functions (e.g. Output high/low)
Accuracy errors
offset error: 1st transition late
gain error: last transition
integral non-linearity(can happen in any reading): may require conitnuous monitoring / exception catching tool
differential non-lienarity(can happen in any reading): transition happens at lesser/higher than 1 lsb change
quantization error – rounding off
absolute accuracy - sum of all above
>> Understand how to calculate ADC output for a given Aref and precision
>> Understand LM335 beahviour over a given range of temperature it handles / the range you need. And then, based on that, figure out what is the best precision / Aref is for you.
Practical observations
Experience of trying lm335 for the first time: with multimeter.
Without adjustment pot.
Vcc = 5v (actual ~4.8v), 2.2K resistor. Current should be ~2.1 mA. Vout ~ 4.521v ~ 180*C (doesn't make sense).
Vcc = 3.3v (actual ~3.2v), 2.2K resistor. Current should be ~1.4 mA. Vout ~ 2.92 v ~ 20*C
Lot of variations in multimeter readings.
With 10k pot, Vout changes from 2.92v-->2.94v~21*C. Not much change.
This got fixed when the sensor was connected 'opposite' to datasheet.
Flat surface facing you, right pin is GND. Once right pin was grounded, a relatively steady 3.091v appeared in multimeter with Vcc = 5v (actual ~4.8v), 2.2K resistor i.e, ~2.1mA current. Same reading with 1K resistor i.e., ~4.7mA current. This is as it should be i.e., sensor gives same (correct) reading as long as it is supplied valid current (between 400uA and 5mA).
Actually, the datasheet has the 'bottom view' of the pinout! Confirmation in arduino forum.
Other Articles referred: instructables, simple-circuit
Not necessary to calibrate the sensor using hardware. No need to connect a POT. Leave the ADJ pin open. Can be calibrated via software if needed.
Connected sensor with avr (which already has a 7-segment attached to it). Wires instead of jumpers.
AREF = AVCC ~4.7v.
With computer USB 5v (actual 4.7v), caibration of -3*C seems to be needed.
With outside power of 5v (actual 4.7v), no calibration seems to be needed.
Code reference: electronicwings
Choosing the right precision
ADC = ( Vin*2^precision ) / Vref
With Vref~5v,
With 10 bit precision, 1 bit change will happen with 4.65 mV
With 8-bit precision, 1 bit change will happen with 18.6 mV
With 9-bit precision, 1 bit change will happen with 9.3 mV (this is closest to the sensor's 10mV change to represent 1*C change)
Observations
Temperature reading on display is changing very frequently – not steady, varying between 29-35*C easily. When breadboard is at an angle, reading goes to 40*C!?
Put decoupling capacitor between AREF and GND – tried 100nF. Value slightly stable but not much – still easily varying 4-5*C.
>confusion due to problem with display_tempertuare function in showing 3-digit numbers.
Once corrected, checked all intermediate values from ADC etc. All seem fine. Problem may be about the sensor being too sensitive.
Next day: value relatively stable. Moves within 1 degree. Added +5 adjustment.
Changed AREF->GND decoupling capacitor to 10nF.
https://www.avrfreaks.net/forum/capacitor-aref-atmega328
Value keeps moving within 1 degree. Later, 4-5 degree variation.
When touched with hand, increases then comes back. So sensor is recognizing warmth created by touching.
Software is reading temperature every 1s.
https://www.avrfreaks.net/forum/lm335-and-adc
>On one of the 7-segments, 4 segments stopped working (very low light at the time of boot, nothing afterwards). Changed wires, 7-segment, breadboard location – all in vain. Finally worked when AVR port changed from C to B. Why? Exact root cause not known.
Given 5v (actual 4.9/4.8/4.7) to AREF directly. Removed 10nF capcitor.
In software, Vcc should be the actual measured value at AREF pin correct to 3 decimal places.
In this configuration, final reading seems “relatively” accurate and stable. No adjustment required.
Problem remains even after taking all above measures
Reading varies in a wider range (4-5*C) & more frequently than we expect.
Also, varies greatly if voltage source is changed e.g. Computer usb via programmer Or wall socket-->programmer Or Wall wart via regulator.
Stabilize the power supply especially Vref as much as possible. Then hardcode the measured stable value in software. You may then expect accurate and stable temperature value without adjustment.
Next steps
Take average of last X readings & only display average.
Try 2 things from datasheet noise cancellation section:
LC b/w Vcc & Avcc
ADC noise canceller function
Look at how to stabilize power (entire system power and not just AVCC/AREF) to 3rd decimal place. Can look into this along with the entire power management / battery study.
Develop a system that is accurate to 1mV & is stable.
Study other people's experience. How anyone uses a bare sensor that is so sensitive?
Read: https://control.com/forums/threads/adc-way-too-sensitive.11719/#post-92339
Capacitors to stabilize power / reduce noise? What else?
Can system read it's voltage at Aref pin dynamically? Instead of us hardcoding a number inside the adc formula?
Ignore 1mV change in software? That would mean 304.1 & 304.9 will be read as 304.
Increase the time interval – we may not need every second change. Every 10-15 seconds? May not impact the voltage fluctuation. Hence, may not be use in this particular issue.
No comments:
Post a Comment