LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

starting and stopping Elapsed Time

I have some code in LabVIEW 8.2.1 I am writing for Qual test with a customer. The basics of the test are the following: monitor and record pressure (thru transducers), temperatures (fluid and ambient), and monitor the opening and closing a valve. The valve has two light switches orientated in such a way, that mechanical counters will count a cycle when it is fully closed to open to closed.

 

The problem I am having, is that I need the elapsed time vi to start counting, once it has moved off of the full open switch. It needs to count to 240 seconds, at which time it will pass on to an on bit, which will energize the valve again. I can get it to start running at the right part, but it will stop once

it gets in between the two light switches. It almost seems like the elapsed time vi doesn't have enough flexibility for what I need. That or I need to write a bunch of code that would enable it to do what I want.

 

I am not sure on how I can post code so it can be viewed in LabVIEW, so here is a word doc. 🙂

 

 

0 Kudos
Message 1 of 16
(6,083 Views)

Chadius wrote:

The problem I am having, is that I need the elapsed time vi to start counting, once it has moved off of the full open switch. 


What does this mean? What is "it"?

 


I am not sure on how I can post code so it can be viewed in LabVIEW, so here is a word doc. 🙂

Well, you could have simply posted the VI. But I'm guessing you're probably looking for the Code Capture Tool.

 

 

As for your code: it doesn't make a whole lot of sense. Whenever I see global variables, red flags go up. Where are these being set? How are these being set? What's in the False case of the case structure of that first frame?

 

Oh, and this:

 

 

 

Really? Do you want to stop and think about that for a nanosecond?

0 Kudos
Message 2 of 16
(6,070 Views)

"It" is a metal blade connected to a rotating shaft. The end of the metal blade has about 45° of travel. At the end of the travel, the blade goes in between to black pieces, which have a voltage to them. When the light is broken, the voltage will decrease to zero. I am using this method for a couple different parts of the vi. One, the voltages are represented by a global (one for open, and one for closed), and then used in a flat sequence to trigger the actuator on and off. Second, it is physically wired to mechanical counters, representing open and closed cycles.

 

Yea, I didn't have the code capture tool. 😞

 

As for the boolean nightmare your pointing at, I am super new to LabView. So I really don't know why that is bad, honest. Wait till you see the whole vi, then you can really critique me. 😞 I have made vi's that work,and work quite well I thought. I do have the suspicion that I could make things way simpler though.

0 Kudos
Message 3 of 16
(6,062 Views)

If you don't have the Capture Tool, then you can simply download it an install it. It's free.

 

Please upload your actual VIs. We can't debug squinty pictures.

 

If you don't understand why the Select function is pointless then you must also be new to programming, and not just programming in LabVIEW. What you coded is this: "If the output of the comparison is True, then pass out a True constant. If the output of the comparison is False, then pass out a False."  See it now?

0 Kudos
Message 4 of 16
(6,055 Views)

Yes, I am pretty new to programming. I am more of a mechanical engineer. (in school and work in a eng lab) I have done more scripting than anything.

 

Here is what the tool got me. If I load up my actual vi, I'll need to post several times, so you get all of my globals.

 

0 Kudos
Message 5 of 16
(6,048 Views)

Atleast you have wait times in your loops so you dont starve the cpu.

 

Why do OR functions with constant False as one parameter, it'll always be the same as the other parameter i.e. a straight wire.

 

Why use globals at all, it's only this vi running, right?

 

Sequence structures aren't necessary if you have wired correctly.

 

/Y 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 16
(6,042 Views)

@Yamaeda wrote:

Atleast you have wait times in your loops so you dont starve the cpu.

 

Why do OR functions with constant False as one parameter, it'll always be the same as the other parameter i.e. a straight wire.

 

Why use globals at all, it's only this vi running, right?

 

Sequence structures aren't necessary if you have wired correctly.

 

/Y 


I was under the assumption, that in order to get a value to another loop, I would need to use globals. We had a guy that used to work here, and he was really fond of globals. So most or all of our vi's have globals in them.
When you say sequence structures aren't needed if wired correctly, what would be another way of doing things in sequence?
I understand what you are saying about the OR function. (me = embarrassed lol)
0 Kudos
Message 7 of 16
(6,026 Views)

Chadius wrote:
I was under the assumption, that in order to get a value to another loop, I would need to use globals. We had a guy that used to work here, and he was really fond of globals. So most or all of our vi's have globals in them.

Then that person didn't know what they were doing. Globals (and locals) are fine, but constantly being abused by programmers, causing race conditions. In fact, you've got one in your middle loop at the top. You are writing to the P1 global and then reading from it in order to write to file. How do you know which one is going to happen first? Answer: you don't. In fact, in this case the read will occur before the write. Race condition. In your case you do not need a single global variable. You could use local variables, but  there's only a couple of places where they would be needed here. There are many ways to transfer data between loops, and this has been discussed many times in this forum, so you can do a search to find these threads.

 


I understand what you are saying about the OR function. (me = embarrassed lol)

Well, that's half of it, at least. How about understanding why the Select function is completely pointless in this case?

 

As for your code: I said to upload the VI, not a picture. It appears your code does not have a loop over the whole thing. This leads me to believe you are using the Run Continuously button. Otherwise, that for-loop will not run again once it completes its iterations. If you are using Run Continuously, STOP. That is only intended to be used for debugging.

 

I don't really understand what your code is intended to do. What is C1R and C2R?

0 Kudos
Message 8 of 16
(6,016 Views)

@smercurio_fc wrote:

Chadius wrote:
I was under the assumption, that in order to get a value to another loop, I would need to use globals. We had a guy that used to work here, and he was really fond of globals. So most or all of our vi's have globals in them.

Then that person didn't know what they were doing. Globals (and locals) are fine, but constantly being abused by programmers, causing race conditions. In fact, you've got one in your middle loop at the top. You are writing to the P1 global and then reading from it in order to write to file. How do you know which one is going to happen first? Answer: you don't. In fact, in this case the read will occur before the write. Race condition. In your case you do not need a single global variable. You could use local variables, but  there's only a couple of places where they would be needed here. There are many ways to transfer data between loops, and this has been discussed many times in this forum, so you can do a search to find these threads.

 


I understand what you are saying about the OR function. (me = embarrassed lol)

Well, that's half of it, at least. How about understanding why the Select function is completely pointless in this case?

 

As for your code: I said to upload the VI, not a picture. It appears your code does not have a loop over the whole thing. This leads me to believe you are using the Run Continuously button. Otherwise, that for-loop will not run again once it completes its iterations. If you are using Run Continuously, STOP. That is only intended to be used for debugging.

 

I don't really understand what your code is intended to do. What is C1R and C2R?




C1r and C2r are for the lab tech to choose between two different cycling/timing conditions. I use the white run arrow. I don't think I have ever used the the other button. And I understand the select function from another post of yours. I haven't taken it out of the vi as of yet. Here is the actual vi and the all of the globals. (sorry) 😞

0 Kudos
Message 9 of 16
(6,005 Views)

Hello Chadius, 

 

Thanks for posting,

I took a look at your code this morning. We at NI recommend using varibales as one of the last resources when trying to pass data out in cases where this is rseally necesary, when looking at your code I realized that the variables to pass data are not needed and that actually there are some misconceptions about the functionality of the vi funtions, do not be ashamed that is totally understandable when you are new to a concept and more understandable if you are new to labVIEW.

 

Before proceeding with the code I would like to encourage you to check the Getting started with LV It gives you the basis to start programming in labVIEW and helps us understand better how LV executes.
There is also a lot of good help loaded in Labview that can help us determine what to use and what is expected of each function, you can access this by pressing ""CTRL+H" and accesing the detailed help when hovering over a specific VI and clicking detailed help.

 

Then if you are a new user to labview and would likely use labview for long term development I will suggest the training.

 

Now, getting to your code I can see that you are doing a bit more code than what you actually need, so for instance:

 

-we can eliminate the constants and the selector and just pass the boolean.

-we can also use less while loops so the part where you write to the variables can be done in the same while loop on the right.

-Instead writing to the variable and reading from that same variable you can just wire a cable so you have the same data

-You can use the error wire out/in of the functions to control code execution.

 

Last but not least, I am asumming here that this application you are coding is most likely to be a state machine where you are making a choice depending of the inputs you have, If "A" then "B"

 

This is an example of a simple state machine based on user input, you can change that input to be an event, a trigger etc.

 

 

Hope this helps, 

 

Luis

Application Engineer
National Instruments. 

 

 

 

 

0 Kudos
Message 10 of 16
(5,995 Views)