Showing posts with label vi. Show all posts
Showing posts with label vi. Show all posts

Wednesday, August 18, 2010

Exercise 7 - Simple State Machine

Create a VI using state machine architecture that simulates a simple test sequence. The VI will have an initial state, where it will display a pop-up message indicating that it is starting the test.  Then it will proceed to the next case and then to the final state where it will ask the user whether to start over or end the test.

Front Panel
Rather than start from scratch, we will use a VI template to create our state machine.

1.      From the initial LabVIEW screen click on New…, and choose Standard State Machine, which is located under the VI from Template » Frameworks » Design Patterns heading.
2.      Examine the template, and then save it in another directory before you begin working on it.


Block Diagram

1.      Right click on the enum constant labeled Next State and select Open Type Def.
2.      On the front panel of the StateMachinesStates.ctl Type Def VI, right click on the States enum control and choose Edit Items.
3.      Add two more states.  Call them “State 1” and “State 2”
1.      Close the State Machines.ctl Type Def Front panel and save the control with the default name when prompted.
2.      Right click on the Case Selector Label of the case structure and choose Duplicate case.  Do this one additional time so that there are four cases: Initialize, State 1, State 2, and Stop.
1.      Change the value connected to the Wait function to 2000.
1.      Right click on the shift register on the left side of the while loop and create an indicator.  Change it’s name to “Current State”.
2.      In the “Initialize”, Default case place a One Button Dialog function and wire a string constant into the Message input.  Type “Now beginning test…” into the string constant.
1.      Change the enum constant labled Next State to “State 1”.
2.      Change to the next state in the case structure (“State 1”) and change the enum constant labled Next State to “State 2”.
3.      Change to the next state (“State2”) and add the following code.
a.       Place a Select function and connect two enum constants
(Tip:  Copy the enum constants from one of the previous cases)
Place a Two Button Dialog and wire create the constants as illustrated below.
14.      Run the VI.
15.      Save and close the VI.

End of Exercise



Exercise 4 - Analyzing and Logging Data

Complete the following steps to build a VI that measures temperature every 0.25 s for 10s. During the acquisition, the VI displays the measurements in real time on a waveform chart. After the acquisition is complete, the VI plots the data on a graph and calculates the minimum, maximum, and average temperatures. The VI displays the best fit of the temperature graph.

Front Panel
1.      Open a new VI and build the following front panel using the following tips.

·         Do not create the Mean, Max, and Min indicators yet.  Create them on the Block Diagram by right clicking on the functions and choosing Create Indicator.  Then position them on the Front Panel.

Block Diagram

1.      Build the following block diagram.

a.       Select Functions»All Functions»Select a VI… and choose Thermometer.vi (from previous exercise). 
b.      Place the Wait Until Next ms Multiple function located on the Functions»All Functions »Time & Dialog palette and create a constant of 250. Much like the Time Delay Express VI, this function causes the For Loop to execute every 0.25 s (250 ms). 
c.       Place the Array Max & Min function located on the Functions»All Functions »Array palette. This function returns the maximum and minimum temperature.
d.      Place the Mean VI located on the Functions»All Functions» Mathematics»Probability and Statistics palette. This VI returns the average of the temperature measurements.
e.       Right-click the output terminals of the Array Max & Min function and Mean VI and select Create»Indicator from the shortcut menu to create the Max, Min, and Mean indicators.
f.       Place the Write LabVIEW Measurements File Express VI located on the Functions»Output palette.  LabVIEW will automatically insert the From DDT function into the wire you connect to the Signals input.
3. Save the VI as Temperature Logger.vi.
4. Display the front panel and run the VI.
5. After pressing STOP a dialog box will appear.  Enter the name of the file to save the spreadsheet.
6. Open the spreadsheet file to make sure the file was properly created by using Notepad or by creating a VI to read the file as follows.
·         Create the following block diagram
·         Place the Read LabVIEW Measurement File Express VI located on the Functions»Input palette.
·         Configure the VI to ask the user to choose the file to read and change the delimiter to Tab
·         Right click on the Signals Output and choose create graph indicator
7. Run the VI
8. Save and close both of the VIs.

End of Exercise

Exercise 2a – Create a SubVI

Front Panel
1.      Select File»Open and navigate to c:\exercises\LV Intro to open the Convert C to F VI.
If you closed all open VIs, click the Open… button on the LabVIEW dialog box.
Tip Click the arrow next to Open… button on the LabVIEW dialog box to open recently opened files, such as Convert C to F.vi.
The following front panel appears.

1.      Right-click the icon in the upper right corner of the front panel and select Edit Icon from the shortcut menu. The Icon Editor dialog box appears.
2.      Double-click the Select tool on the left side of the Icon Editor dialog box to select the default icon.
3.      Press the <Delete> key to remove the default icon.
4.      Double-click the Rectangle tool to redraw the border.
5.      Create the following icon.

a.       Use the Text tool to click the editing area.
b.      Type C and F.
c.       Double-click the Text tool and change the font to Small Fonts.
d.      Use the Pencil tool to create the arrow.
Note To draw horizontal or vertical straight lines, press the <Shift> key while you use the Pencil tool to drag the cursor.
e.       Use the Select tool and the arrow keys to move the text and arrow you created.
f.       Select the B&W icon and select 256 Colors in the Copy from field to create a black and white icon, which LabVIEW uses for printing unless you have a color printer.
g.      When the icon is complete, click the OK button to close the Icon Editor dialog box. The icon appears in the upper right corner of the front panel and block diagram.
2.      Right-click the icon on the front panel and select Show Connector from the shortcut menu to define the connector pane terminal pattern.
LabVIEW selects a connector pane pattern based on the number of controls and indicators on the front panel. For example, this front panel has two terminals, deg C and deg F, so LabVIEW selects a connector pane pattern with two terminals.
3.      Assign the terminals to the digital control and digital indicator.
a.       Select Help»Show Context Help to display the Context Help window. View each connection in the Context Help window as you make it.
b.      Click the left terminal in the connector pane. The tool automatically changes to the Wiring tool, and the terminal turns black.
c.       Click the deg C control. The left terminal turns orange, and a marquee highlights the control.
d.      Click an open area of the front panel. The marquee disappears, and the terminal changes to the data type color of the control to indicate that you connected the terminal.
e.       Click the right terminal in the connector pane and click the deg F indicator. The right terminal turns orange.
f.       Click an open area on the front panel. Both terminals are orange.
g.      Move the cursor over the connector pane. The Context Help window shows that both terminals are connected to floating-point values.
4.      Select File»Save to save the VI because you will use this VI later in the course.
5.      Select File»Close to close the Convert C to F VI.

End of Exercise

Related Posts Plugin for WordPress, Blogger...

Popular Projects

My Blog List

Give support

Give support
Encourage Me through Comments & Followers

Followers