Hey everyone!
I'm having a bit of trouble getting the ADC interrupt to work.
I think the problem may be in the way I handle the interrupt. I'm trying to use:
-Free running mode at 500 kHz (ie: T_clk = 16Khz, so T_clk/32). this is less precise but that is okay.
-ADC 0
When I just print the ADCL register (which holds the converted data), like this, it at least prints:
void loop(){
delay(100);
if (!(ADCSRB & 0x40)){ // ie: anding with 0x40, or 0100-0000, means ADSC (bit 6) is high, meaning conversion is not done. //so, we take the 'not'; if we take the loop, the conversion is done. pp293, 26.8.3
Serial.println(ADCL);
}
}
However, when I use the ISR loop at the bottom of this code (and have nothing in the loop except a delay), the serial monitor prints out just two values, and that is it. Any ideas?
Thanks in advance! Happy to clarify or try things.
// Note: all register definitions found in: // ADC: DOC_2549, section 26
// http://www.atmel.com/Images/doc2549.pdf
void setup(){
ADMUX = 0x80; // 8: 1000, choose 1.1V reference by REFS1=1,REFS0=0 (REFSx=10), left just (ADLAR = 0), Select ADC0 for input (MUXx=0). *!Assume reading ADC 0!*
// also, from 11.9.6, pp 55:
// For analog input pins, the digital input buffer should be disabled at all times
DIDR0 = 0xff; // ie: disable (write to one) to save power
DIDR2 = 0xff; // ie: disable (write to one) to save power
ADCSRA = = 0xed; // e (14): 1110 means "enable ADC (ADEN=1),start ADC(ADSC=1), auto-trigger ADC(ADATE=1), interrupt flag not messed with (ADIF=0)
// d (13): 1101 means "enable ADC interrupt(ADIE=1), then set ADC clock to 1/32 of the input (ADPS=101)
ADCSRB = 0x00; // 0: 0000 means "X (0), for the analog comparator (ACME = 0), for pin selection
// 0: 0000 means "MUX5 for pin selection is zero (MUX5=0), free running (ADTSx = 0)
sei(); //SREG |= 0x80; // 1000-0000 : ie: enable interrupts. See: 7.4.1, pp 14
Serial.begin(9600);
}
ISR(ADC_vect){
Serial.println(ADCL);
sei(); //SREG |= 0x80; // 1000-0000 : ie: enable interrupts. See: 7.4.1, pp 14
}