Main Site Documentation

Snippet - What to expect from interrupts?


#1

What to expect from interrupts?

This testing has been carried out on a EMX Development System. The EMX User Manual states:
“Most digital I/O pins are interrupt capable. Interrupt pins asynchronously call functions in
managed applications. Interrupts can be activated on rising or falling edges with an
optional glitch filter. Enabling interrupts for both rising and falling edges is supported but in
this case the glitch filter is disabled. Interrupt capable pins are marked in the pin-out table.”

The NETMF SDK states:

“When configuring an interrupt port, note the differences between level and nonlevel interrupts. Level interrupts, which are either InterruptEdgeLevelHigh or InterruptEdgeLevelLow interrupts, are dispatched when the value on a pin matches the specified high value or low value, respectively. The system dispatches only the first occurrence of a level interrupt until it is cleared by means of the ClearInterrupt method. With nonlevel interrupts, every specified edge is dispatched, and the ClearInterrupt method throws an InvalidOperationException.
In practice, it is best to use level interrupts when the interrupt condition needs to be checked only periodically.
It is possible to configure an InterruptPort object into an invalid state. In such cases, your program may not generate an exception until it actually uses the InterruptPort object. For example, suppose you create an InterruptPort object with its resistor mode set to Port.ResistorMode.PullUp, the interrupt mode set to Port.InterruptMode.InterruptEdgeLevelHigh, and the glitch filter set to true. This configuration does not generate an exception when you instantiate an InterruptPort object. If you then add an interrupt handler, the .NET Micro Framework throws an exception.”

From testing it is clear:
(1) If a Level interrupt is set the EMX throws an ArgumentException when an interrupt is trigger. Only Edge interrupts are allowed.
(2) If the ResistorMode is changed within program code then this setting triggers an interrupt.
(3) Having ClearInterrupt() in code set for edge interrupts does not throw an exception (contrary to the NETMF reference).
(4) Certain settings of ResistorMode are incompatiable with some InterruptMode settings, for example, ResistorMode should not be “PullDown” for an InterruptMode of “InterruptEdgeLow”. However “PullUp” with “InterruptEdgeHigh” causes single interrupts even though it does not fit the logic test.

InterruptMode ResistorMode Comment


InterruptEdgeLow Disabled No interrups except one at the beginning
InterruptEdgeLow PullDown No interrupts
InterruptEdgeLow PullUp OK for interrupts - single visit
InterruptEdgeHigh Disabled No interrupts
InterruptEdgeHigh PullDown No interrupts
InterruptEdgeHigh PullUp OK for interrupts - single visit
InterruptEdgeBoth Disabled No interrups except one at the beginning
InterruptEdgeBoth PullDown No interrupts
InterruptEdgeBoth PullUp OK for interrupts - double visit

Does the above look ok? Certainly for a button, which is probably pulled high on the EMX board, it may be correct. Much more limited than what one might think.
If someone could repeat these tests for G120 boards that would be great!


3 InterruptEdgeBoth
2 InterruptEdgeHigh
5 InterruptEdgeLevelHigh
4 InterruptEdgeLevelLow
1 InterruptEdgeLow
0 InterruptNone

0 Disabled
1 PullDown
2 PullUp


Found debugger!

Create TS.

Loading start at a0e00000, end a0e1383c

Assembly: mscorlib (4.2.0.0) Assembly: Microsoft.SPOT.Native (4.2.0.0) Assembly: Microsoft.SPOT.Security.PKCS11 (4.2
.0.0) Assembly: System.Security (4.2.0.0) Loading Deployment Assemblies.

Attaching deployed file.

Assembly: System (4.2.0.0) Attaching deployed file.

Assembly: GHI.Premium.Hardware.EMX (4.2.9.0) Attaching deployed file.

Assembly: kgInterrupt2 (1.0.0.0) Attaching deployed file.

Assembly: GHI.Premium.Hardware (4.2.9.0) Attaching deployed file.

Assembly: GHI.Premium.System (4.2.9.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Net (4.2.0.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Hardware (4.2.0.0) Resolving.

GC: 1msec 18564 bytes used, 7321104 bytes available

Type 0F (STRING ): 24 bytes

Type 15 (FREEBLOCK ): 7321104 bytes

Type 17 (ASSEMBLY ): 14424 bytes

Type 1E (BINARY_BLOB_HEAD ): 4044 bytes

Type 34 (APPDOMAIN_HEAD ): 72 bytes

GC: performing heap compaction…

The debugging target runtime is loading the application assemblies and starting execution.
Ready.

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\mscorlib.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Native.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Security.PKCS11.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.Security.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Net.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\GHI Electronics\GHI Premium NETMF v4.2 SDK\Assemblies\le\GHI.Premium.Hardware.EMX.dll’
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Programming\Projects\kgInterrupt_42\kgInterrupt2\bin\Debug\le\kgInterrupt2.exe’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\GHI Electronics\GHI Premium NETMF v4.2 SDK\Assemblies\le\GHI.Premium.System.dll’
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded 'C:\Program Files\GHI Electronics\GHI Premium NETMF v4.2 SDK\Assemblies\le\GHI.Premium.Hardware.dll’
The thread ‘’ (0x2) has exited with code 0 (0x0).
Start Interrupt: 1 Start Resistor: 2
IntButton 1 2 True
Press RHS button!
OnInterrupt: InterruptMode = 1 ResistorMode = 2 IntButton = False
Time finished!
IntButton 1 2 True
Press RHS button!
OnInterrupt: InterruptMode = 1 ResistorMode = 2 IntButton = False
Time finished!
IntButton 1 2 True
Press RHS button!
OnInterrupt: InterruptMode = 1 ResistorMode = 2 IntButton = False
Time finished!
IntButton 1 2 True
Press RHS button!
OnInterrupt: InterruptMode = 1 ResistorMode = 2 IntButton = False
Time finished!
IntButton 1 2 True
Press RHS button!
OnInterrupt: InterruptMode = 1 ResistorMode = 2 IntButton = False
Time finished!
IntButton 1 2 True
Press RHS button!
OnInterrupt: InterruptMode = 1 ResistorMode = 2 IntButton = False
Time finished!
IntButton 1 2 True
Press RHS button!
OnInterrupt: InterruptMode = 1 ResistorMode = 2 IntButton = False
Time finished!
IntButton 1 2 True
Press RHS button!
The program ‘[11] Micro Framework application: Managed’ has exited with code 0 (0x0).


Found debugger!

Create TS.

Loading start at a0e00000, end a0e1383c

Assembly: mscorlib (4.2.0.0) Assembly: Microsoft.SPOT.Native (4.2.0.0) Assembly: Microsoft.SPOT.Security.PKCS11 (4.2
.0.0) Assembly: System.Security (4.2.0.0) Loading Deployment Assemblies.

Attaching deployed file.

Assembly: System (4.2.0.0) Attaching deployed file.

Assembly: GHI.Premium.Hardware.EMX (4.2.9.0) Attaching deployed file.

Assembly: kgInterrupt2 (1.0.0.0) Attaching deployed file.

Assembly: GHI.Premium.Hardware (4.2.9.0) Attaching deployed file.

Assembly: GHI.Premium.System (4.2.9.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Net (4.2.0.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Hardware (4.2.0.0) Resolving.

GC: 1msec 18564 bytes used, 7321104 bytes available

Type 0F (STRING ): 24 bytes

Type 15 (FREEBLOCK ): 7321104 bytes

Type 17 (ASSEMBLY ): 14424 bytes

Type 1E (BINARY_BLOB_HEAD ): 4044 bytes

Type 34 (APPDOMAIN_HEAD ): 72 bytes

GC: performing heap compaction…

The debugging target runtime is loading the application assemblies and starting execution.
Ready.

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\mscorlib.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Native.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Security.PKCS11.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.Security.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Net.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\GHI Electronics\GHI Premium NETMF v4.2 SDK\Assemblies\le\GHI.Premium.Hardware.EMX.dll’
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Programming\Projects\kgInterrupt_42\kgInterrupt2\bin\Debug\le\kgInterrupt2.exe’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\GHI Electronics\GHI Premium NETMF v4.2 SDK\Assemblies\le\GHI.Premium.System.dll’
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded 'C:\Program Files\GHI Electronics\GHI Premium NETMF v4.2 SDK\Assemblies\le\GHI.Premium.Hardware.dll’
The thread ‘’ (0x2) has exited with code 0 (0x0).
Start Interrupt: 3 Start Resistor: 2
IntButton 3 2 True
Press RHS button!
OnInterrupt: InterruptMode = 3 ResistorMode = 2 IntButton = False
OnInterrupt: InterruptMode = 3 ResistorMode = 2 IntButton = True
Time finished!
IntButton 3 2 True
Press RHS button!
OnInterrupt: InterruptMode = 3 ResistorMode = 2 IntButton = False
OnInterrupt: InterruptMode = 3 ResistorMode = 2 IntButton = True
Time finished!
IntButton 3 2 True
Press RHS button!
OnInterrupt: InterruptMode = 3 ResistorMode = 2 IntButton = False
OnInterrupt: InterruptMode = 3 ResistorMode = 2 IntButton = True
Time finished!
IntButton 3 2 True
Press RHS button!
OnInterrupt: InterruptMode = 3 ResistorMode = 2 IntButton = False
OnInterrupt: InterruptMode = 3 ResistorMode = 2 IntButton = True
Time finished!
IntButton 3 2 True
Press RHS button!
OnInterrupt: InterruptMode = 3 ResistorMode = 2 IntButton = False
OnInterrupt: InterruptMode = 3 ResistorMode = 2 IntButton = True
Time finished!
IntButton 3 2 True
Press RHS button!
OnInterrupt: InterruptMode = 3 ResistorMode = 2 IntButton = False
OnInterrupt: InterruptMode = 3 ResistorMode = 2 IntButton = True
Time finished!
IntButton 3 2 True
Press RHS button!
Time finished!
IntButton 3 2 True
Press RHS button!
The program ‘[14] Micro Framework application: Managed’ has exited with code 0 (0x0).


Found debugger!

Create TS.

Loading start at a0e00000, end a0e1383c

Assembly: mscorlib (4.2.0.0) Assembly: Microsoft.SPOT.Native (4.2.0.0) Assembly: Microsoft.SPOT.Security.PKCS11 (4.2
.0.0) Assembly: System.Security (4.2.0.0) Loading Deployment Assemblies.

Attaching deployed file.

Assembly: System (4.2.0.0) Attaching deployed file.

Assembly: GHI.Premium.Hardware.EMX (4.2.9.0) Attaching deployed file.

Assembly: kgInterrupt2 (1.0.0.0) Attaching deployed file.

Assembly: GHI.Premium.Hardware (4.2.9.0) Attaching deployed file.

Assembly: GHI.Premium.System (4.2.9.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Net (4.2.0.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Hardware (4.2.0.0) Resolving.

GC: 1msec 18576 bytes used, 7321092 bytes available

Type 0F (STRING ): 24 bytes

Type 15 (FREEBLOCK ): 7321092 bytes

Type 17 (ASSEMBLY ): 14436 bytes

Type 1E (BINARY_BLOB_HEAD ): 4044 bytes

Type 34 (APPDOMAIN_HEAD ): 72 bytes

GC: performing heap compaction…

The debugging target runtime is loading the application assemblies and starting execution.
Ready.

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\mscorlib.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Native.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Hardware.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Security.PKCS11.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.Security.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\Microsoft.SPOT.Net.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.2\Assemblies\le\System.dll’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\GHI Electronics\GHI Premium NETMF v4.2 SDK\Assemblies\le\GHI.Premium.Hardware.EMX.dll’
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Programming\Projects\kgInterrupt_42\kgInterrupt2\bin\Debug\le\kgInterrupt2.exe’, Symbols loaded.
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\GHI Electronics\GHI Premium NETMF v4.2 SDK\Assemblies\le\GHI.Premium.System.dll’
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded 'C:\Program Files\GHI Electronics\GHI Premium NETMF v4.2 SDK\Assemblies\le\GHI.Premium.Hardware.dll’
The thread ‘’ (0x2) has exited with code 0 (0x0).

Start Interrupt: 0 Start Resistor: 0
IntButton 0 0 True (InterruptNone + Disabled)
Press RHS button!
OnInterrupt: InterruptMode 0 ResistorMode = 0 IntButton = False (Caused by ResistorMode change but InterruptNone!)
Time finished!
IntButton 0 1 False (InterruptNone + PullDown)
Press RHS button!
Time finished!
IntButton 0 2 True (InterruptNone + PullUp)
Press RHS button!
OnInterrupt: InterruptMode 0 ResistorMode = 2 IntButton = True (All of these should not happen as InterruptNone!)
OnInterrupt: InterruptMode 0 ResistorMode = 2 IntButton = False (Random change?)
OnInterrupt: InterruptMode 0 ResistorMode = 2 IntButton = True (All of these should not happen as InterruptNone!)
OnInterrupt: InterruptMode 0 ResistorMode = 2 IntButton = True
OnInterrupt: InterruptMode 0 ResistorMode = 2 IntButton = True
Time finished!
IntButton 1 0 True (InterruptEdgeLow + Disabled)
Press RHS button!
OnInterrupt: InterruptMode 1 ResistorMode = 0 IntButton = True (Probably caused by ResistorMode change even though “Disabled”)
OnInterrupt: InterruptMode 1 ResistorMode = 0 IntButton = False
OnInterrupt: InterruptMode 1 ResistorMode = 0 IntButton = False
Time finished!
IntButton 1 1 False (InterruptEdgeLow + PullDown)
Press RHS button!
Time finished!
IntButton 1 2 True (InterruptEdgeLow + PullUp)
Press RHS button!
OnInterrupt: InterruptMode 1 ResistorMode = 2 IntButton = False
OnInterrupt: InterruptMode 1 ResistorMode = 2 IntButton = False
OnInterrupt: InterruptMode 1 ResistorMode = 2 IntButton = False
Time finished!
IntButton 2 0 True (InterruptEdgeHigh + Disabled)
Press RHS button!
OnInterrupt: InterruptMode 2 ResistorMode = 0 IntButton = True
Time finished!
IntButton 2 1 False (InterruptEdgeHigh + PullDown)
Press RHS button!
Time finished!
IntButton 2 2 True (InterruptEdgeHigh + PullUp)
Press RHS button!
OnInterrupt: InterruptMode 2 ResistorMode = 2 IntButton = True (If the pin is already pulled up then InterruptEdgeHigh should not cause an interrupt)
OnInterrupt: InterruptMode 2 ResistorMode = 2 IntButton = True
OnInterrupt: InterruptMode 2 ResistorMode = 2 IntButton = True
OnInterrupt: InterruptMode 2 ResistorMode = 2 IntButton = True
Time finished!
IntButton 3 0 True (InterruptEdgeBoth + Disabled)
Press RHS button!
OnInterrupt: InterruptMode 3 ResistorMode = 0 IntButton = False
Time finished!
IntButton 3 1 False (InterruptEdgeBoth + PullDown)
Press RHS button!
Time finished!
IntButton 3 2 True (InterruptEdgeBoth + PullUp)
Press RHS button!
OnInterrupt: InterruptMode 3 ResistorMode = 2 IntButton = True
OnInterrupt: InterruptMode 3 ResistorMode = 2 IntButton = False
OnInterrupt: InterruptMode 3 ResistorMode = 2 IntButton = True
OnInterrupt: InterruptMode 3 ResistorMode = 2 IntButton = True
OnInterrupt: InterruptMode 3 ResistorMode = 2 IntButton = True
Time finished!
#### Exception System.ArgumentException - 0xfd000000 (1) ####
#### Message:
#### Microsoft.SPOT.Hardware.InterruptPort::set_Interrupt [IP: 0000] ####
#### MFConsoleApplication1.Program::Main [IP: 0066] ####
OnInterrupt: InterruptMode 4 ResistorMode = 2 IntButton = True
A first chance exception of type ‘System.ArgumentException’ occurred in Microsoft.SPOT.Hardware.dll
Level interrupts not allowed. Exception was thrown: System.ArgumentException
The thread ‘’ (0x1) has exited with code 0 (0x0).
OnInterrupt: InterruptMode 4 ResistorMode = 2 IntButton = True
OnInterrupt: InterruptMode 4 ResistorMode = 2 IntButton = True
OnInterrupt: InterruptMode 4 ResistorMode = 2 IntButton = True
Done.
The program ‘[10] Micro Framework application: Managed’ has exited with code 0 (0x0).