LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to time a case structure

Solved!
Go to solution

Hi,

Im working on a project where I have programmed a machine cycle. I want to time (in seconds) the time it takes to complete a single cycle but I cant come up with a solution and im looking for some help.

 

The machine cycle is a mould closing from open (the true state of the case structure)

and then opening from closed (the false case of the case structure) .

 

The above is one complete cycle. The program will continue this cycle indefinitely and I need to display the time taken to complete every cycle.

 

As you can see from the pics basic arithmetic completes the transition from true to false and vice versa. 

The slide visually represents the mould opening and closing.

 

Thanks in advance.

Download All
0 Kudos
Message 1 of 15
(4,513 Views)

I don't understand your question.  You say you want to time a case structure.  But the code in both cases is pretty basic and will run nearly instantly.

 

The only thing that actually takes time in your code is the 500 mSec wait function.

 

So what are you really trying to do?  You can put timer functions in your code.  The Elapsed Time Express VI is actually one of the better Express VI's.  You can use shift registers to store a time value when something happens, and compare the time in future loop iterations.

0 Kudos
Message 2 of 15
(4,501 Views)

Arrgghh, I hate pictures of code.  Remind me to send you a picture of my C++ program and ask you for help in understanding what it does and where the error is located.

 

Have you looked at the set of Palettes on the Block Diagram?  Did you see one called "Timing"?  Did you try to understand what they did (particularly those that looked like Clocks)?  Are you taking a class?  Have you asked your fellow students for their ideas (in case some of them have been more "curious" than you)?

 

Bob Schor

0 Kudos
Message 3 of 15
(4,497 Views)

Hi,

Thanks for the reply. I need to time how long it takes to fill the slide bar and then empty the slide bar (true case fills the bar, false case empties the slide bar), it takes approx. 17 seconds when I run the v.i. This duration is my cycle time and I want to display this time every time a cycle is complete.

Yes I have been playing around with the elapsed timer and shift registers but I cant figure out how to use it to achieve what I want.

Can you advise me further?. 

Thanks for your help.

 

0 Kudos
Message 4 of 15
(4,421 Views)

Attach an actual VI so that we can easily modify it.

0 Kudos
Message 5 of 15
(4,406 Views)

I would suggest investigating a State Machine architecture. 

Message 6 of 15
(4,405 Views)

Thanks Ravensfan.

The V.I is attached.

Its an injection moulding cycle. 

As you will see the cycle is

mould closes - clamps - plastic injected - mould opened

I need to be able to time how long it takes to complete each cycle

0 Kudos
Message 7 of 15
(4,399 Views)
Solution
Accepted by Bob_Schor

Ah, a Chance to Teach!  I'm deliberately going to go "old-school" to illustrate some important Principles of LabVIEW (including the Principle of Data Flow) and will not be using the Latest-and-Greatest methods, so these techniques will be applicable to single-digit Versions of LabVIEW.

 

Here's a little demo that times a loop (where the execution times are deliberately obscured -- I'll leave it as an Exercise for the Reader to determine the accuracies of the timing, mainly because I forgot to check it, myself).

This is a Snippet in LabVIEW 2018, but is simple enough that you should be able to recreate it in earlier versions.

Measure Loop TimeMeasure Loop Time

The basic idea is there's a loop with a Time Delay being set by a Random Number generator (so you can't "cheat") -- how long does it take the loop to run each time?

  • There's a critical Wire running through this VI, namely the Error Line, which should be central in almost every VI that you write.  Among other things, it provides a way to force the sequential execution of LabVIEW code (recall that the Principle of Data Flow makes LabVIEW do its best to execute everything at the same time if there is no data dependence between them).  We'll return to this shortly.
  • To get "elapsed time", you need to get "time", either as a TimeStamp (with Date and Time of Day) or as "ticks of a clock".  I chose to use TimeStamps.  For "elapsed" time, you need to know the time before and after whatever you are measuring, and then subtract them, right?
  • I start by getting the Time as I enter the loop, saving it in a Shift Register.  I then do the action I want to test (here a random Time Delay).  By putting the "function under test" on the Error Line, I know that it will be executed in "serial" order with every other thing on the Error Line.
  • What's next on the Error Line?  A Sequence Structure, with another Time function inside it.  Note that the "Error Line Runs Through It", which forces this Time function to run after the "Function under Test" (try running this example without that Sequence Frame).  Incidentally, this is one of the (very) few legitimate uses for the Frame Structure (in my humble opinion).
  • So we have (on the Shift Register) the Time before we executed the Time Delay, and (from the Sequence Frame) the Time right after we did the Delay, so we subtract them and get the Elapsed Time, Delta-T.  We also can use the "after" time as the "before" time for the next loop, so we save it in the Shift Register where it will be use for the subsequent loop.

Problem solved.  Try it out and play around with it.  LabVIEW encourages making small Test Routines such as this to learn about LabVIEW Functions and Structures -- playing around with them is one of the best, fastest, and most fun way of learning.

 

Bob Schor

 

 

Message 8 of 15
(4,384 Views)

Attached is an example using a state machine architecture that I believe does what you intended - counts up to 160 by 10 with a 500 ms wait for each count, then counts down from 160 to 0 by 10 with a 500 ms wait for each count, and gets a cycle time. I used the timing approach as outlined by Bob_Schor in his very good tutorial above, though the Elapsed Time Express VI could also be used.

0 Kudos
Message 9 of 15
(4,367 Views)

Hey jimbob,

Bob covered the timing questions fully.

I want to add to johntrich's suggestion of using state machine architecture the attached VI and control. It not only helps clarifying the structure of your code, but also makes it easier to change portions of it.

 

Edit: john was faster.


Ingo – LabVIEW 2013, 2014, 2015, 2016, 2017, 2018, NXG 2.0, 2.1, 3.0
CLADMSD
Download All
0 Kudos
Message 10 of 15
(4,362 Views)