2016-03-22 107 views
0

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

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

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

Cropped simulation output

Original simulation output

我采用Altera的Quartus总理精简版版。

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

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; 
+0

SO不适合您的“问题”。有关代码评论,请使用http://codereview.stackexchange.com/。哦,你不会向我们展示你正在使用的测试平台。 – damage

+1

创建与clk,Sin和Sout上的波形文件上的事件相匹配的测试台我得到了一个不同的结果(http://i.stack.imgur.com/eTHE9.png)。您似乎有一个工具使用问题,或应用模拟刺激方法的问题。还要注意,Ncarros不是时钟事件驱动的,而是每次在敏感列表元素上增加唯一事件。 – user1155120

+0

你的问题不是[最小,完整和可验证的例子](http://stackoverflow.com/help/mcve)没有提供重复显示在你的波形文件中的问题的方法。 – user1155120

回答

0

当你与一个矢量波形文件(VWF)模拟中,Quartus-II实际上模拟综合网表(采用Quartus-II 13.1这里检查)的行为。如果你还没有运行“分析&综合”步骤,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 Edition包含ModelSim Altera版本的安装。您可以直接在Quartus项目设置中使用ModelSim来设置和启动仿真。模拟输出使用我的测试平台第200纳秒如下:

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中,锁存器使用look-实施查找表(LUT)和逻辑元件(LE)内的组合反馈路径。编程FPGA后,这种锁存器的状态是不确定的。综合网表的模拟显示这是'X'es。

我推荐您修复锁存器,并将您的代码转换为完全同步的时钟边驱动设计。也就是说,仅在时钟的上升沿为cancelaNcarros分配新值。 VHDL代码模式是:

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

IEEE Std 1076.6-2004(RTL Synth,撤回)5.验证方法,第2段*使用模拟验证合成结果的过程包括将等效输入应用于原始模型和合成模型,然后比较它们的输出以确保它们是等同的。在这种情况下,等同意味着综合工具应在模型的输入端口,输出端口和双向端口生成一个等效的电路.... *请参阅1.2.2工具合规性c)(需要验证)。这种合成不会符合(因为组合锁存启用)。 – user1155120