LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement for loops (or any loops) to repeat commands for GPIB instrument

I'm a beginner to labview and would greatly appreciate suggestions or advices.

I have a GPIB device that is used to measure voltage and currents of a DC source. I want to send a set of commands: 1)set device voltage = 0 (Vd(i)=0) 2)measure source voltage 3)measure source current 4)Store measurements 5)Compare source voltage to a value of 20. 6)If source voltage is less than 20, increment device voltage by 1 and increment the index of device voltage, and repeat. If source voltage is 20, stop.

This is the part that I can't figure out: After comparing a source voltage, the result is a Boolean (true or false). How do I use boolean result to start a loop (and what type of loop) to repeat the commands?

Newbie
0 Kudos
Message 1 of 7
(3,487 Views)
A while loop and a shift register is all that's needed. Start by initializing the shift register to the first source value, increment inside, and then terminate the while loop when the limit is reached. Here's a picture that explains what I mean.
Message 2 of 7
(3,480 Views)
You probably want a 'while' loop for this. With all the commands you described in your post inside the while loop, right click the loop and select 'stop on true'. Then wire the boolean output of your x=20? comparison to the Stop icon inside your while loop. Unless the voltage is equal to 20, the loop won't stop but keep repeating.
You can use the 'i' icon inside your while loop to keep track of incrementing your device voltage, or use a shift register, which will remember what you set the device voltage to in the previous loop. Search 'shift register' in LabVIEW help or Examples under the Help menu.
Message 3 of 7
(3,476 Views)
I am already using a While Loop that "houses" all my commands to run for an hour. The set of commands posted on my original message is just a portion of what I'm trying to do. Is it possible to have a While Loop, within a While Loop?
0 Kudos
Message 4 of 7
(3,462 Views)
Yes.
- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 7
(3,458 Views)
Thank you everyone for your help. I think I am one step closer to understanding loop functions.

I have another question that expands from my original posting. Instead of stopping at x=20, I want to trigger a sub-loop routine (if that makes sense). I have 'case structure' floating in my head but know do not know how to connect and place within my while loop. I don't feel that I am heading in the right direction using 'case structure'.

Newbie
0 Kudos
Message 6 of 7
(3,426 Views)
I'm not sure what you mean by a sub loop routine, but if you mean a subroutine (or subVI in LVspeak) within the loop, a case structure is what you want. To take Dennis's picture as an example, take the boolean value coming out of the "Greater or Equal" VI and wire it into the selector of a case structure. Then, put your code inside the True case. Keep in mind that you will still need to have some sort of condition for stopping the loop and that if you only want your new code to execute once, you should replace the "Greater or Equal" VI with "Equal". If you do want the loop to end and the code to execute after the loop ends, you need to place the new code outside the loop and force it to run after the loop ends. You can do this by wiring something coming out of the loop (like the stop condition) into the case structure, or you can artificially impose this by using a sequence structure.
To learn more, I suggest you try searching this site and google for LabVIEW tutorials. Here is one you can start with. You can also contact your local NI office and join one of their courses.

Message Edited by tst on 03-15-2005 12:11 PM


___________________
Try to take over the world!
0 Kudos
Message 7 of 7
(3,424 Views)