综合资讯 技术文章 原文阅读 在线商城 下载专区 DATASHEET 技术论坛 商务频道

电子技术 | 技术资料 | 嵌入式系统 | 单片机专题 | DSP专题
EDA/PLD专题 | 电源技术专题 | 电子制作专题 | 其他综合 | 芯片选型

所在的位置:首页在线阅读EDA/PLD专题VHDL程序举例-基本语法正文
 
计数器:generate语句的应用

-- Generated Binary Up Counter
-- The first design entity is a T-type flip-flop. 
-- The second is an scalable synchronous binary up counter illustrating the use of the generate statement to produce regular structures of components. 
-- dowload from: www.fpga.com.cn & www.pld.com.cn


library ieee;
use ieee.std_logic_1164.all;

entity tff is
   port(clk, t, clear : in std_logic; q : buffer std_logic);
end tff;

architecture v1 of tff is
begin
   process(clear, clk)
   begin
      if clear = '1' then
         q <= '0';
      elsif rising_edge(clk) then
         if t = '1' then
            q <= not q;
         else
            null;
         end if;
      end if;      
   end process;
end v1;



library ieee;
use ieee.std_logic_1164.all;

entity bigcntr is
   generic(size : positive := 32);
   port(clk, clear : in std_logic;
         q : buffer std_logic_vector((size-1) downto 0));
end bigcntr;

architecture v1 of bigcntr is

   component tff is
      port(clk, t, clear : in std_logic; q : buffer std_logic);
   end component;

   signal tin : std_logic_vector((size-1) downto 0);

begin

   genttf : for i in (size-1) downto 0 generate
      ttype : tff port map (clk, tin(i), clear, q(i));
   end generate;

   genand : for i in 0 to (size-1) generate
      t0 : if i = 0 generate
         tin(i) <= '1';
      end generate;
      t1_size : if i > 0 generate
         tin(i) <= q(i-1) and tin(i-1);
      end generate;
   end generate;

end v1;

返回 上一页 下一页   信息发布:工号01   转引自: 【 】 【打印】 【关闭

关于我们 ┋ 友情链接


深圳市福田区海滨广场福业大厦12C
电话:0755-88305880 25960580 传真:0755-88305880
Copyright©2005-2007 无忧电子开发网版权所有

粤ICP备05064233号