当前位置:文档之家› 简单频率计的制作

简单频率计的制作

一.设计的基本原理和框图1.1基本原理:数字频率计是用数字显示被测信号的频率的仪器,被测信号可以是正弦波,方波或者其他周期性变化的信号,它的基本原理是时基信号发生器提供标准的时基脉冲信号,若其周期为1s则门控电路的输出信号持续时间亦准确到1s。

闸门电路有标准秒信号控制,当秒信号到来时闸门开通,信号通过闸门送到计数译码显示电路,秒信号结束时闸门关闭,计数器停止计数,由于计数器记得脉冲数N 的是一秒内的累积数,所以被测频率是NHZ。

闸门时间可以取大于或者小于1秒的值,测得的频率时间间隔与闸门时间的取值成正比,在这里取的闸门时间为1s。

在此,数字频率计由分频器,片选电路,计数器,锁存器,译码电路和显示电路作为主要组成部分。

1.2设计框图如图1.1所示:图1.1二.单元电路设计2.1分频电路模块分频器在总电路中有两个作用。

由总图框图中分频器有两个输出,一个给计数器,一个给锁存器。

时钟信号经过分频电路形成了20分频后的门信号。

另一个给锁存器作锁存信号,当信号为低电平时就锁存计数器中的数。

分频电路图如图2.1图2.1 分频电路图2.2片选信号电路模块这个电路有两个用途:一是为后面的片选电路产生片选信号,二是为译码模块提供选择脉冲信号。

电路图如图2.2图2.2 片选信号电路图2.3计数器模块计数器模块为该电路中的核心模块,它的功能是:当门信号为上升沿时,电路开始计算半个周期内被测信号通过的周期数,到下升沿后结束。

然后送给锁存器锁存。

计数器电路图如图2.3所示:图2.3 计数器电路图2.4锁存器模块在分频信号的下降沿到来时,锁存器将计数器的信号锁存,然后送给编译模块中。

其电路图如图2.4所示:图2.4 锁存器电路图2.5译码信号模块此模块是对四个锁存器进行选择,按顺序的将四个锁存器中的数值送给译码模块中译码。

其电路图如图2.5图2.5 译码信号电路图2.6片选模块该模块接收到片选信号后,输出给显示器,选择显示那个显示管。

其电路图如图2.6所示:图2.6 片选电路图2.7译码模块译码模块的作用就是将译码信号模块中选择出的信号进行译码,并将其送给显示器。

其电路图如图2.7所示:图2.7 译码电路图2.8总电路图图2.8总电路图三.编程下载3.1分频模块的程序library ieee;use ieee.std_logic_1164.all;entity fen isport(clk:in std_logic;q:out std_logic);end fen;architecture fen_arc of fen isbeginprocess(clk)variable cnt:integer range 0 to 9;variable x:std_logic;beginif clk'event and clk='1'then if cnt<9 thencnt:=cnt+1;elsecnt:=0;x:=not x;end if;end if;q<=x;end process;end fen_arc;3.2片选信号模块的程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity sel isport(clk:in std_logic;q:out std_logic_vector(2 downto 0));end sel;architecture sel_arc of sel isbeginprocess(clk)variable cnt:std_logic_vector(2 downto 0);beginif clk'event and clk='1' thencnt:=cnt+1;end if;q<=cnt;end process;end sel_arc;3.3计数器模块的程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity corna isport(clr,sig,door:in std_logic;alm:out std_logic;q3,q2,q1,q0,dang:out std_logic_vector(3 downto 0)); end corna;architecture corn_arc of corna isbeginprocess(door,sig)variable c3,c2,c1,c0:std_logic_vector(3 downto 0); variable x:std_logic;beginif sig'event and sig='1' thenif clr='0' thenalm<='0';c3:="0000";c2:="0000";c1:="0000";c0:="0000";elsif door='0' thenc3:="0000";c2:="0000";c1:="0000";c0:="0000";elsif door='1' thenif c0<"1001" thenc0:=c0+1;elsec0:="0000";if c1<"1001" thenc1:=c1+1;else c1:="0000";if c2<"1001" thenc2:=c2+1;elsec2:="0000";if c3<"1001" thenc3:=c3+1;elsec3:="0000";alm<='1';end if;end if;end if;end if;end if;if c3/="0000" thenq3<=c3;q2<=c2;q1<=c1;q0<=c0;dang<="0100";elsif c2/="0000" thenq3<="0000";q2<=c2;q1<=c1;q0<=c0;dang<="0011";elsif c1/="0000" thenq3<="0000";q2<="0000";q1<=c1;q0<=c0;dang<="0010";elseq3<="0000";q2<="0000";q1<="0000";q0<=c0;dang<="0001";end if;end if;end process;end corn_arc;3.4锁存器模块的程序library ieee;use ieee.std_logic_1164.all;entity lock isport(l:in std_logic;a4,a3,a2,a1,a0:in std_logic_vector(3 downto 0);q4,q3,q2,q1,q0:out std_logic_vector(3 downto 0));end lock;architecture lock_arc of lock isbeginprocess(l)variable t4,t3,t2,t1,t0:std_logic_vector(3 downto 0);beginif l'event and l='0' thent4:=a4;t3:=a3;t2:=a2;t1:=a1;t0:=a0;end if;q4<=t4;q3<=t3;q2<=t2;q1<=t1;q0<=t0;end process;end lock_arc;3.5译码信号模块的程序library ieee;use ieee.std_logic_1164.all;entity ch isport(sel:in std_logic_vector(2 downto 0);a3,a2,a1,a0,dang:in std_logic_vector(3 downto 0);q:out std_logic_vector(3 downto 0));end ch;architecture ch_arc of ch isbeginprocess(sel)begincase sel iswhen "000"=>q<=a0;when "001"=>q<=a1;when "010"=>q<=a2;when "011"=>q<=a3;when "111"=>q<=dang;when others=>q<="1111";end case;end process;end ch_arc;3.6片选模块的程序library ieee;use ieee.std_logic_1164.all;entity ym isport(d:in std_logic_vector(2 downto 0);q:out std_logic_vector(7 downto 0)); end ym;architecture ym_arc of ym isbeginprocess(d)begincase d iswhen "000"=>q<="00000001";when "001"=>q<="00000010";when "010"=>q<="00000100";when "011"=>q<="00001000";when "100"=>q<="00010000";when "101"=>q<="00100000";when "110"=>q<="01000000";when "111"=>q<="10000000";when others=>q<="00000000";end case;end process;end ym_arc;3.7译码器模块的程序library ieee;use ieee.std_logic_1164.all;entity disp isport(d:in std_logic_vector(3 downto 0);q:out std_logic_vector(6 downto 0));end disp;architecture disp_arc of disp is beginprocess(d)begincase d iswhen "0000"=>q<="0111111";when "0001"=>q<="0000110";when "0010"=>q<="1011011";when "0011"=>q<="1001111";when "0100"=>q<="1100110";when "0101"=>q<="1101101";when "0110"=>q<="1111101";when "0111"=>q<="0100101";when "1000"=>q<="1111111";when "1001"=>q<="1101111";when others=>q<="0000000";end case;end process;end disp_arc;3.8顶层文件的程序library ieee;use ieee.std_logic_1164.all;entity plj isport(sig,clr,clk:in std_logic;alm:out std_logic;q:out std_logic_vector(6 downto 0);se:out std_logic_vector(7 downto 0));end plj;architecture art of plj iscomponent cornaport(clr,sig,door:in std_logic;alm:out std_logic;q3,q2,q1,q0,dang:out std_logic_vector(3 downto 0)); end component;component fenport(clk:in std_logic;q:out std_logic);end component;component lockport(l:in std_logic;a4,a3,a2,a1,a0:in std_logic_vector(3 downto 0);q4,q3,q2,q1,q0:out std_logic_vector(3 downto 0));end component;component selport(clk:in std_logic;q:out std_logic_vector(2 downto 0));end component;component chport(sel:in std_logic_vector(2 downto 0);a3,a2,a1,a0,dang:in std_logic_vector(3 downto 0);q:out std_logic_vector(3 downto 0));end component;component dispport(d:in std_logic_vector(3 downto 0);q:out std_logic_vector(6 downto 0));end component;component ymport(d:in std_logic_vector(2 downto 0);q:out std_logic_vector(7 downto 0));end component;signal t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t12:std_logic_vector(3 downto 0);signal t11:std_logic;signal t20:std_logic_vector(2 downto 0);beginu1:corna port map (clr=>clr,sig=>sig,door=>t11,alm=>alm,q3=>t1,q2=>t2,q1=>t3,q0=>t4,dan g=>t5);u2: fen port map (clk=>clk,q=>t11);u3: lock port map (l=>t11,a4=>t1,a3=>t2,a2=>t3,a1=>t4,a0=>t5,q4=>t6,q3=>t7,q2=>t8,q1=>t 9,q0=>t10);u4: sel port map (clk=>clk,q=>t20);u5: ch port map (sel=>t20,a3=>t6,a2=>t7,a1=>t8,a0=>t9,dang=>t10,q=>t12);u6: disp port map (d=>t12,q=>q);u7: ym port map (d=>t20,q=>se);end architecture art;四.仿真与调试4.1分频电路模块的仿真在quartus II中打开事先编译好的程序,然后建立工程文件,再打开波形图显示窗口,设置好参数,保存后编译,编译无错误既可以生成电路图。

相关主题