Problem with ntc thermistor and Aref

Status
Not open for further replies.

mshh

Full Member level 6
Joined
May 30, 2010
Messages
349
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
usa
Activity points
3,871
I have problem when i read from ntc thermistor, lcd display -273 C on lcd (proteus) when i connect Aref to ground and program ADC REF to internal cap. but if i connect it to 5v and program its refernce to vcc it works fine. what is the problem?
 

Hi,

* What ADC?
* What schematic?
* What code?

Klaus
 

the code to read temperature
HTML:
/*****************************************************

Chip type               : ATmega8
Program type            : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 256
*****************************************************/
#include <mega8.h>
 #include <delay.h>
 #include <stdlib.h>   
  #include <stdio.h>     
  #include <math.h>     
 #include <delay.h>
// Alphanumeric LCD functions
#include <alcd.h>

// Voltage Reference: Int., cap. on AREF
#define ADC_VREF_TYPE ((1<<REFS1) | (1<<REFS0) | (0<<ADLAR))

// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | ADC_VREF_TYPE;
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=(1<<ADSC);
// Wait for the AD conversion to complete
while ((ADCSRA & (1<<ADIF))==0);
ADCSRA|=(1<<ADIF);
return ADCW;
}

float delta,adc;
char str[16]; //allocate on lcd  
float Tref=23;
 int Vo;
float R1 = 10000;
float logR2, R2, T;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;

void main(void)
{

// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out 
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 
PORTB=0x00;
DDRB=0xFF;
// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTC=0x00;
DDRC=0x00;
// Port D initialization// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out 
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 
PORTD=0x00;
DDRD=0xFF;

// ADC initialization
// ADC Clock frequency: 1000.000 kHz
// ADC Voltage Reference: AREF pin
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x83;
// Alphanumeric LCD initialization// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:// RS - PORTD Bit 0// RD - PORTD Bit 1// EN - PORTD Bit 2
// D4 - PORTD Bit 4// D5 - PORTD Bit 5// D6 - PORTD Bit 6// D7 - PORTD Bit 7// Characters/line: 16
  lcd_init(16); 
      lcd_clear(); 

while (1)
{
    delay_ms(100);

     Vo = read_adc(0); 
     
    lcd_gotoxy(0,1);
    lcd_putsf("T=");
    lcd_gotoxy(2,1);   
    R2 = R1 * (1023.0 / (float)Vo - 1.0);
    logR2 = log(R2);
    T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2)); // temp in kelvin
    T = T - 273.15;
   // adc = (T * 9.0)/ 5.0 + 32.0; c to fehrenhit  
    
    ftoa(T, 0x02, str);
    lcd_puts(str);
    lcd_gotoxy(7,1);
    lcd_putchar(0xdf);    // degree 
    lcd_putsf("C");       
    lcd_gotoxy(1,0);
    lcd_putsf("Hello");     
    delta=(adc-Tref);
    if  ( adc >=Tref && delta>=0.3)//  
    {
    PORTB.1=0;  //turn heater off
    }
                      

    else if (adc <=Tref && delta<=-0.3)//   
    {    

    PORTB.1=1 ; //turn heater on
    }         
  }

    }
when Aref is connected internally it displays
 

Attachments

  • Untitled.jpg
    81.3 KB · Views: 168

Hi,

did you try to debug it on your own?

--> ouptut read_Adc(0) --> to the display instead of temp

if OK then
--> ouptut VO --> to the display

if OK then
--> ouptut R2 --> to the display

and so on....

Tell us the results..

Klaus
 

yes i tried. i tried to display Vo but it displays 1023 and it doesn't change.
 

Hi,

--> Then measure the voltage at VRef pin with a voltmeter.

Klaus
 

the voltage on Aref pin is zero
 

Hi,

this is the problem.
Either it´s grounded outside or it´s not properly set up.

Klaus
 

i tested the same setup with lm35 and it works. please notice that it didn't work on simulation, i still didn't try it on practical setup
 

Hi,

What´s the expected ARef voltage?
What´s the expected ADC0 input voltage?
What´s the expected ADConversion result?

Klaus
 

the expected Aref is 2.5v
the expected ADC0 input voltage is the value of the voltage divider
the expected ADC conversion is different values from 0 to 1023 related to 0 to 5v
 

Hi,
the expected ADC0 input voltage is the value of the voltage divider
What value?

the expected ADC conversion is different values from 0 to 1023 related to 0 to 5v
What value?

Klaus
 

Vcc is 5 v so the input value to ADC0 should be from 0 to 5v according to the temperature of thermistor
the expected ADC conversion is different values from 0 to 1023 related to 0 to 5v
for example 5 v should give 1023, 2.5v should give 512 and so on
 

Hi,

Vcc is 5 v so the input value to ADC0 should be from 0 to 5v according to the temperature of thermistor
You have a simulation tool --> simply use a voltmeter and measure the voltage.

the expected ADC conversion is different values from 0 to 1023 related to 0 to 5v
No.
ADC_Vref is to what the ADC references (thus the name).
--> read the datasheet.
Thus 0...1023 (1024) is the range from 0V to ADC_VRef.

for example 5 v should give 1023, 2.5v should give 512 and so on
5V is a bad example, because it will give 1023 in any case, independent of VRef.

Klaus
 

Hi,

Thus 0...1023 (1024) is the range from 0V to ADC_VRef.
5V is a bad example, because it will give 1023 in any case, independent of VRef.

Klaus

thanks , i got it i think that the ref voltage was the problem. i changed the voltage on the thermistor to 2.5 (which is the Aref voltage ) and it works
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…