Capacitance or software delay?

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm wondering why when I push the botton the light stays on on my output for about .5~.75 seconds before it goes off, is this due to software delay(i.e.) the processor scanning still?

Here is my code:

#include       

int main(void) 
{ 
     DDRB = 0b00000001;   //Sets Port Bit 0 as output

     ADCSRA |= (1 << ADPS2) | (1 << ADPS1);      //ADC Prescalar set to 64 - 125kHz@8MHz 

     ADMUX |= (1 << REFS2) | (1 << REFS1);      //Sets ref. voltage to 2.56v internal reference 
     ADMUX |= (1 << ADLAR);       // Left adjust ADC result to allow easy 8 bit reading 
     ADMUX |= (1 << MUX1);   	//Selects channel ADC2 (PB4) = binary 0010

     ADCSRA |= (1 << ADEN);  // Enable ADC 

  while (1) //loop while 1
  { 
  ADCSRA |= (1 <<ADSC);	//Starts ADC conversion for single ended mode
  while (ADCSRA & (1 << ADSC) );	// 
 if(ADCH < 128)		//If ADCH >  (64x10mv = 1.28v) then Port Bit 0 and 2 are on.
      { 
         PORTB |= (1 << 0); // Turn on Port Bit 0 
      } 

      else 
      {  
        PORTB &= ~(1 << 0); // Turn off Port Bit 0
     } 
  } 
} 

//Notes: 2.56v/256 = 10mV resolution in 8-Bit mode
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you don't have a pulldown or pullup resistor on the ADC input, the capacitance will most likely give the results you describe. You could print out the ADC values and you'll see the voltage decay.