Lab 11 Pre-Lab

docx

School

Texas A&M University *

*We aren’t endorsed by this school

Course

248

Subject

Electrical Engineering

Date

Jan 9, 2024

Type

docx

Pages

3

Uploaded by BrigadierBoulderIbex38

Report
Pre-Lab 11: Traffic-Light Controler Lab Ethan Power, 832004261 According to the table, n has to equal 31. You need 31-bits to successfully count to the highest amount of delay (1,500,000,000). Verilog Code:
`timescale 1ns / 1ps `default_nettype none module tlc_fsm ( output reg [2:0] state, //output for debugging output reg RstCount, //use an always block output reg [1:0] highwaySignal, farmSignal, input wire [30:0] Count, //use n computed earlier input wire Clk, Rst //clock and reset ); parameter Srst = 3'b000, S0 = 3'b001, S1 = 3'b010, S2 = 3'b011, S3 = 3'b100, S4 = 3'b101, S5 = 3'b110; parameter Red = 2'b01, Yellow = 2'b10, Green = 2'b11; reg [2:0] next_state; // Register to hold the next state // Use non-blocking assignments for state transitions with synchronous logic always @(posedge Clk or posedge Rst) begin if (Rst) begin state <= Srst; RstCount <= 1'b1; // Reset the count when in reset state end else begin state <= next_state; // Move to the next state // Check if a state transition has occurred to reset the count RstCount <= (state != next_state); end end // Determine the next state based on the current state and Count value always @(*) begin case (state) Srst: next_state = S0; S0: next_state = (Count == 31'b1) ? S1 : S0; S1: next_state = (Count == 31'b11110) ? S2 : S1; S2: next_state = (Count == 31'b11) ? S3 : S2;
S3: next_state = (Count == 31'b1) ? S4 : S3; S4: next_state = (Count == 31'b1111) ? S5 : S4; S5: next_state = (Count == 31'b11) ? S0 : S5; default: next_state = Srst; endcase end // Output logic for highwaySignal and farmSignal always @(*) begin case (state) S0: begin highwaySignal = Red; farmSignal = Red; end S1: begin highwaySignal = Green; farmSignal = Red; end S2: begin highwaySignal = Yellow; farmSignal = Red; end S3: begin highwaySignal = Red; farmSignal = Red; end S4: begin highwaySignal = Red; farmSignal = Green; end S5: begin highwaySignal = Red; farmSignal = Yellow; end default: begin highwaySignal = Red; farmSignal = Red; end endcase end endmodule
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help