如何在wave环境中去除clk信号?
我仍然想保留所有帮助行(即 t0、t1 等)
代码如下:
\documentclass[11pt]{minimal}
\usepackage{tikz}
\newcounter{wavenum}
\setlength{\unitlength}{1cm}
% advance clock one cycle, not to be called directly
\newcommand*{\clki}{
\draw (t_cur) -- ++(0,.3) -- ++(.5,0) -- ++(0,-.6) -- ++(.5,0) -- ++(0,.3)
node[time] (t_cur) {};
}
\newcommand*{\bitvector}[3]{
\draw[fill=#3] (t_cur) -- ++( .1, .3) -- ++(#2-.2,0) -- ++(.1, -.3)
-- ++(-.1,-.3) -- ++(.2-#2,0) -- cycle;
\path (t_cur) -- node[anchor=mid] {#1} ++(#2,0) node[time] (t_cur) {};
}
% \known{val}{length}
\newcommand*{\known}[2]{
\bitvector{#1}{#2}{white}
}
% \unknown{length}
\newcommand*{\unknown}[2][XXX]{
\bitvector{#1}{#2}{black!20}
}
% \bit{1 or 0}{length}
\newcommand*{\bit}[2]{
\draw (t_cur) -- ++(0,.6*#1-.3) -- ++(#2,0) -- ++(0,.3-.6*#1)
node[time] (t_cur) {};
}
% \unknownbit{length}
\newcommand*{\unknownbit}[1]{
\draw[ultra thick,black!50] (t_cur) -- ++(#1,0) node[time] (t_cur) {};
}
% \nextwave{name}
\newcommand{\nextwave}[1]{
\path (0,\value{wavenum}) node[left] {#1} node[time] (t_cur) {};
\addtocounter{wavenum}{-1}
}
% \clk{name}{period}
\newcommand{\clk}[2]{
\nextwave{#1}
\FPeval{\res}{(\wavewidth+1)/#2}
\FPeval{\reshalf}{#2/2}
\foreach \t in {1,2,...,\res}{
\bit{\reshalf}{1}
\bit{\reshalf}{0}
}
}
% \begin{wave}[clkname]{num_waves}{clock_cycles}
\newenvironment{wave}[3][clk]{
\begin{tikzpicture}[draw=black, yscale=.7,xscale=1]
\tikzstyle{time}=[coordinate]
\setlength{\unitlength}{1cm}
\def\wavewidth{#3}
\setcounter{wavenum}{0}
\nextwave{#1}
\foreach \t in {0,1,...,\wavewidth}{
\draw[dotted] (t_cur) +(0,.5) node[above] {t$_{\t}$} -- ++(0,.4-#2);
\clki
}
}{\end{tikzpicture}}
%%% End of timing.sty
\begin{document}
\begin{wave}{4}{9}
\nextwave{handshake\_out\_RPi}
\bit{0}{1}
\bit{1}{2}
\bit{0}{2}
\bit{1}{3}
\bit{0}{2}
\nextwave{data\_out\_RPi}
\bit{0.5}{1}
\known{}{2}
\bit{0.5}{2}
\known{}{3}
\bit{0.5}{2}
\nextwave{handshake\_out\_UR5}
\bit{0}{2}
\bit{1}{2}
\bit{0}{3}
\bit{1}{2}
\bit{0}{1}
\end{wave}
\end{document}
答案1
你可以这样做:
删除
clk
中的\newenvironment{wave}[3][clk]
,只删除单词,将括号留空,如[]
(第 58 行)。替换
\draw
为\path
in (第 9 行)。\newcommand*{\clki}{ \path (t_cur) -- ++(0,.3) -- ++(.5,0) -- ++(0,-.6) -- ++(.5,0) -- ++(0,.3) node[time] (t_cur) {};}
之前说要添加
[draw=none]
到\draw
,根据 Sigur 的建议已更正。注释此部分(第 47-55 行):
\newcommand{\clk}[2]{ \nextwave{#1} \FPeval{\res}{(\wavewidth+1)/#2} \FPeval{\reshalf}{#2/2} \foreach \t in {1,2,...,\res}{ \bit{\reshalf}{1} \bit{\reshalf}{0} } }
答案2
以防万一tikz-timing
可以考虑,所需的图表可以用类似
\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-timing}
\begin{document}
\begin{tikztimingtable}
handshake\_out\_RPi& 2L 4H 6L 6H 2L\\
data\_out\_RPi & 2Z[black] 4D 4Z[black] 6D 4Z[black]\\
handshake\_out\_UR5 & 4L 4H 6L 4H 2L\\
\extracode
\begin{pgfonlayer}{background}
\vertlines[help lines]{0,2,...,20}
\foreach \i [count=\col from 0] in {0,2,...,20}
\node[font=\scriptsize] at (\i,2) {$t_{\col}$};
\end{pgfonlayer}
\end{tikztimingtable}%
\end{document}