【问题标题】:unexpected TOKBEGIN, expecting AFFECT or SEMICOLON意外的 TOKBEGIN,期待 AFFECT 或 SEMICOLON
【发布时间】:2015-10-03 18:31:12
【问题描述】:

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

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

【问题讨论】:

  • 该代码中缺少很多分号,正如错误消息所述。

标签: vhdl counter


【解决方案1】:

您的个人资料显示您没有使用Tour(可在帮助下找到)。 The Tour 建议在提问前先搜索网站。在这种情况下搜索没有找到一个已回答的问题 ERROR:HDLParsers:164 还提到了预期的分号。

在 VHDL 中,分号是语句和声明的分隔符。使用非常基础,除了解决如何解析 VHDL 语法的扩展 BNF 之外,您在 LRM 的其他任何地方都找不到要求。

你错过了很多分号可能意味着在你被介绍到 VHDL 的地方没有提到分隔符的使用。

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

对 max_plus 选项的赋值不是 std_logic_vector 的子类型 max_plus 值的表达式(“111111111111”和“00000000000000”而不是“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周期性出现:

(可点击)

seq = "111111111111"时我们可以看到max_pulse occurs

(可点击)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-23
    • 2013-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-12
    • 2017-04-08
    相关资源
    最近更新 更多