03-27-2019 09:01 PM
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.
Solved! Go to Solution.
03-27-2019 09:27 PM
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.
03-27-2019 09:36 PM
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
03-28-2019 04:09 AM
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.
03-28-2019 07:09 AM
Attach an actual VI so that we can easily modify it.
03-28-2019 07:12 AM
I would suggest investigating a State Machine architecture.
03-28-2019 07:49 AM
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
03-28-2019 08:25 AM
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.
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?
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
03-28-2019 09:58 AM
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.
03-28-2019 10:15 AM
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.