CO3053 - Lecture 4 - State Machine and Flowchart
CO3053 - Lecture 4 - State Machine and Flowchart
Contents
▪ State machine/chart/diagram to describe an embedded system
anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 3
anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 4
▪ Input
▫ Transition condition
▫ Event
Mealy
▪ Output
▫ Functions of the present states (inputs)
anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 5
▪ Input
▫ Transition condition
▫ Event
Mealy
▪ Output
▫ Functions of the present states (inputs)
anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 6
▫ stop button
▫ start/pause
stop button
STOP
reset
▪ State determination
▫ STOP PAUSE
start/pause
▫ RUN
start/pause
▫ PAUSE stop button
▫ Button click
anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 7
▪ State determination
▫ Opened
▫ Opening
▫ Closed
▫ Closing
▪ Transition condition
▫ Button click
▫ Sensor event
anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 8
anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 9
YELLOW
GREEN
RED
GREEN
N
YELLOW LGREEN
LGREEN
LRED
E
RED LRED
LGREEN
W
LRED
LRED RED
LGREEN YELLOW
S GREEN
GREEN
YELLOW
RED
anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 10
Flow-chart
▪ To represent an algorithm for a specific function. Data
▫ Use a rectangle for a process
▫ Use a rounded rectangle for a terminator (START, END)
▫ Use a diamond shape for a decision
▫ Use a parallelogram for data
▫ Use a rectangle with two vertical lines for predefine process Data
Process
START
NO
Predefine If
process
YES
END
anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 11
B ật đ èn m àu đ ỏ
YES
Temp > 50? Turn_On (Red_Led)
“Tại một thời điểm chỉ có duyRed_Led
nhất một đèn
Temp_Sensor sáng, nghĩa là nếu một đèn được bật thì 2 đèn NO B ật đ èn m àu vàng
ADC còn lại
MCUsẽ tắt.” Yellow_Led
YES
Green_BLue Temp > 28? Turn_On (Yellow_Led)
NO B ật đ èn m àu xanh
Turn_On (Green_Led)
END
anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 12
B ật đ èn m àu đ ỏ
T1 YES
GREEN_ON Temp > 50? Turn_On (Red_Led)
T1 T3
“Tại
T2một thời điểm chỉ có duy nhất một đèn
sáng, nghĩa là nếu một đèn được bật thì 2 đèn NO B ật đ èn m àu vàng
còn lại sẽ tắt.”
T1 YES
Temp > 28? Turn_On (Yellow_Led)
YELLOW_ON NO B ật đ èn m àu xanh
T2
Turn_On (Green_Led)
Transition conditions T2
▪ T1: Temp <= 28
END
▪ T2: 28 < Temp <= 50
▪ T3: Temp > 50
anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 13
Flow-chart - Exercise
▪ Represent the system described by the state machine in forms of flow-chart
stop button
stop button
STOP
reset
PAUSE
start/pause
start/pause
stop button
start/pause
RUN
anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 14
Exercise
▪ Let’s design and implement the control unit of a washing machine that is
described as follows:
▫ The machine can be controlled by three buttons (STOP, RUN, PAUSE).
▫ The washing machine is only able to execute after at least 50-cents is added.
▫ The machine only accepts 10-cent, 20-cent, 50-cent coins.
▫ When there is enough money, the machine will execute if the RUN button is pressed.
Then, the money will be clear without returning the redundancies (if any).
▫ When the machine is running, it will be paused as the PAUSE button is pressed. The
machine will re-execute when the RUN button is pressed again.
▫ The executing machine will be automatically terminated after 30 minutes or when the
STOP button is pressed.
anhpham@hcmut.edu.vn