停车场门的模拟中的未知值(X)

时间:2016-03-22 23:52:56

标签: vhdl simulation quartus

我正在用VHDL设计一个停车场门。当我使用Quartus VWF文件模拟它时,我得到未知值(X),但我不知道为什么。

基本上你只需要验证你的卡(Sin)并且门打开10秒钟。 当一辆汽车驶离停车场(Sout)时,它会计算停车场内的汽车总数。 我为计时器创建了信号Ncarros(计算汽车数量)和s_count

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

Cropped simulation output

Original simulation output

我正在使用Altera Quartus Prime Lite版。

有人可以检查我的代码并告诉我我做错了什么吗?

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;

1 个答案:

答案 0 :(得分:1)

当您使用矢量波形文件(VWF)进行模拟时,Quartus-II实际上模拟了综合网表的行为(在此处使用Quartus-II 13.1进行检查)。如果您还没有运行“Analysis&amp; 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的模拟输出如下:

simulation output

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

在您的VHDL代码中,您描述了信号cancelaNcarros的锁存器,同样也报告了“分析与合成”步骤:

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”。

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

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