【问题标题】:VHDL - Error comparing std_logic_vector with declared constant unsigned? The unsigned has been cast to std_logic_vectorVHDL - 将 std_logic_vector 与声明的无符号常量进行比较时出错?无符号已转换为 std_logic_vector
【发布时间】:2021-11-02 08:15:03
【问题描述】:

我正在尝试使用 VHDL 2008 在 Vivado 2020.2 中创建一个七段显示控制器。实体需要通过系统时钟速率和时间进行参数化,以在显示器中显示每个数字(有 8 个数字)。这是我到目前为止的代码:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.numeric_std_unsigned.all;

entity SevenSeg is
    generic (
        -- Rate in HZ
        CLK_RT          : integer := 100000000;
        -- Time in ms
        DISPLAY_TIME    : integer := 20
    );
    port (
        clk             : in std_logic;
        rst             : in std_logic;
        dataIn          : in std_logic_vector(31 downto 0);
        digitDisplay    : in std_logic_vector(7 downto 0);
        digitPoint      : in std_logic_vector(7 downto 0);
        anode           : out std_logic_vector(7 downto 0);
        segment         : out std_logic_vector(7 downto 0)
    );
end SevenSeg;

architecture rtl of SevenSeg is
    constant ROLL_OVER : unsigned := to_unsigned(20 * 1000000 / (1000000000 / CLK_RT), 32);
    signal cnt       : std_logic_vector(31 downto 0);
    signal anode_sel : std_logic_vector(2 downto 0);
begin

     process (clk)
     begin
         if (clk'EVENT AND clk = '1') then      
             if rst = '1' then 
                 anode_sel <= (others => '0');
             else if cnt = std_logic_vector(ROLL_OVER) then
                 anode_sel <= anode_sel + 1;
             end if;
         end if;
     end process;
end rtl;

在代码的当前状态下,Vivado 将标记语法错误“近端进程”。我很确定cnt = std_logic_vector(ROLL_OVER) 有问题,因为当我注释掉 if 子句的那一部分时,不再有任何语法错误。我一直在研究 vhdl 以及常量无符号/向量类型的比较,但似乎没有任何效果。如果能深入了解导致此错误的原因,我将不胜感激。

【问题讨论】:

  • else if 应该是 elsif,如 elsif unsigned(cnt) = ROLL_OVER then
  • 对于相等,哪个操作数被类型转换在这里可能无关紧要,但对于 std_logic_vector 值的元素,'L' 不 = '0','H' 不 = '1'。尽可能使用数字类型运算符。由于嵌套 if 语句缺少匹配的 end ifs,因此出现语法错误。

标签: vector constants vhdl hdl seven-segment-display


【解决方案1】:

有两种选择,分别是 elsif

if rst = '1' then 
   anode_sel <= (others => '0');
elsif cnt = std_logic_vector(ROLL_OVER) then
   anode_sel <= anode_sel + 1;
end if;

或者:否则

if rst = '1' then 
   anode_sel <= (others => '0');
else
   if cnt = std_logic_vector(ROLL_OVER) then
      anode_sel <= anode_sel + 1;
   end if;
end if;

【讨论】:

    【解决方案2】:

    您没有遵循标准的 VHDL。 else if 引入了一个新的 if 条件,它需要一个额外的 end if 是正确的语法。您可以改用 elsif,您的代码不会产生错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-04
      • 1970-01-01
      • 1970-01-01
      • 2013-10-01
      • 2014-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多