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.
Using pin change interrupts on ATmega325
Moderator: Benj
-
- Flowcode v5 User
- Posts: 12
- Joined: Tue Apr 30, 2013 5:40 pm
- Has thanked: 7 times
- Been thanked: 1 time
Using pin change interrupts on ATmega325
- Attachments
-
- GW325.fcfx
- complete flowcode file this time
- (12.07 KiB) Downloaded 231 times
Last edited by jlschuck on Mon Mar 31, 2014 2:35 pm, edited 2 times in total.
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: Using pin change interrupts on ATmega325
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
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
-
- Flowcode v5 User
- Posts: 12
- Joined: Tue Apr 30, 2013 5:40 pm
- Has thanked: 7 times
- Been thanked: 1 time
Re: Using pin change interrupts on ATmega325
Thank you for catching my mistake. The complete flowcode file is now uploaded.
- Attachments
-
- GW325.fcfx
- pin change interrupts on ATmega325
- (12.07 KiB) Downloaded 207 times
-
- Flowcode v5 User
- Posts: 12
- Joined: Tue Apr 30, 2013 5:40 pm
- Has thanked: 7 times
- Been thanked: 1 time
Re: Using pin change interrupts on ATmega325
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.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Using pin change interrupts on ATmega325
Thanks for letting us know how you fixed it and glad it's working correctly for you now 

Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel