Digital Signal Processing with
LabVIEW 8.6
Lab # 05
Variables, State Machines, Dialog Boxes,
Tab Control
Designed by
Adnan Niazi
Lab Engineer
Signal Processing/Signal & Systems Lab
CECOS University of IT & Emerging Sciences
27th- 28th Feb 2009
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Agenda
What is a Tab Control
How to use Tab Control
What are variables
Types of variables
What are dialog boxes
How to use Dialog Boxes
What is a State Machine
How to make a State Machine
008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Tab Control
Tab control helps to organize and front panel into logical
blocks
Instead of one very long front panel you can divide the
front panel into pages with each page containing only a
portion of the front panel objects
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Block diagram Without Tab Control
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Arranging Block Diagram with Tab Control
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Arranging Block Diagram with Tab Control
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Variable in LabVIEW
There are three types of variable in LabVIEW
Local Variable
Global Variable
Shared Variable
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Local variable
Local variable transfers data within a VI
Allows programmer to access data from a control or
indicator at multiple locations in the block diagram
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
How to make a Local Variable :
Method # 01
Right click on an existing control and select Local
Variable from the create Submenu
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
How to make a Local Variable :
Method # 02
Drag a Local variable from the structures palette
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
How to make a Local Variable :
Method # 02
Right Click this Local Variable and assign it a control
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Local Variable
Local Variables can be written to or read from
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Example of a Local Variable
Scenario
Lets make a VI with two while loops running in parallel
with each other independently. Each while loop will have
its own stop button. We can’t stop these two loops
simultaneously because we can’t work with both the
stop buttons at exactly the same time
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Example of a Local Variable
Both Loops are running in
Parallel with each other.
Consequently y same result
is shown in both the indictors
No matter How Hard you Try,
you can’t stop these two
loops at the same time using
two Stop Buttons
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Use Local Variable to solve this
Problem
Now Both Loops can be
stopped simultaneously by
using just one stop button
with the help of a local
variable
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Caution
By Default the stop button has a latch Action
Local Variables can’t work with Latch type Buttons
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Caution
To successfully run the VI, you need to change the latch
action to a switch action
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Global Variable
Global Variable transfers data within multiple VIs on a
single computer
Global variables are built-in LabVIEW objects.
Global variables have a front panel but no block diagram
Can contain multiple data types
Retain whatever values are set as default
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
How to make Global Variables
Step 1: Place a Global variable from the structures
palette onto the block diagram
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
How to make Global Variables
Step 2: Double click the Global Variable to open its front
panel and place any control that you want to convert to
Global
Variable
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
How to make Global Variables
Step 3: Save and close the front panel for the global
variable
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Caution
Avoid use of Global variables whenever possible
Use Functional Global Variables instead of Global
Variables
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Shared Variable
Transfer data within multiple VIs to multiple computers
over a network.
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Where to find Tab Control
Tab Control
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Type Definition or Type Def
Type definition is custom control file that has been
marked as a Type Def
Instances of Type Def are Linked to their definition
Changes in definition cause all the instances to be
updated
Enumerated constants with type def are widely used in
Enum Driven state Machine Architecture
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
How to Make Type Def of a CTL
Step 1: Follow this path
Right click the control >>> Advanced >>> Customize
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
How to Make Type Def of a CTL
Change the control to Type Def
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
How to Make Type Def of a CTL
Any changes made to the type definition will result in
the automatic update of all the instances of that type def
This saves a lot of time as you only need to change the
definition. All instance of the type def will automatically
update themselves.
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Dialog Boxes
Dialog boxes Pop Up during runtime
They inform the user that something has happened
They require a certain response from the user
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Types of Dialog Boxes
There are Four types of Dialog Boxes
1- One Button Dialog Box
2- Two button Dialog Box
3- Three button Dialog Box
4- Prompt Dialog Box
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
One Button Dialog Box
One Button Dialog Box is used to show some
information to the user and getting back some
acknowledgment
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
One Button Dialog Box
Two button dialog box lets the user select one of two
different options
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Three Button Dialog Box
It allows user to select one of the three available options
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Prompt Dialog Box
Enables user to specify some input
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Prompt Dialog Box
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
State Machine
A state machine or Finite State machine (FSM) consists
of States, Actions and transitions between the different
states
The current state is defined by the previous states
Each state may lead to one or multiple states
A State Machine relies on user input or in-state
calculation to determine which state to go to next
Commonly used for making user interfaces
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
State Machine for an Oven
Power Up
Routine
Cook Food or
Shutdown?
Shutdown
Routine
Set Cooking
Timer
Start
Food
Cooking
Beep
Cooked
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
State Machine for an Oven
State 1: Power Up Routine
In this state the ovens electronics are powered up
Soft Start circuit supplies power to the electronics (LCD
display etc…) after a certain delay when all the
transients have settled down
A delay of 1000ms simulates the delay introduced by the
soft start circuitry
After the soft start has started the electronics, a
Powered up! message is displayed for 1000ms
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
State Machine for an Oven
State 1: Power Up Routine
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
State Machine for an Oven
State 2: Cook Food or Shutdown?
In this state the user is presented with a dialog box
asking the user whether he wants to cook food or just
want to shutdown the oven
If the user Presses Cook Food then the state machine
goes to Set Cooking Timer State otherwise it goes to the
Shutdown Routine state
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
State Machine for an Oven
State 2: Cook Food or Shutdown?
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
State Machine for an Oven
State 3: Set Cooking Timer
In this state the user is presented with a dialog box
asking the user to set Cooking Time in Seconds
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
State Machine for an Oven
State 3: Set Cooking Timer
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
State Machine for an Oven
State 4: Start Cooking
After the user specifies the cooking time, the oven’s
heating mechanism is started and the food starts to
cook.
The remaining cooking time is displayed on the front
panel
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
State Machine for an Oven
State 4: Start Cooking
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
State Machine for an Oven
State 5: Beep
When the Food has been cooked for the specified
amount of time, an alarm, in the form of three beeps, is
sounded to alert the user near by
Mean while The front displays Food Cooked! message
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
State Machine for an Oven
State 5: Beep
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
State 6: Power down Routine
The oven is shut down in this state.
A message Shutting Down is displayed for 2 seconds
and then the display is cleared(simulating the turning off
of the LCD display) and then the VI aborts
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
State Machine for an Oven
State 6: Shutdown Routine
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Task 1
Design a LabVIEW VI that mimics the behavior of the
following state transition diagram
User chooses to go
to next State
State 1
User chooses to go
to previous State
User chooses
Abort or Quit
State 2
State 5
Abort
State 3
State 4
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Lab Report
The lab report must contain
Block Diagram for State 1
Block Diagram for State 2
Block Diagram for State 3
Block Diagram for State 4
Block Diagram for state 5
Black Diagram for Abort State
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Hints For the Task
First Define six states in an Enumerated Type Def. The
states should be:
State 1
State 2
State 3
State 4
State 5 &
Abort
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Hints For the Task
Use Three Button Dialog Box to ask the user whether he
wants to go to next state, previous state or want to abort
the state machine
You can use case structure with the output of the three
button dialog box in order to select the Next, Previous or
Abort States
If you have any problem understanding how the VI should
behave then, refer to the project Task 1.lvprj in the Tasks
folder.
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences
Brain Control with LabVIEW
©2008-2009 All rights reserved.
Contact: [email protected]
CECOS University of IT & Emerging Sciences