基于VHDL的交通灯控制器设计作者:叶展(04008136)杨运峰(04008137)史泰龙(04008115)目录1.题目要求 (2)2.方案设计 (2)(1)总体方案设计 (2)(2)单元模块设计 (5)(3)各单元模块的连接 (6)3.仿真调试 (7)4.设计总结 (9)(1)设计的小结和体会 (9)(2)对设计的进一步完善提出意见或建议 (9)5.成员分工 (9)6.参考文献 (10)7.附录 (11)一、题目要求在两个相邻十字路口处各有四处交通灯,标为A和B,每一处的要求如下:每一处都有3个灯指示左转,直行和右转车辆,并且灯也分红色和黄色绿色,并配有时间显示,调研实际的运行情况并设计出对应的电路。
并且要完成以下附加功能:第一,可以将系统根据时间来调整,在白天某一路段比较繁忙对应的通行时间较长,晚上因为另一路段繁忙则做适当的调整;第二,如系统出现故障不能正常显示,则黄灯全部闪烁以提醒车辆注意。
要求系统有一个系统时钟,按照24小时计时,A处和B处早上7点到晚上8点,南北方向绿灯通行时间为50秒,黄灯5秒,左拐灯15秒,黄灯5秒,红灯40秒。
其余时间分别为60秒,5秒,20秒,5秒,30秒。
A处和B处的交通灯是联动的,即A处驶往B处的车辆,在A处南北方向交通灯绿灯后20秒钟后B处的南北方向交通灯绿灯通行。
二、方案设计(1)总体方案设计我们小组成员展开讨论,结合本题目的要求,并且参考了实际路灯的运行情况和查阅了相关资料后,提出了一种切实可行的路灯控制方案——即路灯八状态轮换循环控制方案。
从单一方向上看,单个路口红绿灯转换顺序为:绿灯(50s)—黄灯(5s)—左拐灯(15s)—黄灯(5s)—红灯(40s)。
(当此方向上路灯为红灯时,即40s的时间内,另一方向上的路灯要完成,绿灯(15s)—黄灯(5s)—左拐灯(15s)—黄灯(5s),的转换。
)当路况处于闲暇时间段的时候,路灯工作于另外一种时间机制。
即,绿灯(60s)—黄灯(5s)—左拐灯(20s)—黄灯(5s)—红灯(30s)。
(当此方向上路灯为红灯时,即30s的时间内,另一方向上的路灯要完成,绿灯(5s)—黄灯(5s)—左拐灯(15s)—黄灯(5s),的转换。
)A ,B 路口详细工作情况见下图。
→→→↑ ↓←←→→←←(注:’/’之前的为南北方向的路灯状况,’/’之后的为东西方向的路灯状况;括号内秒数对应为倒计时时间。
)题目要求A,B两路口联动(即A 处驶往B 处的车辆,在A 处南北方向交通灯绿灯后20秒钟后B 处的南北方向交通灯绿灯通行。
),本设计方案中,B 路口从A 的第六状态开始工作,和A 路口的状态刚好相差20s ,从而可以实现A ,B 路口的联动。
图示为A ,B 路口繁忙时段(7a.m~8p.m )的工作情况,一次状态循环用时115s 。
当时间为闲时段的时候,状态循环模式完全一样,只是路灯倒计时时间如前述对应,作相应的改变,此时一次状态循环用时120s 。
综上所述,本设计方案先采用一个总系统时钟进行一天24小时循环计时,并以此时钟来判断当前处于繁忙时段还是闲时段,已决定当前的工作状态。
当系统处于繁忙时段时,采用115s 的计数器来控制路灯的循环工作;当系统转换到闲时段时,则采用另一120s 的计数器来控制路灯的循环。
黄灯(15s )/红灯绿灯(50s )/红灯左拐灯(5s )/红灯黄灯(5s )/红灯红灯/绿灯(15s )红灯/黄灯(5s ) 红灯/左拐灯(15s ) 红灯/黄灯(5s )黄(15s )/红灯绿(50s )/红灯 左拐灯(5s )/红灯黄灯(5s )/红灯 红灯/绿灯(15s ) 红灯/黄灯(5s )红灯/左拐灯(15s )红灯/黄灯(5s )(2)单元模块设计◆系统时钟单元计数:0 ~ 24*3600◆忙时段计数器单元计数:0 ~ 115◆闲时段计数器单元计数:0 ~ 120◆主控制单元根据系统时钟和计数器单元来控制A,B路口的路灯显示状况,并且各自显示路灯倒计时时间。
(3)各单元模块的连接三、仿真调试据题目要求,为系统设定一个时钟输入(clock),突发事件控制输入(hold),和系统重设输入(reset)。
由功能仿真图可以看到,当系统时钟开始输入时,系统时间对应为凌晨0点,即闲时段。
A1路口从第一状态开始循环,绿灯(60s)—黄灯(5s)—左拐灯(20s)—黄灯(5s)—红灯(30s)。
A2路口循环状态为:红灯(90s)—绿灯(5s)—黄灯(5s)—左拐灯(15s)—黄灯(5s),的转换。
)B1路口状态滞后A1路口20s的时间,B2路口滞后A2路口20s的时间,刚好满足两路口的联动性。
当路况处于忙时间段的时候,路灯工作于另外一种时间机制。
A1:绿灯(50s)—黄灯(5s)—左拐灯(15s)—黄灯(5s)—红灯(40s);A2:红灯(75s)—绿灯(15s)—黄灯(5s)—左拐灯(15s)—黄灯(5s);B1路口状态滞后A1路口20s的时间;B2路口状态滞后A2路口20s的时间。
四、设计总结(1)设计的小结和体会此次VHDL设计我们小组进行的比较顺利,从最开始的题目理解,方案设计分析到具体设计以及最后的仿真调试成功,基本上都是水到渠成。
我觉得这其中最重要的一点是我们提出了比较好的方案,实现简单,条理清楚,并且很好的满足题目要求。
比如用先conunt_system时钟来决定当先的闲/忙状态,然后分别用count1和count2来分别实现闲忙时路灯的具体控制。
在控制路灯的同时显示倒计时时间,更符合实际情况。
(2)对设计的进一步完善提出意见或建议此项关于路灯的VHDL设计基本上达到了题目的功能要求。
但是在时间的显示的功能仿真中,波形有一些毛刺,分析考虑主要是时间向量的各位并没有完全同时随着时钟变化,存在微小的偏差。
由于毛刺时间非常小,在实际显示过程中,时间显示不存在跳变问题。
另外一点就是题目对路灯显示时间的限制使得路灯变换时间并不是十分合理。
如闲时段时A2和B2路口的绿灯时间只有5s。
这个与事实不符,如果能调整路灯显示时间,将会使设计更加合理。
五、成员分工小组成员共同讨论查阅资料,确定系统的主要设计方案。
杨运峰——系统具体框架的确立和vhdl主体程序的编写。
叶展——参与程序的编写和检查修改,并完成编写设计报告。
史泰龙——参与设计报告的编写和检查改进。
六、参考文献计算机结构与逻辑设计/黄正瑾编著–北京:高等教育出版社,2001,6现代电子技术—VHDL与数字系统设计/杨刚,龙海燕编著。
北京:电子工业出版社,2004。
4(高等学校电工电子实践系列)数字电路与可编程技术试验教程/武俊鹏,蒙昭林,付小晶主编—哈尔滨:哈尔滨工程大学出版社,2007,3七、附录library ieee;entity Countersystem isport(Clock:in std_logic;Reset:in std_logic;Hold:in std_logic;CountNum:buffer integer range 0 to 24*3600 );end;architecture Behavoir of Countersystem is beginprocess(Reset,Clock)beginif Reset='1' thenCountNum<=0;elsif rising_edge(Clock) thenif Hold='1' thenCountNum<=CountNum;elseif CountNum=24*3600 thenCountNum<=0;elseCountNum<=CountNum+1;end if;end if;end if;end process;end;library ieee;entity Counter115 isport(Clock:in std_logic;Reset:in std_logic;Hold:in std_logic;CountNum:buffer integer range 0 to 114 );end;architecture Behavoir of Counter115 is beginprocess(Reset,Clock)beginif Reset='1' thenCountNum<=0;elsif rising_edge(clock) thenif Hold='1' thenCountNum<=CountNum;elseif CountNum=114 thenCountNum<=0;elseCountNum<=CountNum+1;end if;end if;end if;end process;end;library ieee;entity Counter120 isport(Clock:in std_logic;Reset:in std_logic;Hold:in std_logic;CountNum:buffer integer range 0 to 119 );end;architecture Behavoir of Counter120 is beginprocess(Reset,Clock)beginif Reset='1' thenCountNum<=0;elsif rising_edge(Clock) thenif Hold='1' thenCountNum<=CountNum;elseif CountNum=119 thenCountNum<=0;elseCountNum<=CountNum+1;end if;end if;end if;end process;end;RedB2,YellowB2,GreenB2,LeftB2:out std_logic);end;architecture Behavior of controller isbeginprocess(Clock)beginif falling_edge(Clock) thenif Hold='1' thenRedA1<='0';YellowA1<='1';GreenA1<='0';LeftA1<='0';RedA2<='0';YellowA2<='1';GreenA2<='0';LeftA2<='0';RedB1<='0';YellowB1<='1';GreenB1<='0';LeftB1<='0';RedB2<='0';YellowB2<='1';GreenB2<='0';LeftB2<='0';elseif(Countsystem>=7*3600 and Countsystem<=20*3600) thenif(Countnum1<50) then --state of crossing A when busyRedA1<='0';YellowA1<='0';GreenA1<='1';LeftA1<='0';NumA1<=50-CountNum1; RedA2<='1';YellowA2<='0';GreenA2<='0';LeftA2<='0';NumA2<=75-CountNum1;elsif Countnum1<(50+5) thenRedA1<='0';YellowA1<='1';GreenA1<='0';LeftA1<='0';NumA1<=55-CountNum1; RedA2<='1';YellowA2<='0';GreenA2<='0';LeftA2<='0';NumA2<=75-CountNum1;elsif Countnum1<(50+5+15) thenRedA1<='0';YellowA1<='0';GreenA1<='0';LeftA1<='1';NumA1<=70-CountNum1; RedA2<='1';YellowA2<='0';GreenA2<='0';LeftA2<='0';NumA2<=75-CountNum1;elsif Countnum1<(50+5+15+5) thenRedA1<='0';YellowA1<='1';GreenA1<='0';LeftA1<='0';NumA1<=75-CountNum1; RedA2<='1';YellowA2<='0';GreenA2<='0';LeftA2<='0';NumA2<=75-CountNum1;elsif Countnum1<(50+5+15+5+15) thenRedA1<='1';YellowA1<='0';GreenA1<='0';LeftA1<='0';NumA1<=115-CountNum1; RedA2<='0';YellowA2<='0';GreenA2<='1';LeftA2<='0';NumA2<=90-CountNum1;elsif Countnum1<(50+5+15+5+15+5) thenRedA1<='1';YellowA1<='0';GreenA1<='0';LeftA1<='0';NumA1<=115-CountNum1; RedA2<='0';YellowA2<='1';GreenA2<='0';LeftA2<='0';NumA2<=95-CountNum1;elsif Countnum1<(50+5+15+5+15+5+15) thenRedA1<='1';YellowA1<='0';GreenA1<='0';LeftA1<='0';NumA1<=115-CountNum1; RedA2<='0';YellowA2<='0';GreenA2<='0';LeftA2<='1';NumA2<=110-CountNum1;elseRedA1<='1';YellowA1<='0';GreenA1<='0';LeftA1<='0';NumA1<=115-CountNum1; RedA2<='0';YellowA2<='1';GreenA2<='0';LeftA2<='0';NumA2<=115-CountNum1;end if;if(Countnum1<15) then --state of crossing B when busyRedB1<='1';YellowB1<='0';GreenB1<='0';LeftB1<='0';NumB1<=20-CountNum1; RedB2<='0';YellowB2<='0';GreenB2<='0';LeftB2<='1';NumB2<=15-CountNum1;elsif(Countnum1<20) thenRedB1<='1';YellowB1<='0';GreenB1<='0';LeftB1<='0';NumB1<=20-CountNum1; RedB2<='0';YellowB2<='1';GreenB2<='0';LeftB2<='0';NumB2<=20-CountNum1;elsif Countnum1<(20+50) thenRedB1<='0';YellowB1<='0';GreenB1<='1';LeftB1<='0';NumB1<=70-CountNum1;RedB2<='1';YellowB2<='0';GreenB2<='0';LeftB2<='0';NumB2<=95-CountNum1;elsif Countnum1<(20+50+5) thenRedB1<='0';YellowB1<='1';GreenB1<='0';LeftB1<='0';NumB1<=75-CountNum1; RedB2<='1';YellowB2<='0';GreenB2<='0';LeftB2<='0';NumB2<=95-CountNum1;elsif Countnum1<(20+50+5+15) thenRedB1<='0';YellowB1<='0';GreenB1<='0';LeftB1<='1';NumB1<=90-CountNum1; RedB2<='1';YellowB2<='0';GreenB2<='0';LeftB2<='0';NumB2<=95-CountNum1;elsif Countnum1<(20+50+5+15+5) thenRedB1<='0';YellowB1<='1';GreenB1<='0';LeftB1<='0';NumB1<=95-CountNum1; RedB2<='1';YellowB2<='0';GreenB2<='0';LeftB2<='0';NumB2<=95-CountNum1;elsif Countnum1<(20+50+5+15+5+15) thenRedB1<='1';YellowB1<='0';GreenB1<='0';LeftB1<='0';NumB1<=115-CountNum1+20; RedB2<='0';YellowB2<='0';GreenB2<='1';LeftB2<='0';NumB2<=110-CountNum1;elseRedB1<='1';YellowB1<='0';GreenB1<='0';LeftB1<='0';NumB1<=115-CountNum1+20; RedB2<='0';YellowB2<='1';GreenB2<='0';LeftB2<='0';NumB2<=115-CountNum1;end if;elseif(Countnum2<60) then --state of crossing A when not busy RedA1<='0';YellowA1<='0';GreenA1<='1';LeftA1<='0';NumA1<=60-CountNum2; RedA2<='1';YellowA2<='0';GreenA2<='0';LeftA2<='0';NumA2<=90-CountNum2;elsif Countnum2<65 thenRedA1<='0';YellowA1<='1';GreenA1<='0';LeftA1<='0';NumA1<=65-CountNum2; RedA2<='1';YellowA2<='0';GreenA2<='0';LeftA2<='0';NumA2<=90-CountNum2;elsif Countnum2<85 thenRedA1<='0';YellowA1<='0';GreenA1<='0';LeftA1<='1';NumA1<=85-CountNum2;elsif Countnum2<90 thenRedA1<='0';YellowA1<='1';GreenA1<='0';LeftA1<='0';NumA1<=90-CountNum2; RedA2<='1';YellowA2<='0';GreenA2<='0';LeftA2<='0';NumA2<=90-CountNum2;elsif Countnum2<95 thenRedA1<='1';YellowA1<='0';GreenA1<='0';LeftA1<='0';NumA1<=120-CountNum2; RedA2<='0';YellowA2<='0';GreenA2<='1';LeftA2<='0';NumA2<=95-CountNum2;elsif Countnum2<100 thenRedA1<='1';YellowA1<='0';GreenA1<='0';LeftA1<='0';NumA1<=120-CountNum2; RedA2<='0';YellowA2<='1';GreenA2<='0';LeftA2<='0';NumA2<=100-CountNum2;elsif Countnum2<115 thenRedA1<='1';YellowA1<='0';GreenA1<='0';LeftA1<='0';NumA1<=120-CountNum2; RedA2<='0';YellowA2<='0';GreenA2<='0';LeftA2<='1';NumA2<=115-CountNum2;elseRedA1<='1';YellowA1<='0';GreenA1<='0';LeftA1<='0';NumA1<=120-CountNum2; RedA2<='0';YellowA2<='1';GreenA2<='0';LeftA2<='0';NumA2<=120-CountNum2;end if;if(Countnum2<15) then --state of crossing B when not busy RedB1<='1';YellowB1<='0';GreenB1<='0';LeftB1<='0';NumB1<=20-CountNum2; RedB2<='0';YellowB2<='0';GreenB2<='0';LeftB2<='1';NumB2<=15-CountNum2;elsif(Countnum2<20) thenRedB1<='1';YellowB1<='0';GreenB1<='0';LeftB1<='0';NumB1<=20-CountNum2; RedB2<='0';YellowB2<='1';GreenB2<='0';LeftB2<='0';NumB2<=20-CountNum2;elsif Countnum2<80 thenRedB1<='0';YellowB1<='0';GreenB1<='1';LeftB1<='0';NumB1<=80-CountNum2; RedB2<='1';YellowB2<='0';GreenB2<='0';LeftB2<='0';NumB2<=110-CountNum2;elsif Countnum2<85 thenRedB2<='1';YellowB2<='0';GreenB2<='0';LeftB2<='0';NumB2<=110-CountNum2;elsif Countnum2<105 thenRedB1<='0';YellowB1<='0';GreenB1<='0';LeftB1<='1';NumB1<=105-CountNum2; RedB2<='1';YellowB2<='0';GreenB2<='0';LeftB2<='0';NumB2<=110-CountNum2;elsif Countnum2<110 thenRedB1<='0';YellowB1<='1';GreenB1<='0';LeftB1<='0';NumB1<=110-CountNum2; RedB2<='1';YellowB2<='0';GreenB2<='0';LeftB2<='0';NumB2<=110-CountNum2;elsif Countnum2<115 thenRedB1<='1';YellowB1<='0';GreenB1<='0';LeftB1<='0';NumB1<=120-CountNum2+20; RedB2<='0';YellowB2<='0';GreenB2<='1';LeftB2<='0';NumB2<=115-CountNum2;elseRedB1<='1';YellowB1<='0';GreenB1<='0';LeftB1<='0';NumB1<=120-CountNum2+20; RedB2<='0';YellowB2<='1';GreenB2<='0';LeftB2<='0';NumB2<=120-CountNum2;end if;end if;end if;end if;end process;end;。