版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、一、设计任务设计一个十字路口的红、绿、黄三色信号交通灯控制电路,具体要求如下: 1)用红、绿、黄三色发光二极管作信号灯。主干道为东西向,有红、绿、黄三个灯;另一支干道为南北向,也有红、绿、黄三个灯。红灯亮禁止通行;绿灯亮允许通行;黄灯亮则给行驶中的车辆有时间停靠到禁行线之外。 2)东西和南北每次绿灯放行26s,红灯禁止30s。 在每次由亮绿灯变成亮红灯的转换过程中间,需要亮5s的黄灯作为过渡,以使行驶中的车辆有时间停靠到禁行线以外。 3)能实现正常的、即时显示功能,用实验箱上的4个七段数码管作为到计时显示器,分别显示东西、南北方向的红灯、绿灯、黄灯时间。 二、设计原理首先要对时钟进行分频。由于
2、系统时钟频率比较大,因此首先分频产生时钟,用于下面的电路的控制;然后是各种颜色之间的转换,在此在添加一个使能端en,当使能端en为1的时候,就开始进行状态循环以及倒计时,然后en就立即变为0;在状态机中一共有四个状态,如下图所示: 然后,我们这里用了BCD码表示倒计时时间。灯亮或闪烁时间(绿、黄、红分别为26s、130s、5s)用BCD码表示(分别为26h、30h、5h),倒计时的时候个位和十位分别是BCD码的高四位和低四位,首先是低四位倒数,当倒数到0时,给它重新赋值为9,且高四位减1,如此循环,直到这个数减到0,此时表示某一个灯亮的时间到,接着进行下一个状态,为了能使进入下一个状态, 必须
3、在时间减到0的时候,给使能端en 赋值1;由于用的BCD码,高四位和低四位就分别是我们要在译码模块的要用数码管显示的十位和个位。用数据选择器来控制东西、南北的灯亮。三、程序流程图 开始计数开始高电平个是否小于5M输出进行反向电平计数累加YN 11分频器的设计流程图 开始是否有清零信号个位是否为4计数开始继续累加NYNY个位输出0 1.2 5进制的设计流程图 开始是否有清零信号个位是否为9计数开始十位是否为2个位十位清零个位加一十位加一输出NYNNYY 1.3 30进制的设计流程图 开始是否有清零信号个位是否为9计数开始十位是否为2个位加一十位加一输出个位是否为5个位加一十位个位清零YNNNY
4、1.4 26进制的设计流程图甲道行驶,乙道禁止状态s0R1=0,G1=1,Y1=0R2=0,G2=0,Y2=0C2是否为1NY甲道停止,乙道禁止R1=0,G1=0,Y1=1R2=0,G2=0,Y2=0C1是否为1N状态s1R1=1,G1=0,Y1=0R2=0,G2=1,Y2=0甲道禁止,乙道行驶状态s2YC2是否为1甲道禁止,乙道停止Y状态s3NC1是否为1NR1=1,G1=0,Y1=0R2=0,G2=0,Y2=1Y 1.5 状态机的程序流程图四、程序设计1、5进制的设计library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_un
5、signed.all;entity jinzhi5 isport(clk,en,rst:in std_logic; ge,shi: out std_logic_vector(3 downto 0); cout:out std_logic); end jinzhi5; architecture behav of jinzhi5 isbegin process(clk,en) variable a,b: std_logic_vector(3 downto 0);begin if(rst=0) then a:=0101;b:=0000 elsif clkevent and clk=1 then if
6、(en=1) then if(a=0) then a:=0101;b:=0000,cout=1; else a:=a-1;b:=0000,cout=0; end if; end if; end if; ge=a;shi=b; end process; end behav; 仿真结果2、 26进制的程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity jinzhi26 isport(clk,en:in std_logic; ge: out std_logic_vector(3 downt
7、o 0); shi: out std_logic_vector(3 downto 0); cout:out std_logic); end jinzhi26; architecture behav of jinzhi26 isbegin process(clk,en) variable a: std_logic_vector(3 downto 0); variable b: std_logic_vector(3 downto 0);begin if(en=0) then a:=0010;b:=0101; elsif clkevent and clk=1 then if(a=0 and b=0)
8、 then a:=0010;b:=0101;cout=1; else if(b=0) then b:=1001;a:=a-1; else b:=b-1;cout=0; end if; end if; end if; ge=b;shi=a; end process; end behav; 仿真结果3、30进制的程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity jinzhi30 isport(clk,en,rst:in std_logic; ge: out std_logic_vect
9、or(3 downto 0); shi: out std_logic_vector(3 downto 0); cout:out std_logic); end jinzhi30; architecture behav of jinzhi30 isbegin process(clk,en) variable a: std_logic_vector(3 downto 0); variable b: std_logic_vector(3 downto 0);begin if(rst=0) then a:=0000;b:=0000; elsif clkevent and clk=1 then if e
10、n=1 then if(a=0 and b=0) then a:=0011;b:=0000;cout=1; else if(b=0) then b:=1001;a:=a-1; else b:=b-1;cout=0; end if; end if; end if; end if; ge=b;shi=a; end process; end behav; 仿真结果4、10M分频器的设计library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity fenpin20 isport(clk:in std_lo
11、gic; c:out std_logic); end fenpin10; architecture art of fenpin10 is signal m: std_logic_vector(31 downto 0); signal c1:std_logic; begin process(clk) begin if rising_edge(clk) then if m then m=m+1; else m0);c1=not c1; end if; end if; c q q q q q q q q q q null; end case; end process; qout=q; end beh
12、av; 仿真波形6、四选一数据分配器的程序 数据选择器中,Y1,Y2,Y2是从状态机中输出的控制信号,sshi,sge分别代表30进制的十位和各位,eshi,ege分别代表26进制的十位和各位,wshi,wge分别代表5进制的十位和各位。jshi,jge分别连接着甲道的数码管来显示时间。Yshi,yge分别连接着甲道的数码管来显示时间。由于仿真时候设置的数据太多了,在这里就不进行波形仿真了。library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity xuanzeqi isport(Y1,Y2,Y
13、3,rst:in std_logic; sshi,sge,eshi,ege,wu:in std_logic_vector(3 downto 0); jshi,jge,yshi,yge:out std_logic_vector(3 downto 0); end xuanzeqi; architecture behav of xuanzeqi is signal yy: std_logic_vector(2 downto 0);begin yy=Y1&Y2&Y3; process(yy)begin if rst=0 then jshi=0000;jge=0000;yshi=0000;yge jsh
14、i=eshi;jge=ege;yshi=sshi;yge jshi=0000;jge=wu;yshi=sshi;yge jshi=sshi;jge=sge;yshi=eshi;yge jshi=sshi;jge=sge;yshi=0000;ygenull; end case; end if; end process; end behav; 7、状态机的设计w1,w2,w3分别为5、26、30进制的进位输出信号,c1,c2,c3分别连接着5、26、30进制的使能端,控制计数器输出信号。Y1,g1,r1分别为甲道的黄灯、绿灯、红灯。,y2,g2,r2分别为乙道的黄灯、绿灯、红灯。Z0,z1,z2连
15、接数据选择器输入端,控制数据选择器的输出数码管。library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity zhuangtaiji is port(reset,clk:in std_logic; w1,w2,w3: in std_logic; c1,c2,c3:out std_logic; y1,y2:out std_logic; g1,g2:out std_logic; r1,r2:out std_logic; z0,z1,z2:out std_logic); end zhuangtaiji;
16、 architecture behv of zhuangtaiji is type fsm_st is (s0,s1,s2,s3); signal c_st,next_state: fsm_st; begin reg:process(reset,clk) begin if reset=0 then c_st=s0; elsif clk=1 and clkevent then c_stg1=1; g2=0;r1=0;r2=1;y1=0;y2=0; c3=1;c2=1;c1=0; z2=0;z1=0;z0=1; if w2=1 then next_state=s1; else next_state
17、g1=0; g2=0;r1=0;r2=1;y1=1;y2=0; c3=1;c2=0;c1=1; z2=0;z1=1;z0=0; if w1=1 and w3=1 then next_state=s2; else next_stateg1=0; g2=1;r1=1;r2=0;y1=0;y2=0; c3=1;c2=1;c1=0; z2=0;z1=1;z0=1; if w2=1 then next_state=s3; else next_stateg1=0; g2=0;r1=1;r2=0;y1=0;y2=1; c3=1;c2=0;c1=1; z2=1;z1=0;z0=0; if w1=1 and w3=1 then next_state=s0; else next_statenext_state=s0; end case; end process com; end behv; 状态图观察顶层电路图五、心得体会本次实验设计了一个简单的十字路口的交通灯亮灯程序,电路关键是在进行时序状态转换,倒计时计数,译码模块控制红、绿、黄灯过程。其实经过分析我们会发现,在控制模块和译码模块都用到了一个分频计数器和东西、南北的亮灯时间都可以使用同一个计数器。我们可以进行优化,在一个模块里共用。 实验的内容是这个学期所做的最系统的一个实验,涉及到以前所做的单个模块的
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 牛奶项目运营方案
- 2026年《中华人民共和国劳动争议调解仲裁法》知识竞赛试卷及答案
- 非煤矿山企业安全管理员检修维修安全操作规程
- 危险货物押运试题专项测试题及答案
- 指挥中心设计方案
- 掌握高分逻辑初中地理环境保护思维暑假思维提升复习课
- 掌握高分逻辑|初中英语写作句式打磨提升课
- 2026年智能能源行业创新报告
- 2026年验孕棒行业发展行业报告
- 2026年智能化安装工程服务行业商业计划书
- 《外卖平台服务管理基本要求》
- 呼吸科医疗质量控制管理
- 不寐病(失眠)中医诊疗方案
- 采购培训教学课件
- 工厂生产线安全规范操作手册
- 卫生院药品卫材管理制度
- YB-T5034-2024《履带用热轧型钢》
- JJF(京) 175-2025 胰岛素泵校准规范
- 胃镜钛夹术后护理
- 《交易心理分析》中文
- 钢结构工程质量验收总结报告
评论
0/150
提交评论