LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help me with valve opening cycle

Lynn,

what is the best way to integrate it into my complete program?

Would it slow down the program? Now I have internal timer 10 ms in my program, that is the speed it reads, writes and plots data.

Sergey.

0 Kudos
Message 11 of 17
(902 Views)
Sergey,

The answer depends on how the rest of the program is structured. The example I sent you uses a very simple state machine (while loop with case structure) with four states. I like the state machine architecture for most programs because of its power and versatility.

You could add states to this VI to accomodate your other needs or add valve states to your other program or the two could run in parallel with commands and data passed between them via queues. Without a lot of information about the rest of your program, I cannot be more specific.

Look at the examples which ship with LV and search th archives of this site for "state machine" or "producer/consumer" for more information.

Lynn
0 Kudos
Message 12 of 17
(899 Views)
Lynn,
state mashine is like Chinese Language for me. I hope that I could understand it. By the way I have included main program. It is written for USB 6008 DAQ. You can see the part of the program I was interested in i upper right corner.
Sergey.
0 Kudos
Message 13 of 17
(881 Views)
NYC,
I have tried to repeat what you have done for me but it does not work. Am I missing something?
I have posted this VI. I have LabView 7.1
Sergey.
0 Kudos
Message 14 of 17
(876 Views)
Sergey,

You missed two key elements of nyc's diagram. (1) Both for loops need to have a delay in them. Otherwise they execute in a fraction of a microsecond and you never see anything happen. (2) The second frame has a local variable of the Valve open indicator wired to the False constant.

See attached VIs for comparison.

I looked at your Vibrafilter.vi. You should look at some of the style guides. Wires running right to left all over the diagram make it very difficult to tell what a program is doing. Imagine that six months from now you need to come back and modify the program. You are likely to be quite unhappy with yourself.

After I cleaned up the diagram a bit this is what I think your program is doing:

Initialize 12 front panel controls from the config file. (Note: No data dependency exists between this and the main loop. The loop could run before the configuration.)
Initialize 3 DAQ tasks.
Start 3 DAQ tasks.
Loop (Until Stop or Error[DAQ Read or DAQ Write DO])
Read DAQ (AI)
Process data
Set Valve indicator
Write to DAQ (DO)
(Conditional) Play sound
Write to DAQ (AO)
Save data to file
Update graph
(Conditional) Read datalog file
Wait until next multiple (10 ms)
If (Stop or Error) then Write config file
End loop
Close 3 DAQ Tasks
Report errors.

A state machine architecture for this might have everything inside the main loop with states like this:

Control init - Read config files and set controls
DAQ Init - Initialize 3 DAQ tasks and start them
Idle - wait for command to start (Change tab control from Settings to Main?)
Read DAQ - Obtain AI data
Process data - Do math and comparisons on results
Save data - Write data to file (No need to do this for each point. Save the data in a shift register and write once a minute, perhaps.)
Play sound - Play sound from .wav file
Update graph - Plot data on display for user (this does not need to be done more than a few times per second)
Write DO and AO - Send data to hardware
Open Valve - Set valve indicator to Open, set data for DO Write and start valve timer
Check Timer - Check current time against valve timer setting
Close Valve - Set valve indicator to Closed, set data for DO Write and start valve timer
Write config - Save current values of controls to config file
Error - Handle or report errors
Halt - Set outputs to safe values (for example, Valve = Closed); Stop loop.

Perhaps this will give you some ideas.

Lynn
Download All
0 Kudos
Message 15 of 17
(869 Views)

Thanks Lynn and NYC as well.

Thanks for your comments. I have tried to include NYC VI to my main program (sorry but I can undesrstand it better than state mashine).

But direct using of it gives another problem: when valve opening started it slows down Plot and probably data logging as well. Plot renews only after valve opening cycle. Is it possible to fix it.

I am sorry about this pretty silly question. Programming is not what I am doing for life, I just need it occasionally. I have never learned how to program. That's why my VIs looks so disorganized.

Sergey.

0 Kudos
Message 16 of 17
(844 Views)
Just in case if you would like to take a look at it.
0 Kudos
Message 17 of 17
(841 Views)