03-13-2009 01:42 AM
Good morning
I have written code to produce a square wave of varying frequency, and a second square wave of constant frequency. These squarewaves are to be output to the computer speakers via the soundcard. I am counting the number of edges in the generated square wave using the PFI0 input on the USB-6009 DAQ. The way in which i want the code to run is as follows:
Output the varying squarewave and count the edges. When the edge count reaches 1000, immediately stop the varying square wave and output the constant square wave. Similarly, count the constant square wave edges and when it reaches 1000 switch back to the varying square wave, and so on... Since there is no "break" statement in LabVIEW graphical code, i have used a case structure to switch between the varying and constant squarewaves.
The problem:
I have inserted a condition statement that checks if the edge count is equal to 1000 but when the code runs, the edge count continues past 1000 and the the condition is thus not met. The case structure therefore doesn't change and the code stays in that state... I have attached my VI.
The frequencies i am sending the DAQ are in the range 0 to 7.4kHz.
03-16-2009 08:35 AM
03-16-2009 08:43 AM
the number of edges produced does not exceed 1000...
03-16-2009 11:32 AM
03-17-2009 12:53 AM
When i clicked Hightlight Execution and ran the VI the following happened:
- On the first iteration of the inner most while loop, the edge count was at approx. 450
- On the second iteration, the edge count was at approx 1020
This would seem to indicate that the loop isn't checking the edge count as fast as i would like...?
When the VI runs, the data1 and data2 indicators display the edge count in real time (one step at a time), so there is surely a way of checking the count just as quickly?
03-17-2009 01:14 AM
I also checked the sound() command by extending the duration of the sound such that it would produce twice as many edges when played to its full length. The result was that when the edge count reached 1000 the sound kept playing until it completed its full duration. In addition to the above problem, is there a way to cut the sound short while it is playing? There is a VI called Sound Output Stop, but i have written my sound() command in Mathscript since the LabVIEW sound operations produce a lot of noise and unwanted pulses.
I have already tried a predictive approach whereby i calculate the waveform required to produce only 1000 steps and output that. There is a large error in the sound production that is random and variable, thus i would prefer to perform the above operations in real time to react to the actual output.
03-17-2009 12:21 PM - edited 03-17-2009 12:22 PM