08-18-2011 12:52 PM
I'm having trouble with a simple VI I wrote. I made a vi that is basically a pulse wave generator, with a specified amplitude, period and duty cycle. When I run the vi by itself, the voltage displays correctly. However, when I make a subvi and include it in a different project, the vi does not display the the proper voltage (it stays static at the specified voltage). Attached is the vi I have created. Is there something I have to do in order to display this voltage correctly? Thank you for your time.
08-18-2011 01:01 PM
Presumably you are expecting to be able to use the "voltage" output at the higher level. Well, that won't work. When the higher level VI calls this subVI, LabVIEW is sitting inside this subVI, and the top-level VI waits until the subVI has finished. Since you have a loop inside the subVI (and WORSE, it's an infinite loop WITH NO WAY TO STOP IT OTHER THAN TO PRESS THE ABORT BUTTON IN THE TOOLBAR), then the top-level VI will only see the value once the subVI has finished - i.e., the last value. Your loop should be in the higher-level VI, not the subVI.
This is a basic programming question.
08-18-2011 01:01 PM
A couple of pointers
08-18-2011 01:08 PM - edited 08-18-2011 01:13 PM
Edit: So basically what you guys are saying, it's going to finish the timing diagram completely, and then output that voltage at that point? Is that why only the final value is showing? What can I do to update it continuously?
08-18-2011 01:21 PM
@j00z wrote:
Edit: So basically what you guys are saying, it's going to finish the timing diagram completely, and then output that voltage at that point?
Yes
Is that why only the final value is showing?
Yes
What can I do to update it continuously?
That really depends on what you are trying to accomplish. What exactly are you trying to write? You could simply use one of the existing VIs to create a waveform. You could do the calculations at the higher-level VI. You could call this VI dynamically, and pass it the control reference for the indicator on the main VI that's supposed to be updated. You could ....
08-18-2011 05:22 PM - edited 08-18-2011 05:25 PM
Typically, your sub-vi will be within your "non-infinite" loop. If you just want it to execute once, wire a boolean constant true to the stop terminal; however, that negates the reason for having the while loop to begin with, doesn't it. I'm with Jeff, I don't know what your trying to accomplish with your Max Voltage. Wiring a control directly, or indirectly through a local variable, to an indicator makes no sense, and only use locals when necessary. Wires are always the best way to do it.
08-18-2011 05:44 PM
So with the max voltage, its just a matter of what the user wants in terms of maximum voltage. Essentially I'm trying to make a square wave that goes from 0 to the maximum voltage. I could of course change it to a constant voltage, but I just want that adaptability.
08-18-2011 06:32 PM
Understood, I just don't understand why you were feeding it into an indicators local variable.
08-19-2011 08:36 AM
The problem does not stem from turning your code into a sub vi. I'm afraid the code never made sense. It only appears to do what you intended it to do.
It does not create a rectangular wave at all. All it does is write zero and "Max Voltage" to an indicator alternately. If you observe this indicator ("Voltage") it SEEMS to display a rectangular wave, but it doesn't.
At any given time there is either zero or "Max Voltage" in the indicator - but there is never a wave in there. Actually a wave would have to be at least a 1D array of points, meaning it couldn't possibly be in the indicator as is.
Regards
Florian
08-19-2011 10:16 AM
If the value alternates between two values, inherently it will be a square wave. The change between the two voltages ideally cannot be instantaneous, and theres going to be a rise time and fall time.