首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通用vhdl简易测试平台

通用vhdl简易测试平台
EN

Stack Overflow用户
提问于 2018-02-28 09:53:14
回答 2查看 1.9K关注 0票数 0

我有非常简单的用VHDL编写的程序

代码语言:javascript
复制
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std;


entity Xand is
    generic(width   : integer:=8);
    port(   clk : in std_logic;
        A,B : in std_logic_vector(width-1 downto 0);
        C   : out std_logic_vector(width-1 downto 0)
    );
end Xand;

architecture Behavioral of Xand is
begin
    C<= A and B;
end Behavioral;

我的测试台看起来是这样的:

代码语言:javascript
复制
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

use ieee.numeric_std.all;

ENTITY Xand_tb IS
    --generic(width : integer);
END Xand_tb;

ARCHITECTURE behavior OF Xand_tb IS 

    COMPONENT Xand IS
        generic(width   : integer);
        port(   clk : in std_logic;
            A,B : in std_logic_vector(width-1 downto 0);
            C   : out std_logic_vector(width-1 downto 0)
        );
    end COMPONENT;

    signal width : integer := 8;

   -- inputs
   signal clk : std_logic := '0';
   signal A, B : std_logic_vector(width-1 downto 0) := (others => '0');

   --Outputs
   signal C : std_logic_vector(width-1 downto 0);
   constant period : time := 10 ns;

BEGIN

    -- instantiate the Unit Under Test (UUT)
   uut: Xand generic map (width => 8)
        PORT MAP (
          clk => clk,
          A => A,
          B => B,
          C => C
        );

    -- Stimulus process
   stim_proc: process
   begin        
      -- hold reset state for 100 ns.
      wait for 100 ns;  

      wait for period*10;

      for i in 0 to 2**width loop
        A <= std_logic_vector( unsigned(A) + 1 );
        for j in 0 to 2**width loop
            B <= std_logic_vector( unsigned(B) + 1 );
            wait for period;
        end loop;
        for j in 0 to width loop
            B(j) <= '0';
        end loop;
        wait for period;
      end loop;

      wait;

    end process;
END;

遗憾的是,我遇到了错误(当我想用--vcd=xand.vcd模拟它时)。

代码语言:javascript
复制
ghdl:error: overflow detected
  from: process work.xand_tb(behavior).stim_proc at Xand_tb.vhd:57
ghdl:error: simulation failed

不工作的是B(j) <= '0';线。据我所知,A和B是有8位的向量。因此,我想测试我的Xand程序的差异A和B值,从[0,256)。遗憾的是,我不知道如何使向量B等于0的方式与循环相比,这是行不通的。有人能解释一下我的泛型()做什么吗?

EN

回答 2

Stack Overflow用户

发布于 2018-02-28 11:09:23

通常,您希望驱动输入信号并验证输出是否具有预期值。

例如,在组件实例化之后,

代码语言:javascript
复制
clk <= not clk after period/2;

stim : process is
begin
   -- first test
   A <= "00000010";
   B <= "00000010";
   wait for 10 ns;
   assert C = "00000100" report "2 + 2 should be 4" severity ERROR;
   -- second test
   A <= "00000000";
   -- etc
   std.env.stop;    -- in VHDL-2008, to end the simulation
end process;

因为这是自我检查,所以通常不需要费心检查波形,除非其中一个断言报告了错误。然后,您必须进一步分析,以了解为什么输出与预期的结果不匹配,同时要记住测试有可能出错。

所以我又看了一遍。

我做到了。第57行是"end loop;",它不能溢出。

但正如ghdl所言,在此之前的线路显然已经溢出。为什么要写入8个元素数组中的9个元素?

您可以使用类型系统而不是对抗它。

代码语言:javascript
复制
for j in B'range loop

将遍历B中的所有元素,而不遍历其他任何

但是,像B <= (others => '0');这样的聚合将完全消除循环。

票数 4
EN

Stack Overflow用户

发布于 2018-02-28 13:56:20

由于@Briandrummond已经回答了您的溢出问题的解决方案,我将只回答以下问题:

有人能解释一下泛型()做什么吗?

泛型用于在实例化时定义实体行为,即将在硬件上实现的行为。它是在实体中使用默认值声明的,就像在示例中那样

代码语言:javascript
复制
entity Xand is
    generic(
       width : integer := 8                            -- generic integer value, default is 8
    );
    port(  
       A,B   : in  std_logic_vector(width-1 downto 0); -- input signals, with length equal to generic value "width"
       C     : out std_logic_vector(width-1 downto 0)  -- output signal, with length equal to generic value "width"
    );
end Xand;

在您的示例中,泛型定义了信号A、B和C的长度--这意味着当编译器创建要在ASIC或FPGA上实现的netlist时,它将创建由泛型值定义的非常长的信号。让我们看看这个实体的两个实例化:

代码语言:javascript
复制
Xand_2bits : entity work.Xand
generic map(
    width => 2
)
port map(
     A => 2bits_signal_A
    ,B => 2bits_signal_B
    ,C => 2bits_signal_C
);

Xand_default : entity work.Xand
port map(
     A => 8bits_signal_A
    ,B => 8bits_signal_B
    ,C => 8bits_signal_C
);

来自同一实体的这两个实例化将不会通过编译工具以相同的方式合成。实例Xand_2bits将被合成为以下公式:

代码语言:javascript
复制
2bits_signal_C(0) <= 2bits_signal_A(0) and 2bits_signal_B(0);
2bits_signal_C(1) <= 2bits_signal_A(1) and 2bits_signal_B(1);

只有2个and门将在您的硬件上实现。

实例Xand_default将被合成为以下公式:

代码语言:javascript
复制
8bits_signal_C(0) <= 8bits_signal_A(0) and 8bits_signal_B(0);
8bits_signal_C(1) <= 8bits_signal_A(1) and 8bits_signal_B(1);
 [...]
8bits_signal_C(6) <= 8bits_signal_A(6) and 8bits_signal_B(6);
8bits_signal_C(7) <= 8bits_signal_A(7) and 8bits_signal_B(7);

这一次,8 and门将在您的硬件上实现。

可以使用if-generate语句定义几种不同的行为。这已经解释过了,here

还可以定义不同的type。这已经解释过了,here

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49026554

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档