【问题标题】:Input assignment in testbench and output values (ghdl and gtkwave)测试台中的输入分配和输出值(ghdl 和 gtkwave)
【发布时间】:2016-03-25 20:59:03
【问题描述】:

我直接说细节。

我正在使用 Ubuntu 14.04LTS、GHDL 编译器和 GTKWave 进行仿真。

我有两个文件用于模拟简单的 2-multiplexer:mux2.vhd 和 mux2_testbench.vhd

这是 mux2.vhd 的代码

-- Libraries

library ieee;
use ieee.std_logic_1164.all;


-- Entity declaration

entity mux2 is

    port(
        e0, e1 : in std_logic;
        c : in std_logic;
        output : out std_logic
    );

end mux2;


-- Architecture declaration

architecture mux2_arch of mux2 is

    begin
    process (e0, e1, c)

        begin
        if c = '0' then
            output <= e0;
        else
            output <= e1;
        end if;
    end process;
end mux2_arch;

测试平台代码

--Libraries

library ieee;
use ieee.std_logic_1164.all;

--Empty entity for simulation

entity mux2_testbench is
end mux2_testbench;

architecture testbench_arch of mux2_testbench is
    component test is
        port(
            c : in std_logic;
            e0, e1 : in std_logic;
            output : out std_logic
        );
    end component;

    signal c: std_logic;
    constant clk: time:=50 ns;
    signal e0: std_logic;
    signal e1: std_logic;
    signal output: std_logic;

    begin
        lab: test
        port map(
            c => c,
            e0 => e0,
            e1 => e1,
            output => output
        );



        process
        begin

            --Case 1: Control signal is low
            c <= '0';

            e0 <= '0';
            e1 <= '0';
            wait for 100 ns;
            e0 <= '0';
            e0 <= '1';
            wait for 100 ns;
            e0 <= '1';
            e0 <= '0';
            wait for 100 ns;
            e0 <= '1';
            e0 <= '1';
            wait for 100 ns;

            --Case 2: Control signal is high
            c <= '1';

            e0 <= '0';
            e1 <= '0';
            wait for 100 ns;
            e0 <= '0';
            e0 <= '1';
            wait for 100 ns;
            e0 <= '1';
            e0 <= '0';
            wait for 100 ns;
            e0 <= '1';
            e0 <= '1';
        end process;

end testbench_arch;

我正在做的事情:

我通过终端编译没有错误: ghdl -a mux2.vhdghdl -a mux2_testbench.vhd

然后,我为测试平台创建可执行文件: ghdl -e mux2_testbench

最后,我创建了我需要使用 gtkwave 的 vcd 文件: ghdl -r mux2_testbench --vcd=test.vcd &

模拟: gtkwave test.vcd

这段代码有两个问题: 1. 即使我在信号 e0 和 e1 中写入不同的值,e1 在模拟中也没有显示任何内容。它始终为“0”。

  1. 输出信号在模拟中显示值“U”,我什至不确定这是什么意思,也无法在 Google 中找到任何明确的信息。

提前谢谢大家了,朋友们。

【问题讨论】:

  • 哪一行向 e1 写入了除 '0' 以外的任何内容?我看不到...是否存在复制/粘贴错误?此外,我没有看到组件“测试”的实体/拱门。
  • 请格式化您的代码。

标签: vhdl ghdl gtkwave


【解决方案1】:

根据 Brian 的评论,我添加了一个配置规范以使用 mux2 而不是在测试台中进行测试:

architecture testbench_arch of mux2_testbench is
    component test is
        port (
            c:       in  std_logic;
            e0, e1:  in  std_logic;
            output:  out std_logic
        );
    end component;

    signal c:       std_logic;
    constant clk:   time := 50 ns;
    signal e0:      std_logic;
    signal e1:      std_logic;
    signal output:  std_logic;

    for lab: test use entity work.mux2; -- added

begin
lab: 
    test
        port map (
            c => c,
            e0 => e0,
            e1 => e1,
            output => output
        );

    process
    begin

        --Case 1: Control signal is low
        c <= '0';

        e0 <= '0';
        e1 <= '0';
        wait for 100 ns;
        e0 <= '0';
        e0 <= '1';
        wait for 100 ns;
        e0 <= '1';
        e0 <= '0';
        wait for 100 ns;
        e0 <= '1';
        e0 <= '1';
        wait for 100 ns;

        --Case 2: Control signal is high
        c <= '1';

        e0 <= '0';
        e1 <= '0';
        wait for 100 ns;
        e0 <= '0';
        e0 <= '1';
        wait for 100 ns;
        e0 <= '1';
        e0 <= '0';
        wait for 100 ns;
        e0 <= '1';
        e0 <= '1';
        wait for 100 ns;  -- added to terminate the simulation
        wait;             -- added ""
    end process;

end architecture testbench_arch;

我还添加了两个等待语句,因此在使用--wave=testbench.ghw 而不是--vcd=test.vcd 时,模拟将在不添加--stop-time=somvalue 标志的情况下终止。

(Gtkwave 也接受 ghdl 独有的 GHW 转储文件格式,它是一种压缩格式,不能通过 CTL-C 停止模拟,否则会连续循环)。

这给出了:

请注意,根据 Matthew 的回答,e1 总是低,您仍然可以区分 output 上显示的输入,证明 c 提供了它的选择功能。

'U' 会出现,因为组件测试未绑定,实体测试未在工作库中找到。

上例中的绑定指示是由配置规范完成的。请参阅 IEEE Std 1076-2008 7.3 配置规范和 7.3.2 绑定指示。

您也可以像 Matthew 所提倡的那样使用直接实体实例化,或者通过使用包含绑定指示的配置声明,让测试组件实例化保持原样。

重用测试台的能力将受到对被测单元(实验室)输入的刺激模式的限制。

【讨论】:

    【解决方案2】:

    首先,'U'std_logic 类型的默认值。这意味着未初始化。任何未分配或未驱动的信号都将具有值'U'。我认为您的输出很可能没有被驱动,因为您已经实例化了一个名为test 的组件,而您的被测设备entity 被称为mux2。我建议将您的组件名称更改为mux2,然后默认绑定规则将使您的实体mux2绑定到组件mux2

    component mux2 is 
      port( c : in std_logic; 
            e0, e1 : in std_logic; 
            output : out std_logic );
    end component;
    

        -- this is component instantiation
        lab: mux2
        port map(
            c => c,
            e0 => e0,
            e1 => e1,
            output => output
        );
    

    所以,entitymux2 没有绑定componenttest。把component 想象成一个IC 插座;将entity 视为插入插座的IC。如果您的component 被称为test 而您的entity 被称为mux2,模拟器如何知道将两者绑定(即连接)在一起?您可以编写所谓的configuration 来执行此绑定,但将component 名称更改为mux2 会容易得多,然后这将自动发生。

    (或者更好的是,为什么要使用组件实例化?为什么要麻烦组件?为什么不使用直接实例化?)

        -- this is direct instantiation
        lab: entity work.mux2
        port map(
            c => c,
            e0 => e0,
            e1 => e1,
            output => output
        );
    

    其次,很明显你不是在驾驶 e1。当然是这样的:

        e0 <= '0';
        e0 <= '1';
    

    应该是

        e0 <= '0';
        e1 <= '1';
    --   ^
    --   |
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 2021-12-25
      • 1970-01-01
      • 2012-07-23
      • 2019-07-26
      • 1970-01-01
      相关资源
      最近更新 更多