jssd 发表于 2010-5-19 09:39:33

诚心诚意问牛人们:关于计数器使用宏的问题

20位计数器就占用了20个宏。有没有其他办法可以减少占用宏的量?

VHDL代码:

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity counter is
    port(clk,reset,slt :in std_logic;
         output :out std_logic_vector(19 downto 0));
end counter;

architecture behav of counter is
begin
    process(clk,reset)
    variable CNT :std_logic_vector(19 downto 0);
    begin
      if(reset ='1') then                  
            CNT := "00000000000000000000";
      else
            if(clk'event and clk = '1') then
                if(slt = '1') then
                  CNT := CNT + '1';               
                else
                  CNT := CNT - '1';
                end if;
            end if;
      end if;
      output <= CNT;
    end process;
end behav;


RTL图
http://cache.amobbs.com/bbs_upload782111/files_29/ourdev_555212.JPG
20位计数器 (原文件名:counter20.JPG)

tear086 发表于 2010-5-19 09:51:58

没有办法。一位对应一个Flip-Flop。

jssd 发表于 2010-5-19 09:56:27

谢谢tear086 .COM 缺氧。发现你在论坛里最活跃了

40130064 发表于 2010-5-19 17:29:43

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity counter is
    port(clk,reset,slt :in std_logic;
         output :out std_logic_vector(19 downto 0));
end counter;

architecture behav of counter is
begin
    process(clk,reset,slt)
    variable d :integer range -1 to 1;
    variable CNT :integer range -524287 to 524287 ;
    begin
      if(slt = '1') then
                  d := 1;               
                else
                  d := -1;
                end if;
               
      if(reset ='1') then                  
            CNT := 0;
      else
            if(clk'event and clk = '1') then
                  CNT := CNT + d;
             else
            CNT:=CNT;               
            end if;
      end if;
      output <= conv_std_logic_vector(CNT,20);
    end process;
end behav;

suipeng70 发表于 2010-5-20 15:59:23

xilinx的Slice只需要10个,其实是因为1个Slice包含2个Flip-Flop,20个Flip-Flop是必须的。
其他的逻辑资源应该能用于一些组合逻辑。

jssd 发表于 2010-5-21 14:04:16

回复【3楼】40130064
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity counter is
    port(clk,reset,slt :in std_logic;
         output :out std_logic_vector(19 downto 0));
end counter;
architecture behav of counter is
begin
    process(clk,reset,slt)
    variable d :integer range -1 to 1;
    variable cnt :integer range -524287 to ......
-----------------------------------------------------------------------

三楼的大哥。编译了你的程序发现还真的少了一个加法器(不知道叫什么,应该就叫加法器吧)。原来可以这样写的。不过宏还是20个。看来是不可以减少了。不过还是谢谢啦!

jssd 发表于 2010-5-21 14:06:27

回复【4楼】suipeng70
xilinx的slice只需要10个,其实是因为1个slice包含2个flip-flop,20个flip-flop是必须的。
其他的逻辑资源应该能用于一些组合逻辑。
-----------------------------------------------------------------------

我在电路中已经用了EPM7064了。当时是没接触过CPLD所以没想到宏居然用得这么快的。可是没得改了。
页: [1]
查看完整版本: 诚心诚意问牛人们:关于计数器使用宏的问题