Page 1 of 1

Using pin change interrupts on ATmega325

Posted: Thu Mar 20, 2014 1:10 pm
by jlschuck
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.

Re: Using pin change interrupts on ATmega325

Posted: Sun Mar 23, 2014 4:34 pm
by Jan Lichtenbelt
Dear jlschuck

The flowcode attached and your description of your problem are not enough to give you any advise.
It is strongly advised to attach the complete Flowcode.

Kind regards,

Jan Lichtenbelt

Re: Using pin change interrupts on ATmega325

Posted: Mon Mar 24, 2014 1:18 pm
by jlschuck
Thank you for catching my mistake. The complete flowcode file is now uploaded.

Re: Using pin change interrupts on ATmega325

Posted: Mon Mar 31, 2014 2:40 pm
by jlschuck
I found the problem on my own. Just in case someone encounters the same problem, I am posting the solution. I had all three variables assigned to one pin. So basic_switch2 and basic_switch4 were assigned to the same variable as basic_switch1. Now it works as expected.

Re: Using pin change interrupts on ATmega325

Posted: Tue Apr 01, 2014 2:52 pm
by Benj
Thanks for letting us know how you fixed it and glad it's working correctly for you now :D