Using pin change interrupts on ATmega325
Posted: Thu Mar 20, 2014 1:10 pm
I have a simple program flowchart. It consists of a main loop in which a basic switch turns an LED on and off. I have inserted a pin change interrupt on PORT E, pins 2, 3, and 4 which correspond to PCINT0, PCINT1, and PCINT2. What I am trying to do is implement an interrupt that is triggered whenever these pins toggle. The interrupt routine is supposed to turn off another LED-not the one in the main loop- if any of the pins has a logic 0 on them. I read these three pins and place their values into varibles L4_ok, L2not_ok, and SW_FLT respectively. Then I put them through a decision block and if any one of the pins is low I turn off the LED, otherwise the LED either turns on or stays on.
For some reason the LED is only responding to the switch on pin 2 PCINT0. I stepped through the DEBUG and watched the values of the three variables, L4_ok, L2not_ok and SW_FLT. The behavior of the switches is not what I expected. I assumed, maybe incorrectly, that if I toggle the basic switch to high it will change to a "1" and if a toggle it low it will change to a value "0". The only time this happens is when I toggle pin 2, PCINT0, or L4_ok. If I toggle pin 3 or pin 4, the switch does not change or if it does change, it does so for one step and then the next step it reverts back to its previous state.
I have uploaded the file for inspection. Any help with this would be greatly appreciated.
For some reason the LED is only responding to the switch on pin 2 PCINT0. I stepped through the DEBUG and watched the values of the three variables, L4_ok, L2not_ok and SW_FLT. The behavior of the switches is not what I expected. I assumed, maybe incorrectly, that if I toggle the basic switch to high it will change to a "1" and if a toggle it low it will change to a value "0". The only time this happens is when I toggle pin 2, PCINT0, or L4_ok. If I toggle pin 3 or pin 4, the switch does not change or if it does change, it does so for one step and then the next step it reverts back to its previous state.
I have uploaded the file for inspection. Any help with this would be greatly appreciated.