【发布时间】: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