VHDL实验 十字路口交通信号灯
实验报告
学号:06101040407 班级:电06A-4
日期:2008.5.23
1、 功能介绍
红黄绿灯由低电平控制开启。首先南北方向红灯、东西方向绿灯亮10周期,其他灯不亮;后所有黄灯亮1周期,其他灯不亮;后南北方向绿灯、东西方向红灯亮10周期,其他灯不亮;后所有黄灯亮1周期,其他灯不亮。此交通灯按以上顺序进行循环。
2、结构介绍
(1)clk时钟脉冲信号
r红灯信号, y黄灯信号, g绿灯信号 r1,y1,g1 南北方向红、黄、绿灯 r2,y2,g2 东西方向红、黄、绿灯 (2)trafficlight1模块是22进制加计数器
trafficlight2 根据计数器产生的信号对r、y、g进行控制:
当时钟在0—9周期范围内南北方向红灯亮,东西方向绿灯亮,其他灯不亮(r1、g2低电平,其他高电平);
当时钟在第10周期范围内所有黄灯亮,其他灯不亮(y1、y2低电平,其他高电平);
当时钟在11—20周期范围内南北方向绿灯亮,东西方向红灯亮,其他灯不亮(g1、r2低电平,其他高电平);
当时钟在第21周期范围内所有黄灯亮,其他灯不亮(y1、y2低电平,其他高电平);
3、 程序代码 (1)
library ieee;
use ieee.std_logic_11.all; use ieee.std_logic_unsigned.all; entity trafficlight1 is
port(clk:in std_logic;
cout:out std_logic_vector(4 downto 0)); end trafficlight1;
architecture rtl of trafficlight1 is
signal q: std_logic_vector(4 downto 0); begin
process(clk) begin
if(clk'event and clk='1') then if(q=21)then
q<=\"00000\"; else
q<=q+1; end if; end if; end process; cout<=q; end rtl;
(2)
library ieee;
use ieee.std_logic_11.all; use ieee.std_logic_unsigned.all; entity trafficlight2 is
port(a:in std_logic_vector(4 downto 0); r,y,g:out std_logic); end trafficlight2;
architecture rtl of trafficlight2 is begin process(a) begin
if(a<10)then r<='0'; y<='1'; g<='1'; elsif(a=10)then r<='1'; y<='0'; g<='1';
elsif(a>10 and a<21)then r<='1'; y<='1'; g<='0'; elsif(a=21)then r<='1'; y<='0'; g<='1';
end if;
end process; end rtl;
4、 仿真波形
5、电路连接
6、对应管脚
clk——79
r1——12 r2——17 y1——13 y2——18 g1——14 g2——19
7、 总结
电路应以计数器控制时间,其时间单位为计数器记数的一个周期,周期的大小可根据时钟脉冲CLK进行调节。由于使用VHDL进行编辑,设计时可不根据实际中的元件进行设计,所以我感觉这样十分方便且简单易行。