简单频率计的制作
- 格式:doc
- 大小:354.50 KB
- 文档页数:21
一.设计的基本原理和框图 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 is port(clk:in std_logic; q:out std_logic); end fen; architecture fen_arc of fen is begin process(clk) variable cnt:integer range 0 to 9; variable x:std_logic; begin if clk'event and clk='1' then if cnt<9 then cnt:=cnt+1; else cnt:=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 is port(clk:in std_logic; q:out std_logic_vector(2 downto 0)); end sel; architecture sel_arc of sel is begin process(clk) variable cnt:std_logic_vector(2 downto 0); begin if clk'event and clk='1' then cnt:=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 is port(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 is begin process(door,sig) variable c3,c2,c1,c0:std_logic_vector(3 downto 0); variable x:std_logic; begin if sig'event and sig='1' then if clr='0' then alm<='0'; c3:="0000"; c2:="0000"; c1:="0000"; c0:="0000"; elsif door='0' then c3:="0000"; c2:="0000"; c1:="0000"; c0:="0000"; elsif door='1' then if c0<"1001" then c0:=c0+1; else c0:="0000"; if c1<"1001" then c1:=c1+1; else c1:="0000"; if c2<"1001" then c2:=c2+1; else c2:="0000"; if c3<"1001" then c3:=c3+1; else c3:="0000"; alm<='1'; end if; end if; end if; end if; end if; if c3/="0000" then q3<=c3; q2<=c2; q1<=c1; q0<=c0; dang<="0100"; elsif c2/="0000" then q3<="0000"; q2<=c2; q1<=c1; q0<=c0; dang<="0011"; elsif c1/="0000" then q3<="0000"; q2<="0000"; q1<=c1; q0<=c0; dang<="0010"; else q3<="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 is port(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 is begin process(l) variable t4,t3,t2,t1,t0:std_logic_vector(3 downto 0); begin if l'event and l='0' then t4:=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 is port(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 is begin process(sel) begin case sel is when "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 is port(d:in std_logic_vector(2 downto 0); q:out std_logic_vector(7 downto 0));