PINCHANGE PROBLEM

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

Hi everybody,

I'm using an ARDUINO ATMEGA2560 board, and  I'm trying to debug my code using the led connected to PB7. The idea is that every time that the button connected to PK0 is pushed, a pin change interruption is generated and the led is toggled. 

 

but this is not happening right now, using the debugger, I can see that every time that I press the button, the ISR is accessed twice, one for turn it on and another one to tunr it off,

If I let the button pushed, the led remains on.

and that is my question...WHY????

I suppose that I'm generating two interruptions, once when I push and the second then I release??? is that correct?, Is there any way to toggle on falling edge?? 

 

Thanks all of you for the help!!

void test_setup_interrupts(){
    PCMSK2 |= (1<<PCINT16);			// SOLO PCINT16 (PORTK0)
    PCICR |= (1 << PCIE2);   		// PIN CHANGE INTERRUPTS ENABLE PCINT23:16
    sei();
}	

void test_setup_PORTS(){																	

    DDRB	= 0b11111111;		//PORT B direction as OUTPUT
    PORTB	= 0b00000000;		//PORT B low state.	

    DDRK	= 0b00000000;		//PORT k direction as INPUT	PORTK0 ENTRADA DE BOTON
    PORTK	= 0b00000000;		//PORT k low state.
};

ISR(PCINT2_vect){
                LED=PORTB;
                switch(LED){
                    case 0b10000000:
                        PORTB	= 0b00000000;	// APAGO led PIN B7
                    break;

                    case 0b00000000:
                        PORTB	= 0b10000000;	// prendo led PIN B7
                    break;

                }

}

int main(void)
{
    est_setup_PORTS();
    test_setup_interrupts();

    while(1) {}
}

 

Last Edited: Sat. Jun 10, 2017 - 02:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Pin change interrupts always fire on both edges. If you are only interested in one edge, just ignore the other one.
.
Yes, it is slightly wasteful compared to INTx interrupts that you can configure to fire in different modes.
OTOH, you can process 8 pins with a single pin change ISR()
.
David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You should learn something about chattering.
If the EICRA register is not operated, the interrupt continues to be generated continuously while pressing the switch.

 

To David
Interrupt conditions can be selected with the EICRA register.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kabasan, what are you talking about? EICRA is for external interrupts not pin change interrupts so is of no relevance here.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You should learn something about chattering.
If the EICRA register is not operated, the interrupt continues to be generated continuously while pressing the switch.

 

 

 

 

________

vital