I've made a controller board of my own for a school project based on an ATMEGA2560-16AU mcu, and I'm working on programming it with AVR. I want to use PWM for motor control and external interrupts to read encoder pulses and positioning sensors. I've followed this tutorial and the datasheet to write the code below for testing and have setup a similar stand, with two led's connected but I use an induction sensor instead of a button (same effect really, I also tested with a button). A weird problem occurs though, namely that when I set either one of the led's (in this case PA0) to blink at 1.5 seconds intervals in the main loop and the other to toggle only when an external interrupt triggers, whenever I try to toggle PA1 with the sensor only PA0 toggles from the main loop somehow. I have no idea why this happens.
Any help is much appreciated.
EDIT 1: I've updated the code a bit.
#define F_CPU 16000000UL #include <avr/io.h> #include <avr/interrupt.h> #include <util/delay.h> int main(void) { DDRE &= ~((1 << DDE4) | (1 << DDE5) | (1 << DDE6) | (1 << DDE7)); PORTE &= ~((1 << PE4) | (1 << PE5) | (1 << PE6) | (1 << PE7)); DDRA |= (1 << DDA0); DDRA |= (1 << DDA1); //SETUP EXTERNAL INTERRUPTS cli(); EICRB |= (1 << ISC40); EIMSK |= (1 << INT4); sei(); while (1) { PORTA ^= (1 << PA0); _delay_ms(1500); } return(0); } ISR(INT4_vect){ if ((PINE & (1 << PINE4))) { PORTA |= (1 << PA1); } else { PORTA &= ~(1 << PA1); } } 