Question

I'm trying to use unsigned integers in VHDL with well defined bit widths. It seems VHDL does not like me trying to assign literal values to these types defined as:

variable LCD_DATA: unsigned(19 downto 0) := 0;

But in my IDE (Quartus), I get a complaint "UNSIGNED type does not match integer literal." I also get complaints for adding numbers to types defined like this. Whats the preferred change I need to make?

Was it helpful?

Solution

See other answers, and note that for non-zero literals, you probably want to do something like:

variable LCD_DATA: unsigned(19 downto 0) := to_unsigned(n, 20);

Substitute a literal for n. This works for n=0 too, of course, but it's not as tidy as (others => '0').

OTHER TIPS

--Either 
variable LCD_DATA: unsigned(19 downto 0) := (others => '0');
--Or you can also write it like 
variable LCD_DATA: unsigned(19 downto 0) := "00000000000000000000";

And for the 2nd part of your question while adding number of this type.

library ieee;
use ieee.std_logic_1164.all;
use IEEE.NUMERIC_STD.ALL;

Check whether you have used above libraries in the code or not.

unsigned is related to std_ulogic, where the value for an element would be '0'.

variable LCD_DATA: unsigned (19 downto 0) := (others => '0');

which provides an aggregate for the default assignment with all elements set to '0'.

You can't assign a single element of integer type to an array of std_ulogic elements.

You can add signed or unsigned to a natural (unsigned) or integer (signed) using "+" functions defined in package numeric_std:

  -- Id: A.5
  function "+" (L: UNSIGNED; R: NATURAL) return UNSIGNED;
  -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0).
  -- Result: Adds an UNSIGNED vector, L, with a non-negative INTEGER, R.

  -- Id: A.6
  function "+" (L: NATURAL; R: UNSIGNED) return UNSIGNED;
  -- Result subtype: UNSIGNED(R'LENGTH-1 downto 0).
  -- Result: Adds a non-negative INTEGER, L, with an UNSIGNED vector, R.

  -- Id: A.7
  function "+" (L: INTEGER; R: SIGNED) return SIGNED;
  -- Result subtype: SIGNED(R'LENGTH-1 downto 0).
  -- Result: Adds an INTEGER, L(may be positive or negative), to a SIGNED
  --         vector, R.

  -- Id: A.8
  function "+" (L: SIGNED; R: INTEGER) return SIGNED;
  -- Result subtype: SIGNED(L'LENGTH-1 downto 0).
  -- Result: Adds a SIGNED vector, L, to an INTEGER, R.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top