版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、fpga课程设计 交通灯控制器通信工程学院电科0701班罗超(17)第一部分 技术规范 1.1功能描述:实现一个由一条主干道和一条支干道的汇合点形成的十字路口的交通灯控制器,具体功能:(1) 主、支干道各设有一个绿、黄、红指示灯,两个显示数码管。(2) 主干道处于长允许通行状态,而支干道有车来时才允许通行。当主干道允许通行亮绿灯时,支干道亮红灯。而支干道允许通行亮绿灯时,主干道亮红灯。(3) 当主干道、支干道均有车时,两者交替允许通行,主干道每次通行45 秒,支干道每次通行25 秒,在每次由绿灯向红灯转换的过程中,要亮5 秒的黄灯作为过渡,并进行减计时显示。每个周期结束时都要进行支干道是否有车
2、的检测,若有车则进行下一个周期,若没有,则主干道亮绿灯,支干道亮红灯,直到检测到支干道有车。1.2系统总体框图:根据设计要求和系统所具有的功能,并参考相关的文献资料,经行方案设计,可以画出如下图所示的交通信号灯控制器的系统框图。时钟分频模块交通灯控制模块 扫描显示译码模块clkrstcarsignal计时模块数码管段码sel数码管位码segled灯i/o管脚的描述名称方向电平位宽功能 clkinput3.3v1系统时钟信号(10khz)carsignal input3.3v1检测支路是否有车rst input3.3v1复位信号led output3.3v6led灯sel output3.3v7
3、数码管段码 seg output3.3v4数码管位码 表一:系统总体i/o管脚的描述注:其中系统时钟的频率选为10khz,复位采取同步复位方式,且低有效。支干道检测到有车时, carsignal=1;否则,carsignal=0。方案核心:在交通灯控制器的设计中,交通灯控制及计时模块是本设计的关键模块。第二部分总体设计方案交通灯2.1系统详细框图:在系统总体框图的基础上进一步详细设计,得到如下系统详细框图。rstled灯carsignalclk显示控制单元定时模块显示单元交通灯控制模块时钟分频模块译码单元数码管显示 图三:系统详细框图注:系统总体i/o管脚描述请查看技术规范。2.2具体模块设计
4、1.时钟分频模块系统的动态扫描需要10khz的脉冲,而系统时钟计时模块需要1hz的脉冲。分频模块主要为系统提供所需的时钟计时脉冲。该模块将10khz的脉冲信号进行分频,产生1s的方波(占空比为50%),作为系统时钟计时信号。clk时钟分频模块rstclk_out 图四:时钟分频模块框图i/o管脚描述如下:名称方向电平位宽功能clkinput3.3v1系统时钟(10khz)rstinput3.3v1复位信号clk_outoutput3.3v1分频后时钟信号(1hz) 表二:时钟分频模块i/o端口描述注:系统时钟的频率为10khz,分频后的时钟信号为1hz(占空比为50%)。复位信号为同步复位,且
5、低有效。2.交通灯控制及计时模块控制模块jtdkzh:根据主干道、支干道输入信号以及时钟信号clk,发出主、支干道指示灯的控制信号,同时向各个定时单元、显示控制单元发出使能控制信号产生系统的状态机,控制其他部分协调工作。计时模块分别实现45s,25s,5s的定时,根据主、支干道输入信号和时钟信号以及交通灯控制器发出的使能信号按要求进行定时用来设定主干道和支干道计时器的初值,并为扫描显示译码模块提供倒计时时间。控制模块采用状态机进行设计,可以定义出5种状态,分别为s0:主干道绿灯,支干道红灯且没有车辆行驶;s1:主干道绿灯,支干道红灯且支干道有车辆驶入;s2:主干道黄灯,支干道红灯;s3:主干道
6、红灯,支干道绿灯;s4:主干道红灯,支干道黄灯。利用case语句定义状态的转换方式及时间的变换方式,达到主干道绿灯亮45秒,支干道绿灯亮25秒,黄灯亮5秒的设计要求。clk_outcarsignalrstled交通灯控制模块count_h_1count_l_1count_h_2count_h_2图五:交通灯控制及计数模块i/o管脚描述如下:名称方向电平位宽功能clk_outinput3.3v1分频后时钟信号(1hz)rstinput3.3v1复位信号(同步复位)carsignalinput3.3v1检测信号(低有效)count_h_1output3.3v4主干道时间高位译码count_l_1o
7、utput3.3v4主干道时间低位译码count_h_2output3.3v4支干道时间高位译码count_l_2output3.3v4支干道时间低位译码ledoutput3.3v6led灯 表三:交通灯控制模块i/o端口描述 系统的状态图如下所示carsignal =0 s0 s3carsignal =1 s1 s2 s0:主干道绿灯,支干道红灯s1:主干道黄灯,支干道红灯s2:主干道红灯,支干道绿灯s3:主干道红灯,支干道黄灯3.扫描显示译码模块扫描显示译码模块可以根据控制信号,驱动交通信号灯以及倒计时数码管的显示,其中数码管的显示采用动态扫描显示。rstclksegsel扫描显示译码模块
8、count_h_1count_l_1count_h_2count_h_2 图六:扫描显示译码模块框图该模块的i/o管脚描述如下:名称方向电平位宽功能clkinput3.3v1系统时钟信号(10khz)rstinput3.3v1复位信号(低有效)count_h_1input3.3v4主干道时间高位译码count_l_1input3.3v4主干道时间低位译码count_h_2input3.3v4支干道时间高位译码count_l_2input3.3v4支干道时间低位译码seloutput3.3v7数码管段码segoutput3.3v3数码管位码表四:扫描显示译码模块i/o端口描述第三部分仿真结果 m
9、odelsim 前仿真 quartus2后仿真第四部分 源代码分频模块:module fenpinqi(clk,rst,clk_odd);input clk,rst;output clk_odd;reg clk_odd;reg13:0 count;parameter n = 10;always (posedge clk)if(! rst)begin count = 1b0;clk_odd = 1b0;endelse if ( count n/2-1)begin count = count + 1b1; endelsebegin count = 1b0;clk_odd = clk_odd; en
10、dendmodule控制及计时模块:modulecontrol(led,car,rst,clk,count_h_1,count_l_1,count_h_2,count_l_2);output3:0count_h_1,count_l_1,count_h_2,count_l_2;output 5:0led;input clk,rst,car;reg 5:0 led;reg3: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(posedg
11、e clk or negedge rst)if(!rst)beginled=6b010100;state=s0;count_h_1=4b0000;count_l_1=4b0000; count_h_2=4b0000;count_l_2=4b0000; end else begincase(state)s0:beginbeginif(!car)begin led=6b010100; /count_h_1=4b0100;count_l_1=4b0101;/? count_h_1=4b0111;count_l_1=4b0111; end else begin if(count_h_1 = 4b011
12、1) begin count_h_1=4b0100;count_l_1=4b0101; count_h_2=4b0101;count_l_2=4b0000; end else if(count_l_1=0) if(count_h_1=0) begin led=6b001100; count_h_1=4b0000;count_l_1=4b0100; state=s1; if(count_l_2=0) begin count_h_2=count_h_2-1b1; count_l_2=4b1001; end elsebegin count_l_2=count_l_2-1b1;end end else
13、 begin count_h_1=count_h_1-1b1; count_l_1=4b1001; if(count_l_2=0) begin count_h_2=count_h_2-1b1; count_l_2=4b1001; end elsebegin count_l_2=count_l_2-1b1; end end elsebegin count_l_1=count_l_1-1b1; if(count_l_2=0) begin count_h_2=count_h_2-1b1; count_l_2=4b1001; end elsebegin count_l_2=count_l_2-1b1;
14、 end end end end /* begin if(!car) begin count_h_2=4b0101;count_l_2=4b0000; end elseif(count_l_2=0) begin count_h_2=count_h_2-1b1; count_l_2=4b1001;end elsebegin count_l_2=count_l_2-1b1; end end */end /* if(count_l_1=0) begin if(count_h_1=0) begin led=6b001100; count_h_1=4b0000;count_l_1=4b0100; sta
15、te=s1; endelse begin count_h_1=count_h_1-1b1;count_l_1=4b1001; endend elsebegin count_l_1=count_l_1-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 s1: beginif(count_l_1=0)
16、begin if(count_h_1=0) begin led=6b100010; count_h_1=4b0010;count_l_1=4b1001; count_h_2=4b0010;count_l_2=4b0100; state=s2; endelsebegin count_h_1=count_h_1-1b1; count_h_2=count_h_2-1b1; endendelsebegin 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
17、_2=0) begin led=6b100001; count_h_2=4b0000;count_l_2=4b0100; state=s3; elsebegin count_h_2=count_h_2-1b1; count_l_2=4b1001; end end else begincount_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 endelse begin count_l_1=count_l_1-1b1; end end s3:begin
18、 if(count_l_2=0) begin if(count_h_2=0) begin led=6b010100; count_h_1=4b0100;count_l_1=4b1001; count_h_2=4b0100;count_l_2=4b0100; state=s0; end elsebegin 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 endcaseend endmodule扫描译码
19、显示模块:modulesaomiao(rst,clk,count_h_1,count_l_1,count_h_2,count_l_2,sel,seg);input rst,clk;input3: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) begin if(!rst)begincoun
20、t=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)/?1msif (!rst)begincnt=2b00;endelse cnt=cnt+1b1; always(negedge rst or posedge clk) if(!rst) begin/ sel = 7b0000000 ;seg = 4b1111 ;endelse begincase (cnt)2b00:
21、beginseg =4b1110 ; data=count_h_1;end 2b01: begiseg= 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 ;endendcaseendalways (data or seg)begincase(data)4b0000:sel=7b1111110;4
22、b0001: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; endcaseend endmodule顶层模块: module jiaotongdeng(clk,rst,car,led,sel,seg,count_h_1,count_l_1
23、,count_h_2,count_l_2,clk_odd);input clk,rst,car;output 3:0 seg;output 6:0 sel;output 5:0 led;output 3:0count_h_1,count_l_1,count_h_2,count_l_2;output clk_odd;wire 3:0count_h_1,count_l_1,count_h_2,count_l_2;wire clk_odd;saomiao ee(rst,clk_odd,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);fen
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 基金从业资格证券投资基金基础知识模拟试题
- 中西医结合执业医师实践技能历年真题解析与操作规范
- 2027年进公司合同二篇
- 2027年双务合同和无名合同二篇
- (2026版)医院科室工作年度总结
- 股权激励计划执行协议范本2026
- 区块链区块链平台合作协议2026年升级
- 跨文化企业品牌授权合作协议
- 临水道路施工方案
- 包头钢铁职业技术学院单招职业技能考试题库及答案
- (2026秋新版)西师大版五年级数学上册全册教案
- DB11∕T 428-2018 种羊场舍区、场区、缓冲区环境质量要求
- 50吨门式起重机拆除施工方案样本
- 2024年度2024行政复议法培训
- 食品毒理学-第二章-毒理学基本概念
- 智能交通概论全套教学课件
- YY/T 1833.4-2023人工智能医疗器械质量要求和评价第4部分:可追溯性
- 中药的贮藏与养护技术-中药饮片保管与养护
- 双液系的气液平衡相图课件
- 中考物理学科双向细目表
- 幼儿园多媒体PPT课件制作PPT完整全套教学课件
评论
0/150
提交评论