好文档 - 专业文书写作范文服务资料分享网站

电子设计自动化交通灯设计实验报告

天下 分享 时间: 加入收藏 我要投稿 点赞

EDA实验报告

Laboratory Exercise 4

Traffic-light controller

杨本栋

学号:201400800145 2014级电子一班

2016年5月12日

一、实验要求

1.当复位时,学术路绿灯亮,文化路红灯亮。

2.每5秒钟,传感器检测一次两条路是否有人。只要学术路有人,交通灯就不变化;当学术路没人时,亮5秒钟黄灯后变红灯,文化路变绿灯;当学术路有人时,文化路同样有5秒钟黄灯的转换过程;当两条路都没人时,学术路绿灯。

二、源代码

顶层实体——traffic_led

entity traffic_led is port ( clk_all: in std_logic; rst_all: in std_logic; a,c: in std_logic; ag,ay,ar,cg,cy,cr: out std_logic ); end entity;

architecture bhv of traffic_led is component traffic_ctrl is port (clk,rst,ta,tc: in std_logic; ga,gc,ra,rc,ya,yc : out std_logic); end component traffic_ctrl; component count_5s is port (clk,rst: in std_logic; cout : out std_logic); end component count_5s;

signal check : std_logic;

begin u1 :count_5s port map(clk_all ,rst_all,check); u2 :traffic_ctrl port map(check ,rst_all,a,c,ag,cg,ar,cr,ay,cy); end bhv;

元件1——traffic_ctrl(交通灯状态转换)

library ieee;

use ieee.std_logic_1164.all;

entity traffic_ctrl is port (

clk: in std_logic; rst: in std_logic; ta,tc: in std_logic; ga,gc,ra,rc,ya,yc: out std_logic ); end entity;

architecture bhv of traffic_ctrl is type states is (s0,s1,s2,s3); signal cs, next_state: states :=s0; begin com: process(ta,tc) begin case cs is when s0 => ga<='1';ra<='0';ya<='0'; gc<='0';rc<='1';yc<='0'; if ta='0' and tc='1' then next_state<=s1; else next_state<=s0; end if; when s1 => ga<='0';ra<='0';ya<='1'; gc<='0';rc<='1';yc<='0'; next_state<=s2; when s2 => ga<='0';ra<='1';ya<='0'; gc<='1';rc<='0';yc<='0'; if ta='0' and tc='1' then next_state<=s2; else next_state<=s3; end if; when s3 => ga<='0';ra<='1';ya<='0'; gc<='0';rc<='0';yc<='1'; next_state<=s0; when others => ga<='1';ra<='0';ya<='0'; gc<='0';rc<='1';yc<='0'; cs<=s0; end case;

end process com;

reg: process(clk,rst) begin if rst='0' then cs<=s0; elsif clk'event and clk='1' then cs<=next_state; end if; end process reg; end bhv;

元件2——count_5s(计时器5秒,每五秒发一个脉冲,50MHz晶振)

entity count_5s is port ( clk: in std_logic; rst: in std_logic; cout:out std_logic ); end entity;

architecture bhv of count_5s is

signal q: integer range 250000000 downto 0 ; begin process(clk,rst) begin if rst='0' then cout<='0';q<=0; elsif clk'event and clk='1' then q<=q+1; end if; if q=249999999 then cout<='1';q<=0; else cout<='0'; end if; end process; end architecture;

电子设计自动化交通灯设计实验报告

EDA实验报告LaboratoryExercise4Traffic-lightcontroller杨本栋学号:2014008001452014级电子一班2016年5月12日
推荐度:
点击下载文档文档为doc格式
22fpe9psu87f1wk0kikf
领取福利

微信扫码领取福利

微信扫码分享