Presentation is loading. Please wait.

Presentation is loading. Please wait.

TODAY’S OUTLINE Finite State Machine Exercise 1 Exercise 1 Exercise 2 Exercise 2 Exercise 3 Exercise 3 Exercise 4 Exercise 4.

Similar presentations


Presentation on theme: "TODAY’S OUTLINE Finite State Machine Exercise 1 Exercise 1 Exercise 2 Exercise 2 Exercise 3 Exercise 3 Exercise 4 Exercise 4."— Presentation transcript:

1 TODAY’S OUTLINE Finite State Machine Exercise 1 Exercise 1 Exercise 2 Exercise 2 Exercise 3 Exercise 3 Exercise 4 Exercise 4

2 Exercise 1

3 Solution 1 module FSM1 (reset, brake, accelerator, clock, constant_speed, decelerating, accelerating ); input reset, brake, accelerator, clock; output constant_speed, decelerating, accelerating ; reg constant_speed, decelerating, accelerating ; parameter S0 = 2'b00; parameter S1 = 2'b01; parameter S2 = 2'b10; parameter S3 = 2'b11; reg [1:0] state, next_state; always @ (posedge clk) begin case (state) S0: begin if (!brake && accelerator) begin next_state = S1; {accelerating,constant_speed,decelerating} = 3’b100; end else if (brake) begin next_state = S0; {accelerating,constant_speed,decelerating} = 3’b010; end

4 Cont.. S1: begin if (!brake && accelerator) begin next_state = S2; {accelerating,constant_speed,decelerating} = 3’b100; end else if (brake) begin next_state = S0; {accelerating,constant_speed,decelerating} = 3’b001; end S2: begin if (!brake && accelerator) begin next_state = S3; {accelerating,constant_speed,decelerating} = 3’b100; end else if (brake) begin next_state = S1; {accelerating,constant_speed,decelerating} = 3’b001; end

5 Cont.. S3: begin if (!brake && accelerator) begin next_state = S3; {accelerating,constant_speed,decelerating} = 3’b100; end else if (brake) begin next_state = S2; {accelerating,constant_speed,decelerating} = 3’b001; end default: begin next_state = S0; {accelerating,constant_speed,decelerating} = 3’b000; end endcase end always @(posedge clk or posedge reset) begin if (reset) state <= S0; else state <= next_state; end endmodule

6 Exercise 2 State Transition Table PS (Present State) NS (Next State) Output (Y) X = 0 X = 1 X = 0 X = 1 AAB00 BCD00 CAD00 DEF01 EAF11 FGF11 GAF01

7 Exercise 3 State Transition Table PS (Present State) NS (Next State) Output (Y) X = 0 X = 1 AAB0 BCD0 CAD0 DEF1 EAF1 FGF1 GAF1

8 Exercise 4 Sequence of events when you answer the telephone. We begin the process by waiting for the telephone to ring; during this time, we are in a wait state, (designated W) We begin the process by waiting for the telephone to ring; during this time, we are in a wait state, (designated W) When the phone rings, you pick up the handset and change to the answer state (designated A). When the phone rings, you pick up the handset and change to the answer state (designated A). At this point, one of four things may happen: At this point, one of four things may happen: the person making the call asks for you; the person making the call asks for you; the person making the call asks for someone who is currently at home; the person making the call asks for someone who is currently at home; the person making the call asks for someone who is currently not at home; the person making the call asks for someone who is currently not at home; it is a wrong number. it is a wrong number. If the call is for you, you say hello and change to the talking state (designated T). If the call is for you, you say hello and change to the talking state (designated T).

9 Cont.. If the call is for someone who is currently at home, you tell the person making the call to wait and move to a state where you are getting the person they desire (designated G). If the call is for someone who is currently at home, you tell the person making the call to wait and move to a state where you are getting the person they desire (designated G). If the call is for someone who is currently not at home, you tell the caller and change to the state where you are taking a message (designated M). If the call is for someone who is currently not at home, you tell the caller and change to the state where you are taking a message (designated M). If it is a wrong number, you tell the caller and move to the state where the call is finishing (designated F). If it is a wrong number, you tell the caller and move to the state where the call is finishing (designated F). Once in the talking state, whenever the caller talks you reply and stay in the talking state. Once in the talking state, whenever the caller talks you reply and stay in the talking state.

10 Cont.. If however, the caller says goodbye, you say goodbye and move to the finish state. If however, the caller says goodbye, you say goodbye and move to the finish state. If you were in the state where you were getting someone else to come to the phone, when they If you were in the state where you were getting someone else to come to the phone, when they arrive they say hello and enter the talking state. If you are taking a message and the caller says goodbye, you say goodbye and move to the finish state. If you are taking a message and the caller says goodbye, you say goodbye and move to the finish state. Once in the finish state, when the caller hangs up, you hang up the handset and change to the wait state. Once in the finish state, when the caller hangs up, you hang up the handset and change to the wait state.

11 Next week Lab 4 (Finite State Machine) Do some homework… That’s all for today. See u on Tuesday….


Download ppt "TODAY’S OUTLINE Finite State Machine Exercise 1 Exercise 1 Exercise 2 Exercise 2 Exercise 3 Exercise 3 Exercise 4 Exercise 4."

Similar presentations


Ads by Google