From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
04-06-2009 04:05 PM
Solved! Go to Solution.
04-06-2009 04:22 PM
There are a few issues with your solution so far, but first I'll try to help answer your original question.
You are correct that you can't have a structure inside the Timed Loop that waits for 5 seconds without blocking the execution of the Timed Loop for that same time period. You are also correct that you can't simply communicate via wires to an external structure. If you wire the output of one loop into another, that creates a dataflow dependency, which means that the loop receiving the data cannot run at all until the other loop terminates its execution entirely and sends it the data.
You have a couple options:
04-08-2009 01:36 PM
Jarrod,
Thank you for your help and your observations. I will time my actual MATLAB code, you make a good point. What would happen if the time loop iteration (6ms) finishes before all the MATLAB code is run? Will this cause the iteration to go longer or will it cut short the MATLAB block?
I tried to implement your suggestion of using the elapsed time express VI. It circumvents the problem of having a different time scale within the timed loop, but I have not been able to get it to work properly. I am having issues with the reset input. I wish for the elapsed time VI to be reset everytime the marker is set to 1. Right now this only occurs the first time. Is there any way to pass this input a "1" only as soon as the marker is set? Presently, if I pass it the "1" from the marker itself, it is constantly reset and "time elapsed" stays at zero infinitely.
I am attaching the updated VI in case it may be of help.
Thank you,
Diego
04-08-2009 06:10 PM
This is true of everything in LabVIEW. No structure (like a Timed Loop, for loop, case structure, etc.) can complete until everything inside it has completed executing. A Timed Loop won't abort code running inside it to maintain a certain speed. If you set a Timed Loop to have a period of 6ms, that only means the loop will try to schedule itself to run at 6ms intervals. If the code inside it takes 100ms to run, it won't be very successful.
The Matlab Script Node has a lot of overhead in communicating with Matlab, an external application that might be busy doing its own things, sending it the script and the data, and then receiving the output data. That wrapper code is not only going to be fairly slow, but undeterministic. That means one time it might take 4ms to finish, the next time 400ms. You never know. Your best bet would be to try to implement that code in LabVIEW in some way if possible to reduce this overhead and increase (hopefully) determinism. You could code this in LabVIEW, use a formula node, or perhaps look into the Mathscript Node, which uses the same m-file syntax, but compiles natively in LabVIEW. The Mathscript Node, however, is not very deterministic either.
As to the Reset problem: the construct you should look into is called a Shift Register. This attaches to loops and allows you to save values from the previous iteration of the loop. Use that wisely, and you'll be able to solve this problem of resetting the Elapsed Time counter every time Marker is 1. You only want to reset when Marker is 1 and its value has changed from something else.