2

This is a follow up to this question.

He has modified the opamp such that the rectangle for the integrator appears, but I have a problem.

The people gave me a solution by removing the plus and minus (which is desired). However, the code did not take into account the number of inputs that the user wants for the analog summer and integrator (in the CircuiTikz package, one can specify the number of inputs to the logic gates). In the previous code, one just drew a line to the middle of the integrator, which is not what I want; I wanted an input sticking out of there depending on the number of inputs.

Here is what I have:

enter image description here

Corresponding equation:

enter image description here

I looked into the code in CircuiTikz for logic gates and the solution provided in the code, but the syntax is super user unfriendly to me. Can someone provide the code to do so with detailed explanation on the terms used in the code? I have no idea what many of the terms mean.

Superman
  • 1,615
  • ... These are not logic gates, they are generic linear blocks (at least in my book) - you are processing analog signals. Said that, you should be able to use the new muxes objects released in 1.0 for an almost straightforward implementation of your circuit. – Rmano Feb 27 '20 at 07:53
  • I know what you are talking about. I think I meant to say that one can vary the number of inputs for logic gates, but I don’t really see a way for op amps and linear blocks, so I wonder if one can modify the code such that one can have as many inputs as he or she wants. – Superman Feb 27 '20 at 07:55
  • And by the way, can u attach a link for me to find it? – Superman Feb 27 '20 at 07:56
  • You can with the mux-demux objects! Have a look at them here: http://circuitikz.github.io/circuitikz/circuitikzmanualgit.pdf – Rmano Feb 27 '20 at 07:56
  • I just took a look: it doesn’t have the desired shapes as I want it to be in my post, though – Superman Feb 27 '20 at 08:01
  • If you mean the rectangular block in front of the input, no, you have to do it by hand - but in the case of the integrators is quite easy. Let me a bit of time and I'll try. – Rmano Feb 27 '20 at 08:04
  • The rectangular block in front of the triangle represents integration, just saying; might if u also give that a try for the derivative symbol for the analog computer? – Superman Feb 27 '20 at 08:06

1 Answers1

3

This is a way of doing it; I am using the difference between border pins and external pins of the muxdemux component to create the boxes. If you maintain the ratio between NL, Lh and w constant you will have nice-looking objects, and of course is quite easy to encapsulate the "rectangle draw" thing into macros.

\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\begin{document}

\begin{circuitikz}[
    ]
    \tikzset{small text/.style={
            font=\tiny,
            right,
            inner xsep=1pt,
        },
    }
    % four input plain thing. I am using two pins more to give space
    % for the text
    \node[muxdemux, no input leads, muxdemux def={Lh=4, NL=6, w=4, Rh=0, NR=1}]
         (A){adder};
    \draw (A.blpin 2) node[small text]{$1$} -- ++(-1,0) node[left]{$u$};
    \draw (A.blpin 3) node[small text]{$-1$} -- ++(-0.8,0);
    \draw (A.blpin 4) node[small text]{$-1.2$} -- ++(-0.6,0);
    \draw (A.blpin 5) node[small text]{$-1.2$} -- ++(-0.4,0);
    \draw (A.brpin 1) -- ++(1,0) coordinate(one);
    % integrator  --- I use three input pins to build the rectangle
    % I use the difference between border pin and exteral pin to build the
    % square block
    \node[muxdemux, no input leads, muxdemux def={Lh=2, NL=3, w=2, Rh=0, NR=1}, anchor=lpin 2]
         (B) at(one) {$\int\quad$};
    \draw[line width=0.8pt] (B.north west -| B.lpin 2) rectangle (B.south west -| B.blpin 2);
    % notice that there is a small overshoot of the triangle for the line bevel. You can adjust for that if you want.
    \draw (B.brpin 1) -- ++(1,0) coordinate(two);
    \node [small text] at (B.lpin 2) {$1$};
    % deriver ---
    \node[muxdemux, no input leads, muxdemux def={Lh=2, NL=3, w=2, Rh=0, NR=1}, anchor=lpin 2]
         (C) at(two) {$\frac{\mathrm{d}}{\mathrm{d}\,t}\quad$} ;
    \draw[line width=0.8pt] (C.north west -| C.lpin 2) rectangle (C.south west -| C.brpin 1);
    \node [small text] at (C.lpin 2) {$1$};
    \draw (C.brpin 1) -- ++(1,0) coordinate(three);
\end{circuitikz}
\end{document}

output for the first snippet

To have a more compact thing, you can use the nice trick by Schrödinger's cat with pics and append after command; in this case, you need to add an anchor to the muxdemux that is missed (I'll add it in a next release!):

\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\makeatletter
\def\pgfaddtoshape#1#2{% https://tex.stackexchange.com/a/14772/38080
  \begingroup
  \def\pgf@sm@shape@name{#1}%
  \let\anchor\pgf@sh@anchor
  #2%
  \endgroup
}
% we need to add an anchor to muxdemux
\pgfaddtoshape{muxdemux}{
    \anchor{top left ext}{%
        \topleft\advance\pgf@x by -\extshift
}}
\makeatother
\begin{document}

\begin{circuitikz}[
    ]
    \tikzset{small text/.style={
            font=\tiny,
            right,
            inner xsep=1pt,
        },
    integral block/.style={append after command={%
        pic{inputrect}}
        },
    derivative block/.style={append after command={%
        pic{fullrect}}
        },
    pics/inputrect/.style={code={\let\mytikzlastnode\tikzlastnode
        % adjust thickness
        \draw[line width=0.8pt] (\mytikzlastnode.top left ext) rectangle (\mytikzlastnode.bottom left);}},
    pics/fullrect/.style={code={\let\mytikzlastnode\tikzlastnode
        % adjust thickness
        \draw[line width=0.8pt] (\mytikzlastnode.top left ext) rectangle (\mytikzlastnode.south east);}},
    }
    % four input plain thing. I am using two pins more to give space
    % for the text
    \node[muxdemux, no input leads, muxdemux def={Lh=4, NL=6, w=4, Rh=0, NR=1}](A){adder};
    \draw (A.blpin 2) node[small text]{$1$} -- ++(-1,0) node[left]{$u$};
    \draw (A.blpin 3) node[small text]{$-1$} -- ++(-0.8,0);
    \draw (A.blpin 4) node[small text]{$-1.2$} -- ++(-0.6,0);
    \draw (A.blpin 5) node[small text]{$-1.2$} -- ++(-0.4,0);
    \draw (A.brpin 1) -- ++(1,0) coordinate(one);
    % integrator  --- I use three input pins to build the rectangle
    % I use the difference between border pin and exteral pin to build the
    % square block
    \node[muxdemux, muxdemux def={Lh=2, NL=3, w=2, Rh=0, NR=1},
        no input leads, integral block,
        anchor=lpin 2](B) at(one) {$\int\quad$};
    % notice that there is a small overshoot of the triangle for the line bevel. You can adjust for that if you want.
    \draw (B.brpin 1) -- ++(1,0) coordinate(two);
    \node [small text] at (B.lpin 2) {$1$};
    % deriver ---
    \node[muxdemux,  muxdemux def={Lh=2, NL=3, w=2, Rh=0, NR=1},
        no input leads, derivative block,
        anchor=lpin 2](C) at(two) {$\frac{\mathrm{d}}{\mathrm{d}\,t}\quad$};
    \node [small text] at (C.lpin 2) {$1$};
    \draw (C.brpin 1) -- ++(1,0) coordinate(three);
    %
    % you can also rotate them...
    %
    \draw (B.brpin 1) ++(0.5,0) -- ++(0,1) coordinate(four);
    \node[muxdemux,  muxdemux def={Lh=2, NL=3, w=2, Rh=0, NR=1},
        no input leads, integral block,
        anchor=lpin 2, rotate=90](D) at(four) {$\int\quad$};
        \draw (B.brpin 1) ++(0.5,0) -- ++(0,-1) coordinate(five);
    \node[muxdemux,  muxdemux def={Lh=2, NL=3, w=2, Rh=0, NR=1},
        no input leads, derivative block,
        anchor=lpin 2, rotate=-90](D) at(five) {$\frac{\mathrm{d}}{\mathrm{d}\,t}\quad$};
\end{circuitikz}
\end{document}

output for the second snippet

Rmano
  • 40,848
  • 3
  • 64
  • 125