// traffic light controller
// CSE140L 3-street, 9-state version
// inserts all-red after each yellow
// uses enumerated variables for states and for red-yellow-green
// 5 after traffic, 10 max cycles for green
// starter (shell) you need to complete the always_comb logic
import light_package ::*; // defines red, yellow, green
// same as Harris & Harris 4-state, but we have added two all-reds
module traffic_light_controller(
input clk, reset, ew_str_sensor, ew_left_sensor, ns_sensor,// traffic sensors, east-west straight, east-west left, north-south
output colors ew_str_light, ew_left_light, ns_light); // traffic lights, east-west straight, east-west left, north-south
// HRR = red-red following YRR; RRH = red-red following RRY;
// ZRR = 2nd cycle yellow, follows YRR, etc.
typedef enum {GRR, YRR, ZRR, HRR, RGR, RYR, RZR, RHR, RRG, RRY, RRZ, RRH} tlc_states;
tlc_statespresent_state, next_state;
integer ctr5, next_ctr5, //5 sec timeout when my traffic goes away
ctr10, next_ctr10; // 10 sec limit when other traffic presents
// sequential part of our state machine (register between C1 and C2 in Harris & Harris Moore machine diagram
// combinational part will reset or increment the counters and figure out the next_state
always_ff @(posedge clk)
if(reset) begin
present_state <= RRH;// so that EWS has top priority after resetctr5<= 0;ctr10 <= 0;endelse beginpresent_state <= next_state;ctr5<= next_ctr5;ctr10 <= next_ctr10;end// combinational part of state machine (“C1” block in the Harris & Harris Moore machine diagram)// default needed because only 6 of 8 possible states are defined/usedalways_comb beginnext_state = HRR;// default to reset statenext_ctr5= 0; next_ctr10 = 0;case(present_state)/* ************* Fill in the case statements ************** */GRR: begin// when is next_state GRR? YRR? // what does ctr5 do? ctr10?end // etc. endcaseend// combination output driver(“C2” block in the Harris & Harris Moore machine diagram)always_comb beginew_str_light = red;// cover all red plus undefined casesew_left_light = red;ns_light = red;case(present_state)// Moore machineGRR: ew_str_light = green;YRR,ZRR: ew_str_light = yellow;// my dual yellow states — brute force way to make yellow last 2 cyclesRGR: ew_left_light = green;RYR,RZR: ew_left_light = yellow;RRG: ns_light = green;RRY,RRZ: ns_light = yellow;endcaseendendmodule
Reviews
There are no reviews yet.