Flip-Flop

A flip-flop is a basic digital memory circuit that can store one bit of state data. Its inputs are a 1-bit data value () and a one-bit clock value () that synchronizes the register to the system. Its output is a one-bit value :

\begin{document}
\usetikzlibrary {shapes.geometric}
\begin{tikzpicture}
   % Draw the flip-flop box
   \draw[thick] (0,0) rectangle (3,4);
   
   % Draw the input (D)
   \draw[thick, ->] (-1,3) -- (0,3) node[at start, left] {Input} node[right] {D};
 
   % Draw the output (Q)
   \draw[thick, ->] (3,3) -- (4,3) node[at start, left] {Q} node[right] {Output};
 
   % Draw the clock (clk)
   \draw[thick, scale=0.25] (1,0) -- (3,0) -- (2,{sqrt(3)}) -- cycle;
   \draw[thick, ->] (0.5,0) -- (0.5,-1) node[below]{clk};
\end{tikzpicture}
\end{document}

On the rising edge of the clock, the output is set to the value of the input (though may be the same across multiple clock rising edges if no new value is passed). The speed at which the clock sets is dependent on its clk-to-q delay, which is the time a flip-flop takes for its output to change. At all other times, the output Q remains steady. This means that the flip-flop can store data, as it will be able to maintain its value between time steps.

Note! -bit register simply consists of flip-flops, each storing 1 bit of data, bundled together.

An

Examples

Plotting 's Waveform

Suppose we have the following SDS diagram of the clock and a flip-flop input :

\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
       
   \end{axis}
\end{tikzpicture}
\end{document}
 

We can then figure out the output waveform by looking at and . Remember that the clock only syncs at rising edges. In this case, at for some and a clock period . The flip-flop in question has a clk-to-q delay of 1 ns.

  1. Since the clock signal is at until , we are unsure of ‘s value in that time frame. may be if was before , or otherwise.
  2. (): The clock updates, and the output syncs with the input 1 ns later due to clk-to-q delay.
  3. (): and the clock syncs at .
  4. (): , so remains at .
  5. (): , so updates to at .
  6. (): again, so there is no change to .
  7. (): again.
  8. : , so updates 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) (27, 0.5) (27, 0) (28, 0)};
       
   \end{axis}
\end{tikzpicture}
\end{document}
 

Here it is important to reiterate that we shift ‘s waveform right by 1 ns due to its clk-to-q delay.