一.實(shí)驗(yàn)?zāi)康?br> 設(shè)計(jì)一個(gè)用于十字路口的交通燈控制器,能顯示十字路口東西、南北兩個(gè)方向的紅、黃、綠的指示狀態(tài);
具有倒計(jì)時(shí)的功能,用兩組數(shù)碼管作為東西和南北方向的倒計(jì)時(shí)顯示,主干道直行(綠燈)60秒后,左轉(zhuǎn)(綠燈)40秒;支干道直行(綠燈)45秒后,左轉(zhuǎn)(綠燈)30秒,在每次綠燈變成紅燈的轉(zhuǎn)換過程中,要亮黃燈5秒作為過渡。黃燈每秒閃亮一次。
只考慮直行和左轉(zhuǎn)車輛控制信號(hào)燈,右轉(zhuǎn)車輛不受信號(hào)燈控制, 南北向車輛與東西向車輛交替方向,同方向等待車輛應(yīng)先方向直行車輛而后放行左轉(zhuǎn)車輛。
二.實(shí)驗(yàn)代碼
主代碼
module traffic_fsm (lights, clk, rst);
input clk, rst;
output [5:0] lights;
wire clk, rst;
reg [5:0] lights;
// define reg
reg [2:0] curr_st;
reg [2:0] next_st;
reg [3:0] count;
// define state
parameter s0 = 3'b000;
parameter s1 = 3'b001;
parameter s2 = 3'b010;
parameter s3 = 3'b011;
parameter s4 = 3'b100;
parameter s5 = 3'b101;
// define lights
parameter light0 = 6'b100_001;
parameter light1 = 6'b100_010;
parameter light2 = 6'b100_100;
parameter light3 = 6'b001_100;
parameter light4 = 6'b010_100;
parameter light5 = 6'b100_100;
// define time delay
parameter delay5 = 5;
parameter delay1 = 1;
// 產(chǎn)生一個(gè)可能的狀態(tài)變化
always @ (posedge clk or negedge rst) begin
if (!rst) begin
curr_st <= s0;
count <= 0;
end
else
// curr_st = next_st;
begin
if (curr_st == s0 | curr_st == s3)
if (count < delay5 - 1)
count <= count + 1;
else begin
curr_st <= next_st;
count <= 0;
end
else if (curr_st == s1 | curr_st == s2 | curr_st == s4 | curr_st == s5) begin
curr_st <= next_st;
count <= 0;
end
end
end
// 產(chǎn)生下一個(gè)狀態(tài)的組合邏輯
always @ (curr_st) begin
case (curr_st)
s0:
next_st <= s1;
s1:
next_st <= s2;
s2:
next_st <= s3;
s3:
next_st <= s4;
s4:
next_st <= s5;
s5:
next_st <= s0;
default: begin
next_st <= s0;
end
endcase
end
// 產(chǎn)生輸出lights的組合邏輯
always @ (posedge clk or negedge rst) begin
if (!rst) lights = light0;
else
case (curr_st)
s0: lights = light0;
s1: lights = light1;
s2: lights = light2;
s3: lights = light3;
s4: lights = light4;
s5: lights = light5;
default: lights = light0;
endcase
end
endmodule
測(cè)試文件代碼(代碼二)
// testbench of ‘traffic_fsm’
module traffic_fsm_tb;
reg clk, rst;
wire [5:0] lights;
traffic_fsm u1 (.lights(lights), .clk(clk), .rst(rst));
initial begin
clk = 0;
rst = 0;
#10 rst = 1;
#80 rst = 0;
#20 rst = 1;
end
always #5 clk = ~clk;
endmodule
三.實(shí)驗(yàn)相關(guān)圖片
1. 代碼運(yùn)行波形圖
2. 代碼運(yùn)行邏輯圖
3. 代碼運(yùn)行引腳圖
四.交通燈控制系統(tǒng)
五.實(shí)驗(yàn)結(jié)果
完成了課題設(shè)置,設(shè)計(jì)了解了相關(guān)的設(shè)計(jì)代碼,自我知識(shí)的能力得到了擴(kuò)充,一門有意義、有效果的課程。文章來源:http://www.zghlxwxcb.cn/news/detail-502753.html
具體操作視頻鏈接如下
modsim或quartus交通燈設(shè)計(jì)實(shí)驗(yàn)(視頻詳解)文章來源地址http://www.zghlxwxcb.cn/news/detail-502753.html
到了這里,關(guān)于交通燈控制系統(tǒng)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!