意外的 TOKBEGIN,期待 AFFECT 或 SEMICOLON

unexpected TOKBEGIN, expecting AFFECT or SEMICOLON

我是 vhdl 的新手,我已经编写了 12 位二进制计数器的代码,但我遇到了这个错误(意外的 TOKBEGIN,期待 AFFECT 或 SEMICOLON)。请指导我解决这个错误

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity bin_count is
Port ( clk : in  STD_LOGIC;
       reset : in  STD_LOGIC;
       seq : out  STD_LOGIC_VECTOR (11 downto 0));
end bin_count;

architecture Behavioral of bin_count is
signal  ff, ff_next, max_pulse : std_logic_vector(11 downto 0)
begin
process(clk,reset)
begin
if(reset = '1') then
ff <= "000000000000"
elsif( rising_edge(clk)) then
ff <= ff_next
end if
end process;
ff_next <= ff + 1;
max_pulse <= '1' when ff = "111111111111" else
0;
seq<= ff
end

end Behavioral;

错误是;

ERROR:HDLParsers:164 - "C:/.Xilinx/New folder/bin_count/bin_count.vhd" Line 39. parse error, unexpected TOKBEGIN, expecting AFFECT or SEMICOLON

您的个人资料显示您还没有参加 Tour(可在“帮助”下找到)。 The Tour 建议在提问之前搜索网站。在这种情况下搜索找不到 ERROR:HDLParsers:164 的单个已回答问题,也提到预期的分号。

在 VHDL 中,分号是语句和声明的分隔符。使用是如此基本,以至于您在 LRM 的其他任何地方都找不到要求,但扩展 BNF 解决了如何解析 VHDL 语法的问题。

您漏掉了很多分号可能意味着在介绍 VHDL 的地方没有提到分隔符的使用。

您的示例代码中存在错误
除了缺少 5 个分号之外,没有可见的“+”运算符(ff 不是无符号或有符号值 - 使用包 numeric_std_unsigned 而不是 numeric_std 或使用类型转换)。

对 max_plus 选择的赋值不是 std_logic_vector 的子类型 max_plus 值的表达式(“111111111111”和“0000000000000”而不是“1”和 0)。

有一个错误的(额外的)结束语句(也没有分号)。

第一个错误出现在您的示例的第 26 行,没有第 39 行。您可以指出位置。

architecture behavioral of bin_count is
    signal  ff, ff_next, max_pulse: 
            std_logic_vector(11 downto 0); -- missing semicolon
begin
    process(clk, reset)
    begin
        if reset = '1' then
            ff <= "000000000000";          -- missing semicolon
        elsif  rising_edge(clk) then
            ff <= ff_next;                 -- missing semicolon
        end if;                            -- missing semicolon
    end process;

   --  ff_next <= ff + 1;     -- no visible operator "+"
   ff_next <= std_logic_vector(unsigned(ff) + 1); -- type converts ff to unsigned
                                                  -- and the result back
    -- or in the context clause use numeric_std_unsigned:
-- use ieee.numeric_std_unsigned.all;  -- makes "+" visible
    -- instead of numeric_std;
    -- 
    -- and here:
    -- ff_next <= ff + 1;

    -- abstract literal 0  and enumeration literal '1' are not values
    -- of std_logic_vector:

    -- max_pulse <= '1' when ff = "111111111111" else
    --              '0'; 

    -- use string literal instead:
    max_pulse <= "111111111111" when ff = "111111111111" else
                 "000000000000";

    -- (and there are other expressions available)

    seq <= ff;                              -- missing semicolon
-- end         -- errant end statement - this doesn't match anything.

end behavioral;

并根据上述更改对您的代码进行分析。还可以进行一些其他更改。

max_pulse不一定是std_logic_vector,可以是std_logic。 (这将允许使用“1”和“0”作为条件赋值语句中赋值。

不需要ff_next

这些给了我们一个稍微不同的架构:

architecture foo of bin_count is
    signal  ff:         std_logic_vector(11 downto 0);
    signal max_pulse:   std_logic;
begin
    process(clk, reset)
    begin
        if reset = '1' then
            ff <= (others => '0');         -- an aggregate
        elsif  rising_edge(clk) then
            ff <= std_logic_vector(unsigned(ff) + 1); 
        end if;                  
    end process;   

    max_pulse <= '1' when ff = "111111111111" else
                 '0';                 
    seq <= ff;

end architecture;

有测试台:

library ieee;
use ieee.std_logic_1164.all;

entity bin_count_tb is
end entity;

architecture fum of bin_count_tb is
    signal clk:     std_logic := '0'; -- default value
    signal reset:   std_logic;
    signal seq:     std_logic_vector (11 downto 0);
begin
CLOCK:
    process
    begin
        wait for 5 ns; -- half the clock period
        clk <= not clk; 
        if now > 85000 ns then -- now returns simulation time
            wait;
        end if;
    end process;
DUT:    
    entity work.bin_count
        port map (
            clk => clk,
            reset => reset,
            seq => seq
        );
STIMULUS:
    process
    begin
        reset <= '1';
        wait for 11 ns;
        reset <= '0';
        wait;
    end process;

end architecture;

我们可以看到重置:

(可点击)

我们可以看到max_pulse周期性发生:

(可点击)

我们可以看到 max_pulse occursseq = "111111111111":

(可点击)