Doubt about Interrupts.

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

Moderator: Benj

Post Reply
407charles
Posts: 122
Joined: Thu Jun 26, 2014 12:01 pm
Has thanked: 41 times
Been thanked: 19 times
Contact:

Doubt about Interrupts.

Post by 407charles »

It's possible to use a bank of inputs for activating two different interrupts? I'm using an arduino mega in my project, I finally finished my oven automatic controller but I already used the available banks for activating my interrupts. Bank J for the quad encoder, in the port B I'm running the SPI communications and the port K the timer using the I2C clock. Now, some parts of my program are a little long and the scan time is not fast enough when trying to navigate through the program so I need to keep the button pressed a little longer than desire or pressing twice to get them to work. therefore, I decide to try running them through an interrupt, the problem is that in the port K I'm using two pins for the timer I just select K0 and K1 for this task but all the other pins are not use. I try to use this other pins in a different interrupt but only works in the simulator bot not in the real hardware. It's possible to use the same bank for two different interrupts??? Do you guys have an example of an interrupt fpr buttons? I may be doing something wrong? Any help is greatly appreciated. Thanks a lot for your help and support.

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: Doubt about Interrupts.

Post by Benj »

Hello,
It's possible to use the same bank for two different interrupts??
Yes but maybe not in the way you are thinking. You can use a single interrupt and then in software you choose what to do based on the pins that have changed.

In your interrupt macro you could have a couple of icons to do this, note OldPort is a global variable so it's value is retained between interrupts, port can simply be a local variable.

Here I am independently checking for a change on Port pins 0-3 and 4-7.

Code: Select all

Input Icon -> Port to Variable port

Decision ( port != OldPort )
{
  Decision ( (port & 0x0F) != (OldPort & 0x0F) )
  {
    Call Macro Lower Nibble Interrupt
  }
  Decision ( (port & 0xF0) != (OldPort & 0xF0) )
  {
    Call Macro Upper Nibble Interrupt
  }
  Calculation ( OldPort = port )
}

407charles
Posts: 122
Joined: Thu Jun 26, 2014 12:01 pm
Has thanked: 41 times
Been thanked: 19 times
Contact:

Re: Doubt about Interrupts.

Post by 407charles »

Thanks a lot for your reply Benj. How do I set this up? You said to use the interrupt macro but do I have to choose custom "interrupt on" and place the code there? because in order for the interrupt to work when this pins are used this is the way needed, right? Or are you talking about placing the code in the macro program that the interrupt will execute? could you please explain? I'm really intrigue about how to make it work and try it. I will really appreciate that if you can. Thanks a lot for your help and support. Thank you!

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: Doubt about Interrupts.

Post by Benj »

Hello,

Setup the interrupt as normal enabling all the pins you want to trigger the interrupt. i.e. not a custom interrupt.

Then inside the interrupt macro add the code I suggested to determine which pins caused the interrupt and therefore which macro to jump to or which code to execute.

407charles
Posts: 122
Joined: Thu Jun 26, 2014 12:01 pm
Has thanked: 41 times
Been thanked: 19 times
Contact:

Re: Doubt about Interrupts.

Post by 407charles »

Thanks a lot for your help. I will try it today.

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: Doubt about Interrupts.

Post by Benj »

I've recently created a new page here detailing more about interrupts.

http://www.matrixtsl.com/wikiv7/index.p ... Interrupts

In the Interrupt on change section the example to count multiple pulses might help.

407charles
Posts: 122
Joined: Thu Jun 26, 2014 12:01 pm
Has thanked: 41 times
Been thanked: 19 times
Contact:

Re: Doubt about Interrupts.

Post by 407charles »

Hi thanks a lot for the valuable information. I got another question regarding interrupts; When I set the pins to enable the interrupt in the bottom left corner of the chip lay out there is three different color boxes: trigger on rising edge (red), trigger on falling edge (gray) and triggered on both edges. There is possible to select this? the question is because I'm running a timer using a I2C clock 1Hz pin, this square wave is my reference time base signal and also enables the interrupt but the thing is that my screen is sometimes adding dots and lines in the seconds digits when the timer updates to a new value and I believe is because the interrupt is being execute more than one time (I may be wrong) during the 1 second signal. I think that trigger in the rising edge will be more accurate because even when the signal is longer than the macro scan time it wont run it more than once since is looking for the low to high transition and not the high value on the input, do I'm correct? Please let me know if is possible.

Post Reply