《4位的十进制的数字频率计(共11页).doc》由会员分享,可在线阅读,更多相关《4位的十进制的数字频率计(共11页).doc(11页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上-VHDL 频率计-一个有效位为4位的十进制的数字频率计。library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity freq isport(fsin:in std_logic;-被测信号 clk:in std_logic;-基准时间,1Hz reset : in std_logic; show:out std_logic_vector(6 downto 0);-数码管段码输出 row:out std_logic
2、_vector(3 downto 0);-数码管选择信号end freq;architecture one of freq issignal test_en:std_logic;signal clear:std_logic;-复位信号signal data:std_logic_vector(15 downto 0);-bcdsignal data_in:std_logic_vector(3 downto 0);-单个数码管显示signal row_in:std_logic_vector(3 downto 0);-数码管的选择begin-分频,得到0.5Hz信号test_enprocess(cl
3、k)beginif clkevent and clk=1 thentest_en=not test_en;end if;end process;clear=not clk and not test_en;-定义clear信号process(fsin)beginif reset= 1 thenrow_in = 0001;elsif fsinevent and fsin=1 thenif row_in=0001 then row_in=0010;elsif row_in=0010 then row_in=0100;elsif row_in=0100 then row_in=1000;elsif r
4、ow_in=1000 then row_in=0001;end if;end if;end process;-在1秒钟时间内对被测脉冲信号计数process(fsin,test_en)beginif clear=1 then data=00000; elsif fsinevent and fsin=1 then if test_en=1 thenif data(15 downto 0)=11001 then data0000elsif data(11 downto 0)=1 then data1000elsif data(7 downto 0)= then data100elsif data(
5、3 downto 0)=1001 then data10else data=data+1;end if;end if;end if;end process;-根据所选数码管显示数据process(row_in)beginrow(3 downto 0)data_indata_indata_indata_indata_inshowshowshowshowshowshowshowshowshowshowshow=;end case;end process;end one; -实验要求:设计一个有效位为4位的十进制的数字频率计。library ieee;use ieee.std_logic_1164.
6、all;use ieee.std_logic_unsigned.all;entity fcounter isport (rst :in std_logic; -异步复位低电平有? clk0 :in std_logic; -已知频率时钟、动态扫描频率 clkf :in std_logic; -待测时钟 led :out std_logic_vector(7 downto 0); -八段数码管 enled:inout std_logic_vector(3 downto 0); -动态显示数码管使能(静态显示无法控制小数点) constant N:integer :=512;-已知时钟的频率,单位H
7、z end entity;architecture bev of fcounter is signal b1,b2,b3,b4,b5,b6,b7:std_logic_vector(3 downto 0); signal bcd :std_logic_vector(3 downto 0); signal dpoint:integer range 0 to 4; signal bcd0,bcd1,bcd2,bcd3 :std_logic_vector(3 downto 0); signal enable,clkable:std_logic; signal counter:integer range
8、 0 to 3*N; beginprocess(clk0,rst) beginif rst=0 then counter=0; enable=0;elsif clk0event and clk0=1 then if counterN then -clk0为N Hz时 counter=counter+1; enable=1; else enable=0; end if;end if;end process;process(clkf,enable)begin clkable=clkf and enable;end process;process(clkable,rst)begin if rst=0
9、 then -复位或显示周期 b1=0000; b2=0000; b3=0000; b4=0000; b5=0000; b6=0000; b7=0000;elsif rising_edge(clkable) then -计数周期中 -各位按顺序如果小于9则加1,等于9则进位回0 if b1=1001 then b1=0000; if b2=1001 then b2=0000; if b3=1001 then b3=0000; if b4=1001 then b4=0000; if b5=1001 then b5=0000; if b6=1001 then b6=0000; if b7=1001
10、 then b7=0000; else b7=b7+1; end if; else b6=b6+1; end if; else b5=b5+1; end if; else b4=b4+1; end if; else b3=b3+1; end if; else b2=b2+1; end if; else b10000 then -10M频率=1M,超出10M无法正确显示 bcd3=b7; bcd2=b6; bcd1=b5; bcd0=b4; dpoint0000 then -1M频率=100K bcd3=b6; bcd2=b5; bcd1=b4; bcd0=b3; dpoint0000 then
11、 -100K频率=10K bcd3=b5; bcd2=b4; bcd1=b3; bcd0=b2; dpoint频率=1K bcd3=b4; bcd2=b3; bcd1=b2; bcd0=b1; dpoint bcd=bcd1; if(dpoint=2) then led(0)=1; else led(0)=0; end if; enled bcd=bcd2; if(dpoint=3) then led(0)=1; else led(0)=0; end if; enled bcd=bcd3; if(dpoint=4) then led(0)=1; else led(0)=0; end if; e
12、nled bcd=bcd0; if(dpoint=1) then led(0)=1; else led(0)=0; end if; enled enledled(7 downto 1)led(7 downto 1)led(7 downto 1)led(7 downto 1)led(7 downto 1)led(7 downto 1)led(7 downto 1)led(7 downto 1)led(7 downto 1)led(7 downto 1)null;end case;end process;end architecture;-六位数字频率计设计设计能实现自动测频十进制数字频率计,并在
13、EDA实验开发系统上进行硬件验证。具体功能如下:1)测量范围: 1HzHz2)测量的数值通过六个数码管显示3)频率超过Hz时,溢出指示灯亮,可以作为扩大测量范围的接口输入端口:1)F_in为待测频率输入端口,可以选用实验开发系统上配备的四组时钟信号;2)CLK为1Hz的基准时钟信号,经过处理后可以产生用于自动测频所需的计数允许、锁存数据和清零三个控制信号。输出端口:led3.0接数码管,其包含所测频率的6组BCD码信息;CARRY_OUT为溢出指示端口,也为扩大测量范围的留接口。底层文件一:cnt10.vhdlibrary ieee;use ieee.std_logic_1164.all;us
14、e ieee.std_logic_unsigned.all;entity cnt10 isport( clk : in std_logic; -时钟信号 clr : in std_logic; -清零信号 ena : in std_logic; -时钟使能信号 cq : buffer std_logic_vector(3 downto 0); cout : out std_logic -进位信号 );end cnt10;architecture one of cnt10 isbegin process(clk,clr,ena) begin if clr=1 then cq=0000; elsi
15、f clkevent and clk=1 then if ena=1 then if cq=9 then cq=0000; else cq=cq+1; end if; end if; end if; end process; process(cq) begin if cq=9 then cout=0; else cout=1; end if; end process;end;底层文件二:ctl.vhdlibrary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity ctl isport( clk :
16、in std_logic; ena : out std_logic; clr : out std_logic; lock : out std_logic );end ctl;architecture behav of ctl is signal div2clk : std_logic;begin process(clk) begin if clkevent and clk=1 then div2clk=not div2clk; end if; end process; process(clk,div2clk) begin if clk=0 and div2clk=0 then clr=1; e
17、lse clr=0; end if; end process; lock=not div2clk; ena=div2clk;end;底层文件三:reg4.vhdlibrary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity reg4 isport( clk : in std_logic; cq : in std_logic_vector(3 downto 0); led : out std_logic_vector(3 downto 0) );end reg4;architecture one of
18、 reg4 isbegin process(clk,cq) begin if clkevent and clk=1 then ledf_in, clr=clr1,ena=ena1, cq=cq1,cout=cout1); u2 : cnt10 port map(clk=cout1,clr=clr1,ena=ena1, cq=cq2,cout=cout2); u3 : cnt10 port map(clk=cout2,clr=clr1,ena=ena1, cq=cq3,cout=cout3); u4 : cnt10 port map(clk=cout3,clr=clr1,ena=ena1, cq
19、=cq4,cout=cout4); u5 : cnt10 port map(clk=cout4,clr=clr1,ena=ena1, cq=cq5,cout=cout5); u6 : cnt10 port map(clk=cout5,clr=clr1,ena=ena1, cq=cq6,cout=carry_out); u7 : ctl port map(clk=clk, clr=clr1,ena=ena1,lock=lock1); u8 : reg4 port map(clk=lock1,cq=cq1, led=led1); u9 : reg4 port map(clk=lock1,cq=cq2, led=led2); u10 : reg4 port map(clk=lock1,cq=cq3, led=led3); u11 : reg4 port map(clk=lock1,cq=cq4, led=led4); u12 : reg4 port map(clk=lock1,cq=cq5, led=led5); u13 : reg4 port map(clk=lock1,cq=cq6, led=led6);end;专心-专注-专业
限制150内