使用';常数';在vhdl中使用数字

使用';常数';在vhdl中使用数字,vhdl,fpga,synthesis,vivado,Vhdl,Fpga,Synthesis,Vivado,为了适应Artix-7 FPGA上现有的大型设计,我实现了一个简单的计数机制,类似于“带常数的结构”,这样将来,我就可以更改常数的值,而不用太担心它在哪里使用 然而,它导致了几次计时失败,我回到了增加计数器的正常方式,添加了1,解决了计时失败的问题。以下是我在Vivado 2016.4工具中尝试合成的实体和2个体系结构。但是Vivado中的Project Summary(项目摘要)选项卡显示,除了使用IO之外,没有其他资源。!所以我的问题是,在VHDL中声明常量会导致比平常更多的硬件吗?这两种实

为了适应Artix-7 FPGA上现有的大型设计,我实现了一个简单的计数机制,类似于“带常数的结构”,这样将来,我就可以更改常数的值,而不用太担心它在哪里使用

然而,它导致了几次计时失败,我回到了增加计数器的正常方式,添加了1,解决了计时失败的问题。以下是我在Vivado 2016.4工具中尝试合成的实体和2个体系结构。但是Vivado中的Project Summary(项目摘要)选项卡显示,除了使用IO之外,没有其他资源。!所以我的问题是,在VHDL中声明常量会导致比平常更多的硬件吗?这两种实现之间的区别是什么

实体

entity counter is
Port(
      i_clk : in std_logic;
      i_rst : in std_logic;
      o_cnt : out std_logic_vector(7 downto 0)
    );
end counter;
具有“常量”的体系结构

architecture Behavioral of counter is
signal s_cnt : unsigned(7 downto 0) := (others => '0');
signal s_max : unsigned(7 downto 0) := (others => '1');

constant c_INCR : unsigned(3 downto 0) := x"1";
begin
process (i_clk) begin
    if rising_edge(i_clk) then
        if i_rst = '1' then
            s_cnt <= (others => '0');
        else
            o_cnt <= std_logic_vector(s_cnt);
            if s_cnt = s_max then
                s_cnt <= (others => '0');
            else
                s_cnt <= s_cnt + c_INCR;
            end if;
        end if;
    end if;
end process;

end Behavioral;
architecture Behavioral of counter is
signal s_cnt : unsigned(7 downto 0) := (others => '0');
signal s_max : unsigned(7 downto 0) := (others => '1');

begin
process (i_clk) begin
    if rising_edge(i_clk) then
        if i_rst = '1' then
            s_cnt <= (others => '0');
        else
            o_cnt <= std_logic_vector(s_cnt);
            if s_cnt = s_max then
                s_cnt <= (others => '0');
            else
                s_cnt <= s_cnt + 1;
            end if;
        end if;
    end if;
end process;

end Behavioral;
计数器的架构是
信号s_cnt:unsigned(7到0):=(其他=>'0');
信号s_max:unsigned(7到0):=(其他=>1');
常数c_INCR:无符号(3到0):=x“1”;
开始
过程(i_clk)开始
如果上升沿(i_clk),则
如果i_rst='1',那么
s_cnt“0”);
其他的
o_cnt‘1’;
开始
过程(i_clk)开始
如果上升沿(i_clk),则
如果i_rst='1',那么
s_cnt“0”);
其他的

两种实现应该产生相同的合成结果。但是,FPGA上的布局和路由可能会有很大的不同(取决于供应商IDE如何控制其布局和路由过程)。因此,这可能会在一个实现中导致时间问题。但你不能说使用常量通常更糟糕。我在Vivado 2017.1中尝试了你的代码,合成后的结果是相同的。(在两种体系结构之间)根据我的经验,代码中的一个小变化可能会对合成工具的实现产生很大影响。我认为这是因为这些工具基于代码的散列生成了一个随机种子,它被用作初始逻辑布局的基础。合成工具的优化从来都不是完美的,因此不同的开始状态将有不同的结束状态。这可能是因为您的常量是4位,而您的“+1”可以被合成器解释为更简单的递增器。但如果这是原因,它证明你的合成器并不是最适合传播常数的。。。您可以通过将常量重新定义为
1
整数和/或
'1'
std\u ulogic
来检查这一点。