LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While loop stops before countdown has finished

Solved!
Go to solution

Hello everyone

 

I have a problem with this scenario:

TEST.jpg

 

What I want is, that I can enter a series of arrays and then it will choose the first row because the first cycle number is 0, the second is 1 and so on. I want this loop to continue until I've left my arrays empty. The probelm is when I test it, it immediately stops, but when I highlight everything seems to work fine.

 

This is a program I'm trying to write so it can control some dosing pumps - I put in a number and weight and then it converts it into a set point % which will trigger the pumps. When the countdown is finished then it should start dosing with the next weight and time.

 

I'm fairly new to labVIEW. I've tried looking everywhere but I haven't found that could help me, I count on you! 😉

 

Thank you very much

 

Theis

TEST.jpg

0 Kudos
Message 1 of 13
(3,688 Views)

I think this will do what you want.

 

TabelTEST2.png



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 13
(3,681 Views)

You don't want to be peeling off an element of the array unless the time has actually elapsed. This means you need to stay at the current index until the time has elapsed. Also, the delay needs to be inside the loop. Otherwise it does you no good. This is assuming that you basically just wanted to check once a second.

 

You can accomplish this with a while loop or a for-loop. Mark posted an example using a for-loop. The thing I don't like about that specific example is that you're sitting inside the for-loop for potentially LOOOONG times with no way out. A better solution is to provide a break-out capability. I don't know where this is being used, but assuming a top-level you can use a front-panel button for that. You just need to loop around and stay at the current setting while the specific time elapses.

 

Attached is a quick 5-minute draw-up of your VI modified.

Message 3 of 13
(3,677 Views)

That will work but you will want to use a constant of 60000 instead of 3600 since the Wait function works with ms.  If your dealing with whole numbers for your time, set your array to U16, not double.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 4 of 13
(3,671 Views)

You are right about the constant. I was thinking seconds per hour for some reason. Mental lapse when whipping up something quick.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 13
(3,668 Views)

You could use the OpenG Wait VI which accepts an abort notifer. This would allow you to abort quickly since it handles the looping for you with the period checks. I didn't want to force the OpenG solution since the OP probably doesn't have them installed right now.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 13
(3,667 Views)

@Mark Yedinak wrote:

You are right about the constant. I was thinking seconds per hour for some reason. Mental lapse when whipping up something quick.


Yes, I figured that's what you were thinking. But even then, smercurio is correct, I would be concerned about spendind so much time within this loop.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 7 of 13
(3,665 Views)

@MoReese wrote:

@Mark Yedinak wrote:

You are right about the constant. I was thinking seconds per hour for some reason. Mental lapse when whipping up something quick.


Yes, I figured that's what you were thinking. But even then, smercurio is correct, I would be concerned about spendind so much time within this loop.


I agree. I just think a nice elegent state machine comparing the current time with the desired wait time, a short wait cycle and check for abort was a bit too much at this time for the user.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 8 of 13
(3,661 Views)

Thank you very much all of you! It almost works!

 

I must say that you guys put a lot of effort into helping me, I'm grateful.


I went with this solution:

BlockDiagram.png

FrontPanel.png

 

I added the "stop 2" button, which starts everything.

I just have a slight problem. When I want to pause I press the stop button again and it pauses. When I start again - by pressing the stop button - it resumes but I can see that it kept counting seconds while it was pause. I guess, that what I want is, that when I pause that it sends a zero signal to the pump which tells it to stop and the same with the timer. And when I start I want it to resume. Ya' follow me? 😉

 

I hope any of you guys, who have already been so helpful, can help!

 

Thank you


Theis

 

 

0 Kudos
Message 9 of 13
(3,646 Views)

How are you hoping to pause the application?  Your timer is still running.  The next iteration of the true case will show this.  I don't know that there is a way to pause this Express VI.  You may have to use an FGV to store the elapsed time when "pause" is pressed.  Then subtract this from time target, then you have the time remaining on your counter, which will be the new time once the operation has resumed.  A bit more elaborate, but it should work.  Rename your Stop2 as run/pause.  Go into the boolean properties for the switch and rename the on state "run", off state "pause."

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 10 of 13
(3,623 Views)