VHDL - type declaration in package

John picture John · Dec 11, 2012 · Viewed 9.2k times · Source

I am trying to scroll a text on the 7 segment display. The text will be entered from a keyboard and I am using BASYS2 as FPGA. My keyboard interface is done, as well as my seven segment controller. But I am having problems with my shifter module. As I'm dealing with scancodes, I need to use an array of bytes. I declared such type in a package, that is "mypackage2". However, as far as I understood, the shifter module is unable to use that type, namely "reg_array". What do I need to change, or is there something I am missing here? As I'm new to VHDL, I might have done some basic errors. Also, the package I've written does not show up in the project hierarchy at the lefthand side of the window. Any help is appreciated. Thank you.

EDIT: I noticed that I shouldn't use reg array as follows: Data_out : out reg_array(REGSIZE-1 downto 0), because its width is already specified. So I changed my code a little bit and reduced the number of errors to 3.

Here's the shifter module:

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.STD_LOGIC_UNSIGNED.ALL; 
use IEEE.STD_LOGIC_ARITH.ALL; 
use work.mypackage2.all; 

entity shifter is 
    generic ( REGSIZE  : integer := 16); -- Text will be composed of 16 characters
    port(clk      : in  std_logic; 
         Scan_Dav : in  std_logic; -- this is '1' when there is a new scancode
         Data_in  : in  std_logic_vector(7 downto 0); --scancode from keyboard
         Data_out : out reg_array ); 
end shifter; 

architecture bhv of shifter is 

        signal shift_reg : reg_array;
begin 
    process (clk, Scan_Dav) begin 
        if rising_edge(clk) then 
            if Scan_Dav = '1' then 
                shift_reg(REGSIZE-1 downto 1) <= shift_reg(REGSIZE-2 downto 0); 
                shift_reg(15) <= shift_reg(0); 
            end if; 
        end if; 
        Data_out <= shift_reg; 
    end process; 
end bhv; 

Here's the package:

library IEEE; 
use IEEE.STD_LOGIC_1164.all; 

package mypackage2 is 

   subtype reg is std_logic_vector(7 downto 0); -- a byte 
        type reg_array is array (0 to 15) of reg; -- array of bytes 

end mypackage2; 


package body mypackage2 is 

end mypackage2; 

And these are the latest errors:

ERROR:HDLParsers:807 - "F:/Projeilk/Shifter.vhd" Line 22. shift_reg can not be used with range downto.
ERROR:HDLParsers:807 - "F:/Projeilk/Shifter.vhd" Line 22. shift_reg can not be used with range downto.

Answer

em.eh.kay picture em.eh.kay · Dec 11, 2012

You've defined the size of the byte array twice. In the package file, you've defined reg_array as a fixed array of 16 reg's. But in the architecture, you're trying to specify the size of shift_reg by defining the size of reg_array again with (REGSIZE-1 downto 0) as if reg_array was a variable-sized array.

You can either keep the fixed declaration of reg_array and define shift_reg as:

signal shift_reg : reg_array;

Or keep your definition of shift_reg and declare reg_array as a variable-width array like:

type reg_array is array (natural range <>) of reg; -- variable-length array of bytes 

It looks like you may have a few more errors in the code, but some of them may be cascading from this problem.