【问题标题】:Delay in Simulation of Output with regard to Input输出相对于输入的仿真延迟
【发布时间】:2019-07-31 10:52:29
【问题描述】:

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

【问题讨论】:

  • 我不太明白你的问题。您的模拟行为似乎不错。
  • @Gautitho 请参考链接中的图片,每当Ent_Car_type 被强制为一个值时,输出Status 就会显示下一个时钟周期的变化。我希望输出显示相同时钟周期内的变化,即给出变化输入时。

标签: vhdl modelsim


【解决方案1】:

首先,一些cmets:

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

【讨论】:

  • 如果您需要更多解释,请不要犹豫:)
  • 谢谢! @ Gautitho,这是我想要的工作,是的,我是 VHDL 的初学者,从顺序编程转移。很难理解流程,你能解释一下你的方法是如何工作的吗?就像我无法掌握代码的执行流程一样。
  • 你提到我的编码风格有点太高级了,你能指定预期的内容吗,提前谢谢。
  • 当您编写 VHDL 代码时,您必须始终牢记与您的代码对应的数字电路。从执行流程的角度思考是一个错误:它不是您正在执行的程序,而是您正在描述的数字电路。如果我们简化很多:在一个程序中,每一行都是顺序执行的(一个接一个);在 VHDL 中,每一行都是同时“执行”的(与其他行同时执行)。在示例中,第一个进程 SEQ 将创建触发器(内存,在时钟沿可用的输出),第二个 SLOT_CHECKING 是纯粹的组合(计算,输出立即可用)。
  • 哦,您指出的差异很大,谢谢您,从现在开始,我将研究这个观点。如果我是正确的,这更像是在编写 VHDL 代码时考虑到数字电路。
猜你喜欢
  • 1970-01-01
  • 2021-02-27
  • 1970-01-01
  • 2022-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多