如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
交通灯模块设计1.分频器模块设计与仿真该模块可将频率为1KHZ的脉冲波,经过分频变为频率为1HZ的脉冲波,这样我们就得到了周期为1S的脉冲波。分频器程序清单如下:libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityfenpinqiisport(clk1khz:instd_logic;clk1hz:outstd_logic);endfenpinqi;architectureaoffenpinqiisbeginprocess(clk1khz)variableq:integer:=0;variabler:std_logic:='0';beginifclk1khz'eventandclk1khz='1'thenifq=512thenr:=notr;q:=0;elseq:=q+1;endif;clk1hz<=r;endif;endprocess;enda;分频器程序仿真结果如图1-1所示:图1-1分频器程序仿真结果图在分频器程序仿真结果图中,clk1khz为输入脉冲信号,频率为1khz;clk1hz为输出脉冲信号,频率为1hz。从图中,我们可以看出clk1hz的周期为1s。这表明程序的确把1khz的信号分频成1hz的信号。2.控制模块设计与仿真控制模块可根据clk的脉冲信号输出S的值,下个模块根据S的值来决定红绿灯的状态。同时对倒计时的信号赋初值。控制模块程序清单:libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entitycontrolisport(clk:instd_logic;s:outstd_logic_vector(2downto0);loadat,loadbt:outstd_logic;at,bt:outintegerrange0to80);endcontrol;architectureaofcontrolissignalt:integer;beginprocess(clk)beginifclk'eventandclk='1'thenloadat<='0';loadbt<='0';ift=0thens<="000";at<=80;loadat<='1';elsift=15thens<="001";bt<=45;loadbt<='1';elsift=60thens<="010";elsift=65thens<="011";bt<=80;loadbt<='1';elsift=80thens<="100";at<=45;loadat<='1';elsift=125thens<="101";endif;t<=t+1;endif;ift=130thent<=0;endif;endprocess;enda;控制模块程序仿真结果如图3-5所示:图3-5控制模块程序仿真结果图在控制模块程序仿真结果图中,只有一个输入信号clk,它是一个频率为1hz的时钟脉冲信号,输出信号有3个分别是s、at、bt。程序中,通过变量t的值来确定输出信号s的值,并由此确定将要赋得倒计时的初值,然后赋给at,bt。在每次给at,bt赋值时,都会使另一个输出信号loadat,loadbt变成高电平,从而可以触发下一模块的装载。3.倒计时模块设计与仿真倒计时模块用来接收控制模块的输出作为初值,并进行减一操作,最后把减一得结果输出。程序里每检测到一个脉冲clk,就进行一次减一操作。倒计时模块程序清单:libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityatdaojishiisport(clk,loadat:instd_logic;atin:inintegerrange0to80;atout:outintegerrange0to80);endatdaojishi;architectureaofatdaojishiissignalcountat:integerrange0to80;beginprocessbeginwaituntilrising_edge(clk);ifloadat='1'thencountat<