06-26-2019 05:36 AM
I am trying to write a program consisting of a for loop, with code also outside the for loop. As the for loop iterates, I need the counter to be used outside the loop to increase the output frequency of an external frequency generator. This needs to occur simultaneously with the main for loop, but I can only seem to pass the final counter value outside the loop; ie: the value is only passed after the for loop has completed all iterations.
Is there a way to continually pass the counter value outside of the loop in 'real time'?
Thanks in advance.
06-26-2019 05:38 AM
06-26-2019 06:47 AM
Hi GerdW,
Could you elaborate a little more on how I would use the functions you mentioned? I am pretty new to LabVIEW and have no experience with local/global variables etc.
Thanks
06-26-2019 07:36 AM - edited 06-26-2019 07:37 AM
Hi niamhw,
when you are so new to LabVIEW you even don't know about local/global variables then I STRONGLY advise to go to that Training section in the header of this LabVIEW board!
Learn LabVIEW first, before starting to code…
06-26-2019 07:47 AM
When you start learning LabVIEW, be sure that you learn the Principle of Data Flow (PDF), the key organizing principle that gives LabVIEW a lot of its power and makes it ideal for being an Engineering Workbench (look at the last two letters of "LabVIEW").
One corollary of PDF is that variables inside Loops (such as the Loop Index) "stay" inside the Loop until it exits, unless you export it using some mechanism. This "breaks" Data Flow, and can often cause difficult-to-find problems, so is not recommended for beginners.
A "safe" thing to do is to use the variable inside the loop. Of course, we don't really know what you want to do, but there may be a "better" (i.e. "safer") way to do it.
I agree with GerdW (of course!) that Learning LabVIEW and Learning How It Works is a good idea. Here's a Pop Quiz -- can you imagine doing whatever it is you want to do in C++ (or VBA, or MatLab) when you just started learning the language? It's challenging enough to write "Hello, World!" ...
Bob Schor
06-26-2019 10:50 AM
@niamhw wrote:
As the for loop iterates, I need the counter to be used outside the loop to increase the output frequency of an external frequency generator. This needs to occur simultaneously with the main for loop...
Then put the updating of the frequency inside of the FOR loop. It will make things A LOT easier on you.