Motion Control and Motor Drives

cancel
Showing results for 
Search instead for 
Did you mean: 

edge count overshoots condition

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.

 

 

0 Kudos
Message 1 of 7
(4,425 Views)
Try using a greater than or equal to for the conditional.
Regards,
Claire Reid
National Instruments
0 Kudos
Message 2 of 7
(4,408 Views)
Indeed, a greater than or equal to will allow the programme to run continuously, however i need the edge count to be exactly equal to 1000 to cause cases to switch. It is important that

the number of edges produced does not exceed 1000...

0 Kudos
Message 3 of 7
(4,404 Views)
If you enable "highlight execution" right before the count goes to 1000, what value is it showing?
Regards,
Claire Reid
National Instruments
0 Kudos
Message 4 of 7
(4,394 Views)

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?

0 Kudos
Message 5 of 7
(4,387 Views)

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.
0 Kudos
Message 6 of 7
(4,386 Views)
In an attempt to keep things on one post, let's continue this discussion in the duplicate post.
Message Edited by Claire R on 03-17-2009 12:22 PM
Regards,
Claire Reid
National Instruments
0 Kudos
Message 7 of 7
(4,371 Views)