1、edavhdl程序设计 汽车灯设计1汽车灯0911020104 吴珺一、设计目的设计一个组合控制电路,使得1 前大灯可以随意打开和关闭;2 当汽车左转弯的时候,前左灯闪烁,同时左后灯的3盏灯由右往左闪烁;3 当汽车右转弯的时候,前右灯闪烁,同时右后灯的3盏灯有左往右闪烁;4 当汽车减速或紧急刹车的时候,左后灯和右后灯同时闪烁;5 当汽车在左转弯的同时减速,则前左转向灯闪烁,左后灯的3盏灯由右往左闪烁,同时右后灯都点亮。6 当汽车在右转弯的同时减速,则前右转向灯闪烁,右后灯的3盏灯有左往右闪烁,同时左后灯都点亮。二实验原理及设计过程指令开关控制:大前灯控制、刹车/减速控制、左转向控制、右转向控制
2、输出的指标:前大灯、前转向灯(分左灯和右灯, 即前左灯和前右灯)、左后灯3盏、右后灯3盏设计过程:后灯的循环移位,因为有三盏灯,所以用有三个状态的状态机,每个状态对应一组3位的输出,控制3盏灯循环地亮。灯的闪烁,用到T触发器的原理,设计一个中间变量,当来第一个时钟脉冲的时候,将这个中间变量取反,再来一个时钟脉冲的时候,再取反一次,有回到原来的初值,从而两个时钟脉冲实现两次翻转,发光二极管闪烁一下。整个设计基本上由循环电路和控制电路组成。为了避免汽车从一个状态切换到另一个状态是灯控制组合出现不稳定现象,所以每一个状态都必须对中间变量初始化。三、设计源程序模块说明:车灯控制器模块:LIBRARY
3、IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_ARITH.ALL;ENTITY car_control IS PORT( turn_fro_big_light : IN std_logic; -前大灯控制开关 turn_left : IN std_logic; -左转 turn_right : IN std_logic; -右转 bake : IN std_logic; -刹车或减速 fro_big_light_con : OUT std_logic; -前大灯 fro_L_light_con : OUT std_logic; -前左灯
4、 fro_R_light_con : OUT std_logic; -前右灯 back_L_lights_con : OUT std_logic_vector( 2 downto 0); -后左灯 back_R_lights_con : OUT std_logic_vector( 2 downto 0) ;- -后右灯 );END car_control;ARCHITECTURE arch_car_control of car_control ISBEGIN process( turn_left, turn_right, bake, turn_fro_big_light) BEGIN if(
5、turn_fro_big_light = 1 ) then fro_big_light_con = 1; else fro_big_light_con = 0;end if; -如果前灯控制为1,则前灯亮;否则不亮-when nothing to do 在匀速直线行驶的情况下,前左右灯不亮,后左右转向灯不亮 if( turn_left = 0 and turn_right = 0 and bake = 0) then fro_L_light_con = 0; fro_R_light_con = 0; back_L_lights_con = 000; back_R_lights_con = 00
6、0; -在只是减速刹车的情况下,前转向灯不亮,后左右转向灯闪烁 elsif( turn_left = 0 and turn_right = 0 and bake = 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 and turn_right = 1 and bake = 0)then fro_L_light_con
7、= 0; fro_R_light_con = 1; back_L_lights_con = 000; back_R_lights_con = 001; -当汽车在右转弯的同时减速,则前右转向灯闪烁,右后灯的3盏灯有左往右闪烁,同时左后灯都点亮。 elsif( turn_left = 0 and turn_right = 1 and bake = 1)then fro_L_light_con = 0; fro_R_light_con = 1; back_L_lights_con = 100; back_R_lights_con = 001; -当汽车左转弯的时候,前左转向灯闪烁,同时左后灯的3盏
8、灯由右往左闪烁;其他左右灯不亮 elsif( turn_left = 1 and turn_right = 0 and bake = 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 and turn_right = 0 and bake = 1)then fro_L_light_con = 1; fro_R_li
9、ght_con = 0; back_L_lights_con = 001; back_R_lights_con = 100; -指令错误,即左转又右转,不刹车,前后左右灯不亮 elsif( turn_left = 1 and turn_right = 1 and bake = 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 and turn_right =
10、1 and bake = 1)then fro_L_light_con = 0; fro_R_light_con = 0; back_L_lights_con = 000; back_R_lights_con = 000; end if; END process;END arch_car_control;2后转向灯控制器模块LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY back_light IS PORT( clk : IN STD_LOGIC; lights_control : IN STD_LOGIC_VECTOR( 2 DOWNTO 0)
11、; lights : OUT STD_LOGIC_VECTOR( 2 DOWNTO 0) );end back_light; ARCHITECTURE arch_back_light OF back_light ISTYPE state1 IS(s0,s1,s2,s3);TYPE state2 IS(t0,t1);SIGNAL presentstate1 : state1;SIGNAL presentstate2 : state2;BEGIN PROCESS( clk, presentstate1 ) BEGIN if(clkevent and clk = 1) then if( lights
12、_control = 000) THEN -灯不亮 lights lights = 001; presentstate1 lights = 011; presentstate1 lights = 111; presentstate1 lights = 000; presentstate1 lights = 000; presentstate2 lights = 111; presentstate2 = t0; end case; -后灯是否全都闪烁一下 elsif( lights_control = 100 ) THEN lights = 111; -灯一直亮 end if; end if;
13、END process;end arch_back_light; 3前灯模块LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_ARITH.ALL;ENTITY fro_light IS PORT( clk : IN STD_LOGIC; glistenab : IN STD_LOGIC; glisten : OUT STD_LOGIC );end fro_light;ARCHITECTURE arch_fro_light OF fro_light ISBEGIN process( clk, glistenab) -实现的功能
14、是前灯的亮灭 BEGIN if( glistenab = 1)THEN glisten = clk; else glisten = 0; end if; end process;end arch_fro_light;仿真结果 仿真图如下所示:以防上面的错误以下是从ise上copy的能够仿真的文件:1 车灯控制器模块library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY car_control IS PORT( turn_fro_big
15、_light : IN std_logic; turn_left : IN std_logic; turn_right : IN std_logic; bake : IN std_logic; fro_big_light_con : OUT std_logic; fro_L_light_con : OUT std_logic; fro_R_light_con : OUT std_logic; back_L_lights_con : OUT std_logic_vector( 2 downto 0); back_R_lights_con : OUT std_logic_vector( 2 dow
16、nto 0) );END car_control;ARCHITECTURE arch_car_control of car_control ISBEGIN 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; end if; if( turn_left = 0 and turn_right = 0 and bake = 0) then fro_L_lig
17、ht_con = 0; fro_R_light_con = 0; back_L_lights_con = 000; back_R_lights_con = 000; elsif( turn_left = 0 and turn_right = 0 and bake = 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 and turn_right = 1 and bake = 0)then fro_L_li
18、ght_con = 0; fro_R_light_con = 1; back_L_lights_con = 000; back_R_lights_con = 001; elsif( turn_left = 0 and turn_right = 1 and bake = 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 and turn_right = 0 and bake = 0)then fro_L_li
19、ght_con = 1; fro_R_light_con = 0; back_L_lights_con = 001; back_R_lights_con = 000; elsif( turn_left = 1 and turn_right = 0 and bake = 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 and turn_right = 1 and bake = 0)then fro_L_li
20、ght_con = 0; fro_R_light_con = 0; back_L_lights_con = 000; back_R_lights_con = 000; elsif( turn_left = 1 and turn_right = 1 and bake = 1)then fro_L_light_con = 0; fro_R_light_con = 0; back_L_lights_con = 000; back_R_lights_con = 000; end if; END process;END arch_car_control;2 后灯模块library IEEE;use IE
21、EE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY back_light IS PORT( clk : IN STD_LOGIC; lights_control : IN STD_LOGIC_VECTOR( 2 DOWNTO 0); lights : OUT STD_LOGIC_VECTOR( 2 DOWNTO 0) );end back_light; ARCHITECTURE arch_back_light OF back_light ISTYPE state1 I
22、S(s0,s1,s2,s3);TYPE state2 IS(t0,t1);SIGNAL presentstate1 : state1;SIGNAL presentstate2 : state2;BEGIN PROCESS( clk, presentstate1 ) BEGIN if(clkevent and clk = 1) then if( lights_control = 000) THEN lights lights = 001; presentstate1 lights = 011; presentstate1 lights = 111; presentstate1 lights =
23、000; presentstate1 lights = 000; presentstate2 lights = 111; presentstate2 = t0; end case; elsif( lights_control = 100 ) THEN lights = 111; end if; end if; END process;end arch_back_light; 3 前灯模块library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY fro_light IS PORT( clk : IN STD_LOGIC; glistenab : IN STD_LOGIC; glisten : OUT STD_LOGIC );end fro_light;ARCHITECTURE arch_fro_light OF fro_light ISBEGIN process( clk, glistenab) BEGIN if( glistenab = 1)THEN glisten = clk; else glisten = 0; end if; end process;end arch_fro_light;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1