Presentation is loading. Please wait.

Presentation is loading. Please wait.

Digital Electronics and Computer Interfacing Tim Mewes 2. LabVIEW Basics part II.

Similar presentations


Presentation on theme: "Digital Electronics and Computer Interfacing Tim Mewes 2. LabVIEW Basics part II."— Presentation transcript:

1 Digital Electronics and Computer Interfacing Tim Mewes 2. LabVIEW Basics part II

2 Digital Electronics and Computer Interfacing2 2.1 SubVIs subVI

3 Digital Electronics and Computer Interfacing3 2.1 SubVIs A SubVI is a VI that can be used within another VI Similar to a subroutine Advantages –Modular –Easier to debug –Allows to effectively reuse code –Makes LabVIEW program code easier to read A SubVI needs: –An icon which represents it in other VIs –A connector that specifies the inputs and outputs (terminals) of the SubVI for data transfer

4 Digital Electronics and Computer Interfacing4 2.1 SubVIs Steps to create a SubVI:  Create the front panel and the block diagram of the SubVI  Create the icon of the SubVI  Define the terminals of the connector  Document the SubVI  Save the SubVI  Insert the SubVI into another VI

5 Digital Electronics and Computer Interfacing5 2.1.1 SubVI connector right-click on the SubVI icon on the front panel to open the short cut menu select “Show Connector” Connector becomes visible:

6 Digital Electronics and Computer Interfacing6 2.1.1 SubVI connector 1. Left click on connector terminal 2. Left click on control/indicator Repeat these steps with all controls and indicators needed. Assign controls to terminals on the left side of the connector. Assign indicators to terminals on the right side of the connector.

7 Digital Electronics and Computer Interfacing7 2.1.1 SubVI connector Right-click on connector terminal opens the short cut menu In case you need more or less terminals you can change the connector pattern You can also disconnect individual or all terminals

8 Digital Electronics and Computer Interfacing8 2.1.2 SubVI Documentation Use the properties dialog box to provide a description for all front panel elements that are assigned to connector terminals Select “File/VI Properties” from the pull down menu and choose “Documentation” from the Category pull down menu to provide a general description of the SubVI. This description will also be visible in the context help window ( +H).

9 Digital Electronics and Computer Interfacing9 2.1.3 Save the SubVI Save the SubVI in the user.lib directory, typically this is: C:\Program Files\National Instruments\LabVIEW 8.0\user.lib\ Creating Labview Libraries (LLB) in this subfolder can help to keep things organized Place related SubVIs in the same LLB Use descriptive and if possible unique names for your SubVI Note: After saving the SubVI it will not appear in the User Libraries sub-palette of the functions palette until you either Completely restart LabVIEW or Choose “Tools/Advanced/Edit Palette Set” from the pull down menu and select “Save Changes” – you can change the appearance of the sub-palette here if needed

10 Digital Electronics and Computer Interfacing10 2.1.4 Insert the SubVI into another VI Select your VI from one of the sub- palettes Place your SubVI on the block diagram Right-click on the block diagram and select “User Libraries” Wire the inputs and outputs of your SubVI as needed

11 Digital Electronics and Computer Interfacing11 2.2 Loop structures Loop structures are used to execute code multiple times While loop –Runs at least once –Stops according to the conditional terminal For loop –Executes the enclosed code exactly N times

12 Digital Electronics and Computer Interfacing12 2.2.1 While loop 1. On the block diagram right-click and select the “Structures” sub-palette 2. Select the “While loop”

13 Digital Electronics and Computer Interfacing13 2.2.1 While loop 1. On the block diagram right-click and select the “Structures” sub-palette 2. Select the “While loop” 3. Left-click on the block diagram and drag a rectangle – objects already present on the block diagram can be enclosed in the While loop. 4. Right-click on the conditional terminal and select “Create control” 5. Add additional objects as needed and drag them into the loop Iteration terminal (i): counts how often the loop has been executed, starting from 0

14 Digital Electronics and Computer Interfacing14 2.2.2 For loop 1. On the block diagram right-click and select the “Structures” sub-palette 2. Select the “For loop” 3. Left-click on the block diagram and drag a rectangle – objects already present on the block diagram can be enclosed in the For loop. 4. Right-click on the loop count (N) terminal and select “Create constant” 5. Add additional objects as needed and drag them into the loop Iteration terminal (i): counts how often the loop has been executed and ranges from 0 to (N-1)

15 Digital Electronics and Computer Interfacing15 2.2.3 Shift registers 1. Right-click on the border of the loop structure 2. Select “Add Shift Register” from the short cut menu 3. The shift register appears in black (no data type) 4. Wire the shift register on the left side (arrow down) from outside the loop – this defines the data type and the initial value used in the loop. 5. Wire the inside of the loop – the value to be used in the next iteration needs to be wired to the shift register on the right side (arrow up) 6. Wire the outside of the loop – the terminal on the right side now holds the last value stored in the shift register Shift registers work with any data type and with any loop structure Use shift registers if you want to pass values from previous iterations of the loop to the next iteration

16 Digital Electronics and Computer Interfacing16 2.2.4 Stacked shift registers 1. Create a shift register 2. Right-click the left shift register (arrow down) and select “Add Element” from the short cut menu 3. An additional shift register appears 4. Wire the shift registers as needed Now values from the last two iterations (i-1) and (i-2) carry over to the next iteration, with the most recent iteration value stored in the top shift register. By using “Add Element” multiple times you can add more stacked shift registers and thus can use values of earlier iterations.

17 Digital Electronics and Computer Interfacing17 2.2.5 Loop tunnels 1. Drag a wire across a loop boundary This creates a loop tunnel The input value present at the start of the loop will be used in all iterations Only the last value present at the end of the loop gets transmitted out of the loop Arrays have more options for loop tunnels…

18 Digital Electronics and Computer Interfacing18 2.3 Arrays Arrays (sometimes also called vectors or lists) hold a series of data elements of the same data type Arrays can be multidimensional Examples: Array of 5 numerical data elements: Array of 7 Boolean data elements: Two-dimensional array of 3x3 numerical data elements:

19 Digital Electronics and Computer Interfacing19 2.3.1 Adding arrays manually to the front panel 1. Right-click on the front panel and select “Array” from the “Array, Matrix & Cluster” sub-palette 2. Drop it on the front panel 3. Select the control/indicator you need as an array and place it in the array shell example: numeric control Don’t forget to give it a meaningful name!

20 Digital Electronics and Computer Interfacing20 2.3.2 Building arrays using loops The loop on the left generates 10 random numbers – it would be nice to get all of those numbers in an array… 1. Drag a wire to the loop boundary 2. The output tunnel has square brackets in it, which indicates that auto-indexing is enabled and that an array is generated at the loop boundary. 3. Create an indicator by right-clicking on the loop tunnel You can disable auto-indexing by right-clicking on the loop tunnel – this way only the last value of the loop is transmitted out and no array is generated.

21 Digital Electronics and Computer Interfacing21 2.3.2 Building arrays using loops - 2D arrays thin wire: one value thick wire: 1D array wire with white center: multidimensional array

22 Digital Electronics and Computer Interfacing22 2.3.3 Build array function When first placed on the block diagram the build array function has only one input and output Use the resize cursor at the upper or lower boundaries and increase the size of the build array function to the required input number Can be used to append elements or entire arrays to another array

23 Digital Electronics and Computer Interfacing23 2.3.3 Build array function Right-click node and select “Concatenate Inputs” from the shortcut menu.

24 Digital Electronics and Computer Interfacing24 2.4 Case structure Executes one of different possible cases, based on the value wired to the selector terminal Use the arrows to edit the different cases

25 Digital Electronics and Computer Interfacing25 2.4 Case structure Integer values can also be used as an input of the selector terminal The “Default” case will be executed if the input does not match any of the defined cases. Right-click on the border of the case structure to add/remove cases.

26 Digital Electronics and Computer Interfacing26 System Controller Feedback-loop outputinput

27 Digital Electronics and Computer Interfacing27 Room LabVIEW program Temperature controller output: Temperatureinput: heater power


Download ppt "Digital Electronics and Computer Interfacing Tim Mewes 2. LabVIEW Basics part II."

Similar presentations


Ads by Google