Portugal
Offline
Newbie
Karma: 0
Posts: 35
|
 |
« on: November 13, 2012, 06:20:31 pm » |
Hey mates! I am experiencing a very strange problem with the LM60 sensor! 1) The formula is simple: Vo = (+6.25 mV/ºC x TºC) + 424 mV. So, for: +125°C +1205 mV +100°C +1049 mV +25°C +580 mV 0°C +424 mV −25°C +268 mV −40°C +174 mV So far so good!  2) The real Vref of my ATmega328 is 1088mV (ok, it was measured with a multimeter and it has error... but for this question it's irrevelante, I think!) 3) Lets assume that I use as Vref 1100, because I don't trust my multimeter. 4) Code: // Print temperature and milivolt on LCD void WriteTemperatureOnLCD(void) { k++; if (k == 50) { Vin=0; temp=0; for(j=0 ; j<=49 ; j++) { samples[j] = (analogRead(analogtemp)); Vin = Vin + samples[j]; } Vin=Vin/50; lcd.setCursor(9, 0); lcd.print(Vin, 1); lcd.print("mV"); } if (k == 100) { temp = ( ((Vin/1024.00) * 1100.00) / 6.250) + minimum; //minimum = (-424.0/6.25)
if ( (temp >=0) & (temp <10) ) { ................. etc.....
4) The sensor as a very big error.... I know that!!! But when the ADC reads (right or wrong) 424mV ... Which temperature reading shoud I get? In my oppinion: 0ºC In my code oppinion: -4ºC And in your oppinion? To conclude, in my oppinion, if the ADC reads 424mV... whatever the error the sensor and/or Vref has, the temperature should follow the formula and point to 0ºC !! Or not? Regards and thanks 
|
|
|
|
« Last Edit: November 13, 2012, 06:25:38 pm by KenshinPT »
|
Logged
|
|
|
|
|
0
Offline
Tesla Member
Karma: 71
Posts: 6596
Arduino rocks
|
 |
« Reply #1 on: November 13, 2012, 06:27:13 pm » |
We need to see all the code - for instance is Vin declared as "int" or "unsigned int" or "long" or what?
And how is this wired up? long cables? Power source?
Have you checked the accuracy specification for the sensor?
Have you calibrated analogRead() with a known voltage?
|
|
|
|
|
Logged
|
|
|
|
|
Portugal
Offline
Newbie
Karma: 0
Posts: 35
|
 |
« Reply #2 on: November 13, 2012, 06:59:19 pm » |
We need to see all the code - for instance is Vin declared as "int" or "unsigned int" or "long" or what?
const int analogtemp=6; // This is the analog pin which is measuring the input voltage from the LM60 temperature sensor double temp=0, Vin=0, samples[50]; double minimum = (-424.0/6.25);
And how is this wired up? long cables? Power source?
It's wired correctly, regular cables and USB powered. Have you checked the accuracy specification for the sensor?
The accuracy here is irrelevant... If I measure a wrong value but if the ADC says it's 424mV the temperature in the LCD (after formula calculation) should be 0ºC, right? And it's not! It's -4ºC. Have you calibrated analogRead() with a known voltage?
I used the internal reference without any calibration. My multimeter says that Vref is 1088mV, instead of 1100mV. Yah, I know the sensor has error but for this issue is irrelevant, I think  The error in the sensor is for this example: The real temperature is 0ºC, but the ADC is measuring 580mV, then the LCD shows 25ºC. Regards and thanks
|
|
|
|
« Last Edit: November 13, 2012, 07:11:15 pm by KenshinPT »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 2
|
 |
« Reply #3 on: November 14, 2012, 02:28:45 am » |
@Kennshin
The measured -4°C should be correct. Reason: The reference voltage for the AD converter has been defined by yourself with 1100mV. According to the datasheet of the sensor, the voltage which will be provided by the sensor at +125°C will be 1205mV (1205mV > VRef). The maximum voltage which will be converted by the ADC is 1100mV. In case you will set 1205mV on the ADC pin, I would expect that there will be an overflow in the µC. Due to that the reference voltage has not been adapted to the max sensor voltage, you will get a lower temparetaure as expected. Also the behaviour U=f(T) of the sensor is not linear according the reference points you mentioned from the datasheet.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 2
|
 |
« Reply #4 on: November 14, 2012, 02:36:29 am » |
@Kennshin Forget my last sentence. I saw that the formular is also mentioned in the datasheet.
|
|
|
|
|
Logged
|
|
|
|
|
Portugal
Offline
Newbie
Karma: 0
Posts: 35
|
 |
« Reply #5 on: November 14, 2012, 05:35:29 am » |
@Kennshin
The measured -4°C should be correct. Reason: The reference voltage for the AD converter has been defined by yourself with 1100mV. According to the datasheet of the sensor, the voltage which will be provided by the sensor at +125°C will be 1205mV (1205mV > VRef). The maximum voltage which will be converted by the ADC is 1100mV. In case you will set 1205mV on the ADC pin, I would expect that there will be an overflow in the µC. Due to that the reference voltage has not been adapted to the max sensor voltage, you will get a lower temparetaure as expected. Also the behaviour U=f(T) of the sensor is not linear according the reference points you mentioned from the datasheet.
I agree with you, I am using Vref = 1100mV but the real value is 1088 (assuming my multimeter is correct). But, to explain the real problem, imagine this: Forget the LM60. I use my stable power supply, and adjust the ouput voltage with the help of my multimeter to 424mV. Then I apply that voltage to the analog input. The real voltage is 424mV. The ADC has error (because of Vref) and measures 400mV. So far so good. But, then I use the formula to convert from voltage do temperature: temp = ( ((Vin/1024.00) * 1100.00) / 6.250) + minimum; What I read on the LCD: temp = 0ºC. Is this right? Or not? What's wrong with the formula?!
|
|
|
|
« Last Edit: November 14, 2012, 06:09:04 am by KenshinPT »
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 114
Posts: 2205
|
 |
« Reply #6 on: November 14, 2012, 07:36:35 am » |
Not sure what points you are trying to make but Vo = (+6.25 mV/ºC x TºC) + 424 mV. That equation can be rewritten so the calculation is done automatically from adc readings, rather than voltage reading, making your life easier. I can help you if you want.
|
|
|
|
|
Logged
|
|
|
|
|
Portugal
Offline
Newbie
Karma: 0
Posts: 35
|
 |
« Reply #7 on: November 14, 2012, 10:59:19 am » |
Not sure what points you are trying to make but Vo = (+6.25 mV/ºC x TºC) + 424 mV. That equation can be rewritten so the calculation is done automatically from adc readings, rather than voltage reading, making your life easier. I can help you if you want. Thanks  After reading a bit more... the first thing I should do is compensate the ADC. I am using the internal reference from the ATmega328 -> 1100mV (in theory) In practice, the measure reference is very stable and it's 1088mV. So my question now is: How can I compensate the ADC reading below? samples[j] = (analogRead(analogtemp)); The ADC is 10bit resolution and in theory Vref is 1100mV -> So each interval is 1100mV/1024 (or 1100mV/1023????) In practice the Vref is 1088mV. So again, my question is: How can I compensate the ADC reading? Thank you so much 
|
|
|
|
« Last Edit: November 14, 2012, 11:01:25 am by KenshinPT »
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 114
Posts: 2205
|
 |
« Reply #8 on: November 14, 2012, 11:40:32 am » |
That's simple: Vref (1100mv) gets translated to 1023 (10-bit adc).
424mv would be translated into 1023/1100*424=?
An adc reading of X would translate into 1100/1023*X=?
|
|
|
|
|
Logged
|
|
|
|
|
Portugal
Offline
Newbie
Karma: 0
Posts: 35
|
 |
« Reply #9 on: November 14, 2012, 12:05:13 pm » |
That's simple: Vref (1100mv) gets translated to 1023 (10-bit adc).
424mv would be translated into 1023/1100*424=?
An adc reading of X would translate into 1100/1023*X=?
Thanks There are 1024 intervals in a 10 bit ADC, right? So: if V=1100mV -> ADC=1023 and if V= 0.000mV -> ADC=0 Thanks 
|
|
|
|
|
Logged
|
|
|
|
|
Dallas, TX
Offline
Sr. Member
Karma: 8
Posts: 314
|
 |
« Reply #10 on: November 14, 2012, 02:08:11 pm » |
KenshinPT, I believe the problem you are seeing is in your equation. To get the correct answer, you must subtract the offset from your mv reading before you divide it by 6.25. temp = (Vin / 1024.00 * 1100.00 -424.0) / 6.250 ;
|
|
|
|
|
Logged
|
|
|
|
|
Dallas, TX
Offline
Sr. Member
Karma: 8
Posts: 314
|
 |
« Reply #11 on: November 14, 2012, 02:22:27 pm » |
That's simple: Vref (1100mv) gets translated to 1023 (10-bit adc).
424mv would be translated into 1023/1100*424=?
An adc reading of X would translate into 1100/1023*X=?
Thanks There are 1024 intervals in a 10 bit ADC, right? So: if V=1100mV -> ADC=1023 and if V= 0.000mV -> ADC=0 Thanks  For a 10-bit ADC with an 1100 mV reference, the most you can measure without saturating the ADC would be (1100 mV - 1100/1024 mV) = 1098.9 mV. In other words, a reading of 1023 from your ADC equals (1023 * 1100/1024 mV) equals 1098.9 mV. Remember, 10 bits can only represent a value as large as b1111111111 or decimal 1023.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 114
Posts: 2205
|
 |
« Reply #12 on: November 14, 2012, 03:02:46 pm » |
temp = (Vin / 1024.00 * 1100.00 -424.0) / 6.250 ; It is always a good idea to use as little floating point math as possible.
|
|
|
|
|
Logged
|
|
|
|
|
Dallas, TX
Offline
Sr. Member
Karma: 8
Posts: 314
|
 |
« Reply #13 on: November 14, 2012, 03:25:40 pm » |
temp = (Vin / 1024.00 * 1100.00 -424.0) / 6.250 ; It is always a good idea to use as little floating point math as possible. Absolutely! That way when you get the equation wrong, you'll hardly notice! :-P
|
|
|
|
|
Logged
|
|
|
|
|
Portugal
Offline
Newbie
Karma: 0
Posts: 35
|
 |
« Reply #14 on: November 14, 2012, 04:43:02 pm » |
temp = (Vin / 1024.00 * 1100.00 -424.0) / 6.250 ; It is always a good idea to use as little floating point math as possible. Absolutely! That way when you get the equation wrong, you'll hardly notice! :-P Hmm ^^! I think both formulas are right! temp = ( ((Vin/1024.00) * 1100.00) / 6.250) + minimum; //minimum = (-424.0/6.25) Let's say: " (Vin/1024.00) * 1100.00 " = Voltage Then: temp = Voltage/6.25 - (424/6.25) Or temp = (Voltage-424)/6.25 So, I don't think there's a problem in the formula ^^! Or it is?! lol
|
|
|
|
|
Logged
|
|
|
|
|
|