我正在尝试重新创建 AHB-lite 和 APB 的时序图,但在重新创建“瞬态”和“高/低到高”时序字符时遇到了一些问题。
目标
当前解决方案
代码
\documentclass{scrartcl}
\usepackage{tikz}
\usepackage{tikz-timing}
\usetikztiminglibrary{either}
\newcommand{\timingaxis}[1][]{%
\begin{scope}[#1]
\draw [timing/table/axis] (0,+1) -- (\twidth+1,+1);
\foreach \n in {0,1,...,\twidth} {
\draw [timing/table/axis ticks]
(\n,+1) -- +(0,-.2)
node [below,inner sep=2pt] {\scalebox{.75}{\tiny\n}};
}
\draw [timing/table/axis] (0,-\rowdist*\nrows+1.5*\rowdist) -- (\twidth+1,-\rowdist*\nrows+1.5*\rowdist);
\foreach \n in {0,1,...,\twidth} {
\draw [timing/table/axis ticks]
(\n,-\rowdist*\nrows+1.5*\rowdist) -- +(0,-.2)
node [below,inner sep=2pt] {\scalebox{.75}{\tiny\n}};
}
\end{scope}
}
\tikzset{%
timing/table/axis/.style={->,>=latex},
timing/table/axis ticks/.style={},
}
\begin{document}
% Defining foreground (fg) and background (bg) colors
\definecolor{bgblue}{rgb}{0.41961,0.80784,0.80784}%
\definecolor{bgred}{rgb}{1,0.61569,0.61569}%
\definecolor{fgblue}{rgb}{0,0,0.6}%
\definecolor{fgred}{rgb}{0.6,0,0}%
\begin{figure}
\centering
\begin{tikztimingtable}[
timing/coldist=4pt, % column distance
xscale=2.05,yscale=1.1, % scale diagrams
semithick % set line width
]
\\
HCLK & 4H 3{4C} [[timing/slope=0]] H\\
\\
HADDR[31:0] & 0.2D 0.4U {7.6D{A}} 0.4U {7.6D{B}} 0.4U 0.4D \\
HWRITE & 0.4H 0.4e 7.7L 0.2E0H 7.7E 0.4U 0.4D \\
HDATA[31:0] & 0.2D 0.4U 7.6D 5U {3D{Data (A)}} 0.4U 0.4D \\
HREADY & 0.4H [| timing/e/background/ ={ fill=gray } |]0.2e 7.8H 0.2e 8H 0.2E0H 0.4E \\
\\
\begin{extracode}
\begin{pgfonlayer}{background}
\begin{scope}[semitransparent,semithick, loosely dotted]
\vertlines[red]{0,2,4,...,16}
\vertlines[blue]{1,3,5,...,16}
\end{scope}
\end{pgfonlayer}
\timingaxis\relax
\tablerules
% \begin{pgfonlayer}{background}
% \foreach \n in {1,...,8}
% \draw [help lines] (A\n) -- (B\n);
% \end{pgfonlayer}
\end{extracode}
\end{tikztimingtable}
\caption{AHB-Lite Read transfer}
\label{fig:ahbl1}
\end{figure}
\end{document}
答案1
我不太熟悉,tikz
但我正在尝试解决你的问题。我认为你已经接近目标了。你所需要的只是阅读手册,尝试不同的想法,多思考,永不放弃!
以下是我的想法:
- 看起来有些多边形没有正确填充,只需将其设为
timing/e/background/.style={fill=gray}
全局,现在所有多边形都填充为灰色: - 但
HWRITE
改变后,这一排看起来很奇怪,HWRITE& 0.4H 0.4e 7.7L 0.2E 0H 7.7D 0.4U 0.4D
看起来很接近我们的目标。然后看了tikz-timing
手册4.3 Overlays
,我们用覆盖层来覆盖奇怪的路径,改成HWRITE & 0.4H 0.4e 7.7L 0.2E 0H O{0D} 7.7D 0.4U 0.4D
,看起来更糟糕!不过不用担心,因为tikz-timing
一直在控制之下tikz
,给覆盖层加一个偏移量HWRITE & 0.4H 0.4e 7.7L 0.2E 0H O{[yshift=-3.9]0D} 7.7D{} 0.4U 0.4D
: - 用同样的方法解决最后一行
HREADY & 0.4H 0.2e 7.8H 0.2e 8H 0.2E 0L O{[yshift=3.9]0D} 0.4D
最终的代码应该是:
\documentclass{scrartcl}
\usepackage{tikz}
\usepackage{tikz-timing}
\usetikztiminglibrary{either}
\newcommand{\timingaxis}[1][]{%
\begin{scope}[#1]
\draw [timing/table/axis] (0,+1) -- (\twidth+1,+1);
\foreach \n in {0,1,...,\twidth} {
\draw [timing/table/axis ticks]
(\n,+1) -- +(0,-.2)
node [below,inner sep=2pt] {\scalebox{.75}{\tiny\n}};
}
\draw [timing/table/axis] (0,-\rowdist*\nrows+1.5*\rowdist) -- (\twidth+1,-\rowdist*\nrows+1.5*\rowdist);
\foreach \n in {0,1,...,\twidth} {
\draw [timing/table/axis ticks]
(\n,-\rowdist*\nrows+1.5*\rowdist) -- +(0,-.2)
node [below,inner sep=2pt] {\scalebox{.75}{\tiny\n}};
}
\end{scope}
}
\tikzset{%
timing/table/axis/.style={->,>=latex},
timing/table/axis ticks/.style={},
}
\begin{document}
% Defining foreground (fg) and background (bg) colors
\definecolor{bgblue}{rgb}{0.41961,0.80784,0.80784}%
\definecolor{bgred}{rgb}{1,0.61569,0.61569}%
\definecolor{fgblue}{rgb}{0,0,0.6}%
\definecolor{fgred}{rgb}{0.6,0,0}%
\begin{figure}
\centering
\begin{tikztimingtable}[
timing/coldist=4pt, % column distance
xscale=2.05,yscale=1.1, % scale diagrams
semithick, % set line width
timing/e/background/.style={fill=gray},
]
\\
HCLK & 4H 3{4C} [[timing/slope=0]] H\\
\\
HADDR[31:0] & 0.2D 0.4U {7.6D{A}} 0.4U {7.6D{B}} 0.4U 0.4D \\
HWRITE & 0.4H 0.4e 7.7L 0.2E 0H O{[yshift=-3.9]0D} 7.7D{} 0.4U 0.4D \\
HDATA[31:0] & 0.2D 0.4U 7.6D 5U {3D{Data (A)}} 0.4U 0.4D \\
HREADY & 0.4H 0.2e 7.8H 0.2e 8H 0.2E 0L O{[yshift=3.9]0D} 0.4D\\
\\
\begin{extracode}
\begin{pgfonlayer}{background}
\begin{scope}[semitransparent,semithick, loosely dotted]
\vertlines[red]{0,2,4,...,16}
\vertlines[blue]{1,3,5,...,16}
\end{scope}
\end{pgfonlayer}
\timingaxis\relax
\tablerules
% \begin{pgfonlayer}{background}
% \foreach \n in {1,...,8}
% \draw [help lines] (A\n) -- (B\n);
% \end{pgfonlayer}
\end{extracode}
\end{tikztimingtable}
\caption{AHB-Lite Read transfer}
\label{fig:ahbl1}
\end{figure}
\end{document}