habibparacha
Junior Member level 2
I am trying to use multiple channels of ADC using interrupts but whenever the I run the simulation in proteus it gives the error.
Only the first conversion is written to the ADCL register and the next conversion is not written to it. It gives the error .
Below is my code and the picture of error I get
Kindly Help,
Only the first conversion is written to the ADCL register and the next conversion is not written to it. It gives the error .
Below is my code and the picture of error I get
Kindly Help,
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 #include <avr/io.h> #include <inttypes.h> #include <avr/interrupt.h> #include <util/delay.h> #include <avr/sleep.h> #define NUMCHANNELS 2 volatile uint8_t CurrentCh; volatile uint8_t Channel; ISR(ADC_vect) { PORTD= ADCL; Channel++; CurrentCh = Channel & 0b00000111; if(Channel<NUMCHANNELS) { ADMUX |= CurrentCh; PORTB= 0xff; } else { Channel=0; ADMUX |= CurrentCh; PORTB= 0x00; } ADCSRA|= (1<<ADSC); //PORTD= ADCL; //PORTB= 0xff; } int main(void) { DDRC=0x00; //initilize as input DDRB=0xff; DDRD=0xff; PORTB=0X00; PORTD=0X00; Channel = 0; CurrentCh = Channel & 0b00000111; //** Setting Sleep mode idle **// //MCUCR |= (1<<SE); //MCUCR &= !((1 << SM0) | (1 << SM1) | (1 << SM2)); ADMUX|=(1<<REFS0); //ADMUX |= (1 << MUX0) | (1<<MUX1);//| (1 << MUX2) | (1 << MUX3) ); ADMUX |= CurrentCh; //Prescaler = 64, free running mode = off, interrupts off. ADCSRA |= (1 << ADPS2) | (1 << ADPS1); //ADCSRA |= (1 << ADIF); //Reset any pending ADC interrupts ADCSRA |= (1 << ADEN) | (1 << ADIE); //Enable the ADC sei(); ADCSRA|= (1<<ADSC); //ADCSRA|=(1<<ADIF); //sei(); while(1) {SLEEP_MODE_IDLE; } }
Last edited by a moderator: