Externally-triggered action using interrupt request (IRQ)
Run a callback VI each time that a digital input transition or an analog input voltage threshold crossing generates an interrupt request (IRQ).
Use cases
Immediately execute a task triggered by an external event defined as a digital input transition or an analog input threshold crossing
Guarantee detection of a state change in an external device or system
Example activities: respond to a user input device such as a pushbutton or joystick; detect and respond to a critical overlimit sensor signal; measure elapsed time between external events
Features
Digital input interrupts:
Detect rising edge, falling edge, or either edge
Detect single or multiple conditions before generating an interrupt, e.g., wait for three rising edges
Analog input interrupts:
Define a voltage threshold between 0 and 5 volts
Generate interrupt on either low-to-high threshold crossing or a high-to-low threshold crossing
Define a hysteresis voltage band to reduce sensitivity to noise
Designate one “callback VI” to run the event is detected
Keep in mind
IMPORTANT: The callback VI must have a front-panel control of type U8 (unsigned 8-bit integer) named “ID” connected to the upper-left corner of the VI terminal pattern
The callback VI should execute as quickly as possible because all other processes suspend while the callback VI runs
Do not include any front-panel elements on the callback VI (other than the “ID” control)
The main VI that initializes the interrupt sources must run continually to sustain the interrupt sources
The main VI should unregister the interrupts as part of general clean-up before shutting down
Interrupts may be generated only on these MXP-A connector inputs:
Digital inputs 0, 1, 2, and 3
Analog inputs 0 and 1
A digital interrupt may also be generated by the onboard button
LabVIEW block diagram elements
Locate these elements with "Quick Drop" (press Ctrl+Space and start typing the name); click on an icon to see more sample code that uses that element:
Example code
Connect your Academic RIO Device to your PC using USBLAN, Ethernet, or Wi-Fi. NOTE: Not all Academic RIO Devices have Ethernet and Wi-Fi connectivity options.
Download and unpack the
rt_event-irq.zip (for use with NI myRIO 1900)
or the
NIELVISIII-rt_event-irq.zip (for use with NI ELVIS III)
archive, and then double-click the ".lvproj" file to open the project. NOTE: This project was written for a NI myRIO 1900 or NI ELVIS III connected by USBLAN at IP address 172.22.11.2.
If you are using a different IP address or another Academic RIO Device (Example: NI myRIO 1950 or NI RIO Control Module) do the following:
If using the NI myRIO 1950 or NI RIO Control Module start with the NI myRIO 1900 Archive.
Different IP address: Right-click on the "NI myRIO 1900" Device, choose "Properties", and then enter the new IP address
Different device:
Right-click on the top of the project hierarchy, select "New Targets and Devices", keep the "Existing target or device" option, and then find and select your particular device
Select all of the components under the "NI myRIO 1900" device: click the first one and then shift+click the last one
Drag the selected components to the new device
Right-click the "NI myRIO 1900" device and select "Remove from project"
Connect the MXP-B digital output 0 (pin 11) to the MXP-A digital input 0 (pin 11)
Connect the MXP-B analog output 0 (pin 2) to the MXP-A analog input 0 (pin 3)
Run “RT Main” and observe the following behavior:
Onboard LED0 changes state when a digital interrupt is detected
Onboard LED1 changes state when an analog interrupt is detected
Toggle the digital output control button and confirm that LED0 changes state
Move the analog output control slider through 2.5 volts and confirm that LED1 changes state
Stop the VI, try other input IRQ configuration options, and restart the VI (you need to restart the VI each time you change any IRQ configuration option):
Digital input IRQ configuration:
Rising edge, falling edge, or either edge
Edge count
Analog input IRQ configuration:
Rising edge or falling edge
Threshold voltage
Hysteresis band voltage (signal must move out of this band before another interrupt will be generated; reduces noise sensitivity)
You may wish to try your own digital and analog signal sources, too
Poll front-panel controls for Boolean button and analog slider
Unregister the IRQ sources
Sequence structure clarifies the three main steps, but could be removed because the error cluster propagation ensures proper ordering
Callback VIs
Uninitialized feedback node preserves LED state from one call to the next
Must include a U8 terminal called “ID” in the upper-left corner
Same VI structure for each LED (0 and 1)
Locate the functions subpalette
Low-level functions
Express VI; can only be configured through dialog box
Register a digital input as an IRQ source
IRQ number 0 to 7
Channel name
Edge type
Edge count
Callback VI reference; search “Callback VI Reference” (or “Static VI Reference” and enable the “Strictly Typed VI Reference” option) and select the callback VI
Register an analog input as an IRQ source
IRQ number 0 to 7 (must be different than previously-selected IRQ numbers)
Channel name
Threshold crossing type
Threshold voltage
Hysteresis voltage
Callback VI reference
Unregister all IRQ sources with a single for-loop
Requires IRQ numbers to be registered in sequence starting with 0