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

help needed

Expand Messages
  • danial_1000
    hi, i m working on a project where i does switching upon multiple adc readings.the problem is when i vary the the pot and enter that region where i want to
    Message 1 of 8 , Oct 21, 2009
    • 0 Attachment
      hi,
      i m working on a project where i does switching upon multiple adc readings.the problem is when i vary the the pot and enter that region where i want to switch the controller outputs starts dancing (blinking) means there is no solid switching as '1' or '0' and its also increasing the voltages on the output pins linearly as i varying the pot and approaching that region.plz help me.
      regards
      dany
      /*************my code is here*************/
      #include <avr/io.h>
      #include <util/delay. h>
      #define F_CPU 8000000ul
      volatile unsigned int ch;
      volatile int adc_result0= 0;
      volatile int adc_result1= 0;
      void adc_init(void)
      {
      //select reference voltage
      ADMUX=0X40;
      //set prescaller and enable ADC
      ADCSRA|=(1<< ADEN)|(1< <ADPS2)|( 0<<ADPS1) ;//prescaller is/64
      }
      int adc_start_conversion(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(); //inite globle interrupt
      adc_init(); //INITILISE ADC MODULE
      while(1)
      {
      adc_result0= adc_start_ conversion( 0); //READ ADC0
      _delay_ms(30) ; //WAIT FOR 30 MILLISECOND

      adc_result1= adc_start_ conversion( 1); //READ ADC0
      _delay_ms(30) ; //WAIT FOR 30 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;

      }

      }
    Your message has been successfully submitted and would be delivered to recipients shortly.