+ Post New Thread
Results 1 to 15 of 15
  1. #1
    Full Member level 5
    Points: 2,933, Level: 12
    Achievements:
    7 years registered

    Join Date
    May 2010
    Location
    usa
    Posts
    313
    Helped
    0 / 0
    Points
    2,933
    Level
    12

    Problem with ntc thermistor and Aref

    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?

  2. #2
    Super Moderator
    Points: 75,476, Level: 67
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,299
    Helped
    3485 / 3485
    Points
    75,476
    Level
    67

    Re: Problem with ntc thermistor and Aref

    Hi,

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

    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



    •   AltAdvertisement

        
       

  3. #3
    Full Member level 5
    Points: 2,933, Level: 12
    Achievements:
    7 years registered

    Join Date
    May 2010
    Location
    usa
    Posts
    313
    Helped
    0 / 0
    Points
    2,933
    Level
    12

    Re: Problem with ntc thermistor and Aref

    the code to read temperature
    HTML Code:
    /*****************************************************
    
    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&#91;16&#93;; //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



  4. #4
    Super Moderator
    Points: 75,476, Level: 67
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,299
    Helped
    3485 / 3485
    Points
    75,476
    Level
    67

    Re: Problem with ntc thermistor and Aref

    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
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  5. #5
    Full Member level 5
    Points: 2,933, Level: 12
    Achievements:
    7 years registered

    Join Date
    May 2010
    Location
    usa
    Posts
    313
    Helped
    0 / 0
    Points
    2,933
    Level
    12

    Re: Problem with ntc thermistor and Aref

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



  6. #6
    Super Moderator
    Points: 75,476, Level: 67
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,299
    Helped
    3485 / 3485
    Points
    75,476
    Level
    67

    Re: Problem with ntc thermistor and Aref

    Hi,

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

    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



    •   AltAdvertisement

        
       

  7. #7
    Full Member level 5
    Points: 2,933, Level: 12
    Achievements:
    7 years registered

    Join Date
    May 2010
    Location
    usa
    Posts
    313
    Helped
    0 / 0
    Points
    2,933
    Level
    12

    Re: Problem with ntc thermistor and Aref

    the voltage on Aref pin is zero



    •   AltAdvertisement

        
       

  8. #8
    Super Moderator
    Points: 75,476, Level: 67
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,299
    Helped
    3485 / 3485
    Points
    75,476
    Level
    67

    Re: Problem with ntc thermistor and Aref

    Hi,

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

    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  9. #9
    Full Member level 5
    Points: 2,933, Level: 12
    Achievements:
    7 years registered

    Join Date
    May 2010
    Location
    usa
    Posts
    313
    Helped
    0 / 0
    Points
    2,933
    Level
    12

    Re: Problem with ntc thermistor and Aref

    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



  10. #10
    Super Moderator
    Points: 75,476, Level: 67
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,299
    Helped
    3485 / 3485
    Points
    75,476
    Level
    67

    Re: Problem with ntc thermistor and Aref

    Hi,

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

    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  11. #11
    Full Member level 5
    Points: 2,933, Level: 12
    Achievements:
    7 years registered

    Join Date
    May 2010
    Location
    usa
    Posts
    313
    Helped
    0 / 0
    Points
    2,933
    Level
    12

    Re: Problem with ntc thermistor and Aref

    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



  12. #12
    Super Moderator
    Points: 75,476, Level: 67
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,299
    Helped
    3485 / 3485
    Points
    75,476
    Level
    67

    Re: Problem with ntc thermistor and Aref

    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
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  13. #13
    Full Member level 5
    Points: 2,933, Level: 12
    Achievements:
    7 years registered

    Join Date
    May 2010
    Location
    usa
    Posts
    313
    Helped
    0 / 0
    Points
    2,933
    Level
    12

    Re: Problem with ntc thermistor and Aref

    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



    •   AltAdvertisement

        
       

  14. #14
    Super Moderator
    Points: 75,476, Level: 67
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,299
    Helped
    3485 / 3485
    Points
    75,476
    Level
    67

    Re: Problem with ntc thermistor and Aref

    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
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  15. #15
    Full Member level 5
    Points: 2,933, Level: 12
    Achievements:
    7 years registered

    Join Date
    May 2010
    Location
    usa
    Posts
    313
    Helped
    0 / 0
    Points
    2,933
    Level
    12

    Re: Problem with ntc thermistor and Aref

    Quote Originally Posted by KlausST View Post
    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



--[[ ]]--