Presentation is loading. Please wait.

Presentation is loading. Please wait.

Traffic Light Behavior IF A=1 AND B=0 Car Sensors B A.

Similar presentations


Presentation on theme: "Traffic Light Behavior IF A=1 AND B=0 Car Sensors B A."— Presentation transcript:

1 Traffic Light Behavior IF A=1 AND B=0 Car Sensors B A

2 Traffic Light Behavior IF A=1 AND B=0 Otherwise Car Sensors B A

3 Traffic Light Behavior IF A=1 AND B=0 Always Otherwise Car Sensors B A

4 Traffic Light Behavior IF A=1 AND B=0 Always Otherwise IF A=0 AND B=1 Car Sensors B A

5 Traffic Light Behavior IF A=1 AND B=0 Always IF A=0 AND B=1 Otherwise Always Car Sensors B A

6 Traffic Light Behavior IF A=1 AND B=0 Always IF A=0 AND B=1 Otherwise Always Note: Clock beats every 4 sec. So Light is Yellow for 4 sec. Car Sensors B A

7 Traffic Light State Machine IF A=1 AND B=0 Always IF A=0 AND B=1 Otherwise Always Note: Clock beats every 4 sec. So Light is Yellow for 4 sec. Car Sensors B A

8 Traffic Light Design We’ve 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?

9 Traffic Light Design Thinking this through: Our machine needs to:

10 Traffic Light Design Thinking this through: Our machine needs to: Remember which state it is in (Memory)

11 Traffic 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 to next (Logic)

12 Traffic 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 to next (Logic) And that’s all !

13 Traffic 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!

14 Traffic 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.

15 Light A Traffic Light States IF A=1 AND B=0 Always IF A=0 AND B=1 Otherwise Light B Otherwise Always

16 Light A Traffic Light States IF A=1 AND B=0 Always IF A=0 AND B=1 Otherwise Light B Otherwise Always 00 01 10 11

17 Traffic Light Design Problem 2: Given the state it is in and input values, it must determine which state to go to next (Logic) Answer:

18 Traffic Light Design Problem 2: Given the state it is in and input values, it must determine which state to go to next (Logic) Answer: Build a Truth Table Use Universal Method!

19 Traffic Light Behavior Build A Truth Table for next state / Output M 1 M 2 ABD 1 D 2 Light A RedLight B Red …

20 Light A Traffic Light Behavior IF A=1 AND B=0 Always IF A=0 AND B=1 Otherwise Light B Otherwise Always 00 01 10 11

21 Traffic Light Behavior Build A Truth Table for next state / Output M 1 M 2 ABD 1 D 2 Light A RedLight B Red … 00100110

22 Light A Traffic Light Behavior IF A=1 AND B=0 Always IF A=0 AND B=1 Otherwise Light B Otherwise Always 00 01 10 11

23 Traffic Light Behavior Build A Truth Table for next state / Output M 1 M 2 ABD 1 D 2 Light A RedLight B Red … 00100110 01**1010

24 Light A Traffic Light Behavior IF A=1 AND B=0 Always IF A=0 AND B=1 Otherwise Light B Otherwise Always 00 01 10 11

25 Traffic Light Behavior Build A Truth Table for next state / Output M 1 M 2 ABD 1 D 2 Light A RedLight B Red … 00100110 01**1010 10011101

26 Light A Traffic Light Behavior IF A=1 AND B=0 Always IF A=0 AND B=1 Otherwise Light B Otherwise Always 00 01 10 11

27 Traffic Light Behavior Build A Truth Table for next state / Output M 1 M 2 ABD 1 D 2 Light A RedLight B Red … 00100110 01**1010 10011101 11**0001

28 Light A Traffic Light Behavior IF A=1 AND B=0 Always IF A=0 AND B=1 Otherwise Light B Otherwise Always 00 01 10 11

29 Traffic Light Behavior Build A Truth Table for next state / Output M 1 M 2 ABD 1 D 2 Light A RedLight B Red … 00100110 01**1010 10011101 11**0001 00000010 …………………

30 Traffic 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) Let’s put it together…

31 Traffic Light Design Input: Sensor A Input: Sensor B

32 Traffic Light Design 2-bit Memory Register Current State Write Sensor A Sensor B M1M1 M2M2 D1D1 D2D2

33 Traffic Light Design 2-bit Memory Register Write Sensor A Sensor B Logic For Next State & Output 6 Outputs: for each Light Current State Next State

34 Traffic Light Design 2-bit Memory Register Write Sensor A Sensor B Logic For Next State & Output 6 Outputs: for each Light Current State

35 Traffic Light Design 2-bit Memory Register Clock Sensor A Sensor B Logic For Next State & Output 6 Outputs: for each Light Current State

36 Design for Any State Machine Memory Register Clock Inputs Logic For Next State & Output Outputs Current State Many bits

37 State Machines in Real Life Elevator control systems Car control systems VCR’s Alarm Clocks Personal Computers … Just about everything!

38 More 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.)

39 Light A Traffic Light Behavior IF A=1 AND B=0 Always IF A=0 AND B=1 Otherwise Light B Otherwise Always

40 More 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!

41 More Sophisticated Designs Can also add other State Machines!

42 More 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

43 More Sophisticated Designs Inputs Outputs Timer State Machine Main State Machine

44 Computers! State Machines that you can program

45 Review 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 build special-purpose digital systems (e.g. traffic lights)

46 General Purpose Computers What makes a PC different? Today your PC can’t play Final Fantasy X. Tonight, you buy the Final Fantasy X CD-ROM Tomorrow your PC can play the game! PC’s are general-purpose computers. Realize state machines for traffic lights, digital cameras, VCR’s, … You can write a program (software) to control the circuitry (hardware) of a general purpose computer

47 The 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

48 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 don’t differentiate –Both are stored in computer’s memory Programming

49 History of Programmable Machines First “programmable system” was the early printing process developed in China circa 800 C.E. First “program” was perhaps Chinese translation of Buddhist Canon (the Tipitaka)

50 History (cont.) Gutenberg’s Printing Press (circa 1450) Main Contribution: Just a few “basic instructions” (smaller alphabet size) suffice.

51 History (cont.) Huygen’s Pendulum Clock (circa 1650) Main Contribution: Timing, “clock ticks” increase accuracy

52 History (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 -> change song!!

53 History (cont.) Jacquard’s Loom (circa 1810) Punched Cards stored program for weaving patterns.

54 History (cont.) Charles Babbage (1822-64): Input -- Punched Cards Hardware -- general-purpose mechanical mathematical system (Analytical Engine) -- never built Could be programmed punched card could say: “Go back 5 punched cards” Instructions could be Executed repeatedly, or in different order.

55 The Modern Computer Basic Idea still the same: A machine that can execute certain instructions. Machine instructions represented by sequences of 0’s and 1’s (Machine Language) Instructions, and data, stored in Memory von Neumann (1945) Princeton, NJ

56 Memory We’ve seen that memory can be used to build State Machines. In modern computers, memory is also used in 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)

57 Programs 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.

58 Programs 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!

59 How Memory (RAM) Works Take a single bit of memory… D Write M

60 RAM (cont.) Group 8 of them together. 8 bits (b) is called a byte (B). Most RAM is arranged in bytes. D M W D M W D M W D M W D M W D M W D M W D M W

61 RAM (cont.) A byte of memory (a.k.a. an 8-bit register) 8 bits (1 byte) of Memory 8 bits Output 8 bits input Write

62 RAM (cont.) We want a HUGE number of such 1 byte memory cells. 1B

63 RAM (cont.) We want a HUGE number of such 1 byte memory cells. Problem: How do we indicate which byte of memory we want to use at any given time? 1B

64 RAM (cont.) Solution: Assign each byte an address. We can number all the bytes in binary. Each byte’s assigned number is called the byte’s address in memory. Then, we can ask the RAM: What is byte number 011010101010? Or tell the RAM: Write “01101100” into memory at address 011010101010

65 RAM (cont.) 2 20 bytes of RAM (1 Mega-byte) Write Address Data input Data Output

66 RAM (cont.) 2 20 bytes of RAM (1 Mega-byte) Write Address Data input Data Output 20 bits of address

67 RAM (cont.) 2 20 bytes of RAM (1 Mega-byte) Write Address Data input Data Output 20 bits of address 8 bits (1 byte) of data


Download ppt "Traffic Light Behavior IF A=1 AND B=0 Car Sensors B A."

Similar presentations


Ads by Google