【问题标题】:VHDL code runs but timing diagram shows nothingVHDL 代码运行,但时序图没有显示任何内容
【发布时间】:2014-12-01 02:47:51
【问题描述】:

我正在尝试在 DesignWorks 5 的 VHDL 中实现 16 * 37 的高速缓存。代码如下。 代码运行,但是当我从 IO 面板更改值甚至模拟时,时序图什么也没有显示,基本上代码由于某种原因没有运行。任何建议都会很有帮助。

代码:

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;

entity Cache is
port(cs, r, clr : in std_logic;
    data : in std_logic_vector(31 downto 0);
    addr : in std_logic_vector(7 downto 0);
    cline : out std_logic_vector(31 downto 0);
    ctag: out std_logic_vector(3 downto 0);
    v : out std_logic);
end Cache;

architecture behav of Cache is
type RAM is array (0 to 15) of std_logic_vector(36 downto 0); 
begin 
 process is
 variable M : RAM; 
 variable locn : natural; 
 variable temp_val : std_logic_vector(36 downto 0); 
 variable cline_val : std_logic_vector(31 downto 0);
 variable ctag_val : std_logic_vector(3 downto 0);
 variable v_val : std_logic;
    begin

        if cs = '1' then
            locn := to_integer(addr); 
            if r = '1' then 
                temp_val := M(locn); 
                cline_val := temp_val(31 downto 0);
                ctag_val := temp_val(35 downto 32);
                v_val := temp_val(36);
            else
                temp_val(31 downto 0) := data;
                temp_val(35 downto 32) := addr(3 downto 0);
                temp_val(36) := '1';
                M(locn) := temp_val;
                v_val := 'Z'; 
                ctag_val:= "ZZZZ"; 
                cline_val:= "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";
            end if; 
        end if; 
        if clr ='1' then
            locn := 0;
            while(locn<16) loop
                M(locn) := X"000000000" + "0";
                locn:=locn+1;
            end loop;
        end if;
    cline <= cline_val; 
    ctag <= ctag_val;
    v <= v_val;
    wait on cs; 
end process;

end behav;

【问题讨论】:

  • 此代码无法合成...我也更喜欢某种注释行或解释,尤其是对于单字符标识符,因此 SF 上的其他读者可以理解您的代码。

标签: caching vhdl ram timing-diagram


【解决方案1】:

这一行:

M(locn) := X"000000000" + "0"; 

看起来不正确。

M 是您的 ram 数组类型,元素长度为 37。添加到零的 36 位零仍然是 36 位(看起来您没有到达此语句,这将是运行时错误)。

要制作一个长度为 37 的 '0' 值向量,请使用 `(others => '0')。

你也可以使用 for 循环来清除内存,你不需要使用 16 的索引,它超出了范围,这告诉我们你也没有达到清除。

我认为你应该向我们展示你的刺激,否则你的问题将无法重现。

您缺少的dataaddr 作为敏感度元素(是的,您使用cs 环绕,但您想在这里构建一个硬件模型)。

切换到敏感列表(cs, data, addr)

locn 是一个不受约束的自然值,应该具有与数组类型 ram 匹配的范围(0 到 15)。注意你的 while 循环达到 16。真的,使用 for 循环(如下所示)。约束locn的原因是为了防止访问ram(locn)时出现绑定错误。

注意将 addr 转换为自然 (locn),您需要使用 AND 屏蔽 addr,长度为 '1' 的四次运行,以防止正常 ram 操作出现范围错误。

numeric_std 包是做作的,它比在分析和阐述过程中将几个命令行选项传递给 ghdl (ieee=synopsys -fexplict) 更容易。

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity cache is
    port (
        cs, r, clr: in  std_logic;
        data:       in  std_logic_vector(31 downto 0);
        addr:       in  std_logic_vector(7 downto 0);
        cline:      out std_logic_vector(31 downto 0);
        ctag:       out std_logic_vector(3 downto 0);
        v:          out std_logic
    );
end entity;

architecture behav of cache is
    type ram is array (0 to 15) of std_logic_vector(36 downto 0);    
begin 

    process (cs, data, addr)
        variable m : ram; 
        variable locn : natural range (ram'range); 
        variable temp_val : std_logic_vector(36 downto 0); 
        variable cline_val : std_logic_vector(31 downto 0);
        variable ctag_val : std_logic_vector(3 downto 0);
        variable v_val : std_logic;
    begin
        if cs = '1' then
            locn := to_integer(unsigned(addr and x"0F")); 
            if r = '1' then 
                temp_val := m(locn); 
                cline_val := temp_val(31 downto 0);
                ctag_val := temp_val(35 downto 32);
                v_val := temp_val(36);
            else
                temp_val(31 downto 0) := data;
                temp_val(35 downto 32) := addr(3 downto 0);
                temp_val(36) := '1';
                m(locn) := temp_val;
                v_val := 'Z'; 
                ctag_val:= "ZZZZ"; 
                cline_val:= (others => 'Z');
            end if; 
        end if; 
        if clr ='1' then
            for i in ram'range loop
                m(i) := (others => '0');
            end loop;
        end if;
        cline <= cline_val; 
        ctag <= ctag_val;
        v <= v_val;
    end process;
end architecture;

这段代码分析和阐述,你可能在我没有提到的地方出现错误,并且在运行时在赋值中出现绑定(范围)错误(表达式无关紧要)。

最后一点:

            temp_val(31 downto 0) := data;
            temp_val(35 downto 32) := addr(3 downto 0);
            temp_val(36) := '1';

可以表示:

            temp_val:= '1' & addr(3 downto 0) & data;

还有:

            locn := to_integer(addr);

表示为:

            locn := to_integer(addr(3 downto 0));

如果您使用泛型设置 ram 大小,您还可以从 ram'range 创建一个长度通过算法定义的 AND 掩码。

在没有看到您的刺激的情况下,有几个地方可能会导致运行时错误。检查您的控制台输出。

【讨论】:

    猜你喜欢
    • 2021-09-22
    • 2023-03-24
    • 2012-09-07
    • 2017-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多