【问题标题】:My inputs keep being ignored in VHDL我的输入在 VHDL 中一直被忽略
【发布时间】:2014-09-29 12:09:29
【问题描述】:

我是 VHDL 新手,我想为编码器信号编写一个简单的计数器,每 100 个周期计数 (duh) 到 1000。我正在使用 Lattice ispMACH 4000ZE Pico DevKit 和软件 ispLEVER Classic Project Navigator 进行编程。

我的代码是:

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
use IEEE.std_logic_unsigned.all;

entity Counter_10B is 
    port (
       reset        : in  std_ulogic := '0';
       updown       : in  std_ulogic := '0';
       clk          : in  std_ulogic := '0';
       cnt_out      : out std_ulogic_vector(9 downto 0) := (others => '0')

     ); 
 end Counter_10B;

 architecture behavior of Counter_10B is

signal int_cnt : unsigned(9 downto 0)  := (others => '0');

begin              


Counter : process(clk, updown, reset)

variable temp1 : unsigned(4 downto 0) := (others => '0'); 
variable temp2 : unsigned(9 downto 0) := (others => '0'); 

begin
    if (reset = '0') then
        temp2 := (others => '0');
    end if;

    if ((clk'event AND clk='1')) then

        temp1 := temp1 + 1; 

        if(temp1 >= 100) then
            if(updown = '0') then

                if(temp2 >= 1000) then
                    temp2 := (others => '0');
                end if;

                temp2 := temp2 + 1;

            elsif(updown = '1') then

                if(temp2 = 0) then
                    temp2 := (others => '1');
                end if;

                temp2 := temp2 - 1;
            end if ;

            temp1 := 0;
        end if;

        int_cnt <= temp2;

    end if;

end process;
        cnt_out <= std_ulogic_vector(int_cnt);
end behavior;

我的问题是每次编译都没有编译错误,但是有很多警告,比如:

Counter.temp2(0) 的所有可达分配赋值为 '0';寄存器被优化移除

修剪 int_cnt(9 downto 0) 的寄存器位 9 到 1

但我最大的问题是:

输入 clk/reset/updown 未使用

我真的需要关于最后一个警告的帮助,我不明白为什么会出现这个错误。这没有任何意义,不是吗?

谢谢!

编辑 30.09

Counter : process(clk, updown, reset)

variable temp1 : natural range 0 to 100 := 0; 

begin
    if (reset = '0') then
        int_cnt <= (others => '0');

    elsif ((clk'event AND clk='1')) then

        temp1 := temp1 + 1; 

        if(temp1 >= 100) then
            if(updown = '0') then

                if(int_cnt >= 1000) then
                    int_cnt <= (others => '0');
                end if;

                int_cnt <= int_cnt + 1;

            elsif(updown = '1') then

                if(int_cnt = 0) then
                    int_cnt <= 1000;
                end if;

                int_cnt <= int_cnt - 1;
            end if ;

            temp1 := 0;
        end if;

    end if;

end process;

cnt_out <= std_ulogic_vector(int_cnt);

【问题讨论】:

  • 请注意,即使您修复了 temp2 没有足够宽的范围,您也会遇到逻辑错误。如果您希望翻转边界为 1000,则计数器下溢应该以 1000 的值结束,而不是 1023,因为 (others =&gt; '1') 将产生。您还将变量视为信号 - 每次翻转时,您还将减去或添加一个意味着您从 1000 滚动到 1,而不是 1000 到 0,因为您多次分配变量。无论如何我都会在这里使用信号,但是如果你使用变量,你必须记住它们会随着每次赋值而改变。

标签: vhdl compiler-warnings


【解决方案1】:

更好地使用数据类型! VHDL 有一个不错的类型系统:不要忽视它!

代替

variable temp1 : unsigned(4 downto 0) := (others => '0');

variable temp1 : natural range 0 to 31 := 0;

更简单、更简洁,并且同样受到大多数综合工具的良好支持。

然后当你写

if(temp1 >= 100) then

您可能会挠头并在问题发生之前解决它......

(应该清楚为什么不使用 updown;遗憾的是,该工具不是很具体,未使用哪个信号。)

只有在您的合成工具过于严格而无法支持时才妥协,并且只有妥协到足以满足有缺陷的工具,并向供应商报告工具缺陷以便他们修复它!

【讨论】:

    【解决方案2】:

    您的流程不是以通常对综合有效的风格编写的。您需要一个“else”,而不是两个单独的 if 块:

    if (reset = '0') then
      temp2 := (others => '0');
    elsif (clk'event AND clk='1') then
      ...
    

    您编写的内容可能在模拟中起作用,但是模拟工具通常按照所写的字面意思执行过程,而综合工具会推断物理逻辑元素,并且对样式更加挑剔。

    如果综合工具优化了temp2,整个过程就变得无关紧要,因此输入将不会被使用(因为它们不再连接到任何东西)。

    【讨论】:

    • 嗨,我也试过了,但我仍然有错误:输入 clk/reset/updown 未使用。我将 temp2 替换为 int_cnt,现在出现错误:
    • 我将 temp2 替换为 int_cnt,现在出现错误:All reachable assignments to int_cnt(0) assign '0'; register removed by optimization
    • 查看 Brian 的回答 - 我错过了您将小向量与超出范围的值进行比较的事实......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多