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

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

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

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

TODAY’S OUTLINETODAY’S OUTLINE

Finite State MachineFinite State Machine

Exercise 1Exercise 1Exercise 2Exercise 2Exercise 3Exercise 3Exercise 4Exercise 4

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

Exercise 1Exercise 1

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

Solution 1Solution 1module 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

end

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

Cont..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

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 end

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

Cont..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 end

default: begin next_state = S0; {accelerating,constant_speed,decelerating} = 3’b000;end

endcaseend

always @(posedge clk or posedge reset) begin if (reset) state <= S0; else state <= next_state; endendmodule

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

Exercise 2Exercise 2State Transition Table

PS PS

(Present State)(Present State)

NS NS

(Next State)(Next State)Output (Y)Output (Y)

X = 0X = 0 X = 1X = 1 X = 0X = 0 X = 1X = 1

AA AA BB 00 00

BB CC DD 00 00

CC AA DD 00 00

DD EE FF 00 11

EE AA FF 11 11

FF GG FF 11 11

GG AA FF 00 11

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

Exercise 3Exercise 3State Transition Table

PS PS

(Present State)(Present State)

NS NS

(Next State)(Next State)Output (Y)Output (Y)

X = 0X = 0 X = 1X = 1

AA AA BB 00

BB CC DD 00

CC AA DD 00

DD EE FF 11

EE AA FF 11

FF GG FF 11

GG AA FF 11

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

Exercise 4Exercise 4Sequence of events when you answer the telephone. Sequence of events when you answer the telephone.

We begin the process by waiting for the telephone to ring; during We begin the process by waiting for the telephone to ring; during this time, we are in a wait state, (designated W)this time, we are in a wait state, (designated W)

When the phone rings, you pick up the handset and change to the When the phone rings, you pick up the handset and change to the answer state (designated A). 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 the person making the call asks for someone who is

currently at home; currently at home; the person making the call asks for someone who is the person making the call asks for someone who is

currently not at home; 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 If the call is for you, you say hello and change to the talking state (designated T). (designated T).

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

Cont..Cont.. If the call is for someone who is currently at home, you If the call is for someone who is currently at home, you

tell the person making the call to wait and move to a tell the person making the call to wait and move to a state where you are getting the person they desire state where you are getting the person they desire (designated G). (designated G).

If the call is for someone who is currently not at home, If the call is for someone who is currently not at home, you tell the caller and change to the state where you are you tell the caller and change to the state where you are taking a message (designated M). taking a message (designated M).

If it is a wrong number, you tell the caller and move to If it is a wrong number, you tell the caller and move to the state where the call is finishing (designated F). the state where the call is finishing (designated F).

Once in the talking state, whenever the caller talks you Once in the talking state, whenever the caller talks you reply and stay in the talking state. reply and stay in the talking state.

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

Cont..Cont.. If however, the caller says goodbye, you say goodbye If however, the caller says goodbye, you say goodbye

and move to the finish state. and move to the finish state.

If you were in the state where you were getting someone If you were in the state where you were getting someone else to come to the phone, when they else to come to the phone, when they arrive they say hello and enter the talking state. arrive they say hello and enter the talking state.

If you are taking a message and the caller says If you are taking a message and the caller says goodbye, you say goodbye and move to the finish state. goodbye, you say goodbye and move to the finish state.

Once in the finish state, when the caller hangs up, you Once in the finish state, when the caller hangs up, you hang up the handset and change to the wait state. hang up the handset and change to the wait state.

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

Next week Lab 4 Next week Lab 4 (Finite State Machine)(Finite State Machine)

Do some homework…Do some homework…

That’s all for today. That’s all for today.

See u on Tuesday….See u on Tuesday….