
实验目的:
设计一个4位十进制频率计,学习复杂数字系统的设计方法。
实验原理:
根据频率的定义和频率测量的基本原理,测定信号的频率必须有一个脉宽为1秒的脉冲计数允许信号,1秒计数结束后,计数值(即所测信号频率)锁入锁存器,并为下一次测频作准备,即将计数器清零。
试验内容:
1、根据频率计的工作原理,将电路划分成控制器、计数器、锁存器和LED显示几个模块,
控制器——产生1秒脉宽的计数允许信号、锁存信号和计数器清零信号
计数器——对输入信号的脉冲数进行累计
锁存器——锁存测得的频率值
LED显示——将频率值显示在数码管上
顶层文件框图如下:
2、用元件例化语句写出频率计的顶层文件。
提示:十进制计数器输出的应是4位十进制数的BCD码,因此输出一共是4×4bit。
实验结果:
各模块电路的VHDL描述:
10进制计数器
library ieee;
use ieeestd_logic_1164all;
use ieeestd_logic_unsignedall;
entity cnt10 is
port (rst,fx,ena:in std_logic;
cout: out std_logic;
outy :out std_logic_vector(3 downto 0));
end cnt10;
architecture behv of cnt10 is
begin
process (rst,ena,fx)
variable cqi :std_logic_vector(3 downto 0);
begin
if rst='1' then cqi :=(others =>'0');
elsif fx'event and fx='1' then
if ena ='1' then
if cqi < 9 then cqi:=cqi+1;cout<='0';
elsif cqi=9 then
cqi :=(others =>'0');
cout<='1';
end if;
elsif ena='0' then cqi:=(others =>'0');
end if;
end if;
outy <=cqi;
end process;
end behv;
4位10进计数器
library ieee;
use ieeestd_logic_1164all;
entity cnt10_4 is
port(fx,rst,ena:in std_logic;
d:out std_logic_vector(15 downto 0));
end entity;
architecture one of cnt10_4 is
component cnt10
port (rst,fx,ena:in std_logic;
cout: out std_logic;
outy :out std_logic_vector(3 downto 0));
end component;
signal e:std_logic_vector(3 downto 0);
begin
u1:cnt10 port map(fx=>fx,rst=>rst,ena=>ena,cout=>e(0),outy=>d(3 downto 0));
u2:cnt10 port map(fx=>e(0),rst=>rst,ena=>ena,cout=>e(1),outy=>d(7 downto 4));
u3:cnt10 port map(fx=>e(1),rst=>rst,ena=>ena,cout=>e(2),outy=>d(11 downto 8));
u4:cnt10 port map(fx=>e(2),rst=>rst,ena=>ena,cout=>e(3),outy=>d(15 downto 12));
end architecture one;
16位锁存器
library ieee;
use ieeestd_logic_1164all;
use ieeestd_logic_unsignedall;
entity latch4 is
port(d:in std_logic_vector(15 downto 0);
ena,clk:in std_logic;
q:out std_logic_vector(15 downto 0));
end latch4;
architecture one of latch4 is
begin
process(clk,ena,d)
variable cqi:std_logic_vector(15 downto 0);
begin
if ena='0' then cqi:=cqi;
elsif clk'event and clk='1' then cqi:=d;
end if;
q<=cqi;
end process;
end one;
LED控制模块
library ieee;
use ieeestd_logic_1164all;
use ieeestd_logic_unsignedall;
entity led_controller is
port(d:in std_logic_vector(3 downto 0);
a:out std_logic_vector(6 downto 0));
end led_controller;
architecture one of led_controller is
begin
process(d)
begin
case d is
when "0000"=> a<="0111111";when "0001"=> a<="0000110";
when "0010"=> a<="1011011";when "0011"=> a<="1001111";
when "0100"=> a<="1100110";when "0101"=> a<="1101101";
when "0110"=> a<="1111101";when "0111"=> a<="0000111";
when "1000"=> a<="1111111";when "1001"=> a<="1101111";
when "1010"=> a<="1110111";when "1011"=> a<="1111100";
when "1100"=> a<="0111001";when "1101"=> a<="1011110";
when "1110"=> a<="1111001";when "1111"=> a<="1110001";
when others=> null;
end case;
end process;
end;
控制模块
library ieee;
use ieeestd_logic_1164all;
use ieeestd_logic_unsignedall;
entity control is
port (clk:in std_logic;
rst,ena: out std_logic);
end control;
architecture behv of control is
begin
process (clk)
variable cqi :std_logic_vector(2 downto 0);
begin
if clk'event and clk='1' then
if cqi <1 then cqi:=cqi+1;ena<='1';rst<='0';
elsif cqi=1 then
cqi :=(others =>'0');
ena<='0';rst<='1';
end if;
end if;
end process;
end behv;
总体例化语句:
library ieee;
use ieeestd_logic_1164all;
use ieeestd_logic_unsignedall;
entity cntf is
port(rset,clk:in std_logic;
fx:in std_logic;
ledout:out std_logic_vector(27 downto 0));
end entity;
architecture one of cntf is
component control
port (clk:in std_logic;
rst,ena: out std_logic);
end component;
component cnt10_4
port(fx,rst,ena:in std_logic;
d:out std_logic_vector(15 downto 0));
end component;
component latch4
port(d:in std_logic_vector(15 downto 0);
ena,clk:in std_logic;
q:out std_logic_vector(15 downto 0));
end component;
component led_controller
port(d:in std_logic_vector(3 downto 0);
a:out std_logic_vector(6 downto 0));
end component;
signal x,z:std_logic;
signal g,h:std_logic_vector(15 downto 0);
signal leds:std_logic_vector(27 downto 0);
begin
u1: control port map(clk=>clk,ena=>x,rst=>z);
u2: cnt10_4 port map(fx=>fx,rst=>z,ena=>x,d=>g);
u3: latch4 port map(clk=>clk,ena=>x,d=>g,q=>h);
u4: led_controller port map(d(3 downto 0)=>h(3 downto 0),a(6 downto 0)=>leds(6 downto 0));
u5: led_controller port map(d(3 downto 0)=>h(7 downto 4),a(6 downto 0)=>leds(13 downto 7));
u6: led_controller port map(d(3 downto 0)=>h(11 downto 8),a(6 downto 0)=>leds(20 downto 14));
u7: led_controller port map(d(3 downto 0)=>h(15 downto 12),a(6 downto 0)=>leds(27 downto 21));
ledout<=leds;
end;
先做下单片机基本解释:
1、TMOD
TMOD=0x02 :定时器0工作模式自动重装8位计数器,8位自动装入时间常数方式。由 TL0构成8位计数器,TH0仅用来存放时间常数。初始化时,8位计数初值同时装入TL0和TH0中。当TL0计数溢出时,置位TF0,同时把保存在预置寄单片机存器TH0中的计数初值自动加载TL0,然后TL0重新计数。如此重复不止。这不但省去了用户程序中的重装指令,而且也有利于提高定时精度。但这种工作方式下是8位计数结构,计数值有限,最大只能到255。 单片机这种自动重新加载工作方式非常适用于循环定时或循环计数应用,例如用于产生固定脉宽的脉冲,此外还可以作串行数据通信的波特率发送器使用。
2、ET0
ET0时定时计数器0溢出中断允许控制位,用于控制定时器生成。
3、TH0/TL0
定时器设置周期控制,根据定时周期长短和晶振频率可以计算出。
4、EA
EA总中断开关,如果EA不打开,任何中断都无法执行。EA=1,表示中断开启。
5、TR0
TR0=1,开始启用T0计数器/定时器。
6、P33
P33,脉冲输出引脚,P33=0表示输出电平初始为高。
7、P3_5
P3_5,按键输入引脚。P3_5电平为高(1)时表示未按键,为低(0)时表示按键。
这个程序的定时周期为250us,其基本功能就是周期性输出脉冲信号。
interrupt就是中断处理函数,4000250us=1s,因此,每中断4000次,代表秒的变量sec就加1。从if(sec==115)可以看出,每115秒,脉冲信号电平(P33~=P33)就变化一次,因此,脉冲输出周期为1152=230秒。
KEY函数是按键处理函数,当P3_5=0时,表示按键,delay(120)是用于按键防抖的,防止误判。当按键时,复位定时器TR0、脉冲输出,以及计数器sec,tcnt。
这些都是verilog HDL基础程序,建议楼主自己写写吧,不难的。如果真的不懂,百度一下,网上很多这类的程序。不过这些练习,书本里面应该会有的,自己多动手,多想才会学到,希望楼主努力
以上就是关于求一VHDL语言的八位十进制频率计程序,要能下载实现功能的.谢谢,能用追加1000财富值.全部的内容,包括:求一VHDL语言的八位十进制频率计程序,要能下载实现功能的.谢谢,能用追加1000财富值.、这个程实现的功能求详细!后追加100!、Verilog HDL 高手进。。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)