39
1 Sate Machine Application Design A- Menu VI Build menu system for a sample application Front Panel 1- open a new VI 2- place a cluster control 3- place Boolean button (OK button) (just one for now) 4- Set the button’s mechanical action to Latch When Released (right click and change) – however, do it from properties so the preview is seen before making the choice. 5- Copy and paste to create the remaining buttons The user basically clicks a button in the cluster to trigger an application in the state machine 6- make sure the order of the elements in the cluster is as shown. Block Diagram

profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

  • Upload
    haliem

  • View
    217

  • Download
    2

Embed Size (px)

Citation preview

Page 1: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

1

Sate Machine Application Design

A- Menu VI

Build menu system for a sample application

Front Panel1- open a new VI2- place a cluster control3- place Boolean button (OK button) (just one for now)4- Set the button’s mechanical action to Latch When Released (right click and change)

– however, do it from properties so the preview is seen before making the choice.5- Copy and paste to create the remaining buttons

The user basically clicks a button in the cluster to trigger an application in the state machine

6- make sure the order of the elements in the cluster is as shown.

Block Diagram

1- place a while loop on the block diagram to enclose the cluster and create a shift register2- place a numeric constant to the left of the loop and set its value to -1. Connect the

constant to the shift register – this is to initialize the state machine to start at the default state.

3- Place a case structure in the while loop. The case structure creates the states for the state machine. Wire as shown. Add 4 more cases to the case structure.

4- Go back to the default case and do the next steps.

Page 2: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

2

5- Place a wait until so the loop executes 10 times a second.6- Place the cluster to array function to convert the cluster of Boolean buttons into an array

of Boolean data types. This way the Boolean object at cluster order 0 becomes the Boolean element at array index 0 and so on.

7- Place the search 1D array function and a True constant on the block diagram8- Wire the True constant to the element input of the search 1D array . Also wire the

cluster to array to the array input of the search 1D array. This allows the function to search for a T value in the Boolean array that cluster to array returns. A true value of any element implies that the corresponding button was clicked. The function returns a value of -1 if no button is pressed.

9- Connect a False constant to conditional terminal of the while loop.

Page 3: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

3

10- Select the 0 from the case structure and put the one button dialog function on the block diagram – right click it and select Create Constant to create a string constant. Enter the exact string Login State. Wire a -1 to the case structure tunnel and a False constant to the conditional terminal. Next to the -1, place the comment: Next State: -1 (No Event)

11- Repeat step 10 for cases 1, 2, 3. the following string constants in order are:: Acquire Data State, Analyze Data State, View File State, and for case number 4 do the following: wire a -1 to the case structure tunnel and place the comment Next State: -1 (No Event) also place the comment Stop the VI. Also wire a True constant to the conditional terminal.

A summary is shown:

Page 4: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

4

Page 5: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

5

Create a subfolder and name it ApplicationSave the VI as Menu in the application folder. Run the VI

Page 6: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

6

B- Acquire Data VI

Goal: Build a VI that acquires, analyzes, and presents data while using error handling techniques.Acquire Data VI

1- close all LabVIEW VIs2- open a new VI and build the following front panel3- make sure you adjust the scales for the waveform graphs in properties>. scale &

>>format and precision

4- build the block diagram shown (NOTE: the sampling info is added on the block diagram next)

The sampling info is added as : create>>control at the sampling info of the “sine waveform.vi”

Page 7: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

7

The front panel should look like this

Page 8: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

8

run it and watch the time and frequency plots.

Save the VI as:Acquire Data in the application folder.

C- Enhance Acquire Data VI

The goal here is to modify a VI to use tab control along with proper user interface design techniques.

1- Open the Acquire Data VI2- Place a horizontal smooth box decoration on the front panel. Place the three dials, the

sampling information cluster, and the stop button on the decoration3- Place a tab control (located in the containers palette) on the front panel. Select the time

waveform graph and place it on the first page of the tab control4- Name the two pages of the tab control Time Domain and Power Spectrum,

respectively.5- Click the Power Spectrum page and add the power spectrum graph to the page.

The following is what you should have so far on the block diagram.

Page 9: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

9

6- Create an icon for the VI7- Create the connector pane and select the pattern with two inputs and one output. Connect

the output to the Time Waveform graph (do not connect anything to inputs)8- Save the VI in the application folder as: Enhanced Acquire Data9- Open the block diagram and modify it as shown:

And the other case:

Page 10: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

10

Note, using the case structure enhances the performance. This is the case since the Power Spectrum operations are only performed when called for.

10 – display the front panel and run the V. Adjust the controls to change the time and frequency waveforms.

11 Make sure tht each of the inputs has a valid nonzero values then >>operate>>make current values default12- Save the vi (after having shrunk the window around the needed items in the block diagram.

Page 11: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

11

D- State Machine with Enhanced Acquire Data

The goal is to add the Enhanced acquire data VI to the state machine application of Part A. Read instructions carefully

1- Open the menu.vi in your application folder2- Open the block diagram3- Display case 1 of the Case structure and delete the One button Dialog function. Add the

Enhanced Acquire Data.VI that you created in part C.

4- Add a shift register to the border of the while loop. Connect the Time waveform output of the Enhanced Acquire Data.VI to the right side of the shift register.

5- Initialize the new shift register you created a. Right click the left side of the shift register and select create>>control to create an

empty Time Waveform control on the front panel.b. Hide the waveform control by right clicking the terminal and selecting Hide

Control. This will prevent confusion to users on the front panel.6- Modify the VI properties of the Enhanced Acquire Data VI so that it appears like a dialog

box when it is called.a. Double click the Enhanced Acquire Data VI to open its front panelb. Select File>>VI Properties>>Window Appearance>>then select Dialog Optionc. Click OK then save and close the Enhanced Acquire Data VI

7- Now, recall, if one case in the Case structure passes data out of the case, then all other cases in the case structure must also send out data. Finish wiring the VI so that the data passes through all other cases unchanged. Make sure that the data passes through other cases correctly (see below)

Page 12: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

12

8- Save AS State Machine With Enhanced Acquire Data.VI in the application folder9- Display the front panel and run the VI

E- Prior to continuation with The State Machine, we must pause to address Object Properties

Complete the following:

Page 13: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

13

Object Properties

START a blank VI

Objectives:- To understand Property Nodes – some review of previous lecture- To understand Graph and Chart properties- To understand how to use control references- To understand how to use LabVIEW type definitions

Property Nodes

The motivation: Think of instances where you would like to see the front panel’s object appearance change due to certain inputs or commands. For example, you may want the graph area to be cleared every time the program starts. Or for another example, you may want a red LED to start blinking if an invalid data is entered. Or maybe want the chart trace colors to change to red if the temperature exceeds a threshold level! In addition, can resize or hide front panel objects.

LabVIEW reference manual has tremendous information on property nodes. In this work we will simply practice changing appearance and functions of a front panel object.

- In order to create a property node, right click an object>>create property node. Can create multiple property nodes for the same object.

- once you create a property node, you can change it to read or write property- may add a terminal to a property: right click on the property node and select

add element. Then you may associate each property terminal with a different property from the short cut menu.

Let us do this:1- create a numeric control on the front panel.2- on the block diagram, right click the object>>create>>property node>>select Class ID as

shown:

3- Using the operating tool, click on the word “ClassID” and select Visible4- change the property node to a Write 5- right click on the input terminal node to the property node and select create control

Page 14: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

14

6- on the front panel you should see the Boolean control and the numeric control

7-8- run the vi with the switch ON, the numeric control disappears.9- Note: if you placed a numeric constant (False) to the input of the property node, the user

will not be able to see the numeric control on the front panel.

10-11-12- Practice the above.

13- Create a Boolean control on the front panel 14- on the block diagram, right click>>create>>property node>>position>all positions15- right click the position item and change to read

16- expand the item to show left and top choices17- collapse the item to show only position18- on the front panel, place two dial controls – call them left and top19- right click each of the controls and change the representation to I32

20- change the max scale to 50021- complete the following on the block diagram

Page 15: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

15

22-23- run the VI and see how you can move the object

24-25- The last practice proves the idea that property nodes execute each terminal in order –

from top to bottom. 26- Start a new VI and place a dial control on the front panel27- on the block diagram, select the visible property node28- expand the property node as shown

29-30- while the context help is on, move over each of the items and read the help on it.31- What is “Disabled Property”32- This property writes or reads the user access status of an object. a value of 0 enables an

object so a user can operate it. a value of 1 disables the object and the user cannot operate it.a value of 2 disables and dims the object.

33- let us practice the above:34- create a numeric control on the front panel

Page 16: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

16

35- on the block diagram create the following36- change the constant to 0, then 1, then 2 and see how you can change control, cannot, and

dimmed.

37-38- The Key focus property: This reads or writes the key focus of a front panel object.

When true, the cursor is active in the associate object. In most controls, you can enter values into the control when you type them on the keyboard.

39- create a numeric control on the front panel (in a new blank vi)40- on the block diagram create the following41- now on the front panel, you can change the numeric control values by typing them with

keyboard

42-43- Blinking Property: do the following in a new vi. When you run it, if the value chosen is

less than 0, the numeric control will

blink44- Value Property: The value property writes or reads the current value of an object. When

the value property is set to write, the value is written to an object no matter f the object is control or indicator .. this can be very useful in programmatically modifying a control value. likewise, if the value property is set to read, the value in the object is read from an indicator or a control.

45- let us write a numeric value to a control and read a string value and write it to another.

Page 17: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

17

46- A constant value is written to a numeric control. The string in a control string is written to an indicator string

47-

48-49- The Bound property: This property reads the boundary of an object on the front panel in

the units of pixels. The value includes the control and all of its parts (including label, legend, scale, and so on..) the property consists of a cluster of two unsigned long integers width in pixels and height is pixels. This property is a read only

50- let us determine the bounds of a numeric control51- in a new blank vi, create a numeric control52- on the block diagram, create a bound property node, unbundle by name, connect

indicators as shown. run it and see the dimenstons. change the control size and run again.

53-

54-55- Numeric Property – format and precision: it sets the format – type of notation, and the

precision – the number of digits displayed after a decimal point of a numeric front panel object. The input is a cluster of unsigned byte integers.

Page 18: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

18

56- let us set the format to an SI notation and the precision to 5 digits. (note: floating point is 0, scientific is 1, SI is 2) I think ! – double check

57-

58-

Property Node Practice -1 (complete it, save to demo to me) this will allow us to build a VI where some characteristics of front panel objects are manipulated.

1- build the following front panel VI

2-3- complete the following block diagram

Page 19: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

19

4-5- This item: is found under “ color box constant” in functions palette>>dialog6- for the tank property node, do the following:7- create a property node>>ClassID, expand it to show three items (do not mind the heading

here, for some reason when I copy and paste, the heading changes !)

8-9- now, use the operating tool, click on classID and select FillColor, click on the next item

(OwingVI) and select position>>all elements, click on the last item and select Disabled

10-11-12- now right click on the property node and select “ change all tow write”

13-14- Run the VI and see some of the features.

Graph and Chart Properties:one can use the property node to manipulate most graph features such as plot, background, grid colors, x,y scale info such as min, max, and increment, the legend whether visible or not, the size of the plot area, cursors, zoom.

Page 20: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

20

Let us take a graph and set the x-axis range from 10 to 110 with a major x-axis increments of 20 and a minor x-axis increments of 2.

1- place a waveform graph on the front panel2- create a property node on the bloc diagram>>X Scale>>range>>all elements3- change to write4- right click on the input node to the property node and create constant5- modify the values and enter the text shown

6-7- run the vi8- here is the resulting graph scale – just like wanted!

9-10-11- Active cursor, cursor position, and cursor index properties set or read the active cursor,

the position of the cursor on the graph, and the index (x-axis position) in the plot. The cursor position is a cluster of two floating point numbers representing x and y positions on the plot.

12- plot area property: to read or change the size of a graph.13- let us practice resizing a graph to increase its width to 5 times and height to 3 times14-15- create a waveform graph on the front panel. size it to small

Page 21: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

21

16-17- complete the following on the block diagram

18-19- run and notice the size change

Property Node Practice -2

Temperature limit VI. This is to create a VI that clears waveform chart and then notifies the user whenever the data exceeds a limit. This is done using property nodes.

1- Download, uncompress, and open the temperature limit VI (UNSOLVED) found on my web site under LabVIEW items. Uncompressed it. (save it and open it with LabVIEW) There should be total of three Vis. Save in the application folder

2- open the block diagram3- (Steps given below) Modify the VI so that the delta X value is set to the sampling rate

and so it also clears the chart prior to start. During the acquiring of data, the VI should turn the high limit trace red whenever the temperature goes above the limit value. In addition, the out of range indicator should blink:

a. create a property node for the temperature chart, and select as follows:i. x-scale>>offset-and multiplier>.multiplier

ii. place in the sequence portioniii. expand to see another item in the property nodeiv. click in the second item, from the choices, pick the history datav. change all to write

Page 22: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

22

vi. in order to clear the chart, send an empty array of data to the history data property. right click on the history node and choose create constant. make sure the constants are empty

vii. you should have this nowviii.

ix. in the case structure create a property node for the temperature chart and make sure it has two terminals: Create the Active Plot Property and the Plot Color Property

x. Since the high limit plot is plot 1, set the active plot property to 1 before setting the plot color property. Send the color constant block to the Plot color property as shown:

xi.

4- for the “False “ case, repeat – remember, connect the active plot property first, then the plot cooler property

5- the false case is shown below

Page 23: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

23

6-7- Right click on the out of range LED and create the blink property (the LED will blink

whenever the temperature is above the high limit) connect as shown

8-9- complete the sample rate limit in the sequence structure by connecting the divide output

to the Xscale multiplier in the property node10- save the VI as Temperature Limit.vi in your application folder.11- Copy the thermometer VI you have created earlier in the course into the application

directory. You may have to scale the values so that is works fine with this new vi. run the vi and confirm the operation. (note, this VI uses your thermometer vi you created earlier) make sure the random number multiplier is such a value that will allow the over the limit to occur every once a while.) Make sure this VI is in the same directory as the one you are to run. You may want to use the thermometer vi on my web site in case the one you had is lost or needs lots of work.

run and enjoy

Page 24: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

24

1- The latest work you have done is: The Temperature Limit Example (above – Property Node Practice 2)

2- The latest State Machine VI you should have completed is: State Machine With Enhanced Acquire Data” (Item D above)

3- NOTE: If you have issues with your VI thus far or if you want to ensure you have the correct items, please download the VI State Machine With Enhanced Acquire Data from my web site. Save in your application folder.

4- Also, may want to download the solved version of the Temperature Limit vi. Save in your application folder.

Page 25: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

25

F- Analyze & Present Data VI

Objective: Create a VI in which you use graph cursors to select a subset of data for analysis.

1- Open the Analyze & Present Data VI found on my web site (on the course’s main page) Save, extract the files and move the three VIs to your application folder.

2- Use the two cursors in the plot window to select a subset of data to analyze. A cursor can move freely or be locked to the plot. You control this action using the Lock control button at the right side of the cursor display. Use the cursors that are locked to the plot. When the user clicks the Analyze Select Button, the VI reads the location of each cursor and uses this information to find the DC, RMS, Frequency, and amplitude values of the subset data.

3- Block Diagram:4- Open and complete the following block diagram as follows:

(many of these steps are already done – but go over them to make sure you understand)

5- Right click the data terminal and select Create>>Property Node to create the data property node. Resize the property node to four terminals. Right click the node and select the Active Cursor and Cursor>>Cursor Index properties from the property menu. Right click each Active Cursor property and select Change to Write from the short cut menu. Note, the property node executes from top to bottom. The property node selects each cursor individually and returns the index of each cursor.

6- Place the Max&Min function. This function helps determine the beginning and the ending index of the cursor locations.

7- Place the Extract Portion of Signal Express VI, located in Signal Manipulation palette, on the block diagram.

8- Complete the following steps to configure the dialog window for the vi as shown:

Page 26: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

26

9- Place the Amplitude and Level measurements Express VI, located in Signal Analysis palette.

10- Configure the dialog window as shown:

Page 27: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

27

11- Place the Tone Measurements Express VI and configure the VI as shown:

Page 28: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

28

12- Place the Feedback Node, located on Functions>>All Functions>>Structures palette, on the block diagram. Feedback node transfers values from one loop iteration to the next (like shift registers)

13- Wire the cluster constant on the left of the while loop to the Feedback node initialize terminal.

14- Place the bundle by name and expand to show 5 inputs. Complete wiring15- Finish the VI so that the data passes from the Feedback Node unchanged through other

cases. Make sure the other cases in the structure pass data correctly. As shown:

16- Save the VI as: Analyze & Present Data.VI in the application folder.17- Display the front panel and run the VI Move the cursors along the graph to select a

subset of data to anakyze and click Analyze Selected Subset button. The results will appear at the right in the Analysis Results. When finished, click Return

18- Close the VI

G- State Machine with Analyze and Present Data VI

To add Analyze & Present Data VI you created above to the State Machine Application

1- Open the State Machine with Enhanced Acquire Data VI you created earlier in the application. The Front panel is already done.

2- Open the block diagram and Display Case 2 of the Case Structure and delete the One Button Dialog function. Use Select VI to navigate the Analyze & Present Data VI

3- Wire the waveform containing the collected data to the Data input

Page 29: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

29

4- Save the file as: State Machine with Analyze & Present Data.vi in the application folder

5- Display the front panel and run the vi. Make sure you can acquire data and analyze the selected date

6- Stop and close

H- Analyze and Present Data with Type Definition (TypeDef) VI

In the application you are developing, you want to build around a program architecture that includes the ability to easily edit the code in the future. Because the Analyze & Present Data VI uses a cluster to store the analyzed data, the complexity of editing the code increases. In this practice you will convert the cluster constant and cluster into a strict type definition to allow you to easily add new data items to the cluster in the future without having to rewrite the code.

Front Panel1- Open the Analyze & Present Data VI (not the state machine …) you completed

earlier.2- Right click the border of the cluster in the Analysis Results as shown below and

select Advanced>>Customize to open the cluster in the Control Editor.

Page 30: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

30

a. In the TypeDef. Status pull-down menu, select TypeDef. For the type definition

b. Select File>>Save and save the type definition as Extracted Data.cti in the application folder

c. Close the control editor. When prompted to replace the current control with the newly created control, choose YES.

3- Block Diagram4- Display the block diagram and replace the cluster constant wired to the Feedback

node Initializer terminal with the custom control as follows: Right Click the border of the cluster constant, select Replace>>All Functions>>Select a VI from the short cut menu, Select the Extracted Data.ctl

5- When you modify the type definition custom cluster, all other clusters connected to it automatically update.

6- Add a string indicator to the type definition custom cluster as follows:a. Right Click the cluster constant and select Open Type Def to open the

Extracted Data.ctl

Page 31: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

31

b. Add a string indicator to the cluster as shown and label it Operatorc. Slect File>>Save to save changes to the controld. Select File>>Apply Changes to update all controls and constants that are

connected to the type definitione. Close the control editor

7- Notice now that a string indicator has been added to the cluster constant wired to the feedback node initializer terminal on the block diagram.

8- Display the Front Panel and notice that a string indicator has been added to the cluster indicator.

9- Display the block diagram and resize the bundle by name function to add an input for the operator string. Right click the input and select Create >>Control. The following block diagram should result.

Page 32: profsalim.comprofsalim.com/Courses/EET420/Sate Machine Application Design.docx · Web viewUsing the operating tool, click on the word “ClassID” and select Visible. change the

32

10- Display the front panel, Add the Operator Control to a terminal on the connector pane as an input

11- Later on, information will be passed about the operator into this VI.12- Save and close the VI