Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
12 years ago

Comparison of numeric_std.unsigned fails

Hi,

I've just started learning VHDL and already experience the first "unsolveable" problems,

Although I've done some research I wasn't able to solve this question myself, please don't be harsh even in case it is a complete newbie-question.

I would like to compare two "unsigned" vectors, however using quartus I always get:

Error (10327): VHDL error at census.vhd(31): can't determine definition

of operator ""<"" -- found 0 possible definitions

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.all;
ARCHITECTURE rtl OF comptest IS
FUNCTION cmp_line(center : UNSIGNED(7 downto 0))
 RETURN UNSIGNED IS
  BEGIN
    RETURN  center < to_unsigned(2, 8); -- probably will require cast when comparison-operator can be resolved
  END cmp_census_line;
BEGIN
....

Another thing i noticed, is that I do not need to specify the bit-count of the unsigned for parameter and return types in the function.

Will those be inferred from the caller or will some (1?) default value be used instead?

Thank you in advance, Reggi

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The 'center < to_unsigned()' itself returns a boolean which doesn't comply with your specified unsigned return type.

    The function specification always specifies an unconstrained returned object, but it is up to you to return a properly constrained object at the exit of the function.

    You may want to get hold of a good introductory book to VHDL like e.g. "Circuit Design with VHDL" by Volnei A. Podroni.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    The 'center < to_unsigned()' itself returns a boolean which doesn't comply with your specified unsigned return type.

    --- Quote End ---

    Thanks a lot for the pointer - indeed after writing a conversion-function everything works as expected. I wasn't aware that the return-type is also involved when looking up a function candidate.

    --- Quote Start ---

    The function specification always specifies an unconstrained returned object, but it is up to you to return a properly constrained object at the exit of the function.

    You may want to get hold of a good introductory book to VHDL like e.g. "Circuit Design with VHDL" by Volnei A. Podroni.

    --- Quote End ---

    I definitively will. However, I am a practitioner when it comes to learning - so I have to start writing code ;)

    Thanks a lot, Reggi