Hello,
I want to read the switch/pin state and have a counter going cyclic 0, 1, 2, 3.
Encoder is connected to PortD pins 2,3 and the pushbutton to PortD pin 4, each component activating its own IOC interrupt.
The sketch “Switch IOC_FC9.fcfx” works fine in simulation as well in reality.
The sketch “Switch and Encoder IOC_FC9.fcfx” does not work properly: the encoder reading is fine, but the pushbutton does not work, neither in simulation nor in reality. Flowcode gives an error and shuts down when I put Breaking point in “IOC_PB” subroutine where “PB_Val = PB_Val + 1” calculation takes place.
What mistake have I done and how may I correct the error?
Switch and IOC Error
-
- Posts: 18
- http://meble-kuchenne.info.pl
- Joined: Mon Jun 27, 2022 2:56 pm
- Has thanked: 5 times
- Been thanked: 1 time
Switch and IOC Error
- Attachments
-
- Switch and Encoder IOC_FC9.fcfx
- (20.78 KiB) Downloaded 483 times
-
- Switch IOC_FC9.fcfx
- (14.73 KiB) Downloaded 566 times
-
- Posts: 18
- Joined: Mon Jun 27, 2022 2:56 pm
- Has thanked: 5 times
- Been thanked: 1 time
Re: Switch and IOC Error
I have tested with 2D panel and also with 3d panel, the same working code from previous post above.
And I got a a fatal error in 2D simulation, Flowcode shuts down.
In reality the code works, also the one with 2D panel.
And I got a a fatal error in 2D simulation, Flowcode shuts down.
In reality the code works, also the one with 2D panel.
- Attachments
-
- Switch IOC_FC9_3D.fcfx
- (14.73 KiB) Downloaded 517 times
-
- Switch IOC_FC9_2D.fcfx
- (14.72 KiB) Downloaded 533 times
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 503 times
- Been thanked: 686 times
Re: Switch and IOC Error
Hello,
I'm afraid you cannot enable the same interrupt twice pointing to two different macros, even selecting different pins the second macro will never get called.
I have tweaked your program to hopefully make it run better on the embedded device and simulate without crashing.
I'm afraid you cannot enable the same interrupt twice pointing to two different macros, even selecting different pins the second macro will never get called.
I have tweaked your program to hopefully make it run better on the embedded device and simulate without crashing.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Posts: 18
- Joined: Mon Jun 27, 2022 2:56 pm
- Has thanked: 5 times
- Been thanked: 1 time
Re: Switch and IOC Error
Thank you for the info with 1 single interrupt at a time and for the corrected code.
Indeed it works now in simulation as well with real hardware.
Could please explain a bit why was necessary to use PB_Old ?
Why the PB_State is changing its value all the time?
I was expecting that PB_State to be always “0” as the pushbutton is active low.
Is it because the interrupt on change on PortD is active on rising edge as well on falling edge? And then we enter in interrupt subroutine on both edges? And the pushbutton is seen/read one time as “0” and next time as “1”?
And what is with the fatal error from 2D panel above?
Indeed it works now in simulation as well with real hardware.
Could please explain a bit why was necessary to use PB_Old ?
Why the PB_State is changing its value all the time?
I was expecting that PB_State to be always “0” as the pushbutton is active low.
Is it because the interrupt on change on PortD is active on rising edge as well on falling edge? And then we enter in interrupt subroutine on both edges? And the pushbutton is seen/read one time as “0” and next time as “1”?
And what is with the fatal error from 2D panel above?
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 503 times
- Been thanked: 686 times
Re: Switch and IOC Error
Hello,
I beleive the fatal error was due to two interrupt macros bening assigned to the same interrupt. As soon as I removed this it went away. Maybe something we need to check for in the app.
The old switch value is used so that we only action the switch once when it's in the active state. otherwise if the switch is in the active state and then the encoder changes state the switch would get actioned multiple times. For the switch to fire again it has to go into the none active state and back again. Hope this makes sense.
I beleive the fatal error was due to two interrupt macros bening assigned to the same interrupt. As soon as I removed this it went away. Maybe something we need to check for in the app.
The old switch value is used so that we only action the switch once when it's in the active state. otherwise if the switch is in the active state and then the encoder changes state the switch would get actioned multiple times. For the switch to fire again it has to go into the none active state and back again. Hope this makes sense.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Posts: 18
- Joined: Mon Jun 27, 2022 2:56 pm
- Has thanked: 5 times
- Been thanked: 1 time
Re: Switch and IOC Error
Thank you for the clarrification about switch old value.
The 2D panel code works fine in simulation, if there is not breakpoint and if I am not too fast by clicking the pushbutton or too fast after simulation just starts.
But if I am too fast or if I assign a breakpoint in the interrupt subroutine at the PB_Val calculation, then Flowcode goes into fatal error and it shuts down.
The 2D panel code works fine in simulation, if there is not breakpoint and if I am not too fast by clicking the pushbutton or too fast after simulation just starts.
But if I am too fast or if I assign a breakpoint in the interrupt subroutine at the PB_Val calculation, then Flowcode goes into fatal error and it shuts down.
- Attachments
-
- Switch IOC_FC9_2D.fcfx
- (14.73 KiB) Downloaded 472 times
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 503 times
- Been thanked: 686 times
Re: Switch and IOC Error
Hello,
There shouldn't be a need to disable and re-enable the interrupt inside the IOC macro, can you try disabling these icons and see if that makes a difference. Maybe that is somehow causing the sim to have a problem. Certainly something for us to look into.
I would also recommend changing the switch debounce property from 1ms to 0 as this could be creating problems when reading inside the interrupt.
There shouldn't be a need to disable and re-enable the interrupt inside the IOC macro, can you try disabling these icons and see if that makes a difference. Maybe that is somehow causing the sim to have a problem. Certainly something for us to look into.
I would also recommend changing the switch debounce property from 1ms to 0 as this could be creating problems when reading inside the interrupt.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel