Lab 4 : Execution Structures In NI LabVIEW

1y ago
5 Views
2 Downloads
735.05 KB
10 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Aiyana Dorn
Transcription

Lab 4 : Execution Structures in NI LabVIEW Execution structures contain sections of graphical code and control how and when the code inside is run. The most common execution structures are While Loops, For Loops and Case Structures which you can use to run the same section of code multiple times or to execute a different section of code based on some condition. The while loop The While Loop is located on the Structures palette. Select the While Loop from the palette then use the cursor to drag a selection rectangle around the section of the block diagram you want to repeat. When you release the mouse button, a While Loop boundary encloses the section you selected. Add block diagram objects to the While Loop by dragging and dropping them inside the While Loop. The While Loop executes the code it contains until the conditional terminal, an input terminal, receives a specific Boolean value. The iteration terminal is an output terminal that contains the number of completed iterations. The iteration count for the While Loop always starts at zero. Note: The While Loop always executes at least once. Graphical code The loop iteration count from 0 to inf. Or until a true value reaches the loop enable which will make the loop iteration to reset Loop enable Rest the loop when it receives a true value

Example (1):Create a system with three leds with the following specification: The first led lights when the iteration is less than 10 The second led lights when the iteration is more than 10 and less than 20 The third led lights when the iteration is more than 20 The system should reset ( iteration 0) when the iteration reaches 30 Solution :1- First create the front panel design which consist of three leds as shown in figure 1 Figure 1 front panel of the system 2- The main idea depends on the iteration value so we need to use the comparison function ( ) in order to meet the system specification, for example the first led should light when the iteration is less than or equals to 10 so we use the function as for the second led it should light when two conditions are true so we use comparison function in addition to an AND gate and final the same for the third led 3- To reset the system at 30 we use the equal function as shown in figure 2 مهم 4- When a loop finishes executing an iteration, it immediately begins executing the next iteration, unless it reaches a stop condition. Most often, you need to control the iteration frequency or timing. For example, if you are acquiring data, and you want to acquire the data once every 10 seconds, you need a way to time the loop iterations so they occur once every 10 seconds. Even if you do not need the

execution to occur at a certain frequency, you need to provide the processor with time to complete other tasks, such as responding to the user interface. Loop delay An indicator to see the value of the iteration This icon is used for slowing the loop down in order for a human to see the leds go on and off in other word the iteration is increased every 1000ms Figure 2 block diagram of the system Report exercise 1- Control the loop delay in the last example so the led can go faster or slower? The For loop The for is used to perform a task according to a number defined by the user. The For Loop differs from the While Loop in that the For Loop executes a set number of times. A While Loop stops executing only if the value at the conditional terminal exists. The for loop has two terminals as in figure 3: 1- The count terminal is an input terminal whose value indicates how many times to repeat the subdiagram 2- The iteration terminal is an output terminal that contains the number of completed iterations. Figure 3 for loop

The for loop iteration always starts from zero. Example (2):Use the for loop structure to make a flashing wave of five leds and control the flashing speed. Solution:1- Design the front panel with five leds and a Knob which is used to control the speed as shown in figure 4 Figure 4 front panel of the system 2- Since we have five led flasher we need the loop to run five time so we put the counter terminal to 5 ,see figure 5 Figure 5 block diagram panel of the system

Report exercise 2 Use the for loop structure to make a flasher of one led with following specification: The user should control the flashing speed Hint (the main idea is to divide the iteration by 2 and see if the result ( )باقي القسمة equal zero or not, you can find the Modulo operator on mathematics ) The Case structure:A Case structure has two or more subdiagrams, or cases. Only one subdiagram is visible at a time, and the structure executes only one case at a time. An input value determines which subdiagram executes. The Case structure is similar to switch statements or if.then.else statements in text-based programming languages see figure 6. Figure 6 Case structure The case selector label at the top of the Case structure contains the name of the selector value that corresponds to the case in the center and decrement and increment arrows on each side. Click the decrement and increment arrows to scroll through the available cases. You also can click the down arrow next to the case name and select a case from the pulldown menu. Wire an input value, or selector, to the selector terminal to determine which case executes. You must wire an integer, Boolean value, string, or enumerated type value to the selector terminal. You can position the selector terminal anywhere on the left border of the Case structure. If the data type of the selector terminal is Boolean, the structure has

a True case and a False case. If the selector terminal is an integer, string, or enumerated type value, the structure can have any number of cases. Right-click the Case structure border to add, duplicate, remove, or rearrange cases, and to select a default case. Example (3):Design a labview program to calculate the area of a circle, and rectangle using case structure. Solution:1- Design the front panel as shown is figure 7. Figure 7 front panel of the system 2- Connect the block diagram as following Figure 8 block diagram of the system

Example (3):Built a function generator that generates sin, square, and triangular waves. The user should control the amplitude, frequency, and phase (delay) using case structure. Solution: The system has three cases ( sin , square , triangular ) so we need a case structure with three case Sine we need to control the amplitude , frequency and delay we need three Knobs. We need a graph screen to see the output. In this example we will use a new item which is the ring menu as the selection for the case structure, figure 9 shows the block diagram screen. Figure 9 front panel of the system The ring menu work as a selection for the case structure, so we need three case and to do than we right click on the menu and choose Edit Items , each item has a value and you enter the name of this item as shown in figure 10

To enter a new item To delete an existing item Figure 10 Edit Items option in ring menu In order to generate a signal in labview we use the simulate signal icon as shown in figure 11 Figure 11 simulate signal

Double click on the simulate signal to choose the output signal as shown in figure 12 Figure 12 simulate signal configuration Now in each case in the case structure put a simulate signal each one produce a different signal and connect the three knob to the simulate signal for example connect the amplitude knob to the amplitude in each simulate signal as shown in figure 13

Report exercise (3):Create a simple Case Structure Application to convert degree from Celsius to Fahrenheit and opposite VI. There is a Boolean control applied to the selector terminal, so the Case Structure is the Boolean data type. When he Boolean control on the Front Panel is in the up position, it returns a FALSE to the selector terminals which invoke the Celsius to Fahrenheit case. Bonus report exercise (no mark lose if not solved) Use the loop structures to make a flashing wave of five leds with following specifications: The user should control the flashing speed The system contains a button to change the flashing direction (bio directional flasher) Hint (you may use a for loop and a case structure)

The iteration terminal is an output terminal that contains the number of completed iterations. The iteration count for the While Loop always starts at zero. Note: The While Loop always executes at least once. The loop iteration count from 0 to inf. Or until a true value reaches the loop enable which will make the loop iteration to reset

Related Documents:

Contents Chapter 1 Lab Algorithms, Errors, and Testing 1 Chapter 2 Lab Java Fundamentals 9 Chapter 3 Lab Selection Control Structures 21 Chapter 4 Lab Loops and Files 31 Chapter 5 Lab Methods 41 Chapter 6 Lab Classes and Objects 51 Chapter 7 Lab GUI Applications 61 Chapter 8 Lab Arrays 67 Chapter 9 Lab More Classes and Objects 75 Chapter 10 Lab Text Processing and Wrapper Classes 87

Biology Lab Notebook Table of Contents: 1. General Lab Template 2. Lab Report Grading Rubric 3. Sample Lab Report 4. Graphing Lab 5. Personal Experiment 6. Enzymes Lab 7. The Importance of Water 8. Cell Membranes - How Do Small Materials Enter Cells? 9. Osmosis - Elodea Lab 10. Respiration - Yeast Lab 11. Cell Division - Egg Lab 12.

Lab 5-2: Configuring DHCP Server C-72 Lab 5-3: Troubleshooting VLANs and Trunks C-73 Lab 5-4: Optimizing STP C-76 Lab 5-5: Configuring EtherChannel C-78 Lab 6-1: Troubleshooting IP Connectivity C-80 Lab 7-1: Configuring and Troubleshooting a Serial Connection C-82 Lab 7-2: Establishing a Frame Relay WAN C-83 Lab 7

Each week you will have pre-lab assignments and post-lab assignments. The pre-lab assignments will be due at 8:00am the day of your scheduled lab period. All other lab-related assignments are due by 11:59 pm the day of your scheduled lab period. Pre-lab assignments cannot be completed late for any credit. For best performance, use only Firefox or

Lab EX: Colony Morphology/Growth Patterns on Slants/ Growth Patterns in Broth (lecture only) - Optional Lab EX: Negative Stain (p. 46) Lab EX : Gram Stain - Lab One (p. 50) Quiz or Report - 20 points New reading assignment 11/03 F Lab EX : Gram Stain - Lab Two Lab EX: Endospore Stain (p. 56) Quiz or Report - 20 points New reading .

Lab Notebook- Students are introduced to the purpose of a lab notebook and set up the lab notebook for session and the day’s lab. Afternoon Laboratory Safety Lab Safety Rules and Contracts Lab Equipment Scavenger Hunt: Students find and identify common lab equipment that they will use throughout the three weeks as well as get

Lab Safety & IR Spectroscopy Reading: Handbook for Organic Chemistry Lab, section on Lab Safety (Chapter 1) and IR Spectroscopy (Chapter 16). Organic Chemistry by Marc Loudon, 6th ed., pp. 569-591 (12.1-12.5). There is no prelab or lab report for today’s experiment. During today’s lab, you will check into a lab drawer.

The lab exercises will count 70%, the clicker average 10% and the Lab Exam 20% of the FINAL LAB AVERAGE. FINAL LAB AVERAGE (Average of Lab Exercises X 0.70) (Clicker Average x 0.10) (Lab Exam X 0.20) Astronomy 105 (Lecture) and Astronomy 105L (Lab) are averaged into one grade and