Explanation in detail of Port B Interrupts.

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Explanation in detail of Port B Interrupts.

Post by daveb0360 »

Hi,
Can anyone please provide an explanation of how port B interrupts are used.
For example, if port B is set as interrupt port, does this encompass all bits of the port or can 2 bits of port be used as interrupts and others used normally?

Sorry if this sounds dumb but I really am new to this programming world and am hampered in my design at the moment by routines being delayed in loops and not responding to buttons etc. I need a way to react to triggers at any point of program execution to implement an emergency stop routine etc.

Thanks in advance.

dave

User avatar
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: Explanation in detail of Port B Interrupts.

Post by Benj »

Hi Dave,

It really depends on the device.

Early PICs used the PORT interrupt for the top half of port b.

Some devices use the entire port b register.

Others allow for single/multiple ports and may have maskable pins.

For devices without maskable pins you can mask in software by retaining a copy of what the register looked like last time an interrupt was fired.

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Re: Explanation in detail of Port B Interrupts.

Post by daveb0360 »

Hi again Ben,
I will use 16F876 or 913,
I am lost by your explanation re: "mask in software by retaining a copy of what the register looked like last time an interrupt was fired"; can you point to any examples on the forum as I can't find anything that makes sense to me.

Cheers
Dave

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: Explanation in detail of Port B Interrupts.

Post by fotios »

Hi Dave
May i reply instead Ben? Moreover Ben is my mentor on this issue. The PORT B interrupt (or IOC = Interrupt On Change state according to Microchip) is available from RB.4 - RB.7 regarding your micros P16F876 and 913. In new generation PICs, like P16F887, it is available on all pins of PORT B, from RB.0 up to RB.7. When you enable the PORT interrupt in FlowCode, by default is applicable on all pins of PORT B. You can exclude some pins from this interrupt by masking them. But this can been done only by using a C code icon. For example, if you want to apply interrupt only in RB.6 and RB.7 pins you have to put a "C code" icon exactly after the "Enable PORT B" icon and to write this command:
iocb = 0b11000000;
In this way, b7 and b6 pins of Port B are masked and used as interrupt sources, while all other pins are excluded and can be used for other tasks. Please don't forget to delete everything is written inside the "C code" icon when you open it for first time, to place the command in the first line and the ";" at the end of command.
Regards
Fotis
Attachments
iocb.jpg
iocb.jpg (105.58 KiB) Viewed 6583 times
Last edited by fotios on Thu Aug 11, 2011 11:36 am, edited 1 time in total.
Best Regards FOTIS ANAGNOSTOU

User avatar
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: Explanation in detail of Port B Interrupts.

Post by Benj »

Hi Dave,

Thanks for posting Fotios :D

The 16F876 does not have the iocb register, the 913 does so you can use Fotios' example c code for this.

To mask the port interrupt using software you can do the following in the interrupt macro when a port interrupt is triggered.

//store variable
tempvar = input: portb

//mask off unwanted pins, here we are selecting the top 2 bits of the port
calc: tempvar = tempvar & 0xC0

//check to see if the wanted pins have changed since the last interrupt
decision: tempvar != oldtempvar
yes: masked pin has changed
no: non masked pin has changed

//At the end of the macro store the value for the next iteration
calc: oldtempvar = tempvar

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Re: Explanation in detail of Port B Interrupts.

Post by daveb0360 »

Thanks guys,
I am really starting to understand. As it happens, I only need two interrupts so the 876 will suffice and I have a few in stock to play with.

This is the type of feedback we need (by we, I mean us newbies and code phobics) I am now progressing.....I wondered what 'IOC' meant, saw it used in numerous posts..


Thanks muchly.
Dave

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: Explanation in detail of Port B Interrupts.

Post by fotios »

Hi Dave
Here are two FlowCode examples for helping you. You can run both on simulator. In the first example "DAVE_INT" i have arranged the program according to Ben's instructions. In the second example "DAVE" you can see a different method that i use many times instead interrupts when strange things hapen (mainly stack overflow using PIC16Fxxx micros which have small memory) in program execution using them. Interrupts are not necessary in all cases, you can use sub-loops like this in "DAVE".
First of all, we need a scenario for the actual hardware: The two momentary switches "SENSOR1" and "SENSOR2" represent two external devices, say two limit switches that can activate two relays. The two relays are represented by the two LED "D0" and "D1". Try both examples in simulator to see the difference in operation. "DAVE_INT" works exactly like an interrupt, you have to release the switch to enable again the interrupt. In "DAVE", if the switch is firmly pressed the corresponding output remains ON untill we release the switch.
Good luck.
Fotis
Attachments
DAVE.fcf
(10 KiB) Downloaded 359 times
DAVE_INT.fcf
(9.5 KiB) Downloaded 328 times
Best Regards FOTIS ANAGNOSTOU

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times
Contact:

Re: Explanation in detail of Port B Interrupts.

Post by daveb0360 »

Thanks again for all this assistance. Am busy putting all the differing elements together. A little bewildered at the moment but it's all starting to make sense.



Many Thanks guys

Post Reply