edavhdl程序设计 汽车灯设计1.docx
《edavhdl程序设计 汽车灯设计1.docx》由会员分享,可在线阅读,更多相关《edavhdl程序设计 汽车灯设计1.docx(15页珍藏版)》请在冰豆网上搜索。
edavhdl程序设计汽车灯设计1
汽车灯
0911020104吴珺
一、设计目的
设计一个组合控制电路,使得
1前大灯可以随意打开和关闭;
2当汽车左转弯的时候,前左灯闪烁,同时左后灯的3盏灯由右往左闪烁;
3当汽车右转弯的时候,前右灯闪烁,同时右后灯的3盏灯有左往右闪烁;
4当汽车减速或紧急刹车的时候,左后灯和右后灯同时闪烁;
5当汽车在左转弯的同时减速,则前左转向灯闪烁,左后灯的3盏灯由右往左闪烁,同时右后灯都点亮。
6当汽车在右转弯的同时减速,则前右转向灯闪烁,右后灯的3盏灯有左往右闪烁,同时左后灯都点亮。
二.实验原理及设计过程
指令开关控制:
大前灯控制、刹车/减速控制、左转向控制、右转向控制
输出的指标:
前大灯、前转向灯(分左灯和右灯,即前左灯和前右灯)、左后灯3盏、右后灯3盏
设计过程:
后灯的循环移位,因为有三盏灯,所以用有三个状态的状态机,每个状态对应一组3位的输出,控制3盏灯循环地亮。
灯的闪烁,用到T触发器的原理,设计一个中间变量,当来第一个时钟脉冲的时候,将这个中间变量取反,再来一个时钟脉冲的时候,再取反一次,有回到原来的初值,从而两个时钟脉冲实现两次翻转,发光二极管闪烁一下。
整个设计基本上由循环电路和控制电路组成。
为了避免汽车从一个状态切换到另一个状态是灯控制组合出现不稳定现象,所以每一个状态都必须对中间变量初始化。
三、设计源程序模块说明:
车灯控制器模块:
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
USEIEEE.STD_LOGIC_ARITH.ALL;
ENTITYcar_controlIS
PORT(
turn_fro_big_light:
INstd_logic;--前大灯控制开关
turn_left:
INstd_logic;--左转
turn_right:
INstd_logic;--右转
bake:
INstd_logic;--刹车或减速
fro_big_light_con:
OUTstd_logic;--前大灯
fro_L_light_con:
OUTstd_logic;--前左灯
fro_R_light_con:
OUTstd_logic;--前右灯
back_L_lights_con:
OUTstd_logic_vector(2downto0);--后左灯
back_R_lights_con:
OUTstd_logic_vector(2downto0);--后右灯
);
ENDcar_control;
ARCHITECTUREarch_car_controlofcar_controlIS
BEGIN
process(turn_left,turn_right,bake,turn_fro_big_light)
BEGIN
if(turn_fro_big_light='1')then
fro_big_light_con<='1';
else
fro_big_light_con<='0';
endif;--如果前灯控制为1,则前灯亮;否则不亮
--whennothingtodo在匀速直线行驶的情况下,前左右灯不亮,后左右转向灯不亮
if(turn_left='0'andturn_right='0'andbake='0')then
fro_L_light_con<='0';
fro_R_light_con<='0';
back_L_lights_con<="000";
back_R_lights_con<="000";
--在只是减速刹车的情况下,前转向灯不亮,后左右转向灯闪烁
elsif(turn_left='0'andturn_right='0'andbake='1')then
fro_L_light_con<='0';
fro_R_light_con<='0';
back_L_lights_con<="010";
back_R_lights_con<="010";
--在只是右转的情况下,前右转向灯闪烁,同时右后灯的3盏灯有左往右闪烁;其他左右灯不亮
elsif(turn_left='0'andturn_right='1'andbake='0')then
fro_L_light_con<='0';
fro_R_light_con<='1';
back_L_lights_con<="000";
back_R_lights_con<="001";
--当汽车在右转弯的同时减速,则前右转向灯闪烁,右后灯的3盏灯有左往右闪烁,同时左后灯都点亮。
elsif(turn_left='0'andturn_right='1'andbake='1')then
fro_L_light_con<='0';
fro_R_light_con<='1';
back_L_lights_con<="100";
back_R_lights_con<="001";
--当汽车左转弯的时候,前左转向灯闪烁,同时左后灯的3盏灯由右往左闪烁;其他左右灯不亮
elsif(turn_left='1'andturn_right='0'andbake='0')then
fro_L_light_con<='1';
fro_R_light_con<='0';
back_L_lights_con<="001";
back_R_lights_con<="000";
--当汽车在左转弯的同时减速,则前左转向灯闪烁,左后灯的3盏灯由右往左闪烁,同时右后灯都点亮。
elsif(turn_left='1'andturn_right='0'andbake='1')then
fro_L_light_con<='1';
fro_R_light_con<='0';
back_L_lights_con<="001";
back_R_lights_con<="100";
--指令错误,即左转又右转,不刹车,前后左右灯不亮
elsif(turn_left='1'andturn_right='1'andbake='0')then
fro_L_light_con<='0';
fro_R_light_con<='0';
back_L_lights_con<="000";
back_R_lights_con<="000";
--指令错误,即左转又右转,刹车,前后左右灯不亮
elsif(turn_left='1'andturn_right='1'andbake='1')then
fro_L_light_con<='0';
fro_R_light_con<='0';
back_L_lights_con<="000";
back_R_lights_con<="000";
endif;
ENDprocess;
ENDarch_car_control;
2.后转向灯控制器模块
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
ENTITYback_lightIS
PORT(
clk:
INSTD_LOGIC;
lights_control:
INSTD_LOGIC_VECTOR(2DOWNTO0);
lights:
OUTSTD_LOGIC_VECTOR(2DOWNTO0)
);
endback_light;
ARCHITECTUREarch_back_lightOFback_lightIS
TYPEstate1IS(s0,s1,s2,s3);
TYPEstate2IS(t0,t1);
SIGNALpresentstate1:
state1;
SIGNALpresentstate2:
state2;
BEGIN
PROCESS(clk,presentstate1)
BEGIN
if(clk'eventandclk='1')then
if(lights_control="000")THEN--灯不亮
lights<="000";
elsif(lights_control="001")THEN--灯的循环闪烁
casepresentstate1IS
WHENs0=>
lights<="001";
presentstate1<=s1;
WHENs1=>
lights<="011";
presentstate1<=s2;
WHENs2=>
lights<="111";
presentstate1<=s3;
WHENs3=>
lights<="000";
presentstate1<=s0;
endcase;
elsif(lights_control="010")THEN
casepresentstate2IS
WHENt0=>
lights<="000";
presentstate2<=t1;
WHENt1=>
lights<="111";
presentstate2<=t0;
endcase;--后灯是否全都闪烁一下
elsif(lights_control="100")THEN
lights<="111";--灯一直亮
endif;
endif;
ENDprocess;
endarch_back_light;
3.前灯模块
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
USEIEEE.STD_LOGIC_ARITH.ALL;
ENTITYfro_lightIS
PORT(
clk:
INSTD_LOGIC;
glistenab:
INSTD_LOGIC;
glisten:
OUTSTD_LOGIC
);
endfro_light;
ARCHITECTUREarch_fro_lightOFfro_lightIS
BEGIN
process(clk,glistenab)--实现的功能是前灯的亮灭
BEGIN
if(glistenab='1')THEN
glisten<=clk;
else
glisten<='0';
endif;
endprocess;
endarch_fro_light;
仿真结果
仿真图如下所示:
以防上面的错误以下是从ise上copy的能够仿真的文件:
1车灯控制器模块
libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
useIEEE.STD_LOGIC_ARITH.ALL;
useIEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITYcar_controlIS
PORT(
turn_fro_big_light:
INstd_logic;
turn_left:
INstd_logic;
turn_right:
INstd_logic;
bake:
INstd_logic;
fro_big_light_con:
OUTstd_logic;
fro_L_light_con:
OUTstd_logic;
fro_R_light_con:
OUTstd_logic;
back_L_lights_con:
OUTstd_logic_vector(2downto0);
back_R_lights_con:
OUTstd_logic_vector(2downto0)
);
ENDcar_control;
ARCHITECTUREarch_car_controlofcar_controlIS
BEGIN
process(turn_left,turn_right,bake,turn_fro_big_light)
BEGIN
if(turn_fro_big_light='1')then
fro_big_light_con<='1';
else
fro_big_light_con<='0';
endif;
if(turn_left='0'andturn_right='0'andbake='0')then
fro_L_light_con<='0';
fro_R_light_con<='0';
back_L_lights_con<="000";
back_R_lights_con<="000";
elsif(turn_left='0'andturn_right='0'andbake='1')then
fro_L_light_con<='0';
fro_R_light_con<='0';
back_L_lights_con<="010";
back_R_lights_con<="010";
elsif(turn_left='0'andturn_right='1'andbake='0')then
fro_L_light_con<='0';
fro_R_light_con<='1';
back_L_lights_con<="000";
back_R_lights_con<="001";
elsif(turn_left='0'andturn_right='1'andbake='1')then
fro_L_light_con<='0';
fro_R_light_con<='1';
back_L_lights_con<="100";
back_R_lights_con<="001";
elsif(turn_left='1'andturn_right='0'andbake='0')then
fro_L_light_con<='1';
fro_R_light_con<='0';
back_L_lights_con<="001";
back_R_lights_con<="000";
elsif(turn_left='1'andturn_right='0'andbake='1')then
fro_L_light_con<='1';
fro_R_light_con<='0';
back_L_lights_con<="001";
back_R_lights_con<="100";
elsif(turn_left='1'andturn_right='1'andbake='0')then
fro_L_light_con<='0';
fro_R_light_con<='0';
back_L_lights_con<="000";
back_R_lights_con<="000";
elsif(turn_left='1'andturn_right='1'andbake='1')then
fro_L_light_con<='0';
fro_R_light_con<='0';
back_L_lights_con<="000";
back_R_lights_con<="000";
endif;
ENDprocess;
ENDarch_car_control;
2后灯模块
libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
useIEEE.STD_LOGIC_ARITH.ALL;
useIEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITYback_lightIS
PORT(
clk:
INSTD_LOGIC;
lights_control:
INSTD_LOGIC_VECTOR(2DOWNTO0);
lights:
OUTSTD_LOGIC_VECTOR(2DOWNTO0)
);
endback_light;
ARCHITECTUREarch_back_lightOFback_lightIS
TYPEstate1IS(s0,s1,s2,s3);
TYPEstate2IS(t0,t1);
SIGNALpresentstate1:
state1;
SIGNALpresentstate2:
state2;
BEGIN
PROCESS(clk,presentstate1)
BEGIN
if(clk'eventandclk='1')then
if(lights_control="000")THEN
lights<="000";
elsif(lights_control="001")THEN
casepresentstate1IS
WHENs0=>
lights<="001";
presentstate1<=s1;
WHENs1=>
lights<="011";
presentstate1<=s2;
WHENs2=>
lights<="111";
presentstate1<=s3;
WHENs3=>
lights<="000";
presentstate1<=s0;
endcase;
elsif(lights_control="010")THEN
casepresentstate2IS
WHENt0=>
lights<="000";
presentstate2<=t1;
WHENt1=>
lights<="111";
presentstate2<=t0;
endcase;
elsif(lights_control="100")THEN
lights<="111";
endif;
endif;
ENDprocess;
endarch_back_light;
3前灯模块
libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
useIEEE.STD_LOGIC_ARITH.ALL;
useIEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITYfro_lightIS
PORT(
clk:
INSTD_LOGIC;
glistenab:
INSTD_LOGIC;
glisten:
OUTSTD_LOGIC
);
endfro_light;
ARCHITECTUREarch_fro_lightOFfro_lightIS
BEGIN
process(clk,glistenab)
BEGIN
if(glistenab='1')THEN
glisten<=clk;
else
glisten<='0';
endif;
endprocess;
endarch_fro_light;