北邮数电综合实验--交通灯_第1页
北邮数电综合实验--交通灯_第2页
北邮数电综合实验--交通灯_第3页
已阅读5页,还剩20页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、北邮数电综合实验-交通灯数字电路与逻辑设计实验 题目:交通灯控制器数字电路与逻辑设计实验报告一设计课题的任务要求设计制作一个用于十字路口的交通灯控制器(1)南北和东西方向各有一组绿、黄、红灯用于指挥交通,绿灯、黄灯和红灯的持续时间分别为20秒、5秒和25秒; (2)当有特殊情况(如消防车、救护车等)时,两个方向均为红灯亮,计时停止,当特殊情况结束后,控制器恢复原来状态,继续正常运行;(3)用两组数码管,以倒计时方式显示两个方向允许通行或禁止通行的时间; 选做:增加左、右转弯显示控制功能;二系统设计(1)基本设计思路: 基本思路是采用状态机的设计方法,共设计了5个状态,具体状态列表如下:s0东西

2、绿灯,南北红灯20ss1东西黄灯,南北红灯5ss2东西红灯,南北绿灯20ss3东西红灯,南北黄灯5ss4东西红灯,南北红灯 状态图如下: (2)最终设计框图和模块化设计方案:最终设计的总体框图:模块化设计方案:模块名称文件名称完成功能分频器模块1frequency1将1mhz时钟分频输出1kz的信号分频器模块2frequency2将1kz时钟分频输出1hz的信号led控制模块jiaotongled完成交通灯的控制,并输出计时信号倒计时显示1shumaguan1倒计时显示倒计时显示2shumaguan2将倒计时信号译码为对应的数码管信号三仿真波形及波形分析:(1)分频器1仿真波形及分析:分频器1

3、元件图:仿真图: 参数设置:end time=5ms f=50mhz仿真波形分析:从时间轴上可以看到,输出时钟间隔为1ms,输出时钟频率为1kz,达到要求。(2)分频器2的仿真波形及分析: 分频器2元件图:参数设置:end time=10s f=1khz仿真波形如图:仿真波形分析:从时间轴上可以看到,输出时间间隔变为1s,实现了将1kz分频为1hz.(3)led控制模块的仿真波形及分析:led的元件图:引脚说明:输入:clk:1hz的时钟。reset:异步复位信号emergency:同步紧急信号输出:east_green_led 东西方向绿灯 east_yellow_led 东西方向黄灯eas

4、t_red_led 东西方向红灯south_green_led 东西方向绿灯south_yellow_led 东西方向黄灯south_red_led 东西方向红灯counter:计数器信号仿真波形1(reset信号和emergency信号一直为0):波形分析:计数器冲1计数到50后,又变为1,东西交通灯在1到20为绿灯,21到25为黄灯,26到50为红灯南北交通灯在1到25为红灯,26到45为绿灯,46到50为黄灯,符合交通灯变化规律,仿真波形正确。仿真波形2(reset信号有效,emergency信号一直无效):注:本实验中复位信号为一部复位,紧急信号为同步信号观察更大范围:波形分析:当遇到

5、异步复位信号后,计数器重新变为1,且红绿灯工作正常。仿真波形2(emergency信号有效,reset信号一直无效):注:本实验中复位信号为一部复位,紧急信号为同步信号观察更大范围:波形分析:当遇到紧急信号时,计数器保持不变,暂停计数,当紧急信号解除时,计数器继续计数,且交通灯输出正常,达到预期要求。(4)倒计时控制模块的仿真波形: 由于倒计时模块设计比较简单,且仿真意义不大,在此仅将元件图列出:shumaguan1:引脚说明:count:上一级jiaotongled的输出信号counter,计数信号 clk:1kz的时钟信号 numin: 输出7段数码管显示数字信号,输出到译码模块 cat_

6、temp: 7端数码管共阴极输出控制信号shumaguan2:引脚说明:num_in:上一级shumaguan1输出地数字信号。 num::7端数码管输出最终总的模块连接图为:四.源程序(配注释):(1)分频器模块:分频器1 library ieee;use frequency1 isport(clk:in std_logic;-输入时钟频率:50mhzclk_out:out std_logic);end frequency1;architecture freq of frequency1 issignal temp:integer range 0 to 49999;-设置分频49999,则为

7、1khzbeginprocess(clk)beginif(clk'event and clk='1')thenif(temp=49999)thentemp<=0;elsetemp<=temp+1;end if;if temp<49999 then clk_out<='0' else clk_out<='1' end if; end if;end process;end;分频器2:library ieee;use frequency2 isport(clk:in std_logic;-输入频率为1kzclk_o

8、ut:out std_logic);end frequency2;architecture freq of frequency2 issignal temp:integer range 0 to 999;-设置分频999,则为1hzbeginprocess(clk)beginif(clk'event and clk='1')thenif(temp=999)thentemp<=0;elsetemp<=temp+1;end if;if temp<999 then clk_out<='0' else clk_out<='1

9、' end if; end if;end process;end;(2)led控制模块(jiaotongled):用library ieee;use jiaotongled is generic(-定义灯亮的时间 east_green_cnt:integer:=20;-东西方向主干道绿灯 east_yellow_cnt:integer:=5;-东西方向主干道黄灯 south_green_cnt:integer:=20;-南北方向支干道绿灯 south_yellow_cnt:integer:=5);-南北方向支干道黄灯 port(clk:in std_logic; rst:in std_

10、logic;-复位信号 exi_sign:in std_logic;-紧急车辆信号 east_green_led:out std_logic; east_yellow_led:out std_logic; east_red_led:out std_logic; south_green_led:out std_logic; south_yellow_led:out std_logic; south_red_led:out std_logic; count:out std_logic_vector(5 downto 0);end jiaotongled;-architecture ex of ji

11、aotongled istype states is(s0,s1,s2,s3,s4);-定义五个状态s0,s1,s2,s3,s4signal state1:states:=s0;signal state:states:=s0;-遇到紧急信号时,将当前状态暂存在state1中signal cnt:integer range 0 to 20;-利用cnt控制状态转换signal save_cnt:integer;-遇到紧急信号时,将cnt暂存在save_cnt中signal enable_cnt:std_logic:='0'signal tempcount:integer rang

12、e 1 to 50:=1;-初始化计数器为1begin-u1:process(rst,clk)-信号灯的时间状态的转换begin if rst='1' then-异步复位 tempcount<=1;state<=s0;cnt<=1; elsif clk'event and clk='1' then if exi_sign='1' then-遇到紧急信号,暂停计数tempcount<=tempcount;cnt<=cnt;elseif tempcount=50 then tempcount<=1;-计数器

13、tempcout达到50,重新从1开始计数else tempcount<=tempcount+1;end if;if enable_cnt='1' then cnt<=cnt+1;elsecnt<=1;end if;end if;case state is when s0=> if exi_sign='1' then-判断是否紧急车辆 save_cnt<=cnt; state1<=s0; state<=s4; elsif(cnt=east_green_cnt)then state<=s1; else state&l

14、t;=s0; end if; when s1=> if exi_sign='1' then-判断是否紧急车辆 save_cnt<=cnt; state1<=s1; state<=s4; elsif(cnt=east_yellow_cnt)then state<=s2; else state<=s1; end if; when s2=> if exi_sign='1' then-判断是否紧急车辆 save_cnt<=cnt; state1<=s2; state<=s4; elsif(cnt=south_g

15、reen_cnt)then state<=s3; else state<=s2; end if; when s3=> if exi_sign='1' then-判断是否紧急车辆 save_cnt<=cnt; state1<=s3; state<=s4; elsif(cnt=south_yellow_cnt)then state<=s0; else state<=s3; end if; when s4=> if exi_sign='1' then-判断是否紧急车辆 state<=s4; elsif exi

16、_sign='0' thenstate<=state1;cnt<=save_cnt+1; end if; end case; end if;end process u1;count<=conv_std_logic_vector(tempcount,6);-将temptount转化为六位二进制,给输出-u2:process(state)-信号灯的状态显示begin case state is when s0=>-s0时,显示东西绿灯,南北红灯 east_green_led<='1' east_yellow_led<='0

17、' east_red_led<='0' south_green_led<='0' south_yellow_led<='0' south_red_led<='1' enable_cnt<='1' if(cnt=east_green_cnt)then enable_cnt<='0'-已达到东西方向绿灯亮时间,暂停计数 end if; when s1=>- s1时,显示东西黄灯,南北红灯 east_green_led<='0' ea

18、st_yellow_led<='1' east_red_led<='0' south_green_led<='0' south_yellow_led<='0' south_red_led<='1' enable_cnt<='1' if(cnt=east_yellow_cnt)then enable_cnt<='0' end if; when s2=>-s2时,显示东西红灯,南北绿灯 east_green_led<='0&#

19、39; east_yellow_led<='0' east_red_led<='1' south_green_led<='1' south_yellow_led<='0' south_red_led<='0' enable_cnt<='1' if(cnt=south_green_cnt)then enable_cnt<='0' end if; when s3=>-s3时,显示东西红灯,南北黄灯 east_green_led<=&#

20、39;0' east_yellow_led<='0' east_red_led<='1' south_green_led<='0' south_yellow_led<='1' south_red_led<='0' enable_cnt<='1' if(cnt=south_yellow_cnt)then enable_cnt<='0' end if; when s4=>-紧急状态上时,显示东西红灯,南北红灯 east_green_

21、led<='0' east_yellow_led<='0' east_red_led<='1' south_green_led<='0' south_yellow_led<='0' south_red_led<='1' enable_cnt<='1' end case;end process u2;end ex; (3)倒计时输出:shumaguan1:library ieee;use shumaguan1 is port( count:in

22、 std_logic_vector(5 downto 0);-计数器输入信号 clk:in std_logic;-时钟信号 numin:out std_logic_vector(3 downto 0);-输出7段数码管显示数字信号,输出到译码模块 cat_temp:out std_logic_vector(5 downto 0);-7端数码管共阴极输出控制信号 numin1:out std_logic_vector (3 downto 0)-输出7段数码管显示数字信号(波形图观察) );end shumaguan1;architecture countshow of shumaguan1 is

23、signal temp:integer range 0 to 3;signal counter:integer range 1 to 50;signal cat:std_logic_vector(5 downto 0):="011111"signal num_in:std_logic_vector(3 downto 0);beginp1:process(clk)-内部时钟,控制7段数码管显示扫描内容begin counter<=conv_integer(count);if(clk'event and clk='1')thenif(temp=3)

24、thentemp<=0;elsetemp<=temp+1;end if;end if;end process p1;p2:process(counter,temp) begin counter<=conv_integer(count); case counter is-通过计数器输入信号控制状态 when 1=>case temp is-在每个状态内部设置数码管扫描过程,由于counter和-扫描时钟不同 -则可在数码管上同时显示4个数字. when 0=>num_in<="0001"cat<="011111"

25、when 1=>num_in<="1001"cat<="101111" when 2=>num_in<="0010"cat<="111101" when 3=>num_in<="0100"cat<="111110" end case; when 2=>case temp is when 0=>num_in<="0001"cat<="011111" when 1

26、=>num_in<="1000"cat<="101111" when 2=>num_in<="0010"cat<="111101" when 3=>num_in<="0011"cat<="111110" end case; when 3=>case temp is when 0=>num_in<="0001"cat<="011111" when 1=>n

27、um_in<="0111"cat<="101111" when 2=>num_in<="0010"cat<="111101" when 3=>num_in<="0010"cat<="111110" end case; when 4=>case temp is when 0=>num_in<="0001"cat<="011111" when 1=>num_in&

28、lt;="0110"cat<="101111" when 2=>num_in<="0010"cat<="111101" when 3=>num_in<="0001"cat<="111110" end case; when 5=>case temp is when 0=>num_in<="0001"cat<="011111" when 1=>num_in<=&q

29、uot;0101"cat<="101111" when 2=>num_in<="0010"cat<="111101" when 3=>num_in<="0000"cat<="111110" end case; when 6=>case temp is when 0=>num_in<="0001"cat<="011111" when 1=>num_in<="01

30、00"cat<="101111" when 2=>num_in<="0001"cat<="111101" when 3=>num_in<="1001"cat<="111110" end case; when 7=>case temp is when 0=>num_in<="0001"cat<="011111" when 1=>num_in<="0011&quo

31、t;cat<="101111" when 2=>num_in<="0001"cat<="111101" when 3=>num_in<="1000"cat<="111110" end case; when 8=>case temp is when 0=>num_in<="0001"cat<="011111" when 1=>num_in<="0010"cat&

32、lt;="101111" when 2=>num_in<="0001"cat<="111101" when 3=>num_in<="0111"cat<="111110" end case; when 9=>case temp is when 0=>num_in<="0001"cat<="011111" when 1=>num_in<="0001"cat<=&q

33、uot;101111" when 2=>num_in<="0001"cat<="111101" when 3=>num_in<="0110"cat<="111110" end case; when 10=>case temp is when 0=>num_in<="0001"cat<="011111" when 1=>num_in<="0000"cat<="1

34、01111" when 2=>num_in<="0001"cat<="111101" when 3=>num_in<="0101"cat<="111110" end case; when 11=>case temp is when 0=>num_in<="0000"cat<="011111" when 1=>num_in<="1001"cat<="101111

35、" when 2=>num_in<="0001"cat<="111101" when 3=>num_in<="0100"cat<="111110" end case; when 12=>case temp is when 0=>num_in<="0000"cat<="011111" when 1=>num_in<="1000"cat<="101111"

36、; when 2=>num_in<="0001"cat<="111101" when 3=>num_in<="0011"cat<="111110" end case; when 13=>case temp is when 0=>num_in<="0000"cat<="011111" when 1=>num_in<="0111"cat<="101111" whe

37、n 2=>num_in<="0001"cat<="111101" when 3=>num_in<="0010"cat<="111110" end case; when 14=>case temp is when 0=>num_in<="0000"cat<="011111" when 1=>num_in<="0110"cat<="101111" when 2=&

38、gt;num_in<="0001"cat<="111101" when 3=>num_in<="0001"cat<="111110" end case; when 15=>case temp is when 0=>num_in<="0000"cat<="011111" when 1=>num_in<="0101"cat<="101111" when 2=>nu

39、m_in<="0001"cat<="111101" when 3=>num_in<="0000"cat<="111110" end case; when 16=>case temp is when 0=>num_in<="0000"cat<="011111" when 1=>num_in<="0100"cat<="101111" when 2=>num_in&

40、lt;="0000"cat<="111101" when 3=>num_in<="1001"cat<="111110" end case; when 17=>case temp is when 0=>num_in<="0000"cat<="011111" when 1=>num_in<="0011"cat<="101111" when 2=>num_in<=&

41、quot;0000"cat<="111101" when 3=>num_in<="1000"cat<="111110" end case; when 18=>case temp is when 0=>num_in<="0000"cat<="011111" when 1=>num_in<="0010"cat<="101111" when 2=>num_in<="

42、0000"cat<="111101" when 3=>num_in<="0111"cat<="111110" end case; when 19=>case temp is when 0=>num_in<="0000"cat<="011111" when 1=>num_in<="0001"cat<="101111" when 2=>num_in<="0000&

43、quot;cat<="111101" when 3=>num_in<="0110"cat<="111110" end case; when 20=>case temp is when 0=>num_in<="0000"cat<="011111" when 1=>num_in<="0000"cat<="101111" when 2=>num_in<="0000"

44、cat<="111101" when 3=>num_in<="0101"cat<="111110" end case; when 21=>case temp is when 0=>num_in<="0000"cat<="011111" when 1=>num_in<="0100"cat<="101111" when 2=>num_in<="0000"cat&l

45、t;="111101" when 3=>num_in<="0100"cat<="111110" end case; when 22=>case temp is when 0=>num_in<="0000"cat<="011111" when 1=>num_in<="0011"cat<="101111" when 2=>num_in<="0000"cat<=&q

46、uot;111101" when 3=>num_in<="0011"cat<="111110" end case; when 23=>case temp is when 0=>num_in<="0000"cat<="011111" when 1=>num_in<="0010"cat<="101111" when 2=>num_in<="0000"cat<="1

47、11101" when 3=>num_in<="0010"cat<="111110" end case; when 24=>case temp is when 0=>num_in<="0000"cat<="011111" when 1=>num_in<="0001"cat<="101111" when 2=>num_in<="0000"cat<="111101

48、" when 3=>num_in<="0001"cat<="111110" end case; when 25=>case temp is when 0=>num_in<="0000"cat<="011111" when 1=>num_in<="0000"cat<="101111" when 2=>num_in<="0000"cat<="111101"

49、; when 3=>num_in<="0000"cat<="111110" end case; when 26=>case temp is when 0=>num_in<="0001"cat<="111101" when 1=>num_in<="1001"cat<="111110" when 2=>num_in<="0010"cat<="011111" whe

50、n 3=>num_in<="0100"cat<="101111" end case; when 27=>case temp is when 0=>num_in<="0001"cat<="111101" when 1=>num_in<="1000"cat<="111110" when 2=>num_in<="0010"cat<="011111" when 3=&

51、gt;num_in<="0011"cat<="101111" end case; when 28=>case temp is when 0=>num_in<="0001"cat<="111101" when 1=>num_in<="0111"cat<="111110" when 2=>num_in<="0010"cat<="011111" when 3=>nu

52、m_in<="0010"cat<="101111" end case; when 29=>case temp is when 0=>num_in<="0001"cat<="111101" when 1=>num_in<="0110"cat<="111110" when 2=>num_in<="0010"cat<="011111" when 3=>num_in&

53、lt;="0001"cat<="101110" end case; when 30=>case temp is when 0=>num_in<="0001"cat<="111101" when 1=>num_in<="0101"cat<="111110" when 2=>num_in<="0010"cat<="011111" when 3=>num_in<=&

54、quot;0000"cat<="101111" end case; when 31=>case temp is when 0=>num_in<="0001"cat<="111101" when 1=>num_in<="0100"cat<="111110" when 2=>num_in<="0001"cat<="011111" when 3=>num_in<="

55、1001"cat<="101111" end case; when 32=>case temp is when 0=>num_in<="0001"cat<="111101" when 1=>num_in<="0011"cat<="111110" when 2=>num_in<="0001"cat<="011111" when 3=>num_in<="1000&

56、quot;cat<="101111" end case; when 33=>case temp is when 0=>num_in<="0001"cat<="111101" when 1=>num_in<="0010"cat<="111110" when 2=>num_in<="0001"cat<="011111" when 3=>num_in<="0111"

57、cat<="101111" end case; when 34=>case temp is when 0=>num_in<="0001"cat<="111101" when 1=>num_in<="0001"cat<="111110" when 2=>num_in<="0001"cat<="011111" when 3=>num_in<="0110"cat&l

58、t;="101111" end case; when 35=>case temp is when 0=>num_in<="0001"cat<="111101" when 1=>num_in<="0000"cat<="111110" when 2=>num_in<="0001"cat<="011111" when 3=>num_in<="0101"cat<="101111" end case; when 36=>case temp is when 0=>num_in<="0000"cat<="111101" when 1=>num_in<="1001"cat<=&qu

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论