LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Execute Case Structure with Button Press Slows Down VI

Hi -

 

I'm fairly new to LabView, and I am having some issues with using a button to run a timed while loop.

 

I am writing a VI that outputs a timed voltage pulse to an output channel on a DAQ; meanwhile, the VI reads and graphs the voltage on three input channels on the DAQ. When I use a timed loop that automatically executes when the VI runs, the program works. However, I would like to include a button so I can control the timing and number of voltage pulses sent to the output channel, instead of sending only one voltage pulse each time the VI runs. I have tried to do this using a button wired to a case structure. If the button is 'true,' the VI should send the voltage pulse. If the button is 'false,' the VI should keep the voltage at zero.

 

When the button is 'false,' the VI runs normally; however, when the button changes to 'true,' the VI slows down and never sends the pulse. Why does this happen? How can I fix it?

 

Also, how can I send the voltage pulse only when the value of the button changes?  I only want the timed loop to execute once when the button changes value.

 

Thanks for any help or advice!!!

0 Kudos
Message 1 of 4
(4,023 Views)

If you want your case structure to only execute when the button is first pressed, then you should make your button be Latch action rather than switch.  With latch buttons, they will pop back up once they are read by the program.

 

If you want a loop to only run once, why do you have a loop?  Also your timed loop is actually going to run twice because it will only stop when the iteration terminal is equal to one.  The first iteration of a loop is i=0.

 

Instead of using a timed loop, just put a wait statement inside the case structure equivalent to how long you want the pulse to last.  Or better yet, create a 1 channel N sample digital output (if your daq device allows you) to send a hardware timed digital output.  Define your data going out to be a square wave of the length of time equal to your pulse.  Just be sure the waveform returns to zero at the end.

0 Kudos
Message 2 of 4
(4,019 Views)

Thanks for your response!

 

I changed the button to latch action, and that seemed to fix that problem. I also changed the timed loop to a case structure with a 'wait (ms)' statement as you suggested. However, my voltage is not a pulse (square shape) - it is a sawtooth!  The voltage goes straight up to the correct value, but during the 'wait,' the voltage falls linearly. How do I keep the voltage high during the wait?  I thought that perhaps I needed to change the mechanical action of the latch, but the voltage fell linearly for all three mechanical action options.

 

Also, the waveform graph stops updating during the wait. The waveform graph is outside the case structure, so I thought the wait would not affect it. Why does that happen?  (To be clear, the data during the wait is still written on the waveform graph, but it does not display until the wait is over.)

 

 

 

0 Kudos
Message 3 of 4
(4,000 Views)

The graph is in the same while loop as the case structure.  The while loop won't iterate until all the code inside of it has completed.  So the graph only gets updated once, and won't update again until the while loop iterates again.  If you need more continual updating you may want to put that in a loop that executes a couple of times, or completely separate your code into 2 while loops.  Is it that long of a wait considering your pulse length is 1 second?

 

Your analog output code is just writing a voltage out (7 volts) until it eventually writes out 0 volts.  There is no reason for it to drop down unless you have some sort of electrical problem between your DAQ device and the device on the other end that is reading the 7 volts.  What are you connecting that analog output too?

 

What if you don't use LabVIEW and try to test out that analog output using Measurement and Automation Explorer?  Does it do the same thing?

0 Kudos
Message 4 of 4
(3,992 Views)