Timer-driven background process using interrupt request (IRQ)
Run a callback VI each time that an FPGA-based interval timer generates an interrupt request (IRQ).
Use cases
Automatically execute an activity at regular and precise intervals of time as a background process
Example activities: collect a data measurement and log it to disk, periodically confirm that an external peripheral device is still attached, and alert the main VI that a prescribed amount of time has elapsed
An alternative to creating a parallel process loop in the main VI, and may simplify the design of the main VI
Features
High-precision timers implemented as part of the Academic RIO Device default FPGA personality
Create up to eight independent timers
Designate a “callback VI” to run when the timer interval expires
Specify a timer interval as low as 1 microsecond and as high as 2^32 microseconds (71.6 minutes)
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 creates the timer must continue to run to sustain the timer running on the FPGA fabric
The main VI should destroy the timer as part of general clean-up before shutting down
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_timer-irq.zip (for use with NI myRIO 1900)
or the
NIELVISIII-rt_timer-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"
Run the “RT Main” VI
Observe the following behavior:
The VI front panel connects to a simple foreground process loop; use the slider to vary the loop time and observe the change in the blink rate
Onboard LEDs 0, 1, and 2 are each driven by their own callback VI which toggles the LED state each time the callback VI runs
Three timers with intervals 0.1, 1, and 10 seconds are associated with each of the three callback VIs
Each timer generates an interrupt when it times out which runs the callback VI one time, therefore, each transition of the onboard LED indicates a new timer interrupt
Poll front-panel for loop time slider control and “Stop” button
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 timer as an IRQ source
Timer ID (IRQ number) 0 to 7
Time interval in microseconds
Callback VI reference; search “Callback VI Reference” (or “Static VI Reference” and enable the “Strictly Typed VI Reference” option) and select the callback VI
Can also use the high-level “Interrupt” Express VI
Unregister all IRQ sources with a single for-loop
Requires IRQ numbers to be registered in sequence starting with 0