交通控制器设计实验一.实验目的1.了解交通灯的亮灭规律。
2.了解交通灯控制器的工作原理。
3.进一步熟悉VHDL语言编程,了解实际设计中的优化方案。
二.实验任务设计一个十字路口交通控制系统,其东西,南北两个方向除了有红、黄、绿灯指示是否允许通行外,还设有时钟,以倒计时方式显示每一路允许通行的时间,绿灯,黄灯,红灯的持续时间分别是40、5和45秒。
当东西或南北两路中任一道上出现特殊情况,例如有消防车,警车要去执行任务,此时交通控制系统应可由交警手动控制立即进入特殊运行状态,即两条道上的所有车辆皆停止通行,红灯全亮,时钟停止计时,且其数字在闪烁。
当特殊运行状态结束后,管理系统恢复原来的状态,继续正常运行。
三.原理分析本系统主要由计数控制器和倒计时显示器电路组成。
计数控制器实现总共90秒的计数,90秒也是交通控制系统的一个大循环;控制器控制系统的状态转移和红黄绿灯的信号输出;倒计时显示器电路实现45秒倒计时和显示功能。
整个系统的工作时序受控制器控制,它是系统的核心。
控制器的整个工作过程用状态机进行描述,其状态转移关系如下图所示。
五种状态描述如下:s0:东西方向红灯亮,南北方向绿灯亮,此状态持续40秒的时间;s1:东西方向红灯亮,南北方向黄灯亮,此状态持续5秒的时间;s2:东西方向绿灯亮,南北方向红灯亮,此状态持续40秒的时间;s3:东西方向黄灯亮,南北方向红灯亮,此状态持续5秒的时间;s4:紧急制动状态,东西方向红灯亮,南北方向红灯亮,当紧急制动信号有效(hold=’0’)时进入这种状态。
当紧急制动信号无效(hold=’1’)时,状态机按照s0→s1→s2→s3→s0循环;当紧急制动有效(hold=’0’)时,状态机立即进入s4,两个方向红灯全亮,计数器停止计数;当紧急制动信号再恢复无效时,状态机会回到原来的状态继续执行。
四.电路设计交通控制器系统顶层原理图如下图所示,它由计数控制器(control),45秒倒计时计数器(M45)模块组成。
下面主要介绍计数控制器和倒计时计数器M45的设计方法。
(1)计数控制器的设计计数控制器(control)的逻辑符号如图所示。
其中,clk为时钟输入信号;hold为紧急制动信号;greenew,yellowew,redew分别为东西方向驱动绿灯、黄灯、红灯指示的输出信号;greensn,yellowsn,redsn分别为南北方向驱动绿灯、黄灯、红灯指示的输出信号。
计数控制器的VHDL描述文件control.vhd如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity control isport(clk, hold: in std_logic;redsn, greensn, yellowsn, redew, greenew, yellowew: out std_logic);end control;architecture one of control istype state_type is (s0, s1, s2, s3, s4);signal current_state, next_state: state_type :=s0;signal cnt: std_logic_vector(6 downto 0) := "0000000";beginsycsh: processbeginwait until clk'event and clk='1';if hold='0' then --当紧急制动信号有效时,计数器停止计数cnt<=cnt;--当紧急制动信号无效时,计数器计数器进行周期为90秒的计数 if cnt<90 thencnt<=cnt+1;elsecnt<="0000001";end if;end if;current_state<=next_state; --状态机的状态转移描述end process;state_trans: process(current_state)begincase current_state iswhen s0 =>if hold='0' thennext_state<=s4; elseif cnt<40 thennext_state<=s0; elsenext_state<=s1; end if;end if;when s1 =>if hold='0' thennext_state<=s4; elseif cnt<45 thennext_state<=s1; elsenext_state<=s2; end if;end if;when s2 =>if hold='0' thennext_state<=s4; elseif cnt<85 thennext_state<=s2; elsenext_state<=s3; end if;end if;when s3 =>if hold='0' thennext_state<=s4; elseif cnt<90 thennext_state<=s3; elsenext_state<=s0;end if;end if;when s4 =>if hold='0' thennext_state<=s4;elseif cnt<40 thennext_state<=s0;elsif cnt<45 thennext_state<=s1;elsif cnt<85 thennext_state<=s2;elsif cnt<90 thennext_State<=s3;end if;end if;end case;end process;output: process(current_state) --每种状态下两个路口红绿灯的状态描述begincase current_state iswhen s0 =>redsn<='0';greensn<='1';yellowsn<='0';redew<='1';greenew<='0';yellowew<='0';when s1 =>redsn<='0';greensn<='0';yellowsn<='1';redew<='1';greenew<='0';yellowew<='0';when s2 =>redsn<='1';greensn<='0';yellowsn<='0';redew<='0';greenew<='1';yellowew<='0';when s3 =>redsn<='1';greensn<='0';yellowsn<='0';redew<='0';greenew<='0';yellowew<='1';when s4 =>redsn<='1';greensn<='0';yellowsn<='0';redew<='1';greenew<='0';yellowew<='0';end case;end process;end one;(2)倒计时计数器M45的设计倒计时计数器M45的逻辑符号如下图所示。
其中clk为时钟输入;hold 为紧急制动输入;cr为清零端,qlsn[3…0]、qhsn[3…0]分别为南北方向BCD码的个位、十位输出。
qlew[3…0]、qhew[3…0]分别为东西方向BCD码的个位、十位输出。
VHDL描述文件m45.vhd如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity m45 isport(clk, hold, cr: in std_logic;qlsn, qhsn, qlew, qhew: out std_logic_vector(3 downto 0);oc: out std_logic);end m45;architecture one of m45 issignal s: std_logic :='0';signal flag, isy: std_logic :='0';signal coul, couh: std_logic_vector(3 downto 0) :="0100";signal cl: std_logic_vector(3 downto 0):= "1001";signal ch: std_logic_vector(3 downto 0):= "0011";signal qqlew, qqhew, qqlsn, qqhsn: std_logic_vector(3 downto 0) :="0000";beginprocess(cr, clk, hold)beginif cr='0' thencoul<="0100";couh<="0100";elsif clk'event and clk='1' then if hold='1' thenif(coul=0 and couh=0) then coul<="0100";couh<="0100";flag <= not flag;elsif coul=0 thencoul<="1001";couh<=couh-1;elsecoul<=coul-1;end if;if(cl=0 and ch=0) thenif isy='0' thencl<="0100";ch<="0000";isy<=(not isy);elsecl<="1001";ch<="0011";isy<=(not isy);end if;elsif cl=0 thencl<="1001";ch<=ch-1;elsecl<=cl-1;end if;if flag='1' thenqqlsn<=coul;qqhsn<=couh;qqlew<=cl;qqhew<=ch;elsif flag='0' then qqlew<=coul;qqhew<=couh; qqlsn<=cl;qqhsn<=ch;end if;elseif s='0' thenqqlew<="1000"; qqhew<="1000"; qqlsn<="1000"; qqhsn<="1000"; s<='1';elseif flag='1' then qqlsn<=coul; qqhsn<=couh; qqlew<=cl;qqhew<=ch; elseqqlew<=coul; qqhew<=couh; qqlsn<=cl;qqhsn<=ch;end if;s<='0';end if;end if;end if;end process;qlew<=qqlew;qhew<=qqhew;qlsn<=qqlsn;qhsn<=qqhsn;end one;五.实验仿真交通控制器的波形仿真如下图所示。