VHDL汽车尾灯
掌握VHDL程序设计
共6个尾灯,汽车正常行驶时,6个灯全灭;
左转时,左边3个灯从右到左依次亮灭;
右转时,右边3上灯从左到右依次亮灭;
刹车时,车灯全亮;故障时,全部闪烁。
在软件工具平台上,进行VHDL语言的各个模块编程输入、编译实现和仿真
验证。
计算机
1.系统设计与
: 根据系统设计要求,采用自顶向下设计方法,顶层设
计采用原理图设计,它由主控模块、左边灯控制模块和右边灯控制模块三部
分组成。
2.系统功能: 用6个发光管模拟6个汽车尾灯(左右各3个),用4个开关
作为汽车控制信号,分别为:左拐、右拐、故障和刹车。4个输入信号为:
3.参考VHDL源程序
(1) 主控制模块
说明:此程序为系统主控制模块。当左转时,lft信号有效;右转时,rit信号有效;当
左右信号都有效的时,lr有效。
library ieee; rit<='0';
use ieee.std_logic_1164.all;
entity kz is
port(left,right:in std_logic;
lft,rit,lr:out std_logic);
end kz;
architecture kz_arc of kz is
begin
process(left,right)
variable a:std_logic_vector(1 downto 0);
begin
a:=left&right;
case a is
when"00"=>lft<='0';----------正常
rit<='0';
lr<='0';
when"10"=>lft<='1';----------左转
lr<='0';
when"01"=>rit<='1';-----------右转
lft<='0';
lr<='0';
when others=>rit<='1';---------STOP
lft<='1';
lr<='1';
end case;
end process;
end kz_arc;
当左右信号都有效时,输出为全“1”
(2)左边灯控制模块
说明:此模块的功能是当左转时控制左边的3个灯,
library ieee;
use ieee.std_logic_1164.all;
entity lfta is
port(en,clk,left:in std_logic;
l_out:out std_logic_vector( 2 downto 0));
end lfta;
architecture lft_arc of lfta is
begin
process(clk,en,left)
variable tmp:std_logic_vector(2 downto 0);
begin
if clk'event and clk='1' then
if en='1' then------------------故障使能端,高电平有效
if tmp="000" then
tmp:="111";
else
tmp:="000";
end if;-------------------------en=’1’,故障,左边三个灯一起闪烁
elsif left='0' then
tmp:="000"; --------------------当left=’0’,左边三个灯全灭
else
if tmp="000" then
tmp:="001";
else
tmp:=tmp(1 downto 0)&'0';------当left有效时,左边三个灯依次闪烁
end if;
end if;
end if;
l_out<=tmp;
end process;
end lft_arc;
仿真图
当en为“1”即故障时,三个灯同时闪烁.且优先级最高;当left,en无效时输出为“0”即
三个灯全灭。当en无效left有效时,三个灯依次闪烁。
(2) 右边灯控制模块
说明:此模块的功能是控制右边的3个灯,与上面模块相似。
library ieee;
use ieee.std_logic_1164.all;
entity rita is
port(en,clk,right:in std_logic;
r_out:out std_logic_vector(2 downto 0));
end rita;
architecture rit_arc of rita is
begin
process(clk,en,right)
variable tmp:std_logic_vector(2 downto 0);
begin
if clk'event and clk='1' then
if en='1' then-------------故障使能端,高电平
if tmp="000" then
tmp:="111";
else tmp:="000";
end if;-------------故障时,三个一起闪烁。
elsif right='0' then
tmp:="000";
else
if tmp="000" then
tmp:="100";
else
tmp:='0'&tmp(2 downto 1);----------当righte 有效时,右边三个灯依次闪烁
end if;
end if;
end if;
r_out<=tmp;
end process;
end rit_arc;
仿真图
当en为“1”即故障时,三个灯同时闪烁.且优先级最高;当right,en无效时输出为“0”
即三个灯全灭。当en无效right有效时,三个灯依次闪烁。
library ieee;
use ieee.std_logic_1164.all;
entity kzcar is
port(left,right,clk,en:in std_logic;
l_out:out std_logic_vector(2 downto 0);
r_out:out std_logic_vector(2 downto 0) );
end kzcar;
architecture kz_arc of kzcar is
signal lft,rit,lr:std_logic;
begin
process(left,right)--------------------------------主模块
variable a:std_logic_vector(1 downto 0);
begin
a:=left&right;
case a is
when"00"=>lft<='0';
rit<='0';
lr<='0';
when"10"=>lft<='1';
rit<='0';
lr<='0';
when"01"=>rit<='1';
lft<='0';
lr<='0';
when others=>rit<='1';
lft<='1';
lr<='1';
end case;
end process;------------------------------------主模块 process(clk,en,lr,lft,rit)----------------------------- 左边灯控制模块
variable tmp:std_logic_vector(2 downto 0);
begin
if lr='1' then
tmp:="111";------------------------左、右都有效时,实现刹车功能
elsif clk'event and clk='1' then
if en='1' then
if tmp="000" then
tmp:="111";
else tmp:="000";
end if;------------------------故障时,同时闪烁 elsif lft='0' and rit='0' then
tmp:="000";
elsif lft='1'then
if tmp="000" then
tmp:="001";
else
tmp:=tmp(1 downto 0)&'0';-----------------依次闪烁
end if;
end if;
end if;
l_out<=tmp;
end process;------------------------------- 左边灯控制模块
process(clk,en,lr,rit)------------------------- 右边灯控制模块
variable tmp:std_logic_vector(2 downto 0);
begin
if lr='1' then
tmp:="111";------------------------左、右都有效时,实现刹车功能
elsif clk'event and clk='1' then
if en='1' then
if tmp="000" then
tmp:="111";
else tmp:="000";
end if; ------------------------故障时,同时闪烁
elsif lft='0' and rit='0' then
tmp:="000";
elsif rit='1'then
if tmp="000" then
tmp:="100";
else
tmp:='0'&tmp(2 downto 1); 依次闪烁
end if;
end if;
end if;
右边灯控制模块 r_out<=tmp;
end kz_arc; end process;-------------------------------------
从仿真图看出,基本功能都实现:
当en=’1’时,发生故障,六个全部同时闪烁。l_out和r_out在clk条件下来,输出全部0 时则输出为1,否输出为0。
当en为0时:
当左、右信号都无效,则六个灯全灭。即当left和right都为0时,输出全为0。
当左、右信号都有效时,则六个灯全亮。即left和right都为1时,输出全为1。
当左信号有效时且右信号无效时,则车左转,左边三个灯从右到左依次亮灭。即当
left=’1’且right=’0’时,则l_out从l_out(0)~l_out(2)依次输出一个脉冲周期的高电平。
当左信号无效时且右信号有效时,则右转,
右转时,右边3上灯从左到右依次亮灭。
即当left=’0’且right=’1’时,则r_out从r_out(0)~l_out(2)依次输出一个脉冲周期的高电平。
当刚接触MAX-puls II这软件时,由自己的英语水平有限,基本功能,操作
不会。对于VHDL很陌生,几个钟的实验时间都白白浪费。经过老师的指导,
请教同学。基本弄懂MAX-puls II操作流程。VHDL语言刚开始很生疏,做汽车
尾灯设计时,不能画出其基本组成框图。一时毫无头绪,经过上网,去图
馆找
资料,还有就是经过几个星期课程设计(课程设计都有VHDL的应用),在老师的指导下,了解到VHDL在教学上的重要性。汽车尾灯的原理基本明白,进行
分模块设计,再进行整合。最终用VHDL实现了汽车尾灯的功能。从陌生到熟
悉,从熟悉到掌握这个过程,是要不继的训练,不断的思考才能实现。正所谓“冰
冻三尺非一日之寒,滴水石穿非一日之功”。要不断的充实自己,学多一点知识,
为自己以后生活提供基本的保障。