VHDL - 包中的类型声明

时间:2012-12-11 20:29:00

标签: text vhdl shift segment

我正在尝试在7段显示屏上滚动文字。文本将从键盘输入,我使用BASYS2作为FPGA。我的键盘界面已完成,还有我的七段控制器。但是我的移位器模块出了问题。在我处理扫描码时,我需要使用一个字节数组。我在包中声明了这种类型,即“mypackage2”。但是,据我所知,移位器模块无法使用该类型,即“reg_array”。我需要改变什么,或者我在这里缺少什么?由于我是VHDL的新手,我可能已经做了一些基本的错误。此外,我编写的包不会显示在窗口左侧的项目层次结构中。任何帮助表示赞赏。谢谢。

编辑:我注意到我不应该使用reg数组,如下所示:Data_out : out reg_array(REGSIZE-1 downto 0),因为它的宽度已经指定。所以我稍微更改了我的代码并将错误数量减少到3。

这是移位器模块:

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; 

这是包裹:

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; 

这些是最新的错误:

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.

3 个答案:

答案 0 :(得分:1)

您已经定义了两次字节数组的大小。在包文件中,您已将reg_array定义为16 reg的固定数组。但是在架构中,您尝试使用shift_reg再次定义reg_array的大小来指定(REGSIZE-1 downto 0)的大小,就像reg_array是一个可变大小的数组一样。

您可以保留reg_array的固定声明,并将shift_reg定义为:

signal shift_reg : reg_array;

或者保留shift_reg的定义并将reg_array声明为可变宽度数组,如:

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

看起来您可能在代码中有更多错误,但其中一些可能会出现此问题。

答案 1 :(得分:0)

我还无法添加评论,所以我必须添加另一个答案。快速地看,我没有看到你的顶级严重错误。我怀疑RTL输出是优化的牺牲品。具体来说,KeyboardController的输出是否在综合中被优化了? DoRead输入不是驱动的,这可能是原因,但没有偷看KeyboardController代码,它只是一种预感。

答案 2 :(得分:-1)

续(新问题)

我会从这里继续而不是打开一个新话题。如果我这样做错了,请纠正我的错误。

我的所有代码编译成功,但我认为与我所写的内容和原理图显示的内容不一致。

这是我的顶级模块:

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

entity TopModule is
    generic ( REGSIZE  : integer := 16);
    Port (Clk        : in STD_LOGIC;
            Reset      : in std_logic; -- System Reset
            PS2_Clk    : in std_logic; -- Keyboard Clock Line
            PS2_Data   : in std_logic; -- Keyboard Data Line
            ANODES     : out STD_LOGIC_VECTOR(3 downto 0);
            SEGMENTS   : out STD_LOGIC_VECTOR(6 downto 0));
end TopModule;

architecture Top_arch of TopModule is

    component clkdivide is
        Port (clkin: in std_logic;
                clkout:out std_logic );
    end component;

    component SevenSegmentController is
        Port (  CLK: in std_logic;
                    DEC1, DEC2, DEC3, DEC4: in std_logic_vector(7 downto 0);
                    SEGMENTS: out std_logic_vector(6 downto 0);
                    ANODES: out std_logic_vector(3 downto 0));
    end component;

    component KeyboardController is
        port (Clk : in std_logic; -- System Clock
                Reset : in std_logic; -- System Reset
                PS2_Clk : in std_logic; -- Keyboard Clock Line
                PS2_Data : in std_logic; -- Keyboard Data Line
                DoRead : in std_logic; -- From outside when reading the scan code
                Scan_Err : out std_logic; -- To outside : Parity or Overflow error
                Scan_DAV : out std_logic; -- To outside when a scan code has arrived
                Scan_Out : out std_logic_vector(7 downto 0));
    end component;

    component shifter is
        port (clk      : in  std_logic;
                Scan_Dav : in  std_logic;
                Data_in  : in  std_logic_vector(7 downto 0);
                Data_out : out reg_array );
    end component;

    signal clk2, scandav, scanerr, doread: std_logic;
    signal sarray: reg_array;
    signal datain: std_logic_vector(7 downto 0);

    begin
        L1: SevenSegmentController 
            port map (SEGMENTS=> SEGMENTS, CLK=> clk2, ANODES=> ANODES,
            DEC1=> sarray(15), DEC2=> sarray(14),
            DEC3=> sarray(13),DEC4=> sarray(12));

        L2: clkdivide 
            port map (clkin=>Clk , clkout=>clk2);

        L3: KeyboardController 
            port map (Clk=> clk2, Reset=> Reset, PS2_Clk=> PS2_Clk,
            PS2_Data=> PS2_Data, DoRead=> doread, Scan_Err=> scanerr,
            Scan_DAV=> scandav, Scan_Out=>datain);

        L4: shifter
            port map (clk=>clk2, Scan_Dav=>scandav, Data_in=> datain, 
            Data_out=>sarray);
end Top_arch;

这是RTL原理图: RTL of Top Module

组件没有相互链接,键盘接口的输出应该指向移位器,然后移位到七段控制器,但移位器本身就是全部。这有什么问题?