module traffic(clk, reset, P1, P2, P3, P4, PL); input clk; input reset; output[4:0] P1; output[4:0] P2; output[4:0] P3; // four...

80.2K

Verified Solution

Question

Electrical Engineering

module traffic(clk, reset, P1, P2, P3, P4, PL);
input clk;
input reset;
output[4:0] P1;
output[4:0] P2;
output[4:0] P3; // four roads
output [4:0] P4;
output[3:0] PL; //Pl is pedestrian

reg [4:0] P1;
reg [4:0] P2;
reg [4:0] P3;
reg [4:0] P4;
reg [3:0] PL;
reg [4:0] sig;

always @(posedge clk or negedge reset)
begin
   if(reset == 1'b0)begin
       P1 <= 5'b00100;
       P2 <= 5'b00100;
       P3 <= 5'b00100;
       P4 <= 5'b00100;
       PL <= 4'b1111;
       sig <= 5'b00000;
   end
   else begin
       sig <= sig + 1;
      
       case(sig[4:0])
       5'b00000:begin
       P1 <= 5'b10011; //path 1 isgreeen
       P2 <= 5'b00100; //all otherpaths are red
       P3 <= 5'b10011;
       P4 <= 5'b10011;
       PL <= 4'b1111;
       end
      
       5'b00100:begin
       P1 <= 5'b01000; //path 1 isyellow
       P2 <= 5'b00100; // all otherpaths are red
       P3 <= 5'b00100;
       P4 <= 5'b00100;
       PL <= 4'b1111;
       end

       5'b01000:begin
       P1 <= 5'b00100; //path 1 isred
       P2 <= 5'b10011; //path 2 isgreen
       P3 <= 5'b00100; // all otherpaths are red
       P4 <= 5'b00100;
       PL <= 4'b1111;
       end

       5'b01100:begin
       P1 <= 5'b00100;
       P2 <= 5'b01000; //path 2 isyellow
       P3 <= 5'b00100; // all otherpaths are red
       P4 <= 5'b00100;
       PL <= 4'b1111;
       end

       5'b10000:begin
       P1 <= 5'b00100;
       P2 <= 5'b00100; //path 3 isgreen
       P3 <= 5'b10011; // all otherpaths are red
       P4 <= 5'b00100;
       PL <= 4'b1111;
       end

       5'b10100:begin
       P1 <= 5'b00100;
       P2 <= 5'b00100; //path 3 isyellow
       P3 <= 5'b01000; // all otherpaths are red
       P4 <= 5'b00100;
       PL <= 4'b1111;
       end

       5'b11000:begin
       P1 <= 5'b00100;
       P2 <= 5'b00100; //all otherpaths are red
       P3 <= 5'b00100; // path 4 isyello
       P4 <= 5'b10011;
       PL <= 4'b1111;
       end

       5'b11100:begin
       P1 <= 5'b00100; //all otherpaths are red
       P2 <= 5'b00100;
       P3 <= 5'b00100;
       P4 <= 5'b00100;
       PL <= 4'b0000; //pedestriangreen
       end

       5'b11111:sig<= 6'b00000;

       default:begin    
      
       end
   endcase

   end
end

endmodule

can anyone write a testbench for this code in Verilog.

Answer & Explanation Solved by verified expert
4.1 Ratings (779 Votes)
TESTBENCH FOR THE GIVEN CODEmodule testbenchtrafficreg clkreg resetwire 40 P1wire 40 P2wire 40 P3 four roadswire 40 P4wire 30 PL Pl is pedestrianwire 40    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students