LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI Not Working

Hello,

 

The attached VI should count the number of pulses it detects within a defined time. There are a couple of problems with it which I have explained, along with the expected operation (see attachment).

 

Thank you

MCU

Message Edited by MCU on 02-07-2009 03:29 PM
0 Kudos
Message 1 of 10
(3,717 Views)

You are not understanding basic data dependency, which is the fundamental paradigm used to write LabVIEW code. The loop that's generating the pulse train will never stop since you wired a False to the condition terminal. The second loop cannot run until it has received the data that the first loop generates (you have wires going from the first loop to the second loop). These wires are not filled with data until the first loop finishes. But the first loop will never stop...

 

To learn more about LabVIEW it is recommended that you go through the tutorial(s) and look over the material in the NI Developer Zone's Learning Center which provides links to other materials and other tutorials. You can also take the online courses for free.

Message 2 of 10
(3,711 Views)
You will never get out of your first loop (the left one because you wired a False constant to the conditional terminal which is set to Stop on True.  The loop will never stop.
Message 3 of 10
(3,709 Views)

Hello,

 

Thank you for the information.

 

I changed the VI to use a flat sequence.The two problems are:

 

-It counts the pulses from the toggle switch correctly, but not from square wave generator.

-The main stop button is not responding.

 

The rest of the VI seems to work. Please give any suggestions for improvement.

 

Thank you

Message Edited by MCU on 02-07-2009 09:03 PM
0 Kudos
Message 4 of 10
(3,676 Views)

I don't think you need your sequence structure, as your data flow seems to force the flow of execution.

 

The stop button is not working because you are reading the stop button in your interior loop, but it doesn't stop your interior loop.  Once the button is read, it changes back to false, so when the interior loop finishes, the stop button is false.  The only way it will stop is if you happen to press it in the very last iteration of the interior loop.

 

You can OR the stop button with your timeout value in the interior loop to stop the interior loop, then your stop button will still be TRUE when it drops to the outer loop and it will fall out.  If you want the interior loop to timeout before the stop button is handled, then you need to move the stop button out of the inner loop and into the outer loop.  Then it will stay pressed until the inner loop finishes.  You will most likely get one more interation as LabVIEW will have already checked the stop button when your interior loop starts unless you place it in a sequence structure so it is read after the inner loop finishes

 

I would recommend the OR in the interior loop so the VI will stop ASAP, regardless of what your sampling duration is set to.

Message Edited by Matthew Kelton on 02-07-2009 10:13 PM
Message 5 of 10
(3,673 Views)
Your pulse generator is not working because you are generating several pulses in that waveform (probe the waveform and you will see 10 periods.  When you wire that into != 0, some of it does equal 0, so it always returns false.  Wire a constant to the sampling info input of the pulse generator and set the number of samples (#s) to 1.
Message 6 of 10
(3,667 Views)

There are two basic concepts you need to get your head wrapped around:

 

First is the idea of nodes: A node is basically anything on a block diagram except the wires. In addition, nodes can be inside other nodes for example, a while loop is a node - however the VI's and other things inside it are also nodes.

 

Second the rules for data flow:

1) A node will begin executing as soon as all its inputs are satisfied

2) A node will only output a value when it finishes executing.

 

Most of the times when you are wonder why something isn't updating when you think it should - its probibly a violation of one of these two rules.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 7 of 10
(3,663 Views)

Hello,

 

I see. There is one output now, but it is not at the right frequency. I wired a constant 1 to the Frequency input, but it seems to be running faster than 1Hz. Also, I made the offset 1 and the amplitute 1 in order to get a 0 -> 1 output (it is giving a 0 -> 2 output though).

 

I moved the generator to a seperate project (attached).

 

Thank you

0 Kudos
Message 8 of 10
(3,644 Views)

The amplitude and offset should be 0.5 (the range of the output is 2 time the amplitude + the offset) to give you 0 to 1.

 

The while loop will run as fast as it can.  If you look at the plot, the period of your signal is 1 Hz.  The issue is that the square wave signal generator doesn't run in real time, it generates a waveform.

 

To simluate the signal in real time, you will want to do something like the attachment, which uses a timed loop to generate data in "real time."  It won't be 100% precise 100% of the time, but it will get you generally in the right ballpark.

 

What you probably want to do is write your own version of Pulse geenrator which will give you single points, but in real time, not as fast as you can call it.

Message 9 of 10
(3,633 Views)

The waveform you are getting is correct.    Offset 1 puts the mean value at a1.  Amplitude of 1 means plus or minus 1.  So you have a 0 to 2 waveform.  Amplitude is half the value of peak to peak.

 

The reason it runs so fast is that you are using the timing of the loop which is running as fast as it can.  The waveform generation is not based on a hardware clock.

Message 10 of 10
(3,632 Views)