Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design a testbench in eda playground for the following verilog module such that waveform results can be viewed / / Moore - type Finite State

Design a testbench in eda playground for the following verilog module such that waveform results can be viewed
// Moore-type Finite State Machine
// For a traffic light controller
module traffic_light_fsm (
//Inputs - Traffic sensors for:
input wire Ta,//Avenue
input wire Tb,//Boulevard
//outputs - Traffic Lights for:
output reg [1:0] La,//Avenue
output reg [1:0] Lb //Boulevard
);
//set up the state encodings
parameter S0=2'b00; //state 0
parameter S1=2'b01; //state 1
parameter S2=2'b10; //state 2
parameter S3=2'b11; //state 3
//set up the current and next state registers
reg [1:0] state, next;
//determine the outputs
always @ (posedge clk or posedge rst) begin
//using this if-else statement makes sure you take care of reset
if (rst) begin
state <= S0; //start at state 0
La <=2'b00; //Avenue light green
Lb <=2'b10; //boulevard light red
end else begin
state <= next;
//start a case statement that sets the outputs based on current state
case(state)
S0: begin
La <=2'b00; //Avenue light green
Lb <=2'b10; //Boulevard light red
end
S1: begin
La <=2'b01; //Avenue light yellow
Lb <=2'b10; //Boulevard light red
end
S2: begin
La <=2'b10; //Avenue light red
Lb <=2'b00; //Boulevard light green
end
S3: begin
La <=2'b10; //Avenue light red
Lb <=2'b01; //Boulevard light yellow
end
//make sure to give a default when using case statements
//for a traffic light, set all lights to red to prevent accidents
default: begin
La <=2'b00; //Avenue light red
Lb <=2'b00; //Boulevard light red
end
endcase
end
end
//State transitions: move on to the next state
//always statement: Ta and Tb are in the sensitivity list
// because the next state are determined by these values
always @ (Ta, Tb) begin
case(state)
S0: begin
if (Ta ==0)//if theres no traffic on Avenue,
next = S1; //move to the next state
else //otherwise,
next = S0; //stay in this state
end
S1: begin
next = S2; //traffic doesn't affect this state. Move on to the next state
end
S2: begin
if(Tb ==0)//if no traffic on Boulevard
next = S3; //move on to the next state
else //otherwise,
next = S2; //stay in this state
end
S3: begin
next = S0; //traffic doesn't affect this state. Move on to the next state
end
//handle the default case for this case statement
default: begin
next = S0;
end
endcase
end
endmodule

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

Describe two different ways to assess the capability of a process.

Answered: 1 week ago