takecの気まぐれブログ

プログラミング等の話題を気まぐれに

tikzを用いたタイミングチャートの描画

tikz-timingパッケージを用いてタイミングチャートを書くことができる。

f:id:takecccc:20170628040943p:plain

\documentclass[dvipdfmx]{standalone}
\usepackage[svgnames]{xcolor}
\usepackage{pgf}
\usepackage{tikz}
\usepackage{tikz-timing}
\usetikztiminglibrary{either}
\usetikztiminglibrary{nicetabs}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{calc}
\usetikzlibrary{fit}
\usetikzlibrary{automata}

\begin{document}
\begin{tikztimingtable}[
        %timing/d/background/.style={fill=white},
        timing/table/header/.style={font=\bf},
        timing/wscale=4,
        timing/nice tabs,
        timing/lslope=0.4,
        timing/zslope=0.4,
        timing/dslope=0.4,
        timing/e/background/.style={fill=gray},
        >=latex,
    ]
    \\
    ACLK    & [c] 20{c} G \\
    & N(WriteAddress) \\
    AWADDR  & 0.4U 1.6D{A} 9U \\
    AWVALID & 0.4L 1.6H    9L \\
    AWREADY & 0.4E 0.6L 1H 9E \\
    & N(WriteData) \\
    WDATA   & 2.4U 1.6D{D(A0)} 0.4U 1.6D{D(A1)} 1.4U 0.6D{D(A2)} 0.4U 0.6D{D(A3)} 2U \\
    WLAST   & 8.4L 0.6H 2L \\
    WVALID  & 2.4L 1.6H 0.4E 1.6H 1.4L 0.6H 0.4E 0.6H 2L \\
    WREADY  & 3.4L 0.6H 1.4L 0.6H 0.4E 1.6H 0.4E 0.6H 2L \\
    & N(WriteResp) \\
    BRESP   & 9.4U 0.6D{OKAY} 1U \\
    BVALID  & 9.4L 0.6H 1L \\
    BREADY  & 2.4L 7.6H 1L \\
    \extracode
    \tableheader{Name}{Timing}
    \tablerules

    \pgfmathsetmacro\sepwidth{9.2}
    \begin{background}
        \path[fill=AntiqueWhite]     (WriteAddress) +(-\sepwidth,-0.3) rectangle +(\twidth,+1.3);
        \path[fill=AntiqueWhite]     (WriteData)    +(-\sepwidth,-0.3) rectangle +(\twidth,+1.3);
        \path[fill=AntiqueWhite]     (WriteResp)    +(-\sepwidth,-0.3) rectangle +(\twidth,+1.3);
    \end{background}
    \begin{pgfonlayer}{background}
        \vertlines[help lines]{0,4,...,\twidth}
        \draw[->,thick] (0,0) -- +(\twidth+1,0);
        \foreach \n in {0,1,...,10}
            \pgfmathsetmacro\nnew{int(\n*4)}
            \draw (\nnew,-0.2) -- +(0,.4) node[above,inner sep=2pt] {\scalebox{.75}{T\n}};
        \path[color=Black]  (WriteAddress) +(-\sepwidth+1,0) node[anchor=base west,inner sep=.5pt] {Write Address Channel};
        \path[color=Black]  (WriteData)    +(-\sepwidth+1,0) node[anchor=base west,inner sep=.5pt] {Write Data Channel};
        \path[color=Black]  (WriteResp)    +(-\sepwidth+1,0) node[anchor=base west,inner sep=.5pt] {Write Response Channel};
    \end{pgfonlayer}
\end{tikztimingtable}

\end{document}