1

I am trying to compare two variables:

variable E1, E2 : unsigned(5 downto 0);

with:

if (E1 < E2) then
lt_val := '1';
end if;

but that error comes up when I try to compile.

I have no idea what I am doing wrong.

EDIT: Here is the full file, I changed unsigned back to std_logic_vector and used the numeric_std library.

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;

entity FPA is
    port (clk, st : in  std_logic;
          d1      : in  std_logic_vector(15 downto 0);
          d2      : in  std_logic_vector(15 downto 0);
          sum     : out std_logic_vector(15 downto 0);
          rdy     : out std_logic);

end FPA;

architecture behav of FPA is

    type state is (s0, s1, s2, s3, s4, s5, s6, s7);
    signal new_state : state;
    signal norm      : std_logic;
    signal lt, gt    : std_logic;

begin

    process is
        variable curr_state : state := s7;
    begin
        if clk = '1' then
            case curr_state is
                when s0 =>
                    if st = '1' then curr_state := s1;
                    end if;
                when s1 =>
                    curr_state := s2;
                when s2 =>
                    if gt = '1' then curr_state := s4;
                    end if;
                    if lt = '1' then curr_state := s3;
                    end if;
                    if not((lt = '1') or (gt = '1')) then
                        curr_state := s5;
                    end if;
                when s3 =>
                    curr_state := s1;
                when s4 =>
                    curr_state := s1;
                when s5 =>
                    if norm = '1' then
                        curr_state := s6;
                    else
                        curr_state := s7;
                    end if;
                when s6 =>
                    curr_state := s7;
                when s7 =>
                    if st = '0' then curr_state := s0;
                    end if;
            end case;
            new_state <= curr_state;
        end if;
        new_state <= curr_state;
        wait on clk;
    end process;

    process is
        variable E1                : std_logic_vector(5 downto 0);
        variable E2                : std_logic_vector(5 downto 0);
        variable sum_val           : std_logic_vector(15 downto 0);
        variable X, Y              : std_logic_vector(11 downto 0);
        variable SGR               : std_logic_vector(11 downto 0);
        variable rdy_val, norm_val : std_logic;
        variable gt_val, lt_val    : std_logic;
    begin

        -- defaults

        rdy_val := '0';
        case new_state is

            when s0 =>
                sum_val := "ZZZZZZZZZZZZZZZZ";
                E1      := d1(15 downto 10);
                X       := "01" & d1(9 downto 0);
                E2      := d2(15 downto 10);
                Y       := "01" & d2(9 downto 0);
            when s1 =>
                if (E1 < E2) then
                    lt_val := '1';
                end if;
                if (E1 > E2) then
                    gt_val := '1';
                end if;
                SGR := X + Y;
            when s2 =>
                if SGR(11) = '1' then
                    norm_val := '1';
                end if;
            when s3 =>
                X  := X ror 1;
                E1 := E1 + "000001";
            when s4 =>
                Y  := Y ror 1;
                E2 := E2 + "000001";
            when s5 =>
            when s6 =>
                SGR := SGR ror 1;
                E2  := E2 + "000001";
            when s7 =>
                sum_val := E2 & SGR(9 downto 0);
                rdy_val := '1';
        end case;

        rdy  <= rdy_val;
        lt   <= lt_val;
        gt   <= gt_val;
        sum  <= sum_val;
        norm <= norm_val;

        wait on new_state;
    end process;

end behav;
4

3 回答 3

1

没有为 std_logic_vector 定义比较运算符,除非您使用非标准包。在您进行您提到的更改之前,我不知道您的代码是什么样的,但是现在的代码应该可以通过更改行来解决这个问题

if (E1<E2) then

if (unsigned(E1) < unsigned(E2)) then

请注意,“+”运算符也没有为 std_logic_vector 定义,因此无论何时对它们进行算术运算,都必须在 unsigned 和 std_logic_vector 之间来回转换 E1 和 E2。在您的情况下,最好将 E1 和 E2 定义为无符号而不是 std_logic_vector,只要您使用 numeric_std 包并且没有来自 IEEE 库的其他非标准包,它应该可以正常工作。(例如std_logic_unsigned)

于 2012-10-01T09:28:29.623 回答
1

声明E1and E2asunsigned是正确的选择,但还不够。

您需要将其他几个变量声明为unsigned,动态地将输入从转换std_logic_vectorunsigned并动态地将您的变量转换sum_valstd_logic_vector以分配输出sum

修补以下行似乎没问题(至少它在 ModelSim 中编译):

    variable E1                : unsigned(5 downto 0);
    variable E2                : unsigned(5 downto 0);
    variable sum_val           : unsigned(15 downto 0);
    variable X, Y              : unsigned(11 downto 0);
    variable SGR               : unsigned(11 downto 0);
    -- ...
    E1      := unsigned(d1(15 downto 10));
    X       := unsigned("01" & d1(9 downto 0));
    E2      := unsigned(d2(15 downto 10));
    Y       := unsigned("01" & d2(9 downto 0));
    -- ...
    sum  <= std_logic_vector(sum_val);
于 2012-10-01T09:40:19.457 回答
0

将所有向量改回unsigned(毕竟它们代表数字)。

如果它仍然不能编译,你可能有一个有缺陷的编译器(对我来说它在 Modelsim 中工作)

于 2012-10-01T10:18:39.350 回答