版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第十章综合设计实例第十章综合设计实例11键盘扫描与显示矩阵式键盘:行,列矩阵是键盘以行列形式排列,键盘上每个按键其实是一个开关电路,当某键被按下时,该按键对应的位置就呈现逻辑0状态.行扫描方式:逐行送0电平,读取列的状态,以判断按下的键号.列扫描方式:逐列送0电平,读取行的状态,以判断按下的键号.1键盘扫描与显示矩阵式键盘:行,列矩阵是键盘以行列形式排列2以行扫描为例:1给行依次送0111,1011,1101,1110信号;2读取列电平状态,以行扫描为例:1给行依次送0111,1011,1101,113数码管显示数码管显示4libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entitykey_scanisport(column:instd_logic_vector(3downto0);--列状态scan_cnt:instd_logic_vector(3downto0);---扫描字row:outstd_logic_vector(3downto0);---行状态key_pressed:outstd_logic);-----按键有效与否,后续判断为零则为有键按下end;architecturertlofkey_scanisbeginrow<="1110"whenscan_cnt(3downto2)="00"else"1101"whenscan_cnt(3downto2)="01"else"1011"whenscan_cnt(3downto2)="10"else"0111";key_pressed<=column(0)whenscan_cnt(1downto0)="00"elsecolumn(1)whenscan_cnt(1downto0)="01"elsecolumn(2)whenscan_cnt(1downto0)=“10"elsecolumn(3);endrtl;按键扫描控制程序libraryieee;按键扫描控制程序5按键处理控制模块libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;useieee.std_logic_arith.all;entityscan_countisport(clk:instd_logic;--clockscan_clk:instd_logic;--1khzclkkey_pressed:instd_logic;--检测按键有效与否,停止计数.scan_cnt:outstd_logic_vector(3downto0));--计数end;architecturebehavofscan_countissignalqscan:std_logic_vector(3downto0);beginscan_1:process(clk,scan_clk,key_pressed)beginif(clk'eventandclk='1')thenif(scan_clk='1'andkey_pressed='1')thenqscan<=qscan+1;endif;endif;endprocess;scan_cnt<=qscan;end;按键处理控制模块libraryieee;6按键消抖控制模块libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;useieee.std_logic_arith.all;entitydebounceisport(key_pressed:instd_logic;clk:instd_logic;--同步时钟scan_clk:instd_logic;--1khzclockkey_valid:outstd_logic);end;architecturebehavofdebounceisbegin
按键消抖控制模块libraryieee;7debounce:process(clk,scan_clk,key_pressed)variabledbnq:std_logic_vector(5downto0);beginif(key_pressed='1')thendbnq:="111111";--unkey_pressed,countresetat63elsif(clk'eventandclk='1')thenifscan_clk='1'thenifdbnq/=1thendbnq:=dbnq-1;--key_pressednotenoughlongtimeendif;endif;endif;ifdbnq=2thenkey_valid<='1';--key_validafterkey_pressed1/63ksecondelsekey_valid<='0';endif;endprocess;end;debounce:process(clk,scan_clk,8键盘译码及按键存储模块libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;useieee.std_logic_arith.all;entitycode_tranisport(clk:instd_logic;--clockforsynchronyscan_cnt:instd_logic_vector(3downto0);--1khzclockkey_valid:instd_logic;butt_code:outstd_logic_vector(3downto0));end;architecturebbofcode_tranisbeginprocess(clk)beginif(clk'eventandclk='1')thenifkey_valid='1'thencasescan_cntis键盘译码及按键存储模块libraryieee;9when"0000"=>butt_code<="0001";--1when"0001"=>butt_code<="0010";--2when"0010"=>butt_code<="0011";--3when"0011"=>butt_code<="1100";--cwhen"0100"=>butt_code<="0100";--4when"0101"=>butt_code<="0101";--5when"0110"=>butt_code<="0110";--6when"0111"=>butt_code<="1101";--dwhen"1000"=>butt_code<="0111";--7when"1001"=>butt_code<="1000";--8when"1010"=>butt_code<="1001";--9when"1011"=>butt_code<="1110";--ewhen"1100"=>butt_code<="1010";--awhen"1101"=>butt_code<="0000";--0when"1110"=>butt_code<="1011";--bwhenothers=>butt_code<="1111";--fendcase;endif;endif;endprocess;end;when"0000"=>butt_code<="0001";10电锁控制模块libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityctrlisport(data_n:instd_logic_vector(3downto0);key_valid,clk:instd_logic;enlock:outstd_logic;d,c,b,a:outstd_logic_vector(3downto0));end;architectureaaaofctrlissignalacc,reg:std_logic_vector(15downto0);signalnc:std_logic_vector(2downto0);signalqa,qb:std_logic;beginkeyin:blockisbegin
process(data_n,key_valid)
电锁控制模块libraryieee;11beginifdata_n="1101"thenacc<="0000000000000000";nc<="000";elsifkey_valid'eventandkey_valid='1'thenifdata_n<"1101"thenifnc<=4thenacc<=acc(11downto0)&data_n;nc<=nc+1;endif;endif;endif;endprocess;endblock;lock:blockisbegin
process(clk,data_n)beginif(clk'eventandclk='1')thenifnc=4thenifdata_n="1110"thenreg<=acc;qa<='1';qb<='0';elsifdata_n="1111"thenifreg=accthenqa<='0';qb<='1';endif;endif;endif;endif;endprocess;endblock;begin12enlock<=qaandnotqb;d<=acc(15downto12);c<=acc(11downto8);b<=acc(7downto4);a<=acc(3downto0);endaaa;enlock<=qaandnotqb;13动态扫描显示控制模块libraryieee;useieee.std_logic_1164.all;useieee.std_logic_arith.all;useieee.std_logic_unsigned.all;entitysel_displayisport(clk:instd_logic;d,c,b,a:instd_logic_vector(3downto0);db_out:outstd_logic_vector(3downto0);dis_out:outstd_logic_vector(3downto0));endentity;architecturertlofsel_displayissignalsel:std_logic_vector(1downto0);signaldis:std_logic_vector(3downto0);signaldb:std_logic_vector(3downto0);begin动态扫描显示控制模块libraryieee;14counter:blockissignalq:std_logic_vector(6downto0);beginprocess(clk)beginifclk'eventandclk='1'thenq<=q+1;endif;endprocess;sel<=q(1downto0);endblockcounter;counter:blockis15multiplexer:blockisbeginprocess(sel)beginifsel=0thendb<=d;dis<="0111";elsifsel=1thendb<=c;dis<="1011";elsifsel=2thendb<=b;dis<="1101";elsifsel=3thendb<=a;dis<="1110";endif;endprocess;endblockmultiplexer;db_out<=db;dis_out<=dis;endrtl;multiplexer:blockis16FPGA综合设计实例ppt课件17FPGA综合设计实例ppt课件18FPGA综合设计实例ppt课件19实例1数字钟设计实时显示时、分、秒分析:1、最小计时单位:秒。因此,首先要由时钟产生1HZ的信号;2、对秒进行0-59的计数,并且有进位功能,且显示;3、对分进行0-59的计数,并且有进位功能,且显示;4、对时进行0-59的计数,且显示;实例1数字钟设计实时显示时、分、秒分析:20FPGA综合设计实例ppt课件21libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.allentitysecondisport(clk,clr:instd_logic;--clk=1Hzsec1,sec0:outstd_logic_vector(3downto0);co:outstd_logic);endsecond;architecturearchofsecondisbeginprocess(clk,clr)variablecnt1,cnt0:std_logic_vector(3downto0);beginifclr='0'thencnt1:="0000";cnt0:="0000";elsifclk'eventandclk='1'thenifcnt1="0101"andcnt0="1000"thenco<='1';cnt0:="1001";elsifcnt0<"1001"thencnt0:=cnt0+1;elsecnt0:="0000";ifcnt1<"0101"thencnt1:=cnt1+1;elsecnt1:="0000";co<='0';endif;endif;endif;
sec1<=cnt1;sec0<=cnt0;endprocess;endarch;libraryieee;process(clk,clr)22实例2出租车计费器设计功能:(1)实现计费功能。车起步开始计费,首先显示起步价,设起步费为8.00元,车在行驶3km以内,只收起步价8.00元。车行驶超过3km后,每公里2元,车费依次累加。当总费用达到或超过40元时,每公里收费4元。当遇到红灯或客户需要停车等待时,则按时间计费,计费单价为每20S收费1元。(2)实现预置功能:预置起步费、每公里收费、车行加费里程、计时收费。(3)实现模拟功能:模拟汽车行驶、停止、暂停等状态。(4)实现显示功能:将路程与车费显示出来,以十进制显示。实例2出租车计费器设计功能:23模块speed模块kmmoney判断总费用kmmoney判断行驶里程kmcount模块kilometers模块timeresetstartsp模块speed模块判断总费用判断行驶里程模块模块timer24系统流程如下:
(1)系统接收到reset信号后,总费用变为8元,同时其他计数器,寄存器等全部清零。
(2)系统接收到start信号后,首先把部分寄存器赋值,总费用不变,单价price寄存器通过对总费用的判断后赋为2元。其他寄存器和计数器等继续保持为0。
(3)speed进程:通过对速度信号sp的判断,决定变量kinside的值。kinside即是行进100m所需要的时钟周期数,然后每行进100m,则产生一个脉冲clkout。
(4)kilometers进程:由于一个clkout信号代表行进100m,故通过对clkout计数,可以获得共行进的距离kmcount。
(5)time进程:在汽车启动后,当遇到顾客等人或红灯时,出租车采用计时收费的方式。通过对速度信号sp的判断决定是否开始记录时间。当sp=0时,开始记录时间。当时间达到足够长时则产生timecount脉冲,并重新计时。一个timecount脉冲相当于等待的时间达到了时间计费的长度。这里选择系统时钟频率为500Hz,20s即计数值为1000。
(6)kmmoney可分为kmmoney1和kmmoney2两个进程。
kmmoney1进程:根据条件对enable和price赋值。当记录的距离达到3公里后enable变为‘1’,开始进行每公里收费,当总费用大于40元后,则单价price由原来的2元每公里变为4元每公里。
kmmoney2进程:在每个时钟周期判断timecount和clkout的值。当其为‘1’时,则在总费用上加上相应的费用。系统流程如下:(1)系统接收到reset信号后,总费用变为25FPGA综合设计实例ppt课件26speed模块speed进程首先根据start信号判断是否开始计费,然后根据输入的速度档位sp[2..0]的判断,确定行驶100M所需要的时钟数,每前进100M,输出一个clkout信号。同时由cnt对clk进行计数,当cnt=kinside时,把clkout信号置‘1’,cnt清0。speed模块27Libraryieee;Useieee.std_logic_1164.all;Useieee.std_logic_unsigned.all;EntityfeesystemisPort(clk:instd_logic;reset:instd_logic;start:instd_logic;stop:instd_logic;sp:instd_logic_vector(2downto0);clkout:outstd_logic);endfeesystem;architecturebehavoffeesystemisbeginprocess(clk,reset,stop,start,sp)typestate_typeis(s0,s1);variables_state:state_type;variablecnt:integerrange0to28;variablekinside:integerrange0to30;begincasespis---7档速度选择,具体每档kinside的值可根据实际情况设定when"000"=>kinside:=0;--停止状态或空挡Libraryieee;28when"001"=>kinside:=28;--第一档,慢速行驶状态,行驶100m需要28个时钟周期when"010"=>kinside:=24;--第二档 when"011"=>kinside:=20;--第三档when"100"=>kinside:=16;--第四档when"101"=>kinside:=12;--第五档when"110"=>kinside:=8;--第六档when"111"=>kinside:=4;--第七档,也是速度最大的档endcase;ifreset='1'thens_state:=s0;elsifclk'eventandclk='1'thencases_stateiswhens0=>cnt:=0;clkout<='0';ifstart='1'thens_state:=s1;elses_state:=s0;endif;
when"001"=>kinside:=28;--第29whens1=>clkout<='0';ifstop='1'thens_state:=s0;--相当于无客户上车elsifsp="000"thens_state:=s1;---有客户上车,但车速位0,即客户刚上车还未起步elsifcnt=kinsidethencnt:=0;clkout<='1';s_state:=s1;elsecnt:=cnt+1;s_state:=s1;endif;endcase;endif;endprocess;endbehav;whens1=>30kilometers模块此模块主要用于记录行进的距离。通过对clkout信号的计数,可以计算行驶的距离kmcount。一个clkout脉冲相当于行进100m,所以只要记录clkout的脉冲数目即可确定共行进的距离。kmcount1为十分位,kmcount2为个位,kmcount3为十位,分别为十进制数。kilometers模块31Libraryieee;Useieee.std_logic_1164.all;Useieee.std_logic_unsigned.all;EntitykilometersisPort(clkout,reset:instd_logic;kmcnt1:outstd_logic_vector(3downto0);kmcnt2:outstd_logic_vector(3downto0);kmcnt3:outstd_logic_vector(3downto0));endkilometers;architecturebehavofkilometersisbeginprocess(clkout,reset)variablekm_reg:std_logic_vector(11downto0);beginifreset='1'thenkm_reg:="000000000000";elsifclkout'eventandclkout='1'then--km_reg(3downto0)对应里程十分位Libraryieee;32ifkm_reg(3downto0)="1001"thenkm_reg:=km_reg+"0111";--十分位向个位的进位处理elsekm_reg(3downto0):=km_reg(3downto0)+"0001";endif;ifkm_reg(7downto4)="1010"thenkm_reg:=km_reg+"01100000";--个位向十位的进位处理endif;endif;kmcnt1<=km_reg(3downto0);kmcnt2<=km_reg(7downto4);kmcnt3<=km_reg(11downto8);endprocess;endbehav;ifkm_reg(3downto0)="1001"t33time模块time模块主要用于计时收费。记录计程车速度为0的时间(如等待红灯)。通过对sp信号的判断,当sp=0,开始记录时间。当时间达到足够长时,产生timecount脉冲,并重新计时。time进程,产生时间计费脉冲timecount,单位计费时间可设定,这里选为20stime模块34Libraryieee;Useieee.std_logic_1164.all;Useieee.std_logic_unsigned.all;EntitytimeisPort(clk,reset,start,stop:instd_logic;Sp:instd_logic_vector(2downto0);Timecount:outstd_logic);Endtime;architecturebehavoftimeisbeginprocess(reset,clk,sp,stop,start)typestate_typeis(t0,t1,t2);variablet_state:state_type;variablewaittime:integerrange0to1000;beginifreset='1'thent_state:=t0;elsif(clk'eventandclk='1')thenLibraryieee;35caset_stateiswhent0=>waittime:=0;timecount<='0';ifstart='1'thent_state:=t1;elset_state:=t0;endif;whent1=>ifsp="000"thent_state:=t2;elsewaittime:=0;t_state:=t1;endif;whent2=>waittime:=waittime+1;timecount<='0';ifwaittime=1000thentimecount<='1';--20s,即1000个clk,产生一个时间计费脉冲waittime:=0;elsifstop='1'thent_state:=t0;elsifsp="000"thent_state:=t2;elsetimecount<='0';t_state:=t1;endif;endcase;endif;endprocess;endbehav;caset_stateis36kmmoney模块kmmoney可分为kmmoney1和kmmoney2两个模块。
kmmoney1用于产生enable和price信号。当记录距离达到3公里后,enable信号为‘1’,开始进行每公里的收费。当总费用大于40元后,单价price由原来的2元变为4元。用作计时收费。通过对sp信号的判断,当sp=0,开始记录时间。当时间达到足够长时,产生timecount脉冲,并重新计时。kmmoney2用于判断timecount和clkout的值,当其为‘1’时,总费用加1。最终输出为总费用。计费采用两个进程kmmoney1和kmmoney2实现;总费用上限位999元,一旦超过上限,显示会出现不正常现象kmmoney模块计费采用两个进程kmmoney1和kmmo37Libraryieee;Useieee.std_logic_1164.all;Useieee.std_logic_unsigned.all;EntitykmmoneyisPort(clk,reset,timecount,clkout:instd_logic;Kmcnt2:instd_logic_vector(3downto0);Kmcnt3:instd_logic_vector(3downto0);Count1:outstd_logic_vector(3downto0);Count2:outstd_logic_vector(3downto0);Count3:outstd_logic_vector(3downto0));Endkmmoney;ArchitecturebehavofkmmoneyisSignalcash:std_logic_vector(11downto0);Signalprice:std_logic_vector(3downto0);Signalenable:std_logic;BeginProcess(cash,kmcnt2)BeginIfcash>="000001000000"thenprice<="0100";Elseprice<="0010";Endif;Libraryieee;38If(kmcnt2>="0011")or(kmcnt3>="0001")thenenable<='1';Elseenable<='0';Endif;Endprocess;kmmoney2:process(reset,clkout,clk,enable,price,kmcnt2)variablereg2:std_logic_vector(11downto0);variableclkout_cnt:integerrange0to10;beginifreset='1'thencash<="000000001000";--起步费用设为8元elsifclk'eventandclk='1'theniftimecount='1'then--判断是否需要时间计费,每20s加一元reg2:=cash;ifreg2(3downto0)+"0001">"1001"thenreg2(7downto0):=reg2(7downto0)+"00000111";ifreg2(7downto4)>"1001"thencash<=reg2+"000001100000";elsecash<=reg2;endif;elsecash<=reg2+"0001";endif;elsifclkout='1'andenable='1'then--里程计费If(kmcnt2>="0011")or(kmcnt3>=39ifclkout_cnt=9thenclkout_cnt:=0;reg2:=cash;if"0000"®2(3downto0)+price(3downto0)>"00001001"thenreg2(7downto0):=reg2(7downto0)+"00000110"+price;ifreg2(7downto4)>"1001"thencash<=reg2+"000001100000";elsecash<=reg2;endif;elsecash<=reg2+price;endif;elseclkout_cnt:=clkout_cnt+1;endif;endif;endif;endprocess;count1<=cash(3downto0);--总费用的个位count2<=cash(7downto4);--总费用的十位count3<=cash(11downto8);--总费用的百位Endbehav;ifclkout_cnt=9then40FPGA综合设计实例ppt课件41分频模块对系统的时钟进行分频,以模拟轮胎的滚动。(a)100分频(b)10分频分频模块42Libraryieee;Useieee.std_logic_1164.all;entityfpisport(clr,clk:instd_logic;newclk:outstd_logic);endfp;architecturebehavoffpissignaltem:integerrange0to99;beginprocess(clk,clr)beginif(clr='1')thentem<=0;newclk<='0';elsif(clk'eventandclk='1')thenif(tem=99)thentem<=0;newclk<='1';elsetem<=tem+1;newclk<='0';endif;endif;endprocess;endbehav;Libraryieee;43Libraryieee;Useieee.std_logic_1164.all;entityfp10isport(clr,clk:instd_logic;newclk:outstd_logic);endfp10;architecturebehavoffp10issignaltem:integerrange0to9;beginprocess(clk,clr)beginif(clr='1')thentem<=0;newclk<='0';elsif(clk'eventandclk='1')thenif(tem=9)thentem<=0;newclk<='1';elsetem<=tem+1;newclk<='0';endif;endif;endprocess;endbehav;Libraryieee;44显示模块显示模块45libraryieee;useieee.std_logic_1164.all;entitysev_yimaisport(s:instd_logic_vector(3downto0);q:outstd_logic_vector(6downto0));endsev_yima;architecturertlofsev_yimaisbeginwithsselectq<="1000000"when"0000","1111001"when"0001","0100100"when"0010","0110000"when"0011","0011001"when"0100","0010010"when"0101","0000010"when"0110","1111000"when"0111","0000000"when"1000","0010000"when"1001","1111111"whenothers;endrtl;libraryieee;46实例3频率计设计要求:对输入信号进行频率的测量并实时显示。实例3频率计设计要求:对输入信号进行频率的测量并实时显示47
分频器模块时钟信号源输出的时钟信号频率高达50MHz,经过分频器将其分频为1Hz、4Hz、500Hz和1000Hz时钟信号。这四种信号再经过1/2分频,得到时间基准信号,其中1000Hz的时钟基准信号用于动态扫描译码电路,1Hz的时钟基准信号用于计数器的始能信号。分频器模块48libraryieee;useieee.std_logic_1164.all;entityfenpinisport(clk:instd_logic;--50MHzclk1:outstd_logic;--1Hzclk2:outstd_logic;--4Hzclk3:outstd_logic;--500hzclk4:outstd_logic--1khz);endfenpin;architecturearchoffenpinisbeginprocess(clk)variablecnt1:integerrange0to49999999;variablecnt2:integerrange0to12499999;variablecnt3:integerrange0to99999;variablecnt4:integerrange0to49999;variablex1,x2,x3,x4:std_logic:='0';beginifclk'eventandclk='1'thenifcnt1<49999999thencnt1:=cnt1+1;elsecnt1:=0;x1:=notx1;endif;ifcnt2<12499999thencnt2:=cnt2+1;elsecnt2:=0;x2:=notx2;endif;ifcnt2<99999thencnt3:=cnt3+1;elsecnt3:=0;x3:=notx3;endif;ifcnt4<49999thencnt4:=cnt4+1;elsecnt4:=0;x4:=notx4;endif;endif;clk1<=x1;clk2<=x2;clk3<=x3;clk4<=x4;endprocess;endarch;libraryieee;cnt1:=cnt1+1;49
计数器模块计数器模块始能端door输入分频器模块分频出的0.5Hz为基准时钟信号频率。计数器sig输入待测信号与基准时钟信号进行比较,并且计数。q0[3..0]对应的是个位输出,q1[3..0]对应的是十位输出,q2[3..0]对应的是百位输出,q3[3..0]对应的是千位输出。计数器模块50libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entitymeasureisport(sig,door:instd_logic;q3,q2,q1,q0,dang:outstd_logic_vector(3downto0));endmeasure;architecturearchofmeasureissignalc0,c1,c2,c3,c4,c5,c6:std_logic_vector(3downto0):="0000";signalsuo:std_logic;--lockthecountnumberbeginprocess(door,sig)beginlibraryieee;51ifsig'eventandsig='1'thenifdoor='1'thensuo<='1';ifc0<"1001"thenc0<=c0+1;elsec0<="0000";ifc1<"1001"thenc1<=c1+1;elsec1<="0000";ifc2<"1001"thenc2<=c2+1;elsec2<="0000";ifc3<"1001"thenc3<=c3+1;elsec3<="0000";ifc4<"1001"thenc4<=c4+1;elsec4<="0000";ifc5<"1001"thenc5<=c5+1;elsec5<="0000";ifc6<"1001"thenc6<=c6+1;elseifsig'eventandsig='1'then52c6<="0000";endif;endif;endif;endif;endif;endif;endif;else--toifdoor='1'c0<="0000";c1<="0000";c2<="0000";c3<="0000";c4<="0000";c5<="0000";c6<="0000";suo<='0';ifsuo='1'thenifc6/="0000"thenq3<=c6;q2<=c5;q1<=c4;q0<=c3;dang<="0100";elsifc5/="0000"thenq3<=c5;q2<=c4;q1<=c3;q0<=c2;dang<="0010";elsifc4/="0000"thenq3<=c4;q2<=c3;q1<=c2;q0<=c1;dang<="0010";elseq3<=c3;q2<=c2;q1<=c1;q0<=c0;dang<="0001";endif;elsenull;endif;endif;--toifdoor='1'elsenull;--toifsig'eventandsig='1'thenendif;endprocess;endarch;c6<="0000";q3<=c6;q2<=c5;q1<53锁存器模块锁存器模块主要由1个锁存器组成,主要作用是锁存计数器的计数值。设置锁存器可以使数据显示稳定可靠,不会由于周期性的清零信号而使数码管不断闪烁。锁存信号由控制电路产生,在1个周期的计数时间结束时,锁存器立即锁存计数值。锁存器的数据输入端与计数器数据输出端连接,数据输出与动态扫描译码电路中的显示译码电路连接,时钟输入端与基准时钟电路端连接。在信号的上升沿,将计数器中的测量数据存入锁存器。a2[3..0]对应的是个位输入,a3[3..0]对应的是十位输入,a4[3..0]对应的是百位输入,a5[3..0]对应的是千位输入,q2[3..0]对应的是个位输出,q3[3..0]对应的是十位输出,q4[3..0]对应的是百位输出,q5[3..0]对应的是千位输出锁存,clk连接的是分频器分频出的1000HZ的信号。锁存器模块a2[3..0]对应的是个位输入,a3[3..0]54libraryieee;useieee.std_logic_1164.all;entitylockisport(clk:instd_logic;a5,a4,a3,a2,a1,a0:instd_logic_vector(3downto0);q5,q4,q3,q2,q1,q0:outstd_logic_vector(3downto0));endlock;architecturearchoflockissignalaa5,aa4,aa3,aa2,aa1,aa0:std_logic_vector(3downto0);beginprocess(clk)beginifclk'eventandclk='0'thenaa5<=a5;aa4<=a4;aa3<=a3;aa2<=a2;aa1<=a1;aa0<=a0;endif;q5<=aa5;q4<=aa4;q3<=aa3;q2<=aa2;q1<=aa1;q0<=aa0;endprocess;endarch;libraryieee;55译码器模块译码器模块主要由4个显示模块组成。主要功能是将锁存器保存的4位二进制计数值转换成相应的数码管显示代码,显示模块输出端与4个7段数码管相连,可以在数码管上显示所测频率的十进制输出值。d[3..0]对应的是译码信号的输入,q[6..0]对应的是译码信号的输出。译码器模块56FPGA综合设计实例ppt课件57FPGA综合设计实例ppt课件58FPGA综合设计实例ppt课件59实例4交通灯模拟系统设计结合DEII实际,拟用不同颜色发光二极管模拟南北方向和东西方向的红绿灯;每个方向有红、绿、黄三个灯,并能对绿灯放行时间进行设置和调整。实例4交通灯模拟系统设计结合DEII实际,拟用不同颜色发光60控制模块设计本模块主要实现对两个方向红绿灯的交替显示控制。其中Clock是时钟源,为分频模块的输出信号;hold是控制信号,起保持功能;countnum是计数模块的输出信号,为一个周期的循环计数值;numa是a组交通灯输出;numb是b组交通灯输出;reda是a组红灯输出;greenda是a组绿灯输出;yellowa是a组黄灯输出;redb是b组红灯输出;greendb是b组绿灯输出;yellowb是a组黄灯输出;flash是闪烁输出控制模块设计其中Clock是时钟源,为分频模块的输出信号;h61libraryieee;useieee.std_logic_1164.all;entitycontrollerisport(clock:instd_logic;hold:instd_logic;countnum:inintegerrange0to49;numa,numb:outintegerrange0to25;reda,greena,yellowa:outstd_logic;redb,greenb,yellowb:outstd_logic;flash:outstd_logic);endcontroller;architecturearchofcontrollerisbeginprocess(clock)beginiffalling_edge(clock)thenifhold='0'thenreda<='0';redb<='0';greena<='1';greenb<='1';yellowa<='1';yellowb<='1';flash<='1';elseflash<='0';------------------------------------------------ifcountnum<=19thennuma<=20-countnum;reda<='1';greena<='0';yellowa<='1';elsifcountnum<=24then
numa<=25-countnum;reda<='1';greena<='1';yellowa<='0';elsenuma<=50-countnum;reda<='0';greena<='1';yellowa<='1';endif;libraryieee;reda<='0';62------------------------------------------------ifcountnum<=24thennumb<=25-countnum;redb<='0';greenb<='1';yellowb<='1';elsifcountnum<=44thennumb<=45-countnum;redb<='1';greenb<='0';yellowb<='1';elsenumb<=50-countnum;redb<='1';greenb<='1';yellowb<='0';endif;
endif;endif;endprocess;endarch;------------------------------63计数模块设计本模块主要实现一个周期的循环计数,在此以50秒为一个周期进行循环计数,当然可以根据实际情况进行调整,如调整为60秒或120秒。0-50的计数范围用二进制表示则需要六位,因此本模块的计数输出为六位,如果需要调整计数周期,则计数的输出位数需要相应调整。计数模块设计64libraryieee;useieee.std_logic_1164.all;entitycounterisport(clock:instd_logic;reset:instd_logic;hold:instd_logic;countnum:bufferintegerrange0to49);endcounter;architecturearchofcounterisbeginprocess(reset,clock)beginifreset='0'thencountnum<=0;elsifrising_edge(clock)thenifhold='0'thencountnum<=countnum;elseifcountnum=49thencountnum<=0;elsecountnum<=countnum+1;endif;endif;endif;endprocess;endarch;libraryieee;65分位模块设计由于十字路口的倒计时范围为:0-25,因此显示的时候需要两个LED数码管,本模块是将计数值由二进制转换为十进制,并分成十位和个位。图中num1是十位输出,num2是个位输出,numin是输入的二进制数,由于输入的数据为0-25,因此五位二进制数即可满足条件。分位模块设计66libraryieee;useieee.std_logic_1164.all;entityfenweiisport(numin:inintegerrange0to25;num1,num2:outintegerrange0to9);endfenwei;architecturearchoffenweiisbeginprocess(numin)beginifnumin>=20thennum1<=2;num2<=numin-20;elsifnumin>=10thennum1<=1;num2<=numin-10;elsenum1<=0;num2<=numin;endif;endprocess;endarch;libraryieee;67显示模块设计本模块的功能是将两个方向的倒计时数值进行显示。显示模块设计68FPGA综合设计实例ppt课件69基于FPGA的红外遥控器设计红外线遥控系统就是指利用红外线来传递控制信号,从而实现对控制对象的远距离控制。具体来讲,就是由发射器发出红外线指令信号,由接受器接受信号并对信号进行处理,最后实现对对象的各种功能的远距离控制。红外线遥控系统一般由发射器和接受器两部分组成。发射器:指令键、指令信号产生电路、调制电路、驱动电路及红外线发射器件。接受器:红外线接受器件、前置放大电
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 企业管理-病历管理制度
- 天津市东丽区2026届初三下学期3月联考数学试题含解析
- 江苏省苏州市梁丰重点达标名校2026年初三第四次模拟考试(5月)数学试题含解析
- 吉林省长春市教研室重点达标名校2026届初三第一次模拟数学试题试卷含解析
- 北京市崇文区名校2025-2026学年初三物理试题5月月考含解析
- 浙江省绍兴市海亮重点名校2025-2026学年初三练习题(一)(全国卷II)物理试题含解析
- 沈阳市铁西区重点中学2025-2026学年重点高中联盟领军考试4月初三物理试题(文)试题含解析
- 广东省汕头市科利园实验校2026年初三5月阶段质量检测试题数学试题含解析
- 山西省吕梁市蕴华国际双语校2026届第一次中考模拟考试物理试题含解析
- 江苏省宜兴市张渚徐舍教联盟重点中学2025-2026学年初三下学期期中数学试题含解析
- 2026年宁夏石嘴山市单招职业适应性测试题库及一套答案详解
- 2026广东广州市黄埔区机关事务管理局招聘政府雇员3人笔试备考题库及答案解析
- 2026年巡特辅警笔试题库及完整答案一套
- 中烟机械技术中心招聘笔试题库2026
- 矿山运输车队运营管理制度
- 钛厂生产耗材领用制度
- 码头安全员培训内容
- 2026年淮南联合大学单招职业技能测试题库附答案
- (正式版)DB61∕T 2107-2025 《矿产资源规划实施评估技术规范》
- 文书模板-申请筹设职业高中的申请书
- SJG 172-2024装配式建筑工程消耗量标准
评论
0/150
提交评论