3

我正在尝试在 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.
4

3 回答 3

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 

看起来您的代码中可能还有更多错误,但其中一些错误可能是此问题的级联错误。

于 2012-12-11T20:48:04.437 回答
0

我还无法添加评论,所以我必须添加另一个答案。快速查看,我认为您的顶级没有任何严格的错误。我怀疑 RTL 输出是优化的受害者。具体来说,是否KeyboardController在综合中优化了输出?DoRead输入不是驱动的,这可能是原因,但不看键盘控制器代码,它只是一种预感。

于 2012-12-11T22:22:16.960 回答
-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

各部件互不相连,键盘接口的输出要先接到移位器,再到移位器到七段控制器,但移位器都是独立的。这里有什么问题?

于 2012-12-11T21:31:16.383 回答