【问题标题】:Unknown values (X) in simulation of parking lot gate停车场大门模拟中的未知值 (X)
【发布时间】:2016-07-10 02:33:30
【问题描述】:

我正在用 VHDL 设计一个停车场大门。当我使用 Quartus VWF 文件对其进行仿真时,我得到未知值 (X),但我不知道为什么。

基本上,您只需验证您的卡 (Sin),大门就会打开 10 秒钟。 当汽车驶出停车场 (Sout) 时,它会计算当前停车场内的汽车总数。 我为计时器创建了信号Ncarros(用于计算汽车数量)和s_count。

这一切都正确编译。但是当我使用 VWF 文件对其进行测试时,我得到的是:

Original simulation output

我正在使用 Altera Quartus Prime Lite Edition。

谁能检查我的代码并告诉我我做错了什么?

library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.all;

entity MicroProj is
    port (clk      : in std_logic;
            Sin      : in std_logic;
            Sout     : in std_logic;
            cancela  : out std_logic;
            timerOut : out std_logic);

end MicroProj;

architecture Behavioral of MicroProj is

    signal Ncarros : integer := 0;
    signal s_count : integer := 0;

begin
    process (Sin,Sout,clk)
    begin
        if (Sin = '0') then
            cancela <= '0';
        else
            if (Ncarros < 99) then
                Ncarros <= Ncarros + 1;
                cancela <= '1';

                if(rising_edge(clk)) then
                    if(s_count /= 0) then
                        if(s_count = 499999999) then
                            timerOut <= '1';
                            s_count <= 0;
                        else
                            timerOut <= '0';
                            s_count <= s_count + 1;
                        end if;
                    else
                        timerOut <= '0';
                        s_count <= s_count + 1;
                    end if;
                end if;
            end if;
        end if;

        if (Sout ='1') then
            Ncarros <= Ncarros - 1;
        end if;
    end process;


end Behavioral;

【问题讨论】:

  • SO 不适合您的“问题”。对于代码审查,请使用 codereview.stackexchange.com。哦,你没有向我们展示你正在使用的测试平台。
  • 创建一个与 clk、Sin 和 Sout 上的波形文件上的事件匹配的测试台我得到了不同的result。您似乎有工具使用问题,或者应用模拟刺激的方法有问题。另请注意,Ncarros 不是时钟事件驱动的,而是在敏感列表元素上的每次唯一事件时递增。
  • 你的问题不是Minimal, Complete, and Verifiable example 没有提供一种方法来复制波形文件中显示的问题。
  • @user1155120 仅供参考:可以使用 Quartus 重现仿真输出,因为使用 VWF 文件时会仿真合成的网表。
  • @damage 在 Quartus 中,您可以使用 VWF 文件指定测试台。

标签: vhdl simulation quartus


【解决方案1】:

当您使用矢量波形文件 (VWF) 进行仿真时,Quartus-II 实际上会仿真合成网表的行为(在此处使用 Quartus-II 13.1 进行检查)。如果您还没有运行“Analysis & Synthesis”步骤,Quartus 会要求这样做。在再次模拟 VWF 之前更改 VHDL 文件时,您必须始终手动运行此步骤。合成的网表作为 Verilog 代码写出,将作为 ModelSim 模拟器的输入。您可以在文件simulation/qsim/microproj.vo 中找到它。

只要 Quartus 报告警告(或错误),综合设计的行为就可能与 VHDL 描述不同。 这就是下面所指出的情况。要直接模拟 VHDL 描述的行为,您必须编写一个测试平台。

以下测试平台将是一个很好的入门。它为前 200 ns 分配与 VWF 文件中相同的输入值。您必须在指定位置扩展代码以添加更多信号转换。

library ieee;
use ieee.std_logic_1164.all;

entity microproj_tb is
end entity microproj_tb;

architecture sim of microproj_tb is

  -- component ports
  signal clk      : std_logic := '0';
  signal Sin      : std_logic;
  signal Sout     : std_logic;
  signal cancela  : std_logic;
  signal timerOut : std_logic;

begin  -- architecture sim

  -- component instantiation
  DUT: entity work.microproj
    port map (
      clk      => clk,
      Sin      => Sin,
      Sout     => Sout,
      cancela  => cancela,
      timerOut => timerOut);

  -- clock generation
  clk <= not clk after 10 ns;

  -- waveform generation
  WaveGen : process
  begin
    Sin  <= '0';
    Sout <= '0';
    wait for 40 ns; -- simulation time =  40 ns
    Sin  <= '1';
    wait for 70 ns; -- simulation time =  110 ns
    Sin  <= '0';
    wait for 50 ns; -- simulation time =  160 ns
    Sin  <= '1';

    -- Extend here to add more signal transistions
    wait;
  end process WaveGen;
end architecture sim;

Quartus Prime Lite 版包括 ModelSim Altera 版的安装。您可以直接在 Quartus 项目设置中使用 ModelSim 设置和启动仿真。使用我的测试平台的前 200 ns 的模拟输出如下:

如您所见,输出与您对 VWF 文件的仿真不同,因为现在仿真的是 VHDL 设计本身。


在您的 VHDL 代码中,您描述了信号 cancela 和 Ncarros 的锁存器,“分析与综合”步骤也报告了这一点:

Warning (10492): VHDL Process Statement warning at MicroProj.vhdl(26): signal "Ncarros" is read inside the Process Statement but isn't in the Process Statement's sensitivity list
Warning (10492): VHDL Process Statement warning at MicroProj.vhdl(27): signal "Ncarros" is read inside the Process Statement but isn't in the Process Statement's sensitivity list
Warning (10492): VHDL Process Statement warning at MicroProj.vhdl(48): signal "Ncarros" is read inside the Process Statement but isn't in the Process Statement's sensitivity list
Warning (10631): VHDL Process Statement warning at MicroProj.vhdl(21): inferring latch(es) for signal or variable "cancela", which holds its previous value in one or more paths through the process
Warning (10631): VHDL Process Statement warning at MicroProj.vhdl(21): inferring latch(es) for signal or variable "Ncarros", which holds its previous value in one or more paths through the process

Info (10041): Inferred latch for "Ncarros[0]" at MicroProj.vhdl(20) 
Info (10041): Inferred latch for "Ncarros[1]" at MicroProj.vhdl(20) 
Info (10041): Inferred latch for "Ncarros[2]" at MicroProj.vhdl(20) 
... 
Info (10041): Inferred latch for "Ncarros[31]" at MicroProj.vhdl(20) 
Info (10041): Inferred latch for "cancela" at MicroProj.vhdl(20)

在 Altera FPGA 上,使用查找表 (LUT) 和逻辑元件 (LE) 内的组合反馈路径来实现锁存器。这种锁存器的状态在对 FPGA 进行编程后是未定义的。合成网表的模拟显示为“X”。

我建议无论如何都要修复锁存器,并将您的代码转换为完全同步、时钟沿驱动的设计。也就是说,仅在时钟的上升沿为cancela 和Ncarros 分配新值。 VHDL 代码模式是:

process(clk)
begin
  if rising_edge(clk) then
    -- put all your assignments to cancela and Ncarros here
  end if;
end process;

【讨论】:

  • IEEE Std 1076.6-2004(RTL Synth,已撤销) 5. 验证方法,第 2 段 使用仿真验证综合结果的过程包括将等效输入应用于原始模型和综合模型然后比较它们的输出以确保它们是等效的。在这种情况下,等效意味着综合工具应生成在模型的输入、输出和双向端口处等效的电路...... 参见 1.2.2 工具合规性 c)(需要验证)。这种综合将不符合要求(因为启用了组合锁存器)。
猜你喜欢
  • 2021-04-20
  • 2016-02-08
  • 2021-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多