LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

switching an iteration on/off with a button

Hello, 

I'm making a VI to generate a pulsed analog signal and deliver it to the hardware device with an NI board. 

My goal is to switch the operation of the for-loop freely without quitting the VI.

jieunyun_0-1714559947633.png

jieunyun_1-1714560393825.png

 

In the front panel, I want to start the for-loop when I press "start" button and end the iteration when I press "stop". (Both buttons are on the right top side in the figure)

The problem is that after I press "stop" once, the whole VI goes frozen and does not work.

I want to have unlimited use of "start" and "stop" button without quitting VI.

The attached VI is the one I made so far and is there anyone who can help me?

0 Kudos
Message 1 of 8
(210 Views)

First of all, avoid using Local Variables.  Use wires and the actual terminals whenever possible.  Doing this will also eliminate the need for the Sequence Structure, letting the data flow determine the order of the code.  This will help you immensely in organizing your code.

 

Now, if you want to update your values inside of a loop, you actually need to be in a loop.  The only part you actually need in the loop is the waveform generation and the DAQmx Write.  I would stop the loop if there is an error or the stop button is pressed.

 

Attached is a cleaned up version of your code.  Hopefully this helps.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 8
(177 Views)

Thank you for your cleaned up version.

But the important point in my task is that "without quitting the VI", I have to turn on and off the signal.

How can I restart the loop without quitting and restarting the whole VI?

0 Kudos
Message 3 of 8
(136 Views)

Hello, 

I'm trying to provide separate signals to analog output 0 and 1 each. 

Here is the front panel screen shot.

jieunyun_0-1714627126068.png

analog output 0(ao0) channel is connected to pulse, and analog output 1(ao1) channel is connected to scanner.

So I intended to give different shapes of signals to two channel.

If I press "pulse on", ao0 channel is operating correctly and after press "pulse off", ao0 channel stops correctly and so does ao1.

However, when I was to press ao0 and ao1 without stopping any of them, only one while loop operated and the other got frozen.

jieunyun_1-1714627551007.png

I configured two while loops parallel and attached the vi.

Is there anyone who knows how to run them simultaneously?

 

0 Kudos
Message 4 of 8
(145 Views)

Hi jie,

 


@jieunyun wrote:

I configured two while loops parallel and attached the vi.

Is there anyone who knows how to run them simultaneously?


Your two (inner) while loops are not really independent, because they are located within the single outer while loop…

(Your code works as programmed, but apparently not as expected/required.)

 

Hint: whenever there are problems with DATAFLOW you should debug your VI using highlight execution debugging! This way you can watch the DATAFLOW and determine why some part of your code does not work as expected.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 8
(139 Views)

Thank you so much for your reply. Your help gave me a good starting point on solving my problem.

According to your advice, I removed the outer while loop and made two other while loops corresponding to two inner while loops each.

However, same problem occurs and I still don't understand why the circled two DAQmx write and start blocks make errors and are not independent each other, checking with highlight execution debugging.

jieunyun_0-1714632399050.png

Can you give some more hints?

 

0 Kudos
Message 6 of 8
(113 Views)

Hi jie,

 


@jieunyun wrote:

However, same problem occurs and I still don't understand why the circled two DAQmx write and start blocks make errors and are not independent each other, checking with highlight execution debugging.


Which errors do you get?

Which hardware do you use?

Does your hardware allow you to start two tasks in parallel for this hardware?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 8
(102 Views)

Actually, I connected two cameras and two lasers in ao0 with BNC cables like octopus legs and also connected a galvanometer scanner in ao1.

I solved the problem with removing one inner loop and change DAQmx write block's option into multi channel like the picture below.

jieunyun_0-1714647166224.png

Your advice helped me a lot. Thank you so much.

 

0 Kudos
Message 8 of 8
(68 Views)