关于输入的输出仿真延迟

时间:2019-07-31 10:52:29

标签: vhdl modelsim

我正在制作一个包含普通入口和出口的多层停车场系统模块,其想法是,当我从信号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;

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

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

1 个答案:

答案 0 :(得分:0)

首先,一些评论:

  • 您的应用程序(多层停车场)不太适合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通信,处理单元...