Use the "Tick Count" function to measure the total elapsed time per iteration of a process loop.
Use cases
Measure and indicate the total processing time in milliseconds per iteration of a process loop
Especially useful to benchmark non-deterministic loops
Features
Negligible CPU effort, i.e., a noninvasive measurement
Easy to code:
“Tick Count” reports the value of a millisecond counter on each call
Use a feedback node to remember the value of the previous call
Subtract the previous value from the current value to measure the elapsed time
Keep in mind
The “Tick Count (ms)” function has a minimum resolution of 1 millisecond
The reference time is officially unspecified, therefore, the value itself returned by “Tick Count” should be interpreted with caution; however, experiments with the Academic RIO Device suggest that the timer resets to zero when the product powers up
The timer is based on a 32-bit unsigned integer which wraps back to zero after reaching the value 2^32 minus 1, therefore, the measurement is erroneous once every 2^32 milliseconds or about every 50 days of continuous operation
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_measure-loop-time.zip (for use with NI myRIO 1900)
or the
NIELVISIII-rt_measure-loop-time.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 “RT Main” that contains a conventional while-loop (non-deterministic) and a timed loop (deterministic) running in parallel, each set for a nominal 100-millisecond loop time
Observe the variation in the non-deterministic loop time compared to the deterministic loop
“Tick Count (ms)” function returns the value of a built-in 32-bit unsigned integer counter that increments every millisecond; initializes to zero when Academic RIO Device powers up
Feedback node and subtraction operation measures the number of elapsed milliseconds since the last time the “Tick Count” function was called, i.e., since the previous loop iteration
Measurement technique embedded in a timed loop set for 100-ms loop time
Same measurement embedded in a conventional loop with “Wait Until Next ms Multiple” to define the 100-ms loop time
Local variable used to stop both loops
Configure the timed loop
Stop both loops from a single front-panel “Stop” button
“Stop” button resides in timed loop
Local variable in conventional loop reads the “Stop” button value
“Stop” button mechanical action must be changed from default “Latch When Released” to “Switch When Pressed” because latching action is not compatible with local variables
Click “Stop” to stop both loops
Unstick the “Stop” button with the “F” constant after both loops have stopped, otherwise the button remains pressed