关于输入的输出模拟延迟

Delay in Simulation of Output with regard to Input

我正在制作一个包含公共入口和出口的多层停车场系统模块,想法是,当我从信号 car entrycar exit 获得输入刺激时,它将检查汽车的类型,然后输出应显示为特定类型保留的级别,汽车应该去哪里,如果为特定类型保留的插槽已满,则显示应如此输出。代码通过输出得到刺激,仅在输入刺激给出后的下一个时钟周期后显示。

我试过使用不同的 if-else 块来计算操作,也尝试过使用标志的不同进程,并尝试将其更改为不同的 if-else 块,但它仍然是一样的。我是vhdl新手,语句的执行比较混乱,网上搜索也帮不上什么忙,请大神指点我是哪里出错了?

library ieee;
    use ieee.std_logic_1164.all;
    use ieee.Numeric_std.all; 
            use work.Parking_Package.all;

entity CarPark is 
port(     clk :in std_logic;
      rst : in std_logic;
      car_in : in std_logic;
      Car_out : in std_logic;
      Ent_car_type : car_type;
          Ext_car_type : car_type;
      Status : out level
    );
end CarPark;

architecture behave of CarPark is 
signal count : counter;
begin         
SLOT_CHECKING: process(rst,clk)
begin 
        if(rst= '1')then
    count <= (others => 0);
    Status <= FULL;

        elsif(rising_edge(clk))then
    if(car_in )then       
                     case(Ent_car_type)is                                    
    when Admin =>                                            
                    if(count(Admin) < 5) then                                                
                            Status <= L1;                                                
                            count(Admin) <= count(Admin) +1;
        else
                         Status <= FULL;                                 
                    end if;
    when Staff =>
         if(count(Staff) < 5) then
            Status <= L2;
            count(Staff) <= count(Staff) + 1;
        else
          Status <= FULL;
               end case;                                                                         
            end if;
      elsif(car_out)then                                 
            case(Ext_car_type)is                                     
        when Admin =>                                            
                            if(count(Admin) >0) then
               Status <= L1a;
               count(Admin) <= count(Admin) - 1;
            else
               count(Admin)<= 0;                  
            end if;
        when Staff =>
            if(count(Staff) >0) then
                Status <= L2a;
                count(Staff) <= count(Staff) - 1;
            else
                count(Staff) <= 0;  
            end if;
     end process;
 end behave;

用户自定义包如下

library ieee;
        use ieee.std_logic_1164.all;
        use ieee.Numeric_std.all;
package Parking_Package is

     type car_type is (Admin, Staff);

     type level is (L1, L2a, FULL);

     type counter is array (Staff downto Admin) of integer range 0 to 22;

     end Parking_Package;

package body Parking_Package is

end Parking_Package;

使用重置初始化后,我将 car_in 的输入设为 1 并且 car_type 作为管理员,输出在 下一个时钟 中显示为 L1 如果我将car_type的值强制为staff,则在下一个时钟周期模拟相应的输出。

![截图模拟]https://imgur.com/a/B6cqADn

首先,一些评论:

  • 您的应用程序(MultiLevel Car Parking)不是很适应VHDL语言。级别太高了您的编码风格有点面向对象(类型和变量名)。
  • 您的代码中存在语法错误(我假设您已经知道了,因为您实现了模拟屏幕)。
  • 您在第一个时钟周期上预期的行为意味着您的输出将是组合逻辑的产物。最好直接从触发器输出。

然后您可以使用 2 个过程(一个纯顺序,另一个纯组合)获得预期行为的代码:

    signal current_count        : counter;
    signal next_count           : counter;
    signal current_status       : level;
    signal next_status          : level;

begin

    SEQ : process(rst_tb, clk_tb)
    begin

        if (rst_tb = '1') then

            current_count   <= (others => 0);
            current_status  <= FULL;

        elsif (rising_edge(clk_tb)) then

            current_count   <= next_count;
            current_status  <= next_status;

        end if;

     end process;

     SLOT_CHECKING : process(current_count, current_status, car_in, car_out, Ent_car_type, Ext_car_type)
     begin

        next_count  <= current_count;
        next_status <= current_status;

        if (car_in = '1') then       

            case (Ent_car_type) is

                when Admin =>                                            
                    if (current_count(Admin) < 5) then                                                
                        next_status         <= L1;                                                
                        next_count(Admin)   <= current_count(Admin) + 1;
                    else
                        next_status         <= FULL;                                 
                    end if;

                when Staff =>
                    if (current_count(Staff) < 5) then
                        next_status         <= L2;
                        next_count(Staff)   <= current_count(Staff) + 1;
                    else
                        next_status         <= FULL;                                                                       
                    end if;

            end case;

        elsif (car_out = '1') then    

            case (Ext_car_type) is  

                when Admin =>                                            
                    if (current_count(Admin) > 0) thenremarques
                        next_status         <= L1a;
                        next_count(Admin)   <= current_count(Admin) - 1;
                    else
                        next_count(Admin)   <= 0;                  
                    end if;

                when Staff =>
                    if (current_count(Staff) > 0) then
                        next_status         <= L2a;
                        next_count(Staff)   <= current_count(Staff) - 1;
                    else
                        next_count(Staff)   <= 0;  
                    end if;

            end case;

         end if;

    end process;

    count   <= next_count   ;
    Status  <= next_status  ;

警告,使用此代码,输出直接来自组合逻辑:不推荐这样做,但这是获得预期行为的唯一方法。

如果这个应用只是一个练习,我也建议你再举一个更适合 VHDL 的例子:过滤器,SPI 通信,处理单元,...