3

I'm trying to make an IO block diagram like that: enter image description here

I'm using a reference implementation block diagram

and currently I'm here and stuck, can someone please help me out in completing block diagram. Any help will be highly appreciated. Regards

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage{amsmath,bm,times}
\newcommand{\mx}[1]{\mathbf{\bm{#1}}} % Matrix command
\newcommand{\vc}[1]{\mathbf{\bm{#1}}} % Vector command
\begin{document}
\pagestyle{empty}
% We need layers to draw the block diagram
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
% Define a few styles and constants
\tikzstyle{sensor}=[draw, fill=blue!20, text width=5em, 
text centered, minimum height=2.5em]
\tikzstyle{ann} = [above, text width=6em]
\tikzstyle{naveqs} = [sensor, text width=6em, fill=red!20, 
minimum height=12em, rounded corners]
\def\blockdist{2.3}
\def\edgedist{2.5}
\begin{tikzpicture}
\node (naveq) [naveqs] {conv\_encoder};
\draw [->] (naveq.50) -- node [ann] {output\_tvalid } + (\edgedist,0) ;
   % node[right] {$\vc{v}^l$};
\draw [->] (naveq.20) -- node [ann] {output\_tdata} + (\edgedist,0); 
    %node[right] { $\mx{R}_l^b$};
\draw [->] (naveq.-25) -- node [ann] {output\_tlast} + (\edgedist,0);
    %node [right] {$\mx{R}_e^l$};
\draw [->] (naveq.-50) -- node [ann] {ctrl\_tvalid} + (\edgedist,0); 
    %node[right] {$z$};
\end{tikzpicture}
\end{document}
4

From the question it is not entirely clear where you are stuck. But there are some things you can do to go from your MWE to something close to the picture:

  • The positioning along the side of the encoder can be solved by using the upper and lower corners. Then you can say ($(naveq.south east)!0.5!(naveq.north east)$) on the middle to the right. You need the tikz library calc.
  • To place the text on the edge of the arrow put the node at the end of the arrow.
  • The left hand side arrows can be drawn reverse, that is, start at the arrow and draw it to the left.
  • The arrow tip you show is quite big, so I have used the library arrows.meta that allow scaling.

Then the picture becomes

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,calc,arrows.meta}
\usepackage{amsmath,bm,times}
\newcommand{\mx}[1]{\mathbf{\bm{#1}}} % Matrix command
\newcommand{\vc}[1]{\mathbf{\bm{#1}}} % Vector command
\begin{document}
\pagestyle{empty}
% We need layers to draw the block diagram
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
% Define a few styles and constants
\tikzstyle{sensor}=[draw, fill=blue!20, text width=5em, 
text centered, minimum height=2.5em]
\tikzstyle{ann} = [above, text width=6em]
\tikzstyle{naveqs} = [sensor, text width=6em, fill=red!20, 
minimum height=12em, rounded corners]
\def\blockdist{2.3}
\def\edgedist{1}
\begin{tikzpicture}[>={Latex[scale=1.5]}]
  %% Encoder
  \node (naveq) [naveqs] {conv\_encoder};
  %% Inputs
  \draw[<-] ($(naveq.south west)!0.9!(naveq.north west)$) -- +(-\edgedist,0) node [left] {clk};
  \draw[<-] ($(naveq.south west)!0.75!(naveq.north west)$) -- +(-\edgedist,0) node [left] {rst};
  \draw[<-] ($(naveq.south west)!0.6!(naveq.north west)$) -- +(-\edgedist,0) node [left] {input\_tvalid};
  \draw[<-] ($(naveq.south west)!0.45!(naveq.north west)$) -- +(-\edgedist,0) node [left] {input\_tdata};
  \draw[<-] ($(naveq.south west)!0.3!(naveq.north west)$) -- +(-\edgedist,0) node [left] {input\_tlast};
  \draw[<-] ($(naveq.south west)!0.1!(naveq.north west)$) -- +(-\edgedist,0) node [left] {ctrl\_tvalid};
  %% Outputs
  \draw[->] ($(naveq.south east)!0.9!(naveq.north east)$) -- +(\edgedist,0) node [right] {ctrl\_tready};
  \draw[->] ($(naveq.south east)!0.75!(naveq.north east)$) -- +(\edgedist,0) node [right] {output\_tvalid};
  \draw[->] ($(naveq.south east)!0.6!(naveq.north east)$) -- +(\edgedist,0) node [right] {output\_tlast};
  \draw[->] ($(naveq.south east)!0.4!(naveq.north east)$) -- +(\edgedist,0) node [right] {output\_tdata};
\end{tikzpicture}
\end{document}

enter image description here

3

This shows how to create a super-node using a local bounding box.

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,calc,backgrounds}
\usepackage{amsmath,bm,times}
\newcommand{\mx}[1]{\mathbf{\bm{#1}}} % Matrix command
\newcommand{\vc}[1]{\mathbf{\bm{#1}}} % Vector command
\begin{document}
% Define a few styles and constants
\tikzstyle{sensor}=[draw, fill=blue!20]%
\tikzstyle{ann} = [above, midway]%
\tikzstyle{naveqs} = [sensor, text width=6em, fill=red!20, 
minimum height=12em, rounded corners]%
\def\blockdist{2.3}%
\def\edgedist{2.5}%
\begin{tikzpicture}
\node (navname) [sensor] {conv\_encoder};% determine size
\begin{scope}[local bounding box=naveq, on background layer]
  \draw[rounded corners, fill=pink] ($(navname.south west) + (-2em,-4em)$) rectangle ($(navname.north east) + (2em,2em)$);
\end{scope}
\draw [->] ($(naveq.north east)!.2!(naveq.south east)$) -- +(\edgedist,0) node [ann] {output\_tvalid }  ;
   % node[right] {$\vc{v}^l$};
\draw [->] ($(naveq.north east)!.4!(naveq.south east)$) -- +(\edgedist,0) node [ann] {output\_tdata}; 
    %node[right] { $\mx{R}_l^b$};
\draw [->] ($(naveq.north east)!.6!(naveq.south east)$) -- +(\edgedist,0) node [ann] {output\_tlast};
    %node [right] {$\mx{R}_e^l$};
\draw [->] ($(naveq.north east)!.8!(naveq.south east)$) -- +(\edgedist,0) node [ann] {ctrl\_tvalid}; 
    %node[right] {$z$};
\end{tikzpicture}
\end{document}

demo

2

with use of matrix package, for encoder shape backgrounds and fit and for arrows arrows.meta:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                backgrounds,
                fit,
                matrix}
\begin{document}
\begin{tikzpicture}
    \matrix (m) [
        matrix of nodes,
        nodes in empty cells,
        nodes = {
            text height=2ex, text depth=0.5ex,
            inner sep=1mm, outer sep=0mm,
        },
        row sep = 0mm, column sep = 7mm,
        column 1/.style = {nodes={align=right, anchor=south east}},
        column 2/.style = {nodes={align=center, anchor=south, text width=13ex}}, % change width of block here
        column 3/.style = {nodes={align=left, anchor=south west}},
    ] {
    clk             &                   &   ctrl\_tready    \\
    rst             &                   &   output\_tvalid  \\
    input\_tvalid   &                   &   output\_tlast   \\
    input\_tdata    &   conv\_encoder   &                   \\
    input\_tlast    &                   &   output\_tdata   \\
                    &                   &                   \\
    ctrl\_tvalid    &                   &                   \\
    };
    \scoped[on background layer]
        \node (enc)  [draw, rounded corners, semithick, fill=gray!10,
                      inner sep = 0mm, outer sep= 0mm,
                      fit=(m-1-2) (m-7-2)] {};
    \foreach    \i in {1,...,5,7}
        \draw[-{Triangle[angle=60:2pt 4]}]    (m-\i-1) -- (m-\i-2);
    \foreach    \i in {1,...,3,5}
        \draw[-{Triangle[angle=60:2pt 4]}]    (m-\i-2) -- (m-\i-3);
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.