02-07-2009 03:28 PM - edited 02-07-2009 03:29 PM
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
02-07-2009 03:35 PM
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.
02-07-2009 03:38 PM
02-07-2009 09:02 PM - edited 02-07-2009 09:03 PM
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
02-07-2009 09:12 PM - edited 02-07-2009 09:13 PM
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.
02-07-2009 09:17 PM
02-07-2009 09:25 PM
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...
02-07-2009 10:50 PM
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
02-07-2009 11:14 PM
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.
02-07-2009 11:17 PM
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.