电路跟踪算法

问题描述

我试图编写用于跟踪电子电路的脚本,其中包括AND与OR之类的逻辑门...我想知道我电路的输出信号。 此图显示了这样的电路。

enter image description here

在我的脚本中:

  1. 每个门都是AND,OR,NOR,NAND类的实例
  2. 类包括允许将门与输入A,B或输出Y连接的方法
  3. 每个门实例具有唯一的名称
  4. 每个门的输入为[实例名称] / [A或B],输出为[实例名称] / [Y]
  5. 有带网的清单

从输入到输出跟踪这种电路,了解输出信号的最佳方法是什么?

解决方法

您可以均衡电路,以确定门评估的正确顺序。在计算门输出之前,必须知道门的所有输入。

级别化将门分为相同级别的集合。如果已经评估了其先前的等级,则可以计算后续等级。从一开始就知道主输入线和恒定输入的电平最小。

来自Levelized Simulation chapter的伪代码:

Levelize(MyCircuit) {
  SET ReadyGates,ReadyNets;
  GATE g;
  NET  n;

  ReadyGates = TheEmptySet;
  ReadyNets  = TheEmptySet;

  For all primary inputs n of MyCircuit do
    n.level = 0;

    For all gates g in the fanout of n do
      If all inputs of g have level numbers Then
        Add g to ReadyGates;
      EndIf            
    EndFor         
  EndFor         
  
  Repeat for constant one,constant zero signals;       
  
  While ReadyGates is not Empty or ReadyNets is not Empty do
    If ReadyGates is not Empty Then
      Select gate g and remove it from ReadyGates;
      MaxLevel = 0;

      For each net n which is an input to g do
        If n.Level > MaxLevel Then MaxLevel = n.Level;
      EndFor               
      g.Level = MaxLevel + 1;

      For each output n of g do
        If all driving gates of n have level numbers Then
          Add n to ReadyNets
        EndIf
      EndFor            
    EndIf            
    
    If ReadyNets is not Empty Then
      Select Net n and remove it from ReadyNets;
      MaxLevel = 0;
      For each driving gate g of n do
        If g.Level > MaxLevel Then MaxLevel = g.Level; 
      EndFor
      n.Level = MaxLevel;
      For gate g in the fanout of n do
        If all inputs of g have level numbers Then
          Add g to ReadyGates
        EndIf               
      EndFor            
    EndIf         
  EndWhile      
} 

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...