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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to send voltage to a device for a few seconds (1-5 s) while the main program keep running?

Hi All,

 

I worked on this a bit over the weekend. I think I got things working the way I want!

 

Please see the attached VI.

 

Actually I want to run 3 loops in parallel. The first is the main loop. The second is a timed loop which takes its time info from the first loop. And finally the third loop runs independently for a specified time.

 

I just wanted your expert opinion as to whether I did everything all right.

 

Thanks again for all your help which has been so useful and a great learning experience!

 

Cheers,

 

Saif

0 Kudos
Message 21 of 25
(400 Views)

Saif,

 

1. If you use the Latch mechanical action on the Stop boolean, you do not need the local variable to reset it.

2. You convert the Dynamic Data Type from the DAQ Assistant to a waveform data type and then you wire it to a scalar indicator. Why not just convert to a scalar?

3. You initialize the array every time the while loop runs.  Move the intialization outside the loop and wire the constant array to the Enqueue.

4. Why do you Enqueue the same data over and over?

5. Why do you Dequeue outside the middle loop? The loop will process the same data on every iteration.  Of course (see 3. and 4.) you are enqueuing the same data anyway so it does not really matter.

6. What keeps the valve from running to Open and to Close at the same time?

7. The two AND gates and the Not could be combined into one compound arithmetic node.

8. You never release the queue.

 

9. This could probably all be done in one loop with a simple state machine.

 

Lynn

0 Kudos
Message 22 of 25
(397 Views)

Hi Lynn,

 

Thank you so much for all your feedback! I will try to answer some of your questions:

 

1. What should I use instead of the local variable?

 

2. This is actually a "mock up" code. I use this for real-time waveform display too. So, I need the dynamic data type.

 

3. Can you please explain this a bit more?

 

4. I don't know much about enqueue. I took this from the code that was suggested by LabView experts. Is there a way around it?

 

5. Same issue -- lack of experience with enqueue?

 

6. I will take care of this in the main code. Actually, the 3rd loop starts at startup. The second loop will start about 15 seconds after startup.

 

7. I will look up the arithmetic node and combine.

 

8. How can I do this?

 

9. If you could upload some basic example of how to do this, I would be grateful!

 

Cheers,

 

Saif

0 Kudos
Message 23 of 25
(391 Views)

Saif,

 

1. You do not need anything. The Latch mechanical action for a boolean control keeps the control in the condtion set by the operator until the code read the value and then it resets to False automatically.  Read the help file for booleans.

 

2. OK. But it still does not make sense to wire a waveform to a scalar display.  Which value of the waveform do you want displayed? The first? Last? 14th from the end? The average?  how do you know which one LV uses?

 

3. Old programmer's adage: Never write code twice to do the same thing. In this praticular case it probably does no harm. Is is good practice to move things which never change outside the loop and wire the value inside.

 

4. & 5. Queues are an excellent way to pass data from one loop to another while both are running.  The issue is with the way you are using them.  I would expect that you would enqueue the data from the DAQ Assistant on each iteration in the top loop and Dequeue the data INSIDE the middle loop so that you get the current data.

 

6. No. Both loops start as soon as this VI begins to run.  There is nothing there to control them from the main program or to delay the start.

 

8. Look for the Release Queue VI (with the big X) in the queue palette.  It should run after all the data is removed from the queue, so probably after the middle loop ends.

 

9. Look at examples and Design Patterns which come with LV. Both the Producer/Consumer and State Machine examples are useful.

 

Lynn

0 Kudos
Message 24 of 25
(365 Views)

Thank you so much Lynn! I will look into all that you mentioned.

 

Cheers,

 

Saif

0 Kudos
Message 25 of 25
(353 Views)