2013年11月30日 星期六

sensor based single way Traffic Light Controller.v

// File        : sensor based single way Traffic Light Controller.v


module TLC_Sensor ( clk ,sensor ,r ,y ,g );

output r ;
reg r ;
output y ;
reg y ;
output g ;
reg g ;

input clk ;
wire clk ;
input sensor ;
wire sensor ;

parameter red = 0;
parameter yellow = 1;
parameter green = 2;

reg [1:0] p_state;
reg [1:0] n_state;

initial p_state = red;

always @ (posedge (clk)) begin
p_state <= n_state;
end

always @ (p_state or sensor) begin
case (p_state)
red : n_state = green ;
green : begin
if (sensor)
n_state = green;
else
n_state = yellow;
end
yellow : n_state = red ;
endcase
end

always @ (p_state) begin
case (p_state)
red : begin
r = 1;
y = 0;
g = 0;
end

yellow : begin
r = 0;
y = 1;
g = 0;
end

green : begin
if (sensor)
n_state = green;
else
n_state = yellow;
r = 0;
y = 0;
g = 1;
end   

endcase
end

endmodule

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...