FPGA(EDA)课程设计——交通灯(附源代码).doc

上传人:土8路 文档编号:10376944 上传时间:2021-05-13 格式:DOC 页数:23 大小:278KB
返回 下载 相关 举报
FPGA(EDA)课程设计——交通灯(附源代码).doc_第1页
第1页 / 共23页
FPGA(EDA)课程设计——交通灯(附源代码).doc_第2页
第2页 / 共23页
FPGA(EDA)课程设计——交通灯(附源代码).doc_第3页
第3页 / 共23页
FPGA(EDA)课程设计——交通灯(附源代码).doc_第4页
第4页 / 共23页
FPGA(EDA)课程设计——交通灯(附源代码).doc_第5页
第5页 / 共23页
点击查看更多>>
资源描述

《FPGA(EDA)课程设计——交通灯(附源代码).doc》由会员分享,可在线阅读,更多相关《FPGA(EDA)课程设计——交通灯(附源代码).doc(23页珍藏版)》请在三一文库上搜索。

1、技术规范功能描述:实现一个由一条主干道和一条支干道的汇合点形成的十字路口的交通灯控制器,具体功能:(1) 主、支干道各设有一个绿、黄、红指示灯,两个显示数码管。(2) 主干道处于长允许通行状态,而支干道有车来时才允许通行。当主干道允许通行亮绿灯时,支干道亮红灯。而支干道允许通行亮绿灯时,主干道亮红灯。(3) 当主干道、支干道均有车时,两者交替允许通行,主干道每次通行45 秒,支干道每次通行25 秒,在每次由绿灯向红灯转换的过程中,要亮5 秒的黄灯作为过渡,并进行减计时显示。AB45秒倒计时绿灯亮50秒倒计时 红灯亮30秒? 红灯亮25秒绿灯亮5秒黄5秒黄图一:交通灯闪烁时序图 每个周期结束时都

2、要进行支干道是否有车的检测,若有车则进行下一个周期,若没有,则主干道亮绿灯,支干道亮红灯,直到检测到支干道有车。系统总体框图:根据设计要求和系统所具有的功能,并参考相关的文献资料,经行方案设计,可以画出如下图所示的交通信号灯控制器的系统框图。数码管位码数码管段码LED灯clkcarrst时钟分频模块交通灯控制及计时模块扫描显示译码模块 图二:系统总体框图I/O管脚的描述名称方向电平位宽功能 clkInput3.3V1系统时钟信号(10KHZ) car Input3.3V1检测信号rst Input3.3V1复位信号led Output3.3V6LED灯sel Output3.3V7数码管段码

3、seg Output3.3V4数码管位码 表一:系统总体I/O管脚的描述注:其中系统时钟的频率选为10KHZ,复位采取同步复位方式,且低有效。支干道检测到有车时, car=1;否则,car=0。方案对比:在交通灯控制器的设计中,交通灯控制及计时模块是本设计的关键模块。这个模块的实现可以用状态机,也可以用ifelse语句来写。相比较而言,用状态机来写比较清楚明白直观,且容易避免出现未知状态。所以选用状态机来写此模块。拟选用的FPGA类型:ep1cq240c8n总体设计方案交通灯一、 系统详细框图在系统总体框图的基础上进一步详细设计,得到如下系统详细框图 数码管位码数码管段码LED灯clkcarr

4、st时钟分频模块交通灯控制及计时模块扫描显示译码模块clk_odd。 图三:系统详细框图注:系统总体I/O管脚描述请查看技术规范。二、 具体模块设计1.时钟分频模块系统的动态扫描需要10KHZ的脉冲,而系统时钟计时模块需要1HZ的脉冲。分频模块主要为系统提供所需的时钟计时脉冲。该模块将10KHZ的脉冲信号进行分频,产生1S的方波(占空比为50%),作为系统时钟计时信号。clk时钟分频模块rstclk_odd 图四:时钟分频模块框图I/O管脚描述如下:名称方向电平位宽功能clkinput3.3V1系统时钟(10KHZ)rstinput3.3V1复位信号clk_oddoutput3.3V1分频后时

5、钟信号(1HZ) 表二:时钟分频模块I/O端口描述注:系统时钟的频率为10KHZ,分频后的时钟信号为1HZ(占空比为50%)。复位信号为同步复位,且低有效。2.交通灯控制及计时模块控制模块根据外部输入信号和计时模块产生的输出信号,产生系统的状态机,控制其他部分协调工作。计时模块用来设定主干道和支干道计时器的初值,并为扫描显示译码模块提供倒计时时间。控制模块采用状态机进行设计,可以定义出5种状态,分别为S0:主干道绿灯,支干道红灯且没有车辆行驶;S1:主干道绿灯,支干道红灯且支干道有车辆驶入;S2:主干道黄灯,支干道红灯;S3:主干道红灯,支干道绿灯;S4:主干道红灯,支干道黄灯。利用CASE语

6、句定义状态的转换方式及时间的变换方式,达到主干道绿灯亮45秒,支干道绿灯亮25秒,黄灯亮5秒的设计要求。clk_oddcarrstled交通灯控制模块count_H_1count_L_1count_H_2count_H_2 图五:交通灯控制及计数模块I/O管脚描述如下:名称方向电平位宽功能clk_oddInput3.3V1分频后时钟信号(1HZ)rstInput3.3V1复位信号(同步复位)carInput3.3V1检测信号(低有效)count_H_1Output3.3V4主干道时间高位译码count_L_1Output3.3V4主干道时间低位译码count_H_2Output3.3V4支干道

7、时间高位译码count_L_2Output3.3V4支干道时间低位译码ledOutput3.3V6LED灯 表三:交通灯控制模块I/O端口描述 系统状态流程图:S0:主干道绿灯,支干道红灯S1:主干道黄灯,支干道红灯S2:主干道红灯,支干道绿灯S3:主干道红灯,支干道黄灯3.扫描显示译码模块扫描显示译码模块可以根据控制信号,驱动交通信号灯以及倒计时数码管的显示,其中数码管的显示采用动态扫描显示。 图六:扫描显示译码模块框图该模块的I/O管脚描述如下:名称方向电平位宽功能clkInput3.3V1系统时钟信号(10KHZ)rstInput3.3V1复位信号(低有效)count_H_1Input3

8、.3V4主干道时间高位译码count_L_1Input3.3V4主干道时间低位译码count_H_2Input3.3V4支干道时间高位译码count_L_2Input3.3V4支干道时间低位译码selOutput3.3V7数码管段码segOutput3.3V3数码管位码表四:扫描显示译码模块I/O端口描述附件:源代码:分频模块:module fenpinqi(clk,rst,clk_odd); input clk,rst; output clk_odd; reg clk_odd; reg13:0 count; parameter N = 10000; always (posedge clk)

9、if(! rst) begin count = 1b0; clk_odd = 1b0; end else if ( count N/2-1) begin count = count + 1b1; end else begin count = 1b0; clk_odd = clk_odd; endendmodule控制及计时模块:module control(led,car,rst,clk,count_H_1,count_L_1,count_H_2,count_L_2); output 3:0count_H_1,count_L_1,count_H_2,count_L_2; output 5:0l

10、ed; input clk,rst,car; reg 5:0 led; reg 3:0count_H_1,count_L_1,count_H_2,count_L_2; reg 1:0state; parameter S0=2b00, S1=2b01, S2=2b10, S3=2b11; always (posedge clk or negedge rst) if(!rst) begin led=6b010100; state=S0; count_H_1=4b0000;count_L_1=4b0000; count_H_2=4b0000;count_L_2=4b0000; end else be

11、gin case(state) S0: begin if(!car) begin led=6b010100; count_H_1=4b0100;count_L_1=4b0101; end else if(count_L_1=0) begin if(count_H_1=0) begin led=6b001100; count_H_1=4b0000;count_L_1=4b0100; state=S1; end else begin count_H_1=count_H_1-1b1; count_L_1=4b1001; end end else begin count_L_1=count_L_1-1

12、b1; / count_L_2=count_L_2-1b1; end if(!car) begin count_H_2=4b0101;count_L_2=4b0000; end else if(count_L_2=0) begin count_H_2=count_H_2-1b1; count_L_2=4b1001; end else begin count_L_2=count_L_2-1b1; end end S1: begin if(count_L_1=0) begin if(count_H_1=0) begin led=6b100010; count_H_1=4b0010;count_L_

13、1=4b1001; count_H_2=4b0010;count_L_2=4b0100; state=S2; end else begin count_H_1=count_H_1-1b1; count_H_2=count_H_2-1b1; end end else begin count_L_1=count_L_1-1b1; count_L_2=count_L_2-1b1; end end S2: begin if(count_L_2=0) begin if(count_H_2=0) begin led=6b100001; count_H_2=4b0000;count_L_2=4b0100;

14、state=S3; end else begin count_H_2=count_H_2-1b1; count_L_2=4b1001; end end else begin count_L_2=count_L_2-1b1; end if(count_L_1=0) begin begin count_H_1=count_H_1-1b1; count_L_1=4b1001; end end else begin count_L_1=count_L_1-1b1; end end S3: begin if(count_L_2=0) begin if(count_H_2=0) begin led=6b0

15、10100; count_H_1=4b0100;count_L_1=4b1001; count_H_2=4b0100;count_L_2=4b0100; state=S0; end else begin count_H_1=count_H_1-1b1; count_H_2=count_H_2-1b1; end end else begin count_L_1=count_L_1-1b1; count_L_2=count_L_2-1b1; end end endcaseend endmodule扫描译码显示模块:module saomiao(rst,clk,count_H_1,count_L_1

16、,count_H_2,count_L_2,sel,seg); input rst,clk; input 3:0count_H_1,count_L_1,count_H_2,count_L_2; output 6:0sel; output 3:0seg; reg 6:0sel; reg 3:0seg; reg 15:0 count; reg 1:0 cnt; reg 3:0 data; reg clk_odd; always(posedge clk or negedge rst)/50M-1k,50M/1k/2/?,50Mhz1khz,?50% begin if(!rst)begin count=

17、0; clk_odd=0; end else if(count=16d2) begin clk_odd=clk_odd; count=0; end else count=count+1b1; end always (negedge rst or posedge clk_odd)/?1ms if (!rst)begin cnt=2b00; end else cnt=cnt+1b1; always(negedge rst or posedge clk) /?if(!rst) begin / sel = 7b0000000 ; seg = 4b1111 ; end else begin case (

18、cnt) 2b00: begin seg =4b1110 ;/ ? data=count_H_1; end 2b01: begin seg = 4b1101 ;/ ? data =count_L_1; end 2b10:begin / ? seg= 4b1011 ; data=count_H_2; end 2b11: begin/ ? seg= 4b0111 ; data=count_L_2; end default : begin / sel = 8b0000000 ; seg = 4b0000 ; end endcase end always (data or seg)begin case

19、(data) 4b0000:sel=7b1111110; 4b0001:sel=7b0110000; 4b0010:sel=7b1101101; 4b0011:sel=7b1111001; 4b0100:sel=7b0110011; 4b0101:sel=7b1011011; 4b0110:sel=7b1011111; 4b0111:sel=7b1110000; 4b1000:sel=7b1111111; 4b1001:sel=7b1111011; default:sel=7b1111110; endcase end endmodule顶层模块: module jiaotongdeng(clk

20、,rst,car,led,sel,seg); input clk,rst,car;output 3:0 seg;output 6:0 sel;output 5:0 led;wire 3:0count_H_1,count_L_1,count_H_2,count_L_2;wire clk_odd;saomiao ee(rst,clk,count_H_1,count_L_1,count_H_2,count_L_2,sel,seg);control rr(led,car,rst,clk_odd,count_H_1,count_L_1,count_H_2,count_L_2);fenpinqi tt(clk,rst,clk_odd);endmodule

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1