绘制数字电路中的所有连接器的问题

绘制数字电路中的所有连接器的问题

我正在尝试将此数字电路转换为 Latex 代码。这是一个完整的减法器。我看到博客中还有其他人发布了相同的函数,但它以不同的形式解析电路。

我已经尝试过,目前我已经成功定位了电路的所有元件,但我无法弄清楚如何绘制所有连接器(--)。

这是我目前拥有的代码:

\documentclass[10pt,border=5mm]{standalone}
\usepackage{circuitikz}

\begin{document}
    \begin{center}
       \begin{circuitikz}[american]
            % ~~~ placing all components ~~~~~~
            \node [xnor port] (N1) at (4.0 ,0.0) {N1};
            \node [xnor port] (N2) at (8.5,-0.3) {N2};
            \node [not port]  (I1) at (5,-1.7) {I1};
            \node [not port]  (I2) at (2.5,-2.5) {I2};
            \node [and port]  (A1) at (8.5,-2.0) {A1};
            \node [and port]  (A2) at (5.0,-3.5) {A2};
            \node [or port]   (O1) at (12.0,-3.25) {O1};
            %    some ports
            \node [ocirc] (A) at (0,0.3) {A};
            \node [ocirc] (B) at (0,-0.3) {B};
            \node [ocirc] (BI) at (6,-0.6) {$B_{in}$};
            \node [ocirc] (DI) at (13,-0.35) {Diff};
            \node [ocirc] (BO) at (13,-3.25) {$B_{out}$};
        
            % ~~~ connections ~~~~~~~~~~~~~~~~
            \draw (A) -- (N1.in 1);
            \draw (B) -- (N1.in 2);
            \draw (N1.out) -- (N2.in 1);
            \draw (N2.out) -- (DI);
            \draw (O1.out) -- (BO);
            
            \draw (I1.out) -- (A1.in 1);
            \draw (1.8,0.3) node[circ]{} |- (I2.in 1);
            \draw (1.3,-0.3) node[circ]{} |- (A2.in 2);
            \draw (N1.out) node[circ]{} |- (I1.in);
            \draw (6.5, -0.6) node[circ]{} |- (A1.in 2);
            \draw (BI) node[circ]{} -- (N2.in 2);
            \draw (I2.out) -- (A2.in 1);
            \draw (A1.out) -- (O1.in 1);
            \draw (A2.out) |- (O1.in 2);
        \end{center}
         \end{circuitikz}
\end{document}

如你所见,我得到的结果是:

![电路乳胶

我尝试复制的模型是:

减法器全模型

答案1

让我们看看我是否可以帮助您学习如何绘制电路---我不会填补您代码上的空白,因为我认为它很难维护。

让我们开始吧。最佳逻辑端口形状circuitikz是 IEEE 标准形状;让我们使用它们,此外,让我们添加风格用浅青色填充。这是通过

\ctikzset{logic ports=ieee, logic ports/fill=cyan!30}

(看着那(这造型手册的一部分。我知道它很长。抱歉,你可能需要读一下;我向你保证,写它花了更多时间

答案2

这是第二种方法,不如 Rmano 的教程好,但遵循了不同的理念:

  • 不要一次性完成所有事情(尽管你可以)
  • 首先放置组件
  • 连接第二个
  • 就像你在原理图或 PCB 中所做的那样

结果远非理想,存在许多缺陷。如果结合 Rmano 的建议,您可以获得非常干净且易于阅读的代码。

草图

\documentclass[10pt,border=5mm]{standalone}
\usepackage{circuitikz}

\begin{document}
 \begin{circuitikz}[american]
    % ~~~ placing all components ~~~~~~
    \node [xnor port] (N1) at (4.0 ,0.0) {N1};
    \node [xnor port] (N2) at (8.5,-0.3) {N2};
    \node [not port]  (I1) at (6.0,-1.5) {I1};
    \node [not port]  (I2) at (2.5,-2.5) {I2};
    \node [and port]  (A1) at (8.5,-2.0) {A1};
    \node [and port]  (A2) at (5.0,-3.5) {A2};
    \node [or port]   (O1) at (11.0,-3.5) {O1};
    %    some ports
    \node [ocirc] (A) at (0,0.3) {A};
    \node [ocirc] (B) at (0,-0.3) {B};
    \node [ocirc] (DI) at (13,-0.6) {Diff};
    \node [ocirc] (BO) at (13,-3.5) {Borrow out};

    % ~~~ connections ~~~~~~~~~~~~~~~~
    \draw (A) -- (N1.in 1);
    \draw (B) -- (N1.in 2);
    \draw (N1.out) -- (N2.in 1);
    \draw (N2.out) -- (DI);
    \draw (O1.out) -- (BO);
    
    \draw (I1.out) -- (A1.in 1);
    \draw (I2.out) -- (A2.in 1);
    \draw (A1.out) -- (O1.in 1);
    \draw (A2.out) |- (O1.in 2);
 \end{circuitikz}
\end{document}

答案3

在 CTAN 上的 Circuit_macros 分布中的逻辑示例中发现了另一种方法(需要 m4 和 dpic,但可以产生 tikz 输出)。以下代码绘制了实现该功能的电路:

Autologix(
  Xor( Xor(A,B), Borrow);
  Or( And( Not(Xor(A,B)), Borrow), And( Not(A), B)),
  R)

这是严格的函数符号,画出两个 Xor(A,B) 门。要画出只有一个 Xor(A,B) 门的电路,需要进行一些调整:

    F2: Autologix(Or( And( Not(Xor(A,B)), Borrow), And( B, Not(A))),R)
      "A" wid textht at F2.InA above
      "B" wid textht at F2.InB above
      "Borrow" at F2.InBorrow+(0,3*textht) "in"
      "Borrow" wid 5*textht at F2.Out ljust "out" ljust
    F1: XOR_gate with .Out at F2.Out+(-3/2*L_unit,11*L_unit)
      line from F1.Out right 3/2*L_unit
      "Diff" wid 4*textht ljust
      line from F1.In2 to (F2.Out7,F1.In2) then to F2.Out7; dot
      dot(at F2.InBorrow+(0,-2*L_unit))
      line right_ 3*L_unit; continue to (Here,F1.In1) then to F1.In1

答案4

更让人困惑的是,此版本使用相对定位。除了 A1(直接放置在 N2 下方)之外,所有组件都相对于其入锚点或出锚点进行定位。这最大限度地减少了曲折,并使更改距离更加容易。

\documentclass[10pt,border=5mm]{standalone}
\usepackage{circuitikz}

\begin{document}
  \begin{circuitikz}[american]
    \draw (0,0) node [ocirc] (A) {} node[left] {A} -- ++(1.5,0)
          node [xnor port,anchor=in 1] (N1) {N1};
    \draw (N1.in 2) -- (N1.in 2 -| A) node [ocirc] (B) {} node[left] {B};
    \draw (N1.out) -- ++(2,0) node[xnor port, anchor=in 1] (N2) {N2};
    \draw (N2.out) -- ++(1.6,0) node[ocirc] (D1) {} node[right] {Diff};
%
    \draw (N2.in 2) node[circ]{} -- ++(-0.5,0) node[ocirc]{} node[left] {B\textsubscript{in}};
    \draw (N2) ++ (0,-1.5) node[and port] (A1) {A1};
    \draw (A1.in 2) -| (N2.in 2);
    \draw (A1.in 1) -- ++(-0.5,0) node [not port, anchor=out, scale=0.7] (I1) {I1};
    \draw (I1.in) -| (N1.out) node[circ]{};
%
    \draw (D1) ++(0,-2) node [ocirc] (BO) {} node[right]{B\textsubscript{out}}
          (BO.left) node [or port, anchor=out] (O1) {O1};
    \draw (O1.in 2) -- ++(-3,0) node [and port, anchor=out] (A2) {A2};
    \draw (A2.in 1) node [not port, anchor=out, scale=0.7] (I2) {I2};
    \draw (I2.in) -| ($(A) + (1,0)$) node[circ]{};
    \draw (A2.in 2) -| ($(B) + (0.5,0)$) node[circ]{};
%
    \draw (A1.out) |- (O1.in 1);
  \end{circuitikz}
\end{document}

演示

相关内容