0% found this document useful (0 votes)
80 views18 pages

Lesson G - Common Design Techniques and Patterns SMME

This document discusses common design techniques and patterns in LabVIEW, including sequential programming, state programming, and state machines. It describes using structures like sequences and case structures to control execution order in sequential programming. For state programming, it introduces state transition diagrams and explains that state machines are useful for processes that can be represented by flow charts. The key components of a state machine are described as states, transitions, a while loop, case structure, and shift register to track the current state. Different methods for implementing state transitions are presented.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views18 pages

Lesson G - Common Design Techniques and Patterns SMME

This document discusses common design techniques and patterns in LabVIEW, including sequential programming, state programming, and state machines. It describes using structures like sequences and case structures to control execution order in sequential programming. For state programming, it introduces state transition diagrams and explains that state machines are useful for processes that can be represented by flow charts. The key components of a state machine are described as states, transitions, a while loop, case structure, and shift register to track the current state. Different methods for implementing state transitions are presented.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Advanced Instrumentation and

Experimental Methods
Module code ME 820

Dr Riaz A Mufti
(B.Sc, M.Sc Eng (UK), PhD (UK), CEng (UK), MIMechE (UK), P.E (PEC))

Common Design Techniques and Patterns


Lesson 8
Common Design Techniques and Patterns

TOPICS
A. Using Sequential Programming
B. State Programming
C. State Machines

NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
A. Using Sequential Programming
• Many of the VIs you write accomplish sequential tasks
• There is nothing in this block diagram to force the execution
order of these tasks - any one of these tasks could happen first

NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
A. Using Sequential Programming

Use error clusters to force order of execution

NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
A. Using Sequential Programming
To force execution order, use a Sequence structure
• A structure with frames, where each frame executes in order
• The second frame cannot begin execution until everything in the first
frame completes execution

NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
A. Using Sequential Programming
• Avoid overusing Sequence structures
• It guarantees the order of execution but prohibits parallel operations
• You cannot stop the execution part way through a sequence

NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
A. Using Sequential Programming

The best way to write this VI is to enclose the dialog boxes in


Case structures, wiring the error cluster to the case selectors

NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
B. Using State Programming

Although Sequence structures or sequentially wired subVIs


accomplish the purpose, it is not always the best choice:
• What if you need to change the order of the sequence?
• What if you need to repeat one item in the sequence more
often than the other items?
• What if some items in the sequence execute only when
certain conditions are met?
• What if you need to stop the program immediately, rather
than waiting until the end of the sequence?

NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
B. Using State Programming –
State Transition Diagram
Type of flowchart that indicates the states of a program and
transitions between states

State - Part of a program that satisfies a condition,


performs an action or waits for an event

Transition - Condition, action, or event that causes the


program to move to the next state

NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
B. Using State Programming –State Transition Diagram

NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
C. State Machines

The state machine design pattern is a common and very


useful design pattern for LabVIEW. You can use the state
machine design pattern to implement any algorithm that can
be explicitly described by a state diagram or flow chart. A
state machine usually implements a moderately complex
decision-making algorithm, such as a diagnostic routine or a
process
monitor.

NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
C. State Machines

• The state machine design pattern implements a state


diagram or flow chart
• When to use state machines?
− Commonly used to create user interfaces, where different user
actions send the user interface into different states
− Commonly used for process tests, where a state represents
each segment of the process

NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
C. State Machines – Infrastructure
• A state machine consists of a set of states and a transition
function that maps to the next state
• Each state can lead to one or multiple states or end the
process flow
While Loop

Shift Register Case Structure


NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
C. State Machines – Infrastructure

• While Loop—Continually executes the various states


• Case Structure—Contains a case for each state and the code to
execute for each state
• Shift Register—Contains state transition information
• State Functionality Code—Implements the function of the state
• Transition Code—Determines the next state in the sequence

The flow of the state transition diagram is implemented by the While Loop.
The individual states are represented by cases in the Case structure. A
shift register on the While Loop keeps track of the current state and
communicates the current state to the Case structure input.

NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
C. State Machines – Default Transition
The default transition, no code is needed to determine the next state.

NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
C. State Machines – Transition Between Two States
The following method involves making a decision on a transition between
two states. This method works well if you know that the individual state
always transitions between two states. If you need to modify the state to
transition among more than two states, this solution would not work and
would require a major modification of the transition code.

NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
C. State Machines – Case Structure Transition
Case Structure—Use a Case structure instead of the Select function for
the transition code. One advantage to using a Case structure is that the
code is self documenting. Because each case in the Case structure
corresponds to an item in the enumerated type control, it is easy to read
and understand the code. A disadvantage to using a Case structure is that
not all the code is visible at once.

NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
C. State Machines – Transition Array Transition
If you need more of the code to be visible than a Case structure allows,
you can create a transition array for all the transitions that can take place
in the transition code for a state and index the array for the next state.

NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST

You might also like