Main Site Documentation

Interrupting an interrupt FEZ Mini


#1

Hi,
I am writing a machine control program. I am using an interrupt port as the input method to start the machine cycle using a pushbutton. Another interrupt port acts as an ‘E-Stop’ (no this is not safety critical). The pushbutton fires the first interrupt, which runs a method that acts as the machine cycle control (activates some pneumatic cylinders).

Is it possible to interrupt the machine cycle method with the safety interrupt? Can I stop midway through the method and shut the pneumatic outputs off if the safety interrupt is tripped? Sort of exit the method midway and terminate what was happening there? I don’t want to have to poll the safety input after every instruction in the machine control method. Sorry, I am not phrasing this in the most clear manner.
Thanks,
Tom


#2

It would be better to not run your machine control method in the interrupt processing thread. You are essentially preventing yourself from receiving any more interrupts. An interrupt routine should be short, sweet and to the point. It would be best to communicate with your machine control method through shared variables or an Auto Reset Event or something similar.

The idea is when you get the start button event, you can check if you should really start the machine (is it already running or in EStop) then you set a shared variable that lets the machine control method continue to run.

The EStop button event handler would operate in the same general fashion.


#3

Or your first interrupt will start an initialization thread.
Second interrupt will kill the thread, if it is still running, and will do any necessary clean-up.

You can also reset the board completely on second interrupt.


#4

Is this covered in the documentation? If not, do you have a short example on how to start and kill the thread?
Thanks,
Tom


#5

Read through these two blogs on NETMF threads: http://blogs.msdn.com/b/netmfteam/archive/2011/01/17/threads-and-thread-priorities-in-netmf.aspx

That will get you started :slight_smile:


#6

Thanks for the links and info. I am trying to set up a thread by declaring it globally, and then starting it when an interrupt fires. The problem is that I cannot seem to access it within the code for the interrupt. This will not allow me to start a thread with one interrupt, and kill it with another. Ideas?
Thanks,
Tom


#7

Check static/non-static scope of your methods and global members


#8

Use an AutoResetEvent between the interrupt and the thread, not a global variable

Start the thread before you get an interrupt and blocks it on the event.
Then on the interrupt handler, Set the event to unblock the thread.