Page 1 of 1

Interrupt On Change ( IOC ) identifying by reading Flag

Posted: Sun Jun 12, 2022 10:00 pm
by miggarc
Hi

On this example from you (original) about IOC,

InterruptOnChange_Pulse_Counter.fcfx
(15.3 KiB) Downloaded 50 times

the interrupt macro is identifying on which pin the interrupt occurred by testing which portB bit changed.

1.jpg
1.jpg (37.91 KiB) Viewed 1614 times

Can't we do the same simply by reading the correspondents IOC Flags :
IOCBF7 , IOCBF6 , IOCBF5 , IOCBF4


By the way, if I want to do that, how do I read those flags in flowcode.
(if this implies C code portion, please give me an example of it).

Re: Interrupt On Change ( IOC ) identifying by reading Flag

Posted: Mon Jun 13, 2022 8:12 am
by medelec35
Hello.
Attached is one way you can do it by reading the interrupt flags.
I have changed the interrupt properties to set the flags for rising edge only.
Note that more than one switch press detection could occur due to contact bounce.
That can easily by fixed if required.

Re: Interrupt On Change ( IOC ) identifying by reading Flag

Posted: Mon Jun 13, 2022 1:51 pm
by miggarc
Hi

A meda some changes but it doesn't work.

Can you please take a look ?

InterruptOnChange_Pulse_Counter v2_a.fcfx
(16.68 KiB) Downloaded 54 times

Re: Interrupt On Change ( IOC ) identifying by reading Flag

Posted: Mon Jun 13, 2022 2:44 pm
by medelec35
Hi.
In what way is not working simulation or hardware or both?
I Should have stated that it will not work with simulation, it will only work on hardware.
Also, with the 16F1937 you can use pins 0 to 7.
You are not restricted to pins 4 to 7, like you are with the more older devices.
Personally, if you want it to work with simulation and hardware then I would use the flowchart you posted in the very first post.
At least then it will work with other target devices.
There is a risk that if you change your target device then the flowchart with the C code might not work as the register names could of changed.

Re: Interrupt On Change ( IOC ) identifying by reading Flag

Posted: Mon Jun 13, 2022 11:22 pm
by miggarc
Hi

Only on FC simulation it wasn't working.
On correspondent hardware it was working correctly .

Is there any other way to identify IOC changed pin by reading its correspondent Flag, that can also be FC simulated ?

Re: Interrupt On Change ( IOC ) identifying by reading Flag

Posted: Tue Jun 14, 2022 8:08 am
by medelec35
Although there is some C code that can be simulated, registers can not.
As I stated in my previous post, Flowcode can simulate by using the first flowchart you posted.
The port will need to be read within the interrupt, then check to see what has been changed.

Re: Interrupt On Change ( IOC ) identifying by reading Flag

Posted: Tue Jun 14, 2022 1:50 pm
by miggarc
Hi