Return from an interrupt

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Alberta2012
Flowcode v5 User
Posts: 63
Joined: Fri Apr 19, 2013 2:18 am
Has thanked: 10 times
Been thanked: 14 times
Contact:

Return from an interrupt

Post by Alberta2012 »

Hi Everyone,

It is my understanding that when an interrupt occurs, the program will stop where it was, execute a macro related to the interrupt, then return from where it came from.

In my case, for a timer interrupt, that's fine.

If I have an input interrupt, I want to "forget" where I was, execute the macro associated with my interruption, then go to a specific place within my program... How can that be done ?

Jasmin

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Return from an interrupt

Post by kersing »

You have to return from an interrupt. Only after return a new interrupt can occur.

The are two ways to solve this:
- do not use interrupts for the input but 'poll' the input by reading the input value within your code regularly.
- in the interrupt routine set a global variable. In the main code check if that variable is set, call the appropriate routine and 'jump' to the place you want to go with connection points.

Just remember to always return from macro's to the main program before jumping or you will overflow the stack. (Each macro call is added to the stack, jumps do not 'clear' the stack)

General rules of thumb:
- keep interrupt routines short.
- try not to call other macros in an interrupt routine to prevent unintentional delays and stack overflows.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: Return from an interrupt

Post by Kenrix2 »

In flowcode v4.5 it looks like you should be able to specify the location but it won't compile, you get a general error.

According to the boostc manual this should work:
put this into supplementary code (anything is just a made up macro name and 0x100 is the location).

void FCM_ANYTHING()@0x100;

Maybe someone with flowcodev5 could try it out and see if it works. I think flowcodeV5 uses a different boostc version.

Strange that it does compile with the following, but that won't help you much.

void FCM_ANYTHING()@0x100
{
}

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: Return from an interrupt

Post by Benj »

Hello,

Best bet is to set a variable with a value in the interrupt and then process this variable in the main program loop. If the variable is clear then continue on with what your doing, If the variable is set then stop what you are doing and process the flag.

If this is not good enough then maybe doing a power on reset would help. I think Microchip use this with their bootloader. Basically when you power on the device the POR bit in the status register is clear. If you set this bit and then software reset the device by calling the reset function I think then the bit will still be set and you can check at the start of your program to see if this is a power reset or a interrupt reset.

Post Reply