VHDL:"变量 "的类型与<=的类型不兼容[英] VHDL: Type of "variable" is incompatible with type of <=

本文是小编为大家收集整理的关于VHDL:"变量 "的类型与<=的类型不兼容的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

可以解释为什么我在此代码中遇到语法错误.

An <= "1110" when anode = "00" else
AN <= "1101" when anode = "01" else
An <= "1011" when anode = "10" else 
An <= "0111" when anode = "11";

segment <= counter_1r    when anode = "00" else
segment <= counter_10r   when anode = "01" else
segment <= counter_100r  when anode = "10" else
segment <= counter_1000r When anode = "11";

它说

ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 181. Type of An is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 182. Type of An is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 183. Type of An is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 181. Type of An is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 182. Type of An is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 183. Type of An is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 186. Type of segment is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 187. Type of segment is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 188. Type of segment is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 186. Type of segment is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 187. Type of segment is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 188. Type of segment is incompatible with type of <=.

我不明白,因为在我的代码中,我将实体中的所有受影响元素设置为输出,它们都使用相同的类型.

PORT(
    CLK: in std_logic;
--  LED: out std_logic_vector (7 downto 0);
--  Switch: in std_logic_vector(7 downto 0);
    Segment: out std_logic_vector (7 downto 0); 
    AN: out std_logic_vector (3 downto 0) 
);
end Main;

architecture Behavioral of Main is
    signal counter_1000:  integer range 0 to 9;
    signal counter_100:   integer range 0 to 9;
    signal counter_10:    integer range 0 to 9;
    signal counter_1:     integer range 0 to 9;
    signal counter_1r:    std_logic_vector(7 downto 0);
    signal counter_10r:   std_logic_vector(7 downto 0);
    signal counter_100r:  std_logic_vector(7 downto 0);
    signal counter_1000r: std_logic_vector(7 downto 0);
    signal prescaler:     integer range 0 to 50000000;
    signal limit:         integer range 0 to 50000000;
    signal Anode:         std_logic_vector(1 downto 0);
begin

推荐答案

要查看为什么收到错误消息,请查看这样的代码:

An <= "1110" when anode = "00" else (AN <= "1101")....

else子句将作为AN与1101的比较进行编译,以查看其是否不那么含量或等于.这是类型boolean,它与An的类型不兼容. (我希望VHDL没有选择<=作为作业操作员,但是我们在这里!)

您需要的语法更像是这样(请注意其他行上缺少<=)

An <= "1110" when anode = "00" else
      "1101" when anode = "01" else
      "1011" when anode = "10" else    
      "0111" when anode = "11" else
      null;

其他推荐答案

条件信号分配(在过程之外)写为:

An <=
    "1110" when anode = "00" else
    "1101" when anode = "01" else
    "1011" when anode = "10" else 
    "0111" when anode = "11" else
    "0000";

segment <=
    counter_1r    when anode = "00" else
    counter_10r   when anode = "01" else
    counter_100r  when anode = "10" else
    counter_1000r When anode = "11" else
    "00000000";

在过程中,您要么需要使用 if 语句或 case 语句.

本文地址:https://www.itbaoku.cn/post/2091014.html

问题描述

Could some explain why i get syntax error with this piece of code..

An <= "1110" when anode = "00" else
AN <= "1101" when anode = "01" else
An <= "1011" when anode = "10" else 
An <= "0111" when anode = "11";

segment <= counter_1r    when anode = "00" else
segment <= counter_10r   when anode = "01" else
segment <= counter_100r  when anode = "10" else
segment <= counter_1000r When anode = "11";

it says

ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 181. Type of An is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 182. Type of An is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 183. Type of An is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 181. Type of An is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 182. Type of An is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 183. Type of An is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 186. Type of segment is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 187. Type of segment is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 188. Type of segment is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 186. Type of segment is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 187. Type of segment is incompatible with type of <=.
ERROR:HDLParsers:800 - "C:/.Xilinx/Stopur/main.vhd" Line 188. Type of segment is incompatible with type of <=.

Which i Don't understand, because In my code i've set all the affected element in my entity to be output, they are all using the same type.

PORT(
    CLK: in std_logic;
--  LED: out std_logic_vector (7 downto 0);
--  Switch: in std_logic_vector(7 downto 0);
    Segment: out std_logic_vector (7 downto 0); 
    AN: out std_logic_vector (3 downto 0) 
);
end Main;

architecture Behavioral of Main is
    signal counter_1000:  integer range 0 to 9;
    signal counter_100:   integer range 0 to 9;
    signal counter_10:    integer range 0 to 9;
    signal counter_1:     integer range 0 to 9;
    signal counter_1r:    std_logic_vector(7 downto 0);
    signal counter_10r:   std_logic_vector(7 downto 0);
    signal counter_100r:  std_logic_vector(7 downto 0);
    signal counter_1000r: std_logic_vector(7 downto 0);
    signal prescaler:     integer range 0 to 50000000;
    signal limit:         integer range 0 to 50000000;
    signal Anode:         std_logic_vector(1 downto 0);
begin

推荐答案

To see why you get the error message, look at your code like this:

An <= "1110" when anode = "00" else (AN <= "1101")....

The else clause will be compiled as a comparison of AN with 1101 to see if it's less-than-or-equal-to. Which is of type boolean, which is incompatible with the type of An, a vector. (I wish VHDL hadn't picked <= as an assignment operator, but there we are!)

The syntax you need is more like this (note the lack of <= on the other lines)

An <= "1110" when anode = "00" else
      "1101" when anode = "01" else
      "1011" when anode = "10" else    
      "0111" when anode = "11" else
      null;

其他推荐答案

Conditional Signal Assignment (outside of a process) is written as:

An <=
    "1110" when anode = "00" else
    "1101" when anode = "01" else
    "1011" when anode = "10" else 
    "0111" when anode = "11" else
    "0000";

segment <=
    counter_1r    when anode = "00" else
    counter_10r   when anode = "01" else
    counter_100r  when anode = "10" else
    counter_1000r When anode = "11" else
    "00000000";

Inside of a process, you will either need to use an if statement or a case statement.