Setup Time

A flip-flop’s setup time is the minimum amount of time before the clock’s rising edge that the data input to a flip-flop must remain stable:

\begin{document}
\begin{tikzpicture}[scale=1, transform shape]
   % Draw the waveform
   \draw[thick] (0,0) node[left, at start] {t=0} -- (1,0) -- (1,1) -- (3,1) -- (3,0) -- (5,0) -- (5,1) -- (7,1) -- (7,0) -- (9,0);
 
   % Label setup times
   \draw[<->, thick, orange] (4, -0.5) -- (5, -0.5) node[midway, below, align=center] {Setup \\ Time};
   \draw[<->, thick, orange] (0, -0.5) -- (1, -0.5) node[midway, below, align=center] {Setup \\ Time};
\end{tikzpicture}
\end{document}

If the clock signal above has a setup time of 1 ns, then any change to the input 1 ns before the rising edge will result in a setup-time violation, causing the output to become undefined.

Understanding

The setup time of a flip-flop ensures that the data is correctly captured and stored in the flip-flop on the triggering edge of the clock signal. If the data changes during this setup window, the flip-flop may fail to capture the correct input value, leading to potential errors in the digital system.

Examples

Plotting 's Waveform

Consider the plot of a register’s output that we constructed in 5.2a.2. If the register has a setup time of 1 ns, then there is a setup-time violation at , as it is ns before the clock’s rising edge:

\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
   \begin{axis}[
       width=12cm,
       height=6cm,
       xlabel={Time (ns)},
       ylabel={},
       ymin=-0.5, ymax=3,
       xmin=0, xmax=28,
       xtick={0,2,4,6,8,10,12,14,16,18,20,22,24,26,28},
       ytick={0.25, 1.25, 2.25},
       yticklabels={Q, D, clk},
       grid=major,
       grid style={dotted, gray},
       xmajorgrids=true, 
       ymajorgrids=false,
       extra y ticks={0, 0.5, 1, 1.5, 2, 2.5},
       extra y tick labels={},
       extra y tick style={grid=major},
       ]
       
       % Clock signal
       \addplot[thick, black] coordinates {(0, 2) (2, 2) (2, 2.5) (4, 2.5) (4, 2) (6, 2) (6, 2.5) (8, 2.5) (8, 2) (10, 2) (10, 2.5) (12, 2.5) (12, 2) (14, 2) (14, 2.5) (16, 2.5) (16, 2) (18, 2) (18, 2.5) (20, 2.5) (20, 2) (22, 2) (22, 2.5) (24, 2.5) (24, 2) (26, 2) (26, 2.5) (28, 2.5)};
       
       % D signal
       \addplot[thick, blue] coordinates {(0, 1.5) (4, 1.5) (4, 1) (7.5, 1) (7.5, 1.5) (8.5, 1.5) (8.5, 1) (11, 1) (11, 1.5) (12, 1.5) (12, 1) (13, 1) (13, 1.5) (16, 1.5) (16, 1) (17.5, 1) (17.5, 1.5) (24, 1.5) (24, 1) (26.5, 1) (26.5, 1.5) (28, 1.5)};
       
       % Q signal
       \addplot[thick, red] coordinates {(3, 0.5) (7, 0.5) (7, 0) (15, 0) (15, 0.5) (27, 0.5) (27, 0) (28, 0)};
       
       % Circling the setup time violation.
       \draw[orange, thick] (axis cs: 17.75, 1.75) ellipse [x radius=0.5cm, y radius=1.25cm];
       
   \end{axis}
\end{tikzpicture}
\end{document}

We must then fix the output waveform by accounting for the unknown output during the setup-time violation. Since the clk-to-q delay is 1 ns, the setup-time violation will reflect in ‘s waveform 1 ns late, at . For the same reason, the output reappears 1 ns after the clock’s rising edge, at :

\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
   \begin{axis}[
       width=12cm,
       height=6cm,
       xlabel={Time (ns)},
       ylabel={},
       ymin=-0.5, ymax=3,
       xmin=0, xmax=28,
       xtick={0,2,4,6,8,10,12,14,16,18,20,22,24,26,28},
       ytick={0.25, 1.25, 2.25},
       yticklabels={Q, D, clk},
       grid=major,
       grid style={dotted, gray},
       xmajorgrids=true, 
       ymajorgrids=false,
       extra y ticks={0, 0.5, 1, 1.5, 2, 2.5},
       extra y tick labels={},
       extra y tick style={grid=major},
       ]
       
       % Clock signal
       \addplot[thick, black] coordinates {(0, 2) (2, 2) (2, 2.5) (4, 2.5) (4, 2) (6, 2) (6, 2.5) (8, 2.5) (8, 2) (10, 2) (10, 2.5) (12, 2.5) (12, 2) (14, 2) (14, 2.5) (16, 2.5) (16, 2) (18, 2) (18, 2.5) (20, 2.5) (20, 2) (22, 2) (22, 2.5) (24, 2.5) (24, 2) (26, 2) (26, 2.5) (28, 2.5)};
       
       % D signal
       \addplot[thick, blue] coordinates {(0, 1.5) (4, 1.5) (4, 1) (7.5, 1) (7.5, 1.5) (8.5, 1.5) (8.5, 1) (11, 1) (11, 1.5) (12, 1.5) (12, 1) (13, 1) (13, 1.5) (16, 1.5) (16, 1) (17.5, 1) (17.5, 1.5) (24, 1.5) (24, 1) (26.5, 1) (26.5, 1.5) (28, 1.5)};
       
       % Q signal
       \addplot[thick, red] coordinates {(3, 0.5) (7, 0.5) (7, 0) (15, 0) (15, 0.5) (19, 0.5)};
       \addplot[thick, red] coordinates {(23, 0.5) (27, 0.5) (27, 0) (28, 0)};
       
       % Circling the setup time violation.
       \draw[orange, thick] (axis cs: 17.75, 1.75) ellipse [x radius=0.5cm, y radius=1.25cm];
       
   \end{axis}
\end{tikzpicture}
\end{document}