交通灯控制系统EDA实验报告
来源:造价师 发布时间:2020-10-24 点击:
交通灯控制系统
EDA 实验报告
姓名:
学号:
2014
一、 课题名称 用状态机设计的交通信号控制系统。
二、 实验目的 利用所学习的 EDA 相关知识,完成对交通灯控制系统的设计并实现,提高对所学知识的理解和利用熟练程度。
三、 设计任务 设计一个十字路口交通控制系统,要求如下:
a. 东西(用 A 表示)、南北(用 B 表示)方向均有绿灯、黄灯、红灯指示,持续时间分别是 40 秒、五秒和 45 秒,交通灯运行的切换示意图与时间关系如下。
交通控制系统运行切换示意图
更方向灯光时间关系
b. 系统设有时钟,以倒计时的方式显示每一路允许通行的时间。
c. 当东西或南北两路中任意一路出现特殊状况时,系统可由交警手动控制立即进入特殊运行状态,即红灯全亮,始终停止计时,东西、南北两路所有车辆禁止通行;当特殊状况结束后,系统恢复工作,继续正常运行。
四、 实验过程 a. VHDL 设计流程
b. 交通控制系统顶层原理图如下,它主要由 50MHz 分频器(devide50M)、控制器(control)、45 秒倒计时计数器(m45)、7 字段译码器(SEG7)组成。
1) 控制器的设计
控制器的逻辑符号如图所示。其中CLK为时钟输入信号;HOLD为紧急制动信号;ARED、AGREEN、AYELLOW 分别为东西方向的红灯、绿灯、黄灯指示的输出信号;BRED、BGREEN、BYELLOW 分别为南北方向的红灯、绿灯、黄灯指示的输出信号。
控制器的 VHDL 描述文件 control.vhd 如下:
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;
entity control is
port(clk,hold:in std_logic;
ared,agreen,ayellow,bred,bgreen,byellow:out std_logic); end control;
architecture behavior of control is
type state_type is (s0,s1,s2,s3,s4);
signal current_state,next_state:state_type;
signal counter : std_logic_vector(6 downto 0);
begin synch:process begin
wait until clk"event and clk="1";
if hold="0" then
--当紧急制动信号有效时,计数器停止计数
counter<=counter;
else
if counter<89 then
counter<=counter+1;
else
counter<=(others=>"0");
end if;
end if;
end process;
process
--待机状态 begin
wait until clk"event and clk="1";
current_state<= next_state; end process;
state_trans:process(current_state) begin
case current_state is
when s0=>
if hold="0" then
next_state<=s4;
else
if counter<39 then
next_state<=s0;
else
next_state<=s1;
end if;
end if; when s1=>
if hold="0" then
next_state<=s4;
else
if counter<44 then
next_state<=s1;
else
next_state<=s2;
end if;
end if; when s2=>
if hold="0" then
next_state<=s4;
else
if counter<84 then
next_state<=s2;
else
next_state<=s3;
end if;
end if; when s3 =>
if hold="0" then
next_state<=s4;
else
if counter<89 then
next_state<=s3;
else
next_state<=s0;
end if;
end if; when s4=>
if hold="0" then
next_state<=s4;
else
if counter<39 then
next_state<=s0;
elsif counter<44 then
next_state<=s1;
elsif counter<84 then
next_state<=s2;
elsif counter<89 then
next_state<=s3;
end if;
end if; end case; end process;
output:process(current_state)
--每种状态下两个路口红绿灯的状态描述 begin case current_state is when s0=>
ared<="0";
agreen<="1";
ayellow<="0";
bred<="1";
bgreen<="0";
byellow<="0"; when s1=>
ared<="0";
agreen<="0";
ayellow<="1";
bred<="1";
bgreen<="0";
byellow<="0"; when s2=>
ared<="1";
agreen<="0";
ayellow<="0";
bred<="0";
bgreen<="1";
byellow<="0"; when s3=>
ared<="1";
agreen<="0";
ayellow<="0";
bred<="0";
bgreen<="0";
byellow<="1"; when s4=>
ared<="1";
agreen<="0";
ayellow<="0";
bred<="1";
bgreen<="0";
byellow<="0"; end case; end process; end behavior;
2) 倒计时计数器 M45 的设计 倒计时计数器 M45 的逻辑符号如图。其中 CLK、EN、CR 分别是时钟、计数使能和清零端,QL[3..0]、QH[3..0]、OC 分别是 BCD 码的个位、十位和进位输出。
VHDL 描述文件 m45.vhd 如下:
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity m45 is port(
CLK
: in std_logic;
EN
: in std_logic;
CR
: in std_logic;
QL,QH : out std_logic_vector(3 downto 0);
OC
: out std_logic
); end m45;
architecture behave of m45 is
signal couL,couH:std_logic_vector(3 downto 0); begin
process(CR,CLK,EN)
begin
if CR="0" then
--异步清零
couL<="0000";
couH<="0000";
elsif clk"event and clk="1" then
if EN="1" then
if( couL=0 and couH=0) then
--减法计到 00 后,重新置数 44
couL<="0100";
couH<="0100";
elsif couL=0 then
--否则个位计到 0 时置为 9,十位减 1
couL<="1001";
couH<=couH-1;
else
couL<=couL-1;
--否则个位减 1
end if;
end if;
end if;
end process;
process(couL,couH) begin
if(couL=0 and couH=0)then
OC<="1";
--减到 00 时有借位输出
else
OC<="0";
end if; end process;
QL<=couL;
QH<=couH; end behave;
3) 7 字段译码器电路的设计 7 字段译码器的功能是将 8421BCD 码译成 7 个信号,用以启动 7 段数码管显示相应的十进制数码,逻辑符号如图。dat[3..0]是 8421BCD 码的输入,a、b、c、d、e、f、g 是驱动数码管显示的 7 个输出信号(低电平有效)。
VHDL 描述文件 seg7.vhd 如下:
library ieee; use ieee.std_logic_1164.all;
entity seg7 is port( dat : in std_logic_vector(3 downto 0);
a,b,c,d,e,f,g : out std_logic );
end seg7;
architecture arc of seg7 is signal tmp : std_logic_vector(6 downto 0); begin
process(dat)
begin case dat is
when "0000"=>tmp<="0000001";
--输入 0000 时,显示 0
when "0001"=>tmp<="1001111";
--输入 00001 时,显示 1
when "0010"=>tmp<="0010010";
when "0011"=>tmp<="0000110";
when "0100"=>tmp<="1001100";
when "0101"=>tmp<="0100100";
when "0110"=>tmp<="0100000";
when "0111"=>tmp<="0001111";
when "1000"=>tmp<="0000000";
when "1001"=>tmp<="0000100";
--显示 9
when "1010"=>tmp<="0001000";
--显示 A
when "1011"=>tmp<="1100000";
when "1100"=>tmp<="0110001";
when "1101"=>tmp<="1000010";
when "1110"=>tmp<="0110000";
when "1111"=>tmp<="0111000"; end case; end process; a<=tmp(6); b<=tmp(5); c<=tmp(4); d<=tmp(3); e<=tmp(2); f<=tmp(1); g<=tmp(0); end arc;
4) 50MHz 分频器的设计 逻辑符号如图,目的是将输入信号转化为 1HZ 输出。clk 为信号输入端,clk_out 为信号输出端。
VHDL 描述文件 devide50M.vhd 如下:
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity devide50M is port(
clk
: in std_logic;
clk_out : out std_logic
); end devide50m;
architecture arc_devide50M of devide50M is
signal count: std_logic_vector (25 downto 0); begin
process
begin
wait until clk"event and clk="1";
if (count<50000000) then
count<=count+1;
clk_out<="0";
else
count<=(others =>"0");
clk_out<="1";
end if;
end process; end architecture arc_devide50M;
c. 管脚设计 因为使用的是 Cyclone III_EP3C16F484C6 型号的电路板,因此管脚连接如下:
Cyclone III_EP3C16F484C6 型号的电路板
管脚连接图
五、 实验结果
波形仿真结果
六、 实验心得 通过这次设计,进一步加深了对 VHDL 语言的了解,让我对它有了更加浓厚的兴趣。在文件编写的过程中,我遇到了不少问题,包括最开始的无从下手到各元件之间的连接,引脚的设定,但最终还是克服了这些困难。建议以后的课程中将上机操作与课程理论教学相结合,这样也许就能够更好的帮助我们学习 EDA。
推荐访问:交通灯 控制系统 实验