Example Code

Software Triggered Timing Source for Timed Loops

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW Real-Time Module
  • LabVIEW

Code and Documents

Attachment

Overview

This example demonstrates how to use a software timing source for a Timed Loop and a software trigger to control the execution of the loop.

 

Description

In LabVIEW Real-Time, Timed Loops allow you to prioritize tasks and use external timing sources. In some instances, it may be necessary to execute a Timed Loop iteration programmatically. You can create a software-triggered timing source using the Create Timing Source VI in the Timed Structures palette (Programming»Structures»Timed Structures).

 

Requirements

 Software

  • LabVIEW Base Development System 2012 (or compatible)
  • LabVIEW Real-Time Module 2012 (or compatible)

 Hardware

  • No hardware is necessary to use this example VI

 

Steps to Implement or Execute Code

  1. Download and open the attached VI
  2. Set the Timed Loop Iterations per Trigger
  3. Run the VI
  4. Every time you click on the Fire Software Trigger button, the Timed Loop will increment the number of loop iterations
  5. Stop the VI

 

Additional Information or References

Software Triggered Timing Source for Timed Loops - Front Panel.png
Software Triggered Timing Source for Timed Loops - Block Diagram.png

 

When using the Stop Timed Structure VI, the Timed Loop will iterate one more time. Use the Wakeup Reason data node set to Aborted to configure a case structure for handling this instance.

 

**The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
massic76
Member
Member
on

Hi,

I have just downloaded this vi and I am not sure I understand if it does what you wrote in your code and in this post. I liked it from the description but I doesn't do what you describe here and in the code. It seems that if you use dt=1ms then it works as described. However, the loop time is dictated by the 100 ms delay inside the timed loop. That is interesting. Is that the correct behavior? Also, I found out that the number of actual iteration is equat to: "Number of timed loop iterations" divided by the dt. So for instance if I set the Number of timed loop iterations to 100, and dt from 1ms to 5 ms then the system will iterate only up to 20 times and the loop time will be 100 ms.

Is this the behavior you were expecting from your system? Please let me know.

Maybe I am not totally understanding this Timed loop architecture at all. Please advise if you can.

Best, Massimo.

massic76
Member
Member
on

Hi,

I understand now the code you did. I am sorry I did not understand it at first. As this is a software triggered loop the unit of the dt is not in mSec but it is just a counter so that should stay as 1. Therefore, the code will go as fast as possible and therefore the actual speed is dictated by the wait. Sorry I did not understand your code before. If you don't mind I have modified it a bit so that it stops when it reaches the number of iterations or there is an error or the user push the stop button.

Thank you for sharing this code.

I am not sure how to include the code I have made as attachment. LEt me know if you want me to send it to you.

Best, Massimo.

Smootastic
NI Employee (retired)
on

Massimo,

I'm glad you were able to understand it and I certainly appreciate the feedback.  If you want to upload the modified version, just create a new document to attach the files, and create a link in this comments list so that other users can be directed to it.

Shehzaada
Member
Member
on

Great example! Question for you - I'm trying to create a software timer to synchronize data acquisition for many different devices, each running in separate VIs. The trick is that I need to be able to pause acquisition for a particular device if the device is busy.
The example VI works well for the case above, except for an issue that arises when a devices comes online AFTER the timer has been going on for a while. Consider the following logic:

1) We create a main loop (called Timekeeper) with the Create Software Triggered Timing Source VI. This fires an "Acquire Data" event every 1 second.
2) Other device loops wait on the "Acquire Data" signal, and "wake up" when the event fires.
3) After 10 iterations, I start another device loop -> let's call it "Delayed Device"
4) The delayed device will then fire 10 times consecutively before synchronizing with the timekeeper.

 

I can "filter" this backlog of filter events by monitoring the "Finished Late" indicator of the timed loop, however, that isn't the best solution if the timer is at 32,000 something. Does anyone have a solution in this case to discard this backlog without filtering it out?

 

I've previously implemented the above with a simple QMH, but then I've had to maintain one queue for each device which doesn't seem to be very scalable.

Shehzaada
Member
Member
on

Edit to my post above: Notifiers are an easy alternative for my use case, instead of using one dedicated queue for each potentially new device.


@Smootastic wrote:
Overview

This example demonstrates how to use a software timing source for a Timed Loop and a software trigger to control the execution of the loop.

 

Description

In LabVIEW Real-Time, Timed Loops allow you to prioritize tasks and use external timing sources. In some instances, it may be necessary to execute a Timed Loop iteration programmatically. You can create a software-triggered timing source using the Create Timing Source VI in the Timed Structures palette (Programming»Structures»Timed Structures).

 

Requirements

 Software

  • LabVIEW Base Development System 2012 (or compatible)
  • LabVIEW Real-Time Module 2012 (or compatible)

 Hardware

  • No hardware is necessary to use this example VI

 

Steps to Implement or Execute Code

  1. Download and open the attached VI
  2. Set the Timed Loop Iterations per Trigger
  3. Run the VI
  4. Every time you click on the Fire Software Trigger button, the Timed Loop will increment the number of loop iterations
  5. Stop the VI

 

Additional Information or References

Software Triggered Timing Source for Timed Loops - Front Panel.png
Software Triggered Timing Source for Timed Loops - Block Diagram.png

 

When using the Stop Timed Structure VI, the Timed Loop will iterate one more time. Use the Wakeup Reason data node set to Aborted to configure a case structure for handling this instance.

 

**The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**