首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复代码中的“索引名称不是std_logic_vector”错误

如何修复代码中的“索引名称不是std_logic_vector”错误
EN

Stack Overflow用户
提问于 2019-05-04 20:54:38
回答 1查看 2.2K关注 0票数 0

我试图通过简单地计算正常代码来制作一个格雷码计数器,然后将其转换为格雷码。

我得到了这个错误

代码语言:javascript
复制
Line 52: Indexed name is not a std_logic_vector

即使我将该信号声明为std_logic_vector。

代码语言:javascript
复制
GrayCount <= count(3) & count(3) xor count(2) & count(2) xor count (1) & count (1) xor count(0);

我是52号。线路

代码语言:javascript
复制
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity GrayCounter is
     Port ( clock : in  STD_LOGIC;
              ud : in  STD_LOGIC;
              freq_sel : in  STD_LOGIC_VECTOR (1 downto 0);
              GrayCount : out  std_logic_vector (3 downto 0));
end GrayCounter;

architecture Behavioral of GrayCounter is
    signal count : std_logic_vector(3 downto 0);
    signal hz : integer range 0 to 100000000;
    signal clk  : std_logic;
begin
    process(clock)
    begin 
        case freq_sel is
            when "00" => hz <= 2000000;  
            when "01" => hz <= 4000000;
            when "10" => hz <= 10000000;
            when others => hz <= 100000000;
        end case;
    end process;

    process(clock)
    variable temp : integer range 0 to 100000000;
    begin
        if(clock'event and clock = '1') then
            temp := temp + 1;
            if (temp>(hz/2)) then 
                clk <= not clk;
                temp := 0;
            end if;
        end if;
    end process;

    process(clk)
    begin
        if(clk'event and clk = '1') then
            if(ud = '1') then
                count <= count + 1;
            else
                count <= count - 1 ;
            end if;
        end if;
    end process;

    GrayCount <= count(3) & count(3) xor count(2) & count(2) xor count (1) & count (1) xor count(0);

end Behavioral;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-04 21:37:23

运算符的优先级可能不是您所期望的。

您应该添加括号:

代码语言:javascript
复制
GrayCount  <= count(3) & (count(3) xor count(2)) & (count(2) xor count (1)) & (count (1) xor count(0));
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55982725

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档