LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Timing with a For Loop

Hello all.

I am trying to get the timing down for a For Loop. I need the code in the For Loop that is in the Case Structure to run for a X amount of minutes that the user can set on the front panel. If there's a better way to set this up, let me know.

The VI is attached.

Thanks
0 Kudos
Message 1 of 20
(3,944 Views)
Unfortunately, I do not have LV installed on this PC, so I cannot look at your code.
 
However, when you mention running a loop for a prescribed duration (time duration instead of loop iteration), then I would use a While Loop.  You can get a timestamp just before entering the loop and take timestamps within the loop and compare if the elapsed time is greater than or equal to the desired run time.  If ture, then stop the loop.  You can wire the output of the time compare to the conditional terminal of the while loop.
 
R
0 Kudos
Message 2 of 20
(3,939 Views)
Your VI has no control for the number of minutes. The only control is the temperature setpoint. The logic of the application also doesn't make much sense. What are you trying to accomplish, conceptually?

Note that you have a couple of wiring problems:
  • Extra tunnel at case structure.
  • Unconnected Feedback Node.



Message Edited by smercurio_fc on 07-07-2008 11:44 AM
0 Kudos
Message 3 of 20
(3,932 Views)
Hey, thanks for the replies.

With this application, I'm trying to control an infrared heater. It's supposed to take the difference between the temperature setpoint and actual temperature and output voltage to the controller of the heater accordingly. However, after it reaches that setpoint, it's supposed to hold that temperature for the X minutes (the case structure part). I just starting using LabView two weeks ago so I'm completely new to this. Everything I've learned has come off this website so if there's things that I need to fix on that VI please let me know, or if there is a better way to code something.

Thanks.
0 Kudos
Message 4 of 20
(3,924 Views)

To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here and here are a couple you can start with. You can also contact your local NI office and join one of their courses.

In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).

An excellent book is LabVIEW for Everyone: Graphical Programming Made Easy And Fun.  The author visits this site regularly (J. Kring)

R



Message Edited by JoeLabView on 07-07-2008 01:55 PM
0 Kudos
Message 5 of 20
(3,907 Views)
Thanks Joe. I'm going to try using a While Loop and a timestamp and see how it goes.

0 Kudos
Message 6 of 20
(3,881 Views)

If you have any problems, just post your code & question in this thread.

🙂

0 Kudos
Message 7 of 20
(3,876 Views)
Joe, would I use the Get Time/Date in Seconds before entering the While Loop? Also, the elapsed time structure would act as my setpoint right? I can edit the time so it would return a true statement after X seconds.

Thanks
0 Kudos
Message 8 of 20
(3,869 Views)
Do you guys that this would work? The set time is subtracted from the elapsed time, and if the difference is <0, the While Loop terminates.

Bunches of thanks to all of you.
0 Kudos
Message 9 of 20
(3,851 Views)

@mjagani wrote:
Hey, thanks for the replies.

With this application, I'm trying to control an infrared heater. It's supposed to take the difference between the temperature setpoint and actual temperature and output voltage to the controller of the heater accordingly. However, after it reaches that setpoint, it's supposed to hold that temperature for the X minutes (the case structure part). I just starting using LabView two weeks ago so I'm completely new to this. Everything I've learned has come off this website so if there's things that I need to fix on that VI please let me know, or if there is a better way to code something.

If this is what you're supposed to do, then that VI won't do it,as it is too simplistic. There are also a few logical issues.
  • You're subtracting the current temperature from the setpoint. This means this value can be positive or negative. You are then taking that difference and coercing it to be between 0 and 5 and using that coerced value as the voltage value to program. What happens when the difference is negative? Your VI will still set a voltage of zero (due to the coercion, meaning nothing changes.
  • There is an assumption in the code that the difference in temperature between the setpoint and the current reading is a direct 1-1 relationship to the voltage that you want to set. Is this true? If so, it seems that you can only tolerate a 5 degree difference. Again, due to your coercion. It seems to me that there is a linear relationship between temperature and voltage, and that slope is not 1.
  • You said that "after it reaches that setpoint, it's supposed to hold that temperature for the X minutes". You are checking to see if the difference is less than or equal to zero. This means if the reading is above your setpoint or exactly equal to it. Again, what if it's 20 degrees too high? What's your tolerance?
  • In the loop you are continuously setting the voltage, which is the difference between your setpoint and your current temperature reading. You are coercing the voltage to set to be between 0 and 5. But the only way you would have gotten in this case is if the difference is negative. So, you would always be coercing a negative value (meaning your temperature is above your setpoint) to zero.
  • The Elapsed Time has a "Time has Elapsed" output. This is what you need to look at. Set the Elapsed Time's "Time Target" to your "X" minutes (in seconds), and simply look at that output to stop the loop. Try it on its own in a simple VI to learn how to use that Express VI.
0 Kudos
Message 10 of 20
(3,842 Views)