Lab-01-ENG.pdf
-
Upload
blid-razvan -
Category
Documents
-
view
214 -
download
0
Transcript of Lab-01-ENG.pdf
-
8/16/2019 Lab-01-ENG.pdf
1/16
Lab no. 1 – Solving the quadric equation
Defining the problem
You have to build a Virtual Instrument (VI) that displays the roots of a quadratic (equation)
and indicates if those roots are real or not. The coefficients of the equation (a, b and c) will bespecified by the user.
Description of virtual instrument
The user will use three Horizontal Pointer Slide elements to specify the values of the three
coefficients (a, b, and c) of the equation. The a, b and c coefficients can take integers valuesbetween [-10, 10]. The Horizontal Pointer Slide elements will have visible digital displays.
Virtual instrument will display numerical values representing the roots of the equation X1 andX2 as numerical indicator elements.
Virtual instrument will signal by lighting a red Round LED and will display the message "NaN" through the X1 and X2 numerical indicator elements if the equation has not real solutions.Round LED Boolean indicator turns green if the equation has real solutions.
Front Panel example
Fig. 1.1. Front Panel example
-
8/16/2019 Lab-01-ENG.pdf
2/16
Indications
Complete the following steps to launch a LabVIEW program: START ProgramsNational Instruments LabVIEW … (figur e 1.2).
Fig. 1.2. Launching LabView
The Getting Started window, shown in Figure 1.3, appears when you launch LabVIEWprogram. Use this window to create a new VI (click the Blank VI link in the New section).
Fig. 1.3. The Getting Started window
-
8/16/2019 Lab-01-ENG.pdf
3/16
When a new Virual Instrument will open, LabVIEW displays two windows: the Front Panelwindow and the Block Diagram window. The Front Panel appears with a gray background
and the Block Diagram window appears with a white background (figure 1.4).
Fig. 1.4. The Front Panel window and the Block Diagram window
For defining the coefficients a, b and c of the equation, you have to add three numericalcontrol elements - Horizontal Pointer Slide – from the Front Panel (right-click on the FrontPanel select Modern menu from Controls Palette select Numeric Numeric control
Horizontal Pointer Slide) (figure 1.5). You have to click on the Horizontal Pointer Slide
element and after you can place it on the Front Panel and type the name a. Then repeat thesteps for defining the other coefficients b and c or you can copy twice the Horizontal PointerSlide who you just added on the Front Panel pressing CTRL + left button mouse and
dragging down the element and then you can rename elements, b respectively c (figure 1.5).
Fig. 1.5. Numeric control elements
The specified values by the user for a, b and c have to be integers. For setting this, right-clickover the element a and then select Representation Byte (figure 1.6).
-
8/16/2019 Lab-01-ENG.pdf
4/16
Fig. 1.6. Representation numerical values
The numerical values have to be included into the range [-10, 10]. In this order, you canselect option Data Entry from the contextual menu of the Horizontal Pointer Slide element,
and then you can uncheck Use Default Limits option from the window which appears.
Complete the Maximum, Minimum and Increment values like in figure 1.7.
Fig. 1.7. Configuration of the numeric control elements
The user should also specify the values for the a, b and c coefficients by typing values intodigital displays of the three Horizontal Pointer Slide elements. For making digital displays to
be visible you should selects Visible Items - Digital Display option from the contextual menu
of the elements (figure 1.8).
-
8/16/2019 Lab-01-ENG.pdf
5/16
Fig. 1.8. Showing digital display
The output data of the program represented by numerical solutions of the equation X1 and X2
(the roots) can be defined in the Front Panel by right-click mouse on the Front Panel Controls Palette Modern Numeric Numeric indicator ) (Figure 1.9).
Fig. 1.9. Adding numeric indicator elements
The other output data of the program is a led which will indicate if the equation’s roots are realor complex. For defining the led you have to add a Round LED element on the Front Panelgo to Controls Palette Modern Boolean Round Led) (figure 1.10).
-
8/16/2019 Lab-01-ENG.pdf
6/16
Fig. 1.10. Adding Boolean indicator element
The Front Panel of the virtual instrument for solving of the quadric equation is shown in figure
1.11.
Fig. 1.11. The Front Panel of the virtual instrument
After the Front Panel is done the next step is to build the program’s algorithm in the Block
Diagram.
When the control or indicator elements are added on the Front Panel, the terminals of the
elements appear on the Block Diagram (figure 1.12).
-
8/16/2019 Lab-01-ENG.pdf
7/16
Fig 1.12. Terminals of the elements
For the calculation of the solutions X1 and X2 of the equation, according with a, b and c
values, you must add the functions which will be used for calculus and then you must wire theelements together for building the data flow of the virtual instrument. The relations that will be
used are the following:
(1.1)
√
(1.2)
√
(1.3)
For the calculation of the discriminant Delta value, first, you must calculate b2 value.The multiply function will be added on the Block Diagram (right-click mouse on the BlockDiagram , from Functions Palette select Programming menu Numeric Multiply) and
then you have to wire objects together (figure 1.13).
-
8/16/2019 Lab-01-ENG.pdf
8/16
Fig. 1.13 . Multiply function
For calculating the term 4ac you can use Compound Arithmetic function (right-click mouse
on the Block Diagram , from Functions Palette select Programming menu Numeric Compound Arithmetic) (figure 1.14).
Fig. 1.14. Adding Compound Arithmetic function on Block Diagram
Compound Arithmetic function has two input terminals available by default, which allows the
calculation of the two numerical values. To manipulate three terms (inputs) you have to dragthe lower border and add another input of the Compound Arithmetic function (Figure 1.15).
Fig. 1.15. Adding input terminals to the Compound Arithmetic function
By default, Compound Arithmetic function performs the operation of addition. To change itto multiply select from the context menu of the function the Change Mode option and click onMultiply (Figure 1.16). Then wire terminals in order to calculate the 4ac result.
-
8/16/2019 Lab-01-ENG.pdf
9/16
Fig. 1.16. Compound Arithmetic fuction
Using Subtract function (that is available in Functions palette, Numeric menu) you will
calculate Delta value, according to relation 1.1 (figure 1.17).
Fig. 1.17. Subtract function
If the Delta value will be greater than zero, the equation will have real solutions. Use theGrater or Equat to 0? Function (available in the Comparison menu)in order to comparesDelta value with zero value (figure 1.18).
-
8/16/2019 Lab-01-ENG.pdf
10/16
The Virtual Instrument will light on red the element LED Round if the equation does not havereal solutions. The Boolean Round LED indicator turns green if the equation has real
solutions.
Fig. 1.18. Grater Or Equal To 0? Function
X1 solution of the equation will be calculated according to the relation 1.2 using the following
functions: Negate, Square Root, Add, Multiply, Divide. You have to wire the terminals andthe value obtained from the output terminal of the function Divide will be connected to the
input terminal of the numeric indicator element called “X1" (Figure 1.19).
Fig. 1.19. Calculus of the X1 solution
X2 solution of the equation will be calculated according to the relation 1.3 using the following
functions: Negate, Square Root, Subtract, Multiply, Divide. You have to wire the terminals
-
8/16/2019 Lab-01-ENG.pdf
11/16
and the result obtained to the output terminal of the function Divide will be connected to the
input terminal of the numeric indicator element called “X2" (Figure 1.20).
Fig. 1.20. Calculus of the X2 solution
Running modes
Running a virtual instrument will execute the algorithm designed in the Block Diagram of theprogram. You can run a virtual instrument if the Run button on the toolbar appears as a solid
white arrow. If there is any error in the program the Run button will look like a broken arrowand if you will press it than the list of errors will be displayed.
Complete the following steps to run the virtual instrument:
- display the Front Panel by pressing the CTRL - E keys or by clicking the front panel;- give values fro the input data by entering values into digital displays of the a, b and c
Horizontal Pointer Slide elements or you can change the value of the controls using
operating tool;- click the Run button or press the CTRL - R keys to run the virtual instrument once
(figure 1.21). The VI will be executed once and it will stop when the VI completes its
data flow.
-
8/16/2019 Lab-01-ENG.pdf
12/16
Fig. 1.21. Running the virtual instrument
Running continuously
Clicking the Run Continuously button runs the virtual instrument continuously until you stopit manually by pressing the red button Abort Execution. In this running mode it is possible to
follow the data flow (Figure 1.22).
Fig. 1.22. Running continuously a virtual instrument
The Abort Execution button stops the virtual instrument immediately, before the program
finishes the current iteration (figure 1.23).
-
8/16/2019 Lab-01-ENG.pdf
13/16
Fig. 1.23. Abort execution
If you want to follow the data flow of the virtual instrument then you can press HighlightExecution button from the Block Diagram (figure 1.24).
-
8/16/2019 Lab-01-ENG.pdf
14/16
Fig. 1.24. Data flow of the virtual instrument
If you want to temporary Stop running the application you can use Pause button from both
Front Panel or Block Diagram toolbar (Figure 1.25).
-
8/16/2019 Lab-01-ENG.pdf
15/16
Fig. 1.25. Stop temporary the virtual instrument
Save virtual instrument
Save the virtual instrument pressing the CTRL – S keys or selecting Save from File menu inthe Front Panel or in the Block Diagram .
Choosing Save as option, the virtual instrument can be saved with another name (figure
1.26).
-
8/16/2019 Lab-01-ENG.pdf
16/16
Fig. 1.26. Save the virtual instrument
Learning outcomes
Open a new virtual instruments
Using the Front Panel window and Block Diagram windows and switching between them
Defining numerical and Boolean controls and indicators as input and output data.
Customizing control and indicators in the front panel.
How to define functions on the Block Diagram.
Using scalar functions function according to the data types and operations needed
Make connections between functions and terminals of the elements
Identifying errors and solving the bad connections. Using different running modes
Save the virtual instrument