0% found this document useful (0 votes)
47 views

CO3053 - Lecture 4 - State Machine and Flowchart

The document discusses using state machines and flow charts to describe embedded systems. It provides examples of state machines for a music player and garage door controller. It also shows a flow chart for a temperature control system. State machines consist of states, inputs that trigger transitions between states, and outputs associated with each state. Flow charts represent algorithms using common symbols like rectangles, diamonds, and arrows. The document encourages representing examples like a traffic light controller using both models to compare their expressions.

Uploaded by

THỊNH CHUNG
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

CO3053 - Lecture 4 - State Machine and Flowchart

The document discusses using state machines and flow charts to describe embedded systems. It provides examples of state machines for a music player and garage door controller. It also shows a flow chart for a temperature control system. State machines consist of states, inputs that trigger transitions between states, and outputs associated with each state. Flow charts represent algorithms using common symbols like rectangles, diamonds, and arrows. The document encourages representing examples like a traffic light controller using both models to compare their expressions.

Uploaded by

THỊNH CHUNG
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

CO3053 – Embedded Systems

4. State Machine & Flow-Chart


CO3053 – Lecture Notes 2

Contents
▪ State machine/chart/diagram to describe an embedded system

▪ Present algorithms by flow-chart

anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 3

State Machine Diagram


▪ A state machine is any device that stores the status of something at
a given time and can operate on input to change the status and/or
cause an action or output to take place for any given change.

anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 4

System Description by State Machine


▪ State
▫ Present state
▫ Next state Moore

▪ Input
▫ Transition condition
▫ Event
Mealy
▪ Output
▫ Functions of the present states (inputs)
anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 5

System Description by State Machine


▪ State
▫ Present state
▫ Next state Moore

▪ Input
▫ Transition condition
▫ Event
Mealy
▪ Output
▫ Functions of the present states (inputs)
anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 6

State Machine – Example


▪ Music Player stop button

▫ stop button
▫ start/pause
stop button

STOP
reset
▪ State determination
▫ STOP PAUSE
start/pause
▫ RUN
start/pause
▫ PAUSE stop button

▪ Transition condition RUN


start/pause

▫ Button click
anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 7

State Machine – Example


▪ Garage Door Control
▫ Remote control
▫ Door Actuators

▪ State determination
▫ Opened
▫ Opening
▫ Closed
▫ Closing

▪ Transition condition
▫ Button click
▫ Sensor event
anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 8

State Machine – Exercise (Traffic Light 1)

anhpham@hcmut.edu.vn
CO3053 – Lecture Notes 9

State Machine – Exercise (Traffic Light 2)

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

Flow-chart - Example START

temp = ADC_Read (Temp_Sensor) Đọc giá trị cảm biến

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

State Machine and Flow-Chart


START
Start T3 T3
RED_ON Đọc giá trị cảm biến
temp = ADC_Read (Temp_Sensor)

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

You might also like