08-13-2011 02:57 PM
Hello,
As you can see in the attached picture, I have a sequence structure that reads voltage from a physical channel in successive frames. The idea is to read the voltage, wait, some time, and read it again, and follow with some calculations based on the difference between voltage 1 and voltage 2. (I realize that there is no WAIT function installed yet, so, please just don't pay attention to the interval between readings for purposes of this question.)
In the attached screenshot, you can see that I have one physical channel wired to the voltage readers in both frames of the sequence structure. Is this a better way that wiring a separate physical channel in each frame? Obviously, I am hoping for the most efficient/fast code possible.
Thanks,
Dave
08-13-2011 03:22 PM
The better way is to use a looping structure for the repeated parts of the code. For the type of process which you describe a state machine architecture is much more versatile, robust, and easier to maintain or modify. The sequence structure is generally not a good way to do something like this.
A state machine for your process might have an Initialize state which contains all the configuration information, a Read state to read voltages from the DAQ device, a Wait state, and other states for analysis and saving the data, and a Shutdown state to close the DAQ tasks. Look at the examples and search for state machine on the Forums.
Lynn
08-13-2011 03:41 PM - edited 08-13-2011 03:43 PM
Lynn, I if I use a looping structure, how do compare the succeeding voltage values. E.g. I want to achieve
1.) Measure V1, then V2,
2.) Do V2-V1,
3.) Measure V3
4.) Do V3-V2
5.) Measure V4
6.) Do V4-V3 etc....
With the sequence structure, I can do these succesive measurments. How do you use a looping structure to compare successive values without the sequence structure? The loop measures only one value, unless there is a sequence structure inside the loop structure.
Thanks,
Dave
08-13-2011 03:48 PM
Use a shift register to pass the value from the previous iteration to the current one.
If you have not done so, look at the on-line tutorials about LabVIEW. They cover a lot of basic information.
Lynn
08-13-2011 05:15 PM
@dav2010 wrote:
Lynn, I if I use a looping structure, how do compare the succeeding voltage values. E.g. I want to achieve
1.) Measure V1, then V2,
2.) Do V2-V1,
3.) Measure V3
4.) Do V3-V2
5.) Measure V4
6.) Do V4-V3 etc....
With the sequence structure, I can do these succesive measurments. How do you use a looping structure to compare successive values without the sequence structure? The loop measures only one value, unless there is a sequence structure inside the loop structure.
Thanks,
Dave
You can accomplish all of this with a state machine architecture. Using shift registers as storage locations will allow you to read them back in other states (cases). You can stack the registers for multiple measurements. You can also use functional global variables to store these values and calculations into an array for later retrieval as well. Lynn is correct, for this type of application, a sequence structure is not the best method. A state machine is much more versatile and flexible, giving you the ability to control program flow based on conditional results. You don't have this ability with a sequence structure. You would have to add additional unnecessary coding to your sequence in order to bypass what does not need to be executed.