1
\documentclass{article}
%decoder
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,calc,arrows.meta}
\usepackage{circuitikz}
\usetikzlibrary{circuits.logic.IEC,calc}

\begin{document}
\begin{circuitikz}[circuit logic IEC]


\node[and gate,inputs={nnn},and gate IEC symbol={Decoder 3:8},text height=6cm,text width=4cm,
 ] (A) {};

\node[and gate,inputs={nnnnnnnn},and gate IEC symbol={},text height=6cm,text width=4cm, xscale=-1
 ] (B) {};
 \node[and gate,inputs={nn},and gate IEC symbol={},text height=6cm,text width=4cm, yscale=-1
 ] (C) {};
 
\foreach \V/\X in {3/B,2/C,1/D} 
{
  \draw  ([xshift=-10pt]A.input \V) node[left] {$\X$} -- (A.input  \V);
}
\foreach \V/\X in {3/2,2/1,1/0} 
{
  \draw  ([xshift=10pt]A.input \V) node[right] {$\X$} (A.input  \V);
}

%\foreach \T/\S in {1/0000,2/0001,3/0010,4/0011,5/0100,6/0101,7/0110,8/0111,9/1000,10/1001,11/1010,12/1011,13/1100,
%14/1101,15/1110,16/1111} 
%{
%  \draw  ([xshift=-10pt]B.input \T) node[left] {$\S$} -- (B.input  \T);
%}

\foreach \T/\S in {1/Y_0,2/Y_1,3/Y_2,4/Y_3,5/Y_4,6/Y_5,7/Y_6,8/Y_7} 
{
  \draw  ([xshift=-10pt]B.input \T) node[left] {$\S$} -- (B.input  \T);
}

\draw (8,4) node[or port, scale=2, number inputs=5] (or1) {};

% \draw ( $ (A.south east)!.888!(A.north east) $ ) -| (myor1.in 1) {};
% \draw ( $ (A.south east)!.777!(A.north east) $ ) -| (myor1.in 2) {};

\draw (or1.in 1)  node [anchor=east] {$Y_0$}
(or1.in 2)  node [anchor=east] {$Y_6$}
(or1.in 3)  node [anchor=east] {$Y_8$}
(or1.in 4)  node [anchor=east] {$Y_{11}$}
(or1.in 5)  node [anchor=east] {$Y_{13}$}
(or1.out)   node [anchor=west] {$f_1$};

\draw (8,1) node[or port, scale=2, number inputs=5] (or2) {};

% \draw ( $ (A.south east)!.888!(A.north east) $ ) -| (myor2.in 1) {};
% \draw ( $ (A.south east)!.777!(A.north east) $ ) -| (myor2.in 2) {};

\draw (or2.in 1)  node [anchor=east] {$Y_1$}
(or2.in 2)  node [anchor=east] {$Y_5$}
(or2.in 3)  node [anchor=east] {$Y_9$}
(or2.in 4)  node [anchor=east] {$Y_{10}$}
(or2.in 5)  node [anchor=east] {$Y_{14}$}
(or2.out)   node [anchor=west] {$f_2$};

\draw (8,-2) node[or port, scale=2, number inputs=5] (or3) {};

% \draw ( $ (A.south east)!.888!(A.north east) $ ) -| (myor2.in 1) {};
% \draw ( $ (A.south east)!.777!(A.north east) $ ) -| (myor2.in 2) {};

\draw (or3.in 1)  node [anchor=east] {$Y_4$}
(or3.in 2)  node [anchor=east] {$Y_7$}
(or3.in 3)  node [anchor=east] {$Y_8$}
(or3.in 4)  node [anchor=east] {$Y_{11}$}
(or3.in 5)  node [anchor=east] {$Y_{15}$}
(or3.out)   node [anchor=west] {$f_3$};
\end{circuitikz}
\end{document}

What I get Example of what I want

3

1 Answer 1

1

Unless you perfectly know what you are doing, never mix the internal circuit libraries of TikZ with circuitikz; it's documented at the start of the manual.

You can obtain a quite similar decoder with the (highly configurable) muxdemux component in circuitikz. See the example here, commented to explain the values of the keys, that you can find in the manual.

\documentclass[border=10pt]{standalone}
\usepackage{circuitikz}
% define the component
\tikzset{my3to8/.style={
        muxdemux, muxdemux def={
            Lh=8, Rh=8, w=6, % both left and right size =8 units, wide top
            NT=1, NB=0, % one terminal on the top, none bottom
            NR=8, % 8 pins on the right
            % we will define 9 pins on the left, to have them
            % centered, but we will draw just the central three
            NL=9,
        },
        draw only left pins = {4-6},
    }
}
\begin{document}
\begin{tikzpicture}[]
    \draw (0,0) node[my3to8](D){\tiny\ttfamily 3:8 decoder};
    % left labels
    \foreach \i [count=\iz from 0] in {1,...,8} {
        \node[left, font=\tiny\ttfamily] at (D.brpin \i) {\iz};
        \node[right, font=\tiny\ttfamily] at (D.rpin \i) {Y\iz};
    }
    % right labels
    \foreach \i/\lab [count=\iz from 0] in {4/d,5/c,6/b} {
        \node[right, font=\tiny\ttfamily] at (D.blpin \i) {\iz};
        \node[left, font=\tiny\ttfamily] at (D.lpin \i) {\lab};
    }
    % top label
    \node [below, font=\tiny\ttfamily] at (D.btpin 1) {EN}; 
    \node [above, font=\tiny\ttfamily] at (D.tpin 1) {a'}; 
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .