Lesson G - Common Design Techniques and Patterns SMME
Lesson G - Common Design Techniques and Patterns SMME
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))
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
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
NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
B. Using State Programming
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
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
NI LabVIEW Academy
Dr Riaz A Mufti National Instruments Texas USA
Advanced Instrumentation and Measurement NI Academy at SMME - NUST
C. State Machines
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
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