Interrupt issues.

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
robin223
Posts: 9
Joined: Thu Jul 10, 2014 10:41 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Interrupt issues.

Post by robin223 »

Hi there,

I'm having an stange issue with interrupts in flowcode6.
The program I'm writing is for a relay switched volume control with input,
output and trim selector switches. I'd like for the input and output switches to trigger an interrupt,which calls a macro to read the switch values and turn on the correct lamps/relays.
All of the relay/lamp and switch inputs and outputs are attached via the i2c bus, using pcf8574 expander chips.
the INTs pin of the pcf8574 input cards are pulled up to +5v and connected to PORTB inputs 0-3.

The individual parts of this design have been tested and are working, however when I set up a test to flash the input and output lamps when the interrupt is triggered, it repeats the macro 14 times before returning to the main loop.
On the simulation it seems to work just fine.

I'm sure this is my error rather than a bug, but it's got me stumped, If anyone fancies taking a look I'd appreciate it.
file attached

cheers,
Robin.

Program version 6, professional licence
EB006v9 - 16f1937.
5v, external power supply.
Attachments
intproblem.fcfx
(67.67 KiB) Downloaded 207 times
intproblem.c
(72.8 KiB) Downloaded 206 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Interrupt issues.

Post by medelec35 »

Hi Robin,
When you compile, you must take notice of any stack corruption warnings.
With your flowchart:

Code: Select all

Building CASM file
Serious Warning: Possible sw stack corruption, function 'FCM_i2c' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCD_005f1_I2C_Master1__Start' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCD_005f1_I2C_Master1__TransmitByte' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCD_005f1_I2C_Master1__Stop' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'delay_ms' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Corruption occurs if you use the same type of component/delay/calculation within an interrupt as is used outside the interrupt.

Interrupts should be kept to a minimum, so it's executed and exited as fast as possible.
You could use the flag method.
If interrupt is triggered set a flag to 1.
Within main, if flag = 1 then flag = 0: Do something different as interrupt has been triggered.

Martin
Martin

robin223
Posts: 9
Joined: Thu Jul 10, 2014 10:41 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Interrupt issues.

Post by robin223 »

Martin,

How do I set the flag you describe if I'm using the interrupts on portB, can I call a macro and add set it using a calculation within the macro or would I need to write a custom interrupt with this option (not sure how this is done)

If you could show me an example that'd be excellent.

Thanks very much for your help.

robin.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Interrupt issues.

Post by medelec35 »

Hi Robin,
Your welcome.

just place a calculation box within Interrupt macro with something like

Code: Select all

SwitchDetected = 1


Then within main:

Code: Select all

If SwitchDetected = 1: SwitchDetected = 0: Rest of code for switch detection 
After changing flowchart, if still stuck, attach it so I can look at it for you.

Martin
Martin

Post Reply