Loading ...
Sorry, an error occurred while loading the content.

Re: [booksbybibin,www.booksbybibin.tk] having problem to read multiple ADC channel

Expand Messages
  • ciuciu
    Nitin, saying that a while(1) loop can be implemented in an ISR is like saying you CAN jump off a building. Of course you can, but would you ? :) ISRs are not
    Message 1 of 3 , Oct 13, 2009
    • 0 Attachment
      Nitin,

      saying that a while(1) loop can be implemented in an ISR is like saying you CAN jump off a building.

      Of course you can, but would you ? :) ISRs are not meant to have while(1) loops in them. If you are in doubt, recheck your references. If still in doubt, try jumping off a building.

      I hope I'm not to harsh in my explanation, and I do beg your apologies if I have offended you.

      Mihai Galos
      PhD, Lyon

      --- In booksbybibin@yahoogroups.com, nitin chaudhary <nitin2162000@...> wrote:
      >
      > Every condition is true. But in 1st condition,if you put endless loop in isr then no other interrupt routine will be called because ISR disables all inrerrupts while executing itself.
      >
      > --- On Sat, 10/10/09, danial_1000 <danial_1000@...> wrote:
      >
      > From: danial_1000 <danial_1000@...>
      > Subject: [booksbybibin,www.booksbybibin.tk] having problem to read multiple ADC channel
      > To: booksbybibin@yahoogroups.com
      > Date: Saturday, 10 October, 2009, 2:06 PM
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >  
      >
      >
      >
      >
      >
      > hello,
      >
      > i making an effort to read multiple ADC channels and make some conditional switching upon these multiple ADC channels readings inside the ISR(ADC_vect) routine.i having some questions related ISR();
      >
      > 1:can i run a while(1)loop inside the ISR()?
      >
      > 2:can i call any function inside the ISR()?
      >
      > 3:can i apply multiple ADC condition?
      >
      > for example,
      >
      > ISR(ADC_vect)
      >
      > {
      >
      > if ((adc_result_ one >=409 && adc_result_one <=830 )&& (adc_result_ two >=409 )
      >
      > {
      >
      > init_timer0( );
      >
      > PORTB|=(1<<PB0) ;
      >
      > }
      >
      > else
      >
      > {
      >
      > TIMSK&=~(1<< TOIE0);// shut down the timer0
      >
      >
      >
      > PORTB&=~(1<< PB0);
      >
      > }
      >
      >
      >
      > my code is origionally here which i m trying to run.but i don,t suceed to do so as i want to do plz help me to find a bug in this code.i will be thankfull to all of my group members.
      >
      > regards
      >
      > dany
      >
      >
      >
      > #include <avr/io.h>
      >
      > #include <avr/pgmspace. h>
      >
      > #include <avr/interrupt. h>
      >
      > #include <util/delay. h>
      >
      > volatile unsigned int ch;
      >
      > volatile int adc_result0= 0;
      >
      > volatile int adc_result1= 0;
      >
      > volatile unsigned int count;
      >
      > void init_timer0( void)
      >
      > {
      >
      > // Prescaler = FCPU/64
      >
      > TCCR0|=(1<<CS01) | (1<<CS00);
      >
      > //Initialize Counter
      >
      > TCNT0=0;
      >
      > //Initialize our varriable
      >
      > count=0;
      >
      > }
      >
      > void adc_init(void)
      >
      > {
      >
      > //select reference voltage
      >
      > ADMUX=0X40;
      >
      > //set prescaller and enable ADC
      >
      > ADCSRA|=(1<< ADEN)|(1< <ADPS2)|( 0<<ADPS1) |(0<<ADPS0) ;
      >
      > }
      >
      > int adc_start_conversio n(unsigned int ch)
      >
      > {
      >
      > //set ADC channel
      >
      > unsigned int channel=ch & 0b00000111;
      >
      > ADMUX=ADMUX| channel;
      >
      > //Start conversion with Interupt
      >
      > ADCSRA |= (1<<ADSC)|(1< <ADIE);
      >
      > return (ADC);
      >
      > }
      >
      > int main(void)
      >
      > {
      >
      >
      >
      >
      >
      > DDRB=0XFF; // OUT PUTS
      >
      > sei();
      >
      > adc_init(); //INITILISE ADC MODULE
      >
      > init_timer0( ); //INITILISE timer0
      >
      > while(1)
      >
      > {
      >
      > adc_result0= adc_start_ conversion( 0); //READ ADC0
      >
      > _delay_ms(20) ; //WAIT FOR 20 MILLISECOND
      >
      >
      >
      > adc_result1= adc_start_ conversion( 1); //READ ADC0
      >
      > _delay_ms(20) ; //WAIT FOR 20 MILLISECOND
      >
      > }
      >
      > return 0;
      >
      > }
      >
      > ISR(ADC_vect)
      >
      > {
      >
      > if((adc_result0 >347 && adc_result0 <409) && (adc_result1 < 833))
      >
      >
      >
      > {
      >
      > PORTB|=(1<<PB0) ;
      >
      > PORTB&=~(1<< PB1);
      >
      > PORTB&=~(1<< PB2);
      >
      > PORTB|=(1<<PB3) ;
      >
      > PORTB&=~(1<< PB4);
      >
      > PORTB|=(1<<PB5) ;
      >
      > }
      >
      > else if((adc_result0 > 409)&&(adc_result1 >613&&adc_result1 <833 ))
      >
      > {
      >
      > PORTB|=(1<<PB0) ;
      >
      > PORTB&=~(1<< PB1);
      >
      > PORTB&=~(1<< PB2);
      >
      > PORTB&=~(1<< PB3);
      >
      > PORTB&=~(1<< PB4);
      >
      > PORTB|=(1<<PB5) ;
      >
      > }
      >
      > else
      >
      > {
      >
      > PORTB=0X00;
      >
      >
      >
      > }
      >
      >
      >
      > }
      >
      >
      >
      > ISR(TIMER0_OVF_ vect)
      >
      > {
      >
      > //This is the interrupt service routine for TIMER0 OVERFLOW Interrupt.
      >
      > //CPU automatically call this when TIMER0 overflows.
      >
      >
      >
      > //Increment our variable
      >
      > count++;
      >
      > if(count==61)
      >
      > {
      >
      > PORTD|=(1<<PD0) ;
      >
      > count=0;
      >
      > }
      >
      > else
      >
      > {
      >
      > PORTD&=~(1<< PD0) ;
      >
      >
      >
      > }
      >
      > }
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      >
      > Connect more, do more and share more with Yahoo! India Mail. Learn more. http://in.overview.mail.yahoo.com/
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.