Hi Freaks,
I am using a M48 and gcc with AVRStudio and internal clock. I have an NTC thermistor from Sparkfun (spec. is attached). I have written this simple ADC code:
#include#include #include int main (void) { DDRB = 0xFF; ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0) | (1 << ADATE); // Set ADC prescaler to 128 - 125KHz sample rate @ 16MHz ADMUX |= (1 << REFS0); // Set ADC reference to AVCC ADMUX |= (1 << ADLAR); // Left adjust ADC result to allow easy 8 bit reading // No MUX values needed to be changed to use ADC0 ADCSRA |= (1 << ADEN); // Enable ADC ADCSRA |= (1 << ADIE); // Enable ADC Interrupt sei(); // Enable Global Interrupts ADCSRA |= (1 << ADSC); // Start A2D Conversions for(;;) // Loop Forever { } } ISR(ADC_vect) { if(ADCH < 180) //temperature is > 65 deg C { PORTB = 0x01; // Turn on LED2 } else // LED normally off for room temperature { PORTB = 0x00; // Turn off LED2 } }
I am using the ADC channel 0 (PC0) in interrupt mode according to the tutorial. In the ISR, I am checking if the ADC value is less than 180(which translates to 65 deg C). I have calculated this value based on the NTC spec. and the temperature sensing tutorial by Guillem.(see attached Excel spreadsheet)
Also attached is a schematic. Basically, I am using a potential divider topology with ratiometric reference for my ADC.
Here is how I tried it: I put a heated soldering gun near my NTC and hoped to see the LED glow on PB0 but I did not see anything. I have already checked the NTC with a multimeter and the soldering gun and it works just fine. (resistance decreases with temp. increase)
I also tried to turn on LED in the else part of the ISR to check if the ISR was firing or not and I did NOT see the LED glow. This probably indicates that the ISR is not firing.
Why would that be? Is there something I am missing in ADC initialization?
Appreciate any help.