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

Vhdl 停车场大门模拟中的未知值(X),vhdl,simulation,quartus,Vhdl,Simulation,Quartus,我正在用VHDL设计一个停车场大门。当我使用Quartus VWF文件模拟它时,我得到了未知值(X),但我不知道为什么 基本上,你只需验证你的卡(Sin),门就会打开10秒钟。 当一辆车离开停车场(Sout)时,它会计算停车场内当时的总车数。 我已经为计时器创建了信号Ncarros(用于计算车辆数量)和s\u count 这一切都编译正确。但当我使用VWF文件测试它时,我得到的是: 我用的是Altera Quartus Prime Lite版 有人能检查我的代码并告诉我我做错了什么吗 lib

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

基本上,你只需验证你的卡(
Sin
),门就会打开10秒钟。 当一辆车离开停车场(
Sout
)时,它会计算停车场内当时的总车数。 我已经为计时器创建了信号
Ncarros
(用于计算车辆数量)和
s\u count

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

我用的是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;
IEEE库;
使用IEEE.STD_LOGIC_1164.all;
使用IEEE.NUMERIC_STD.all;
实体微处理机
端口(时钟:在标准逻辑中;
Sin:标准逻辑;
来源:标准逻辑;
cancela:输出标准逻辑;
时间路由:输出标准逻辑);
末端微探针;
microj-is的体系结构
信号Ncarros:整数:=0;
信号s_计数:整数:=0;
开始
过程(Sin、Sout、clk)
开始
如果(Sin='0'),则

cancela当您使用矢量波形文件(VWF)进行模拟时,Quartus II实际上模拟了合成网表的行为(此处使用Quartus II 13.1进行了检查)。如果您尚未运行“分析与合成”步骤,Quartus会要求您这样做。在再次模拟VWF之前更改VHDL文件时,必须始终手动运行此步骤。合成的网表以Verilog代码的形式输出,该代码将作为ModelSim模拟器的输入。您可以在文件
simulation/qsim/microj.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;
在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;

因此,这不是你提出“问题”的正确地点。对于代码审查,请使用。哦,你没有向我们展示你正在使用的测试台。创建一个测试台来匹配你的clk、Sin和Sout波形文件中的事件,我得到了一个不同的结果。您似乎有工具使用问题,或者应用模拟刺激的方法有问题。还要注意的是,Ncarros不是时钟事件驱动的,而是为Sensitivity列表元素上的每个时间唯一事件递增。您的问题不是没有提供一种方法来复制波形文件中显示的问题。@user1155120仅供参考:可以使用Quartus复制模拟输出,因为合成的网络列表是模拟的使用VWF文件时,可以使用VWF文件指定测试台。IEEE Std 1076.6-2004(RTL Synth,撤销)5。验证方法,第2段使用仿真验证合成结果的过程包括将等效输入应用于原始模型和合成模型,然后比较其输出,以确保其等效。在本文中,等效意味着合成工具应产生在模型的输入、输出和双向端口等效的电路。。。。见1.2.2工具合规性c)(需要验证)。这种合成不符合要求(因为组合锁存启用)。
process(clk)
begin
  if rising_edge(clk) then
    -- put all your assignments to cancela and Ncarros here
  end if;
end process;