LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to keep generating sine wave after VI is completed? (daqmx)

Hello Community,

 

I have a very simple VI which generates a signal and write it to one my Analog Outputs. I'd like to keep the signal generation going even if the VI is finished its execution, but with the current code it stops when the VI stops.

 

(Test case: I need to generate the DC + ripple voltage and then perform several measurements. I must use Teststand so it seems logical that I start the signal generation in step1 and then perform the measurments in step2, step3... etc. But currently it seems that once step1 is finished the signal generation finishes as well.)

 

Is there a way to keep the signal generation on after I have finished my VI? If yes, what would be that. If not what would be the proper approach to handle this problem?

 

Thanks.

 

signal_gen.png

0 Kudos
Message 1 of 8
(3,149 Views)

Two changes will do it.  First, put Start Task before the Write.  Second, since you want to do multiple Writes until, say, you push a Stop button, put the Write inside a While Loop with a Stop Button wired to the Stop indicator.  Note you might want to put a Stop Task and/or Clear Task after the While Loop exits.

 

Bob Schor

0 Kudos
Message 2 of 8
(3,146 Views)

Probably I was not that clear, so let me rephrase the problem:

 

  1. The signal generation works fine and if I put a breakpoint after the start task VI then I will see the desired signal on my scope
  2. I can't put a while loop or a stop button to this VI. My plan - and I have no idea if this is possible at all -  was that I set up the right signal on the output and then finish this VI and go to the next step in teststand which actually performs a certain operation. Then go to the 3rd one etc until I'm done.

So my real problem is that the signal generation finishes once this VI is completed and my question is if I can write a code which sets my PXI AO channel to keep generating the signal even if the VI is done. (My PXI environment is non RT)

 

thx.

0 Kudos
Message 3 of 8
(3,136 Views)

LabVIEW's central "Principle of Data Flow" means that you can Talk and Chew Gum at the Same Time, i.e. you can do tasks in parallel.  In particular, you could use the Producer/Consumer Design Pattern to have your main TestStand routine be the Producer, and a parallel Loop, acting as a Queued State Machine with states Setup (to initialize the DAQmx code), Start (to start the Task running), Stop (to, perhaps temporarily, stop the Task), and Quit (the final call, which clears the Task and stops the Consumer).  The Producer calls Setup early, then when it wants the Stimulation to start, puts Start on the Queue.  [I'm using an Enum with the four values Setup, Start, Stop, and Quit to make the code more mnemonic and self-documenting].

Continuous Stimulation during TestStand.png

 

Bob Schor

0 Kudos
Message 4 of 8
(3,111 Views)

Yes, I am aware of the parallelism in LabVIEW. But as I have my test steps in teststand already, it does make sense to reuse them instead of compile them into one VI. So thanks for your thoughts, I certainly appreciate them, but the question remains the same: is it possible to keep the signal generation going after my VI above finished?

0 Kudos
Message 5 of 8
(3,108 Views)

With the code as written, I think the answer's NO.  Much like what would happen if you ran the code in the LV development environment or as an executable.  The vi stops executing and once it leaves the run state, the LV runtime engine will start freeing up the resources the vi used, including DAQmx task resources.

 

You'll need some version of what Bob_Schor recommended.   Some way to launch free-running code that keeps the AO generation vi in run state, and some further way to signal to that free-running code when it's time to quit.   

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 6 of 8
(3,098 Views)

I'm no expert in TestStand, but I recall you can run a step as a parallel process.  But you have to modify the current code you have to run in a loop, and to get some kind of signal to let it know it's time to quit.

 

It's probably a lot easier to modify the code to use the Consumer/Producer design pattern than to get two separate VIs to communicate with each other via TestStand.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 8
(3,084 Views)

Thanks folks. Yeah a producer-consumer or master-slave would be nice, but I probably have to go with TS + parallel sequences and using notifiers.

0 Kudos
Message 8 of 8
(3,060 Views)