版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、华中科技大学基于xilinx FPGA的VHDL交通灯控制器的设计-基于Spartan3E开发板专业: 电子信息工程1. 任务设计要求 设计一个十字路口交通信号灯的定时控制电路。要求红、绿灯按一定的规律亮和灭,并在亮灯期间进行倒计时,并将运行时间用数码管/液晶显示出来。绿灯亮时,为该车道允许通行信号,红灯亮时,为该车道禁止通行信号。要求主干道每次通行时间为99秒,支干道每次通行时间为30秒。每次变换运行车道前绿灯闪烁,持续时间为5秒。即车道要由主干道转换为支干道时,主干道在通行时间只剩下5秒钟时,绿灯闪烁显示,支干道仍为红灯,以便主干道上已过停车线的车继续通行,未过停车线的车停止通行。同理,当
2、车道由支干道转换为主干道时,支干道绿灯闪烁显示5秒钟,主干道仍为红灯。 对红、绿灯的运行时间要能比较方便的进行重新设置。 对器件进行在系统编程和实验验证。用VHDL语言对设计进行描述,设计一个测试方案,通过ISE对设计进行仿真验证。并能够下载到实验板上调试成功。任务扩展:在原设计的基础上加入指示方向的功能。2. 系统设计1.系统原理图与说明由系统设计原理图,我以清楚地将系统分为六个模块:分频模块,时间设置模块,状态转换模块,时间计算模块,LED流水灯模块,LCD显示模块。1)分频模块 分频模块其作用为:由于Spartan3E板上提供的时钟信号为50MHz,而设计所需时钟信号为1Hz,故使用分频
3、模块将50MHz信号分频为1Hz信号。2)时间置数模块由于任务设计要求可以对主干道,支干道上左转、绿灯运行的时间进行重新设置调整,所以要对系统进行参数化设计。首先引入一组参数,main_gh,main_gl,main_lh,main_ll,branch_gh,branch_gl,branch_lh,branch_ll(下划线后面的字母分别取green,left,high,low首字母).需要置数时,首先选择对主干道还是支干道时间置数,这里设置一个main_or_branch参数,当main_or_branch为高时设置支干道时间,为低时设置主干道时间。置数时,通过s_set_button,l_
4、set_button对时间进行设置,具体方法参见代码。为了置数方便,引入一个add_or_decent参数,低电平时按下button可以增计数,高电平时按下可以减计数。3)状态转换模块状态转化模块是整个系统的核心模块它控制整个交通灯系统的状态变化,整个过程划分为四个基本状态:主干道绿灯、主干道左转、支干道绿灯、支干道左转,用state、s_or_l为00、01、10、11来代表。每当一个状态的计数器为00时,state、s_or_l发生改变,以实现状态间的转换,进而控制交通灯的变化。4)时间计算模块这次设计中扩展了左转向的功能,因此红灯时间不仅仅是另一干道的直行时间,而是直行时间和左转时间之和
5、。5)LCD显示模块Spartan3E板上只有LCD显示模块,所以采用此模块显示当前亮灯的剩余时间和设置时间模块的时间显示。通过输入counterplay_1l,counterplay_1h,counterplay_2l,counterplay_2h四位二进制数,加上0011显示成十进制数,分别代表两位数的低位和高位6)LED显示模块由输入信号state、s_or_l、flash,分别取000,001,010,011,100,101,110,111所得到的main_green,main_left,main_red,branch_left,branch_green,branch_red的不同值,
6、来控制主干道,支干道红绿左转灯的亮灭。其中 1表示亮,0表示灭。如表3-1 所示。由上表可得到: main_green <= NOT(state) AND NOT(s_or_l) AND (NOT(flash AND clk); main_left <= NOT(state) AND s_or_l AND (NOT(flash AND clk); main_red <= state; branch_green <= state AND NOT(s_or_l) AND (NOT(flash AND clk); branch_left <= state AND s_o
7、r_l AND (NOT(flash AND clk); branch_red <= NOT(state);2.输入输出设计任务设计开发板基于Spartan3E板,具体输入输出设定如下:1)输入: 开关:main_or_branch:设置主干道还是支干道 EN:使能信号 run_or_set:设置运行模式还是时间设置模式 add_or_decent:置数模式:增加或者减少 按键:s_set_button:直行时间设置按键 l_set_button: 左转时间设置按钮 时钟:clk2) 输出: LCD显示屏:分别显示当前亮灯的剩余秒数 LED灯:main_green,main_red,ma
8、in_left branch_left,branch_green,branch_red3、状态转换图S0状态:主干道绿灯、支干道红灯S1状态:主干道左转、支干道红灯S2状态:支干道绿灯、主干道红灯S3状态:支干道左转、主干道红灯三各模块代码以及仿真波形u 分频模块代码因为1HZ波形太长,不易仿真,故仿真波形采用100HZ的输入clk :50MHZ输出clk1:100HZu 时间设置模块部分代码以上是直行时间设置代码。左转设置类似,在此不再复制仿真 设置 输入:clk main_or_branch 设置为0 add_or_decent 设置为0 s_set_button 设置为周期为1周期的信号
9、 l_set_button 设置为低电平波形如下u 时间计算模块代码波形仿真输入输出与预期相符合。u 状态转换模块波形仿真分别给主干道,支干道个颜色灯持续时间赋值,再给定,当前亮灯的剩余时间,然后又进行仿真,结果符合预期u LED模块代码波形仿真分别给予输入不同周期的高低点评,相互叠加的结果符合预期。u LCD模块代码library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity LCD isport(clk : in STD_LOGIC;r
10、st_n : in STD_LOGIC;counter_play1h, counter_play1l : in STD_LOGIC_VECTOR(3 downto 0); counter_play2h, counter_play2l : in STD_LOGIC_VECTOR(3 downto 0); -degree1, degree2 : in STD_LOGIC_VECTOR(3 downto 0); SF_D : out STD_LOGIC_VECTOR(3 downto 0);LCD_E, LCD_RS, LCD_RW: out STD_LOGIC);end LCD;architect
11、ure behavior of LCD istype tx_sequence is (high_setup, high_hold, oneus, low_setup, low_hold, fortyus, done); signal tx_state : tx_sequence := done; signal tx_byte : std_logic_vector(7 downto 0);signal tx_init : std_logic := '0'type init_sequence is (idle, fifteenms, one, two, three, four, f
12、ive, six, seven, eight, done);signal init_state : init_sequence := idle;signal init_init, init_done : std_logic := '0'signal i : integer range 0 to 750000 := 0;signal i2 : integer range 0 to 2000 := 0;signal i3 : integer range 0 to 82000 := 0;signal SF_D0, SF_D1 : std_logic_vector(3 downto 0
13、);signal LCD_E0, LCD_E1 : std_logic;signal mux : std_logic;-?type display_state is (init, function_set, entry_set, set_display, clr_display, pause, set_addr,max_degree_1,max_degree_2,temperature_1,temperature_2,degree_1,degree_2,blank1,blank2,blank3);signal cur_state : display_state := init;begin-LE
14、D <= tx_byte; -for diagnostic purposes-SF_CE0 <= '1' -disable intel strataflashLCD_RW <= '0' -write only-The following "with" statements simplify the process of adding and removing states.-when to transmit a command/data and when not towith cur_state selecttx_init
15、<= '0' when init | pause , '1' when others;-control the buswith cur_state selectmux <= '1' when init, '0' when others;-control the initialization sequencewith cur_state selectinit_init <= '1' when init, '0' when others;-register selectwith cur
16、_state selectLCD_RS <= '0' when function_set|entry_set|set_display|clr_display|set_addr, '1' when others;-what byte to transmit to lcd-refer to datasheet for an explanation of these valueswith cur_state selecttx_byte <= "00101000" when function_set, - ? "00000110
17、" when entry_set, "00001100" when set_display, "00000001" when clr_display, "10000000" when set_addr, "0011"&counter_play1h when max_degree_1, "0011"&counter_play1l when max_degree_2, "00100000" when blank1, "0011"&am
18、p;counter_play2h when temperature_1, "0011"&counter_play2l when temperature_2, "00100000" when blank2, "00100000" when degree_1, "00100000" when degree_2, "00100000" when blank3, "00100000" when others;-main state machinedisplay: proces
19、s(clk, rst_n)beginif(rst_n='0') thencur_state <= function_set;elsif(clk='1' and clk'event) thencase cur_state is-refer to intialize state machine belowwhen init =>if(init_done = '1') thencur_state <= function_set;elsecur_state <= init;end if;-every other state
20、 but pause uses the transmit state machinewhen function_set =>if(i2 = 2000) thencur_state <= entry_set;elsecur_state <= function_set;end if;when entry_set =>if(i2 = 2000) thencur_state <= set_display;elsecur_state <= entry_set;end if;when set_display =>if(i2 = 2000) thencur_stat
21、e <= clr_display;elsecur_state <= set_display;end if;when clr_display =>i3 <= 0;if(i2 = 2000) thencur_state <= pause;elsecur_state <= clr_display;end if;when pause =>if(i3 = 82000) thencur_state <= set_addr;i3 <= 0;elsecur_state <= pause;i3 <= i3 + 1;end if;when set_
22、addr =>if(i2 = 2000) thencur_state <= max_degree_1;elsecur_state <= set_addr;end if;when max_degree_1 =>if(i2 = 2000) thencur_state <= max_degree_2;elsecur_state <= max_degree_1;end if;when max_degree_2 =>if(i2 = 2000) thencur_state <= blank1;elsecur_state <= max_degree_2;
23、end if;when blank1 =>if(i2 = 2000) thencur_state <= temperature_1;elsecur_state <= blank1;end if;when temperature_1 =>if(i2 = 2000) thencur_state <= temperature_2;elsecur_state <= temperature_1;end if;when temperature_2 =>if(i2 = 2000) thencur_state <= blank2;elsecur_state &l
24、t;= temperature_2;end if;when blank2 =>if(i2 = 2000) thencur_state <= degree_1;elsecur_state <= blank2;end if;when degree_1 =>if(i2 = 2000) thencur_state <= degree_2;elsecur_state <= degree_1;end if;when degree_2 =>if(i2 = 2000) thencur_state <= blank3;elsecur_state <= deg
25、ree_2;end if;when blank3 =>if(i2 = 2000) thencur_state <=set_addr ;elsecur_state <= blank3;end if;end case;end if;end process display;with mux selectSF_D <= SF_D0 when '0', -transmit SF_D1 when others; -initializewith mux selectLCD_E <= LCD_E0 when '0', -transmit LCD_E
26、1 when others; -initialize-specified by datasheettransmit : process(clk, rst_n, tx_init)beginif(rst_n='0') thentx_state <= done;elsif(clk='1' and clk'event) thencase tx_state iswhen high_setup => -40nsLCD_E0 <= '0'SF_D0 <= tx_byte(7 downto 4);if(i2 = 2) thentx
27、_state <= high_hold;i2 <= 0;elsetx_state <= high_setup;i2 <= i2 + 1;end if;when high_hold => -230nsLCD_E0 <= '1'SF_D0 <= tx_byte(7 downto 4);if(i2 = 12) thentx_state <= oneus;i2 <= 0;elsetx_state <= high_hold;i2 <= i2 + 1;end if;when oneus =>LCD_E0 <= &
28、#39;0'if(i2 = 50) thentx_state <= low_setup;i2 <= 0;elsetx_state <= oneus;i2 <= i2 + 1;end if;when low_setup =>LCD_E0 <= '0'SF_D0 <= tx_byte(3 downto 0);if(i2 = 2) thentx_state <= low_hold;i2 <= 0;elsetx_state <= low_setup;i2 <= i2 + 1;end if;when low_hol
29、d =>LCD_E0 <= '1'SF_D0 <= tx_byte(3 downto 0);if(i2 = 12) thentx_state <= fortyus;i2 <= 0;elsetx_state <= low_hold;i2 <= i2 + 1;end if;when fortyus =>LCD_E0 <= '0'if(i2 = 2000) thentx_state <= done;i2 <= 0;elsetx_state <= fortyus;i2 <= i2 + 1;en
30、d if;when done =>LCD_E0 <= '0'if(tx_init = '1') thentx_state <= high_setup;i2 <= 0;elsetx_state <= done;i2 <= 0;end if;end case;end if;end process transmit;-specified by datasheetpower_on_initialize: process(clk, rst_n, init_init) -power on initialization sequencebe
31、ginif(rst_n='0') theninit_state <= idle;init_done <= '0'elsif(clk='1' and clk'event) thencase init_state iswhen idle =>init_done <= '0'if(init_init = '1') theninit_state <= fifteenms;i <= 0;elseinit_state <= idle;i <= i + 1;end if;w
32、hen fifteenms =>init_done <= '0'if(i = 750000) theninit_state <= one;i <= 0;elseinit_state <= fifteenms;i <= i + 1;end if;when one =>SF_D1 <= "0011"LCD_E1 <= '1'init_done <= '0'if(i = 11) theninit_state<=two;i <= 0;elseinit_state&
33、lt;=one;i <= i + 1;end if;when two =>LCD_E1 <= '0'init_done <= '0'if(i = 205000) theninit_state<=three;i <= 0;elseinit_state<=two;i <= i + 1;end if;when three =>SF_D1 <= "0011"LCD_E1 <= '1'init_done <= '0'if(i = 11) theninit_state<=four;i <= 0;elseinit_state<=three;i <= i + 1;end if;when four =>LCD_E1 <= '0'init_done <= '0'if(i = 5000) theninit_state&l
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年宠物宠物美容师合作协议
- 中北大学《国际商务》2025-2026学年期末试卷
- 莆田学院《药学史》2025-2026学年期末试卷
- 长春工业大学人文信息学院《设计色彩》2025-2026学年期末试卷
- 信誉楼视客为友服务
- 2026年苏教版小学二年级数学上册计算进阶练习卷含答案
- 深度解析(2026)《GBT 4169.2-2006塑料注射模零件 第2部分:直导套》
- 2026年人教版小学六年级数学上册利润问题初步卷含答案
- 深度解析(2026)《GBT 3634.2-2011氢气 第2部分:纯氢、高纯氢和超纯氢》
- 《JBT 10755-2017超声波电动机 通 用技术条件》专题研究报告
- 豆豉合同购买合同范本
- 服装行业质量控制手册
- 2025年国家公务员录用考试《行测》真题试卷【含解析】附参考答案详解【完整版】
- 水利建设工程文明标准化工地创建指导手册
- 书法茶艺基础知识培训课件
- 工笔花鸟画教学课件
- 涵洞施工安全风险及应对措施
- 2025年海南辅警考试题库
- (高清版)DB11∕T 1455-2025 电动汽车充电基础设施规划设计标准
- 智能建筑危险性较大分部分项工程清单及安全措施
- 2025年贵州省中考理科综合(物理化学)试卷真题(含答案详解)
评论
0/150
提交评论