⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testctl.txt

📁 本程序实现了一个数字频率计。它由一个测频控制信号发生器TESTCTL
💻 TXT
字号:
程序(1):
library ieee; --有时钟使能的十进制计数器
use ieee.std_logic_1164.all;
entity cnt10 is
    port(clk:in std_logic;--计数时钟信号
           clr:in std_logic;--清零信号
           ena:in std_logic;--计数使能信号
             cq:out integer range 0 to 15;--4位计数结果输出
         carry_out:out std_logic);--计数进位
end cnt10;
architecture behav of cnt10 is
     signal cqi:integer ranger 0 to15;
begin
     process(clk,clr,ena)
     begin
          if clr='1' then cqi<=0;--计数器异步清零
          elsif clk'event and clk='1' then
              if ena='1' then
                  if cqi<9 then cqi<=cqi+1;
                  else cqi<=0; end if ;--等于9,则计数器清零
              end if ;
           end if;
      end process;
      process(cqi)
      begin
           if cqi=9 then carry_out <='1';--进位输出
                       else  carry_out <='0';
       end process;
       cq <=cqi;
end behav;
程序(2):
library ieee;--32位锁存器
use ieee.std_logic_1164.all;
entity reg32b is
     port(load:in std_logic;
             din:in std_logic_vector(31 downto 0);
            dout:out std_logic_vector(31 downto 0));
end reg32b;
architecture behav of reg32b is
begin
   process(load,din)
   begin
   if load'event and load='1' then dout<=din;--锁存输入数据
   end if;
   end process;
end behav;
程序(3):
library ieee;--测频控制信号发生器
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity testctl is
    port(clk:in std_logic;--1Hz测频控制时钟			
         tsten:out std_logic;--计数器时钟使能
        clr_cnt:out std_logic;--计数器清零
          load:out std_logic);--输出锁存信号
end testctl;
architecture behav of testctl is
       signal div2clk:std_logic;
begin
     process(clk)
     begin
          if clk'event and clk='1' then--1Hz时钟二分频
             div2clk<=not div2clk;
          end if;
      end process;
      process(clk,div2clk)
      begin
           if clk='0' and div2clk='0' then--产生计数器清零信号
                 clr_cnt<='1';
           else clr_cnt<='0';end if;
      end process;
      load <=not div2clk;   tsten <=div2clk;
end behav;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -