LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help Initializing Outputting Loop Variable Only Once

I posted this question before, but later realized that it was hard to explain the problem without sample code.

I have attached a VI with this post that explains the problem. This is what the code should do:

1. There is a WHILE loop monitoring a certain Analog Input Channel on a DAQ board.

2. There is Microsoft Media Player included in the VI as an ActiveX Control.

3. When the voltage on the analog channel being monitored exceeds a certain limit, I want Media Player to automatically start playing.

The problem is this: the voltage on the analog channel constantly fluctuates above and below the threshold. It starts off as being below threshold, therefore Media Player is initially in the STOP condi
tion. When it reaches threshold, Media Player should switch to the PLAY condition. BUT, when it drops back below threshold, I don't want Media Player to return to the STOP condition, I want it to continue to PLAY until the VI terminates.

The condition is, I cannot terminate the WHILE loop once voltage on the channel reaches threshold. In the program, the WHILE loop does much other stuff besides monitoring voltage on the channel.

I am trying to find a solution in which the WHILE loop can continue to play for the duration of the VI, but the signal to the Media Player should be ignored after the FIRST time that the voltage reaches threshold.

Any help is appreciated.
0 Kudos
Message 1 of 2
(2,571 Views)
There are a number of ways to do this. I would suggest that you draw yourself a logic table and timing diagram to determine what is going on and what needs to happen.

Your code simply monitors the analog input and then stops when the output reaches your trigger level.

What you need, it sounds like, is for the media player to activate once you reach a level, period. To do that, you need to look for a rising edge. You need the following data:

Voltage
Previous Voltage
Media Player State (playing or waiting)

In order to get these, and to accomplish what you need, you need multiple loops, and a shift register in your DAQ Loop. Your logic results should be that the Media Player Starts ONLY when the voltage IS above the threshold (use an avera
ging or windowing filter to eliminate noise from your readings), the Previous Voltage IS NOT above the threshold AND the Media Player State is NOT playing. When you create a timing chart and logic table, you can quickly see how to tell the Media Player to start. Running and monitoring the Media Player is a matter of setting a local variable.

I have modified your code to show you what was done. I still suggest building a timing diagram and logic table to illustrate to yourself how it is done.
0 Kudos
Message 2 of 2
(2,571 Views)