Title: Traffic Light Behavior
1Traffic Light Behavior
IF A1 AND B0
2Traffic Light Behavior
Otherwise
IF A1 AND B0
3Traffic Light Behavior
Otherwise
IF A1 AND B0
Always
4Traffic Light Behavior
Otherwise
IF A1 AND B0
Always
IF A0 AND B1
Otherwise
5Traffic Light Behavior
Otherwise
IF A1 AND B0
Always
Always
IF A0 AND B1
Otherwise
6Traffic Light Behavior
Otherwise
NoteClock beats every 4 sec.So Light is
Yellow for 4 sec.
IF A1 AND B0
Always
Always
IF A0 AND B1
Otherwise
7Traffic Light State Machine
Otherwise
NoteClock beats every 4 sec.So Light is
Yellow for 4 sec.
IF A1 AND B0
Always
Always
IF A0 AND B1
Otherwise
8Traffic Light Design
- Weve figured out the logical behavior of the
Traffic Light in terms of a State Machine - We know what the states are.
- For each state, given any input,we know which
state to go to next. - How do we build it?
9Traffic Light Design
- Thinking this through
- Our machine needs to
10Traffic Light Design
- Thinking this through
- Our machine needs to
- Remember which state it is in (Memory)
11Traffic Light Design
- Thinking this through
- Our machine needs to
- Remember which state it is in (Memory)
- Given the state it is in and input values, it
must determine which state to go tonext (Logic)
12Traffic Light Design
- Thinking this through
- Our machine needs to
- Remember which state it is in (Memory)
- Given the state it is in and input values, it
must determine which state to go tonext (Logic) - And thats all !
13Traffic Light Design
- Problem 1
- Remember which state it is in (Memory)
- How do represent the states?
- We could keep one bit of memory for whether Light
A is Green or not, whether it is Yellow or not,
- This would take 6 bits of memory.
- There is a much simpler way!
14Traffic Light Design
- Problem 1
- Remember which state it is in (Memory)
- How do represent the states?
- Answer
- Just number them (using binary numbers).
- We have 4 states.
- Call them 00, 01, 10, 11.
- We (human designers) will keep track of what
these names mean.
15Traffic Light States
Otherwise
IF A1 AND B0
Light A
Always
Always
IF A0 AND B1
Otherwise
Light B
16Traffic Light States
Otherwise
IF A1 AND B0
01
00
Light A
Always
Always
IF A0 AND B1
11
10
Otherwise
Light B
17Traffic Light Design
- Problem 2
- Given the state it is in and input values, it
must determine which state to go tonext (Logic) - Answer
18Traffic Light Design
- Problem 2
- Given the state it is in and input values, it
must determine which state to go tonext (Logic) - Answer
- Build a Truth Table
- Use Universal Method!
19Traffic Light Behavior
Build A Truth Table for next state / Output
20Traffic Light Behavior
Otherwise
IF A1 AND B0
01
00
Light A
Always
Always
IF A0 AND B1
11
10
Otherwise
Light B
21Traffic Light Behavior
Build A Truth Table for next state / Output
22Traffic Light Behavior
Otherwise
IF A1 AND B0
01
00
Light A
Always
Always
IF A0 AND B1
11
10
Otherwise
Light B
23Traffic Light Behavior
Build A Truth Table for next state / Output
24Traffic Light Behavior
Otherwise
IF A1 AND B0
01
00
Light A
Always
Always
IF A0 AND B1
11
10
Otherwise
Light B
25Traffic Light Behavior
Build A Truth Table for next state / Output
26Traffic Light Behavior
Otherwise
IF A1 AND B0
01
00
Light A
Always
Always
IF A0 AND B1
11
10
Otherwise
Light B
27Traffic Light Behavior
Build A Truth Table for next state / Output
28Traffic Light Behavior
Otherwise
IF A1 AND B0
01
00
Light A
Always
Always
IF A0 AND B1
11
10
Otherwise
Light B
29Traffic Light Behavior
Build A Truth Table for next state / Output
30Traffic Light Design
- We understand how to represent which state the
system is in (so we can store it in Memory) - We understand how the system can determine which
state to go to next (Logic) - Lets put it together
31Traffic Light Design
Input Sensor A
Input Sensor B
32Traffic Light Design
Current State
D1
M1
2-bit Memory Register
D2
M2
Write
Sensor A
Sensor B
33Traffic Light Design
Current State
Next State
2-bit Memory Register
Logic For Next State Output
Write
Sensor A
6 Outputs for eachLight
Sensor B
34Traffic Light Design
Current State
2-bit Memory Register
Logic For Next State Output
Write
Sensor A
6 Outputs for eachLight
Sensor B
35Traffic Light Design
Current State
2-bit Memory Register
Logic For Next State Output
Clock
Sensor A
6 Outputs for eachLight
Sensor B
36Design for Any State Machine
Manybits
Current State
Memory Register
Logic For Next State Output
Clock
Inputs
Outputs
37State Machinesin Real Life
- Elevator control systems
- Car control systems
- VCRs
- Alarm Clocks
- Personal Computers
- Just about everything!
38More Sophisticated Designs
- Just add more states, more inputs, more outputs,
more rules - Example Add a longer delay before Traffic Light
changes from Yellow to Red. (Say 8 seconds
instead of 4.)
39Traffic Light Behavior
Otherwise
IF A1 AND B0
Always
Always
Light A
Always
Always
IF A0 AND B1
Otherwise
Light B
40More Sophisticated Designs
- Note that the new delay states we added
correspond to the SAME combinations of lights as
other states (Red/Yellow). - The purpose of the new states is only to add
delays. - Logical states need not correspond to different
observable states of the machine!
41More Sophisticated Designs
- Can also add other State Machines!
42More Sophisticated Designs
- Example (Fairness)
- We might want a separate Timer machine for the
Traffic Light - If cars keep coming, Light should decide after 3
minutes to switch lights. - A Timer is just a state machine that keeps
counting beats of the Clock
43More Sophisticated Designs
Inputs
Outputs
Timer StateMachine
44Computers!
State Machines that you can program
45Review
- In designing state machines, we used
- Binary Representation (to represent states)
- Memory (to store the current state)
- Logic Circuits Universal Method (to determine
the next state) - In this way, we learned how to buildspecial-purpo
se digital systems(e.g. traffic lights)
46General Purpose Computers
- What makes a PC different?
- Today your PC cant play Final Fantasy X.
- Tonight, you buy the Final Fantasy X CD-ROM
- Tomorrow your PC can play the game!
- PCs are general-purpose computers.
- Realize state machines for traffic lights,
digital cameras, VCRs, - You can write a program (software) to control the
circuitry (hardware) of a general purpose computer
47The Stored Program
- Idea is simple
- Build a machine that can execute certain
instructions. - Then, write down different lists of instructions
(programs) to accomplish different things. - One program plays an adventure game
- Another program lets you write papers
- Another lets you surf the Web
48Programming
- Using software to control hardware
- Hardware is fixed circuitry
- Software is instructions to the processor to
control the inputs to the fixed circuitry - Inputs to the hardware are of 2 types
- Data
- Program
- We dont differentiate
- Both are stored in computers memory
49History of ProgrammableMachines
- First programmablesystem was the early
printing process developed in China circa 800
C.E. - First program wasperhaps Chinese translation
ofBuddhist Canon(the Tipitaka)
50History (cont.)
- Gutenbergs Printing Press(circa 1450)
- Main Contribution
- Just a few basic instructions
(smalleralphabet size) suffice.
51History (cont.)
- Huygens Pendulum Clock(circa 1650)
- Main Contribution
- Timing, clock ticks increase accuracy
52History (cont.)
- Musical Machines Barrel Organs (1500!) Music
boxes (between) Player Pianos (c. 1700) - Main Contributions
- Drive cylinder or disk with pins (bits!!) which
play notes at the right time - Change disk -gt change song!!
53History (cont.)
- Jacquards Loom(circa 1810)
- Punched Cards stored program for
weaving patterns.
54History (cont.)
- Charles Babbage (1822-64)
- Input -- Punched Cards
- Hardware -- general-purpose
mechanical mathematical system - (Analytical Engine) -- never built
- Could be programmed
- punched card could sayGo back 5 punched cards
- Instructions could be Executed repeatedly, or in
different order.
55The Modern Computer
von Neumann (1945) Princeton, NJ
- Basic Idea still the sameA machine that can
execute certain instructions. - Machine instructions represented by sequences of
0s and 1s(Machine Language) - Instructions, and data, stored in Memory
56Memory
- Weve seen that memory can be used to build State
Machines. - In modern computers, memory is also usedin a
different way - Big arrays of Memory called RAM Random Access
Memory - RAM is a place to store information while the
computer is running - The information includes the data that the
program reads and writes, as well as the program
itself (I.e. its instructions)
57Programs are Just Like Data
- One of the important features of the von Neumann
model is the fact that - The instructions themselves
- And
- The data the instructions manipulate
- are all stored in the same RAM.
- This was one of the revolutionary features of the
modern computer, totally unlike Punch-Card
computers proposed in the past.
58Programs are Just Like Data
- This innovation is crucial to modern computing.
- It even allows for the possibility of programs
that change themselves as they are executed. - With great power comes great risk
- Computer Viruses!
59How Memory (RAM) Works
- Take a single bit of memory
D
M
Write
60RAM (cont.)
- Group 8 of them together.
- 8 bits (b)is called abyte (B).
- Most RAMis arrangedin bytes.
61RAM (cont.)
- A byte of memory (a.k.a. an 8-bit register)
8 bits input
8 bits Output
8 bits (1 byte)of Memory
Write
62RAM (cont.)
- We want a HUGE number of such 1 byte memory
cells.
63RAM (cont.)
- We want a HUGE number of such 1 byte memory
cells. - Problem How do we indicate which byte ofmemory
we want to use at any given time?
64RAM (cont.)
- Solution Assign each byte an address.
- We can number all the bytes in binary.
- Each bytes assigned number is called the bytes
address in memory. - Then, we can ask the RAM
- What is byte number 011010101010?
- Or tell the RAM
- Write 01101100 into memory at
address011010101010
65RAM (cont.)
Address
Data Output
Data input
Write
66RAM (cont.)
20 bits of address
Address
Data Output
Data input
Write
67RAM (cont.)
20 bits of address
Address
Data Output
Data input
Write
8 bits (1 byte)of data