\section{Karnaugh Diagramme (KVD)}

KV-Diagramme sind eine äquivalente Darstellungsform von Schaltfunktionen in Matrizenform. KVD ermöglichen die unkomplizierte Bildung der \emph{vereinfachten} DNF/KNF. \medskip

Schema zum ausfüllen eines 4 Variablen KV-Diagramm:

\begin{center}
    \includegraphics[width = 0.4\linewidth]{images/KVDia.jpg}
\end{center}

\begin{center}
    \begin{minipage}{0.45\linewidth}
        \begin{center}
            \begin{tikzpicture}
                \matrix (kv) [
                    matrix of nodes,
                    nodes in empty cells,
                    column sep=-\pgflinewidth, row sep=-\pgflinewidth,
                    nodes = {
                            rectangle,
                            draw = black,
                            text width = 5mm,
                            text height = 5mm,
                            align = center
                        }
                ]{
                    $0$ & $1$                   & $X$ & \\
                        &                       &     & \\
                        & $\textcolor{blue}{1}$ &     & \\
                        &                       &     & \\
                };

                \path[draw, decorate, decoration=brace] (kv-1-1.north west) -- (kv-1-2.north east) node [midway, above] {$\not{A}$};
                \path[draw, decorate, decoration=brace] (kv-1-3.north west) -- (kv-1-4.north east) node [midway, above] {$A$};
                \path[draw, decorate, decoration=brace] (kv-2-1.south west) -- (kv-1-1.north west) node [midway, left] {$\not{C}$};
                \path[draw, decorate, decoration=brace] (kv-4-1.south west) -- (kv-3-1.north west) node [midway, left] {$C$};
                \path[draw, decorate, decoration=brace] (kv-2-4.north east) -- (kv-3-4.south east) node [midway, right] {$D$};
                \path[draw, decorate, decoration=brace] (kv-1-4.north east) -- (kv-1-4.south east) node [midway, right] {$\not{D}$};
                \path[draw, decorate, decoration=brace] (kv-4-4.north east) -- (kv-4-4.south east) node [midway, right] {$\not{D}$};
                \path[draw, decorate, decoration=brace] (kv-4-3.south east) -- (kv-4-2.south west) node [midway, below] {$B$};
                \path[draw, decorate, decoration=brace] (kv-4-1.south east) -- (kv-4-1.south west) node [midway, below] {$\not{B}$};
                \path[draw, decorate, decoration=brace] (kv-4-4.south east) -- (kv-4-4.south west) node [midway, below] {$\not{B}$};
            \end{tikzpicture}
        \end{center}
    \end{minipage}
    \hfill
    \begin{minipage}{0.45\linewidth}
        \begin{center}
            \begin{tikzpicture}
                \matrix (kv) [
                    matrix of nodes,
                    nodes in empty cells,
                    column sep=-\pgflinewidth, row sep=-\pgflinewidth,
                    nodes = {
                            rectangle,
                            draw = black,
                            text width = 5mm,
                            text height = 5mm,
                            align = center
                        }
                ]{
                    \node[kvbinhead] {};                     & \node[kvbinhead] {00}; & \node[kvbinhead, text = red] {01}; & \node[kvbinhead] {11}; & \node[kvbinhead] {10}; \\
                    \node[kvbinhead] {00};                   & $0$                    & $1$                                & $X$                    &                        \\
                    \node[kvbinhead] {01};                   &                        &                                    &                        &                        \\
                    \node[kvbinhead, text = darkgreen] {11}; &                        & $\textcolor{blue}{1}$              &                        &                        \\
                    \node[kvbinhead] {10};                   &                        &                                    &                        &                        \\
                };

                \node[] at ($(kv-1-1.north east) + (-6mm, +2mm)$) {AB};
                \node[] at ($(kv-1-1.south west) + (-1mm, +5mm)$) {CD};
                \draw[] ($(kv-1-1.north west) + (-3mm, 3mm)$) -- ($(kv-1-1.south east) + (-3.5mm, 3.5mm)$);
            \end{tikzpicture}
        \end{center}
    \end{minipage}
\end{center}

\begin{center}
    \begin{minipage}{0.45\linewidth}
        \begin{center}
            \begin{tikzpicture}
                \matrix (kv) [
                    matrix of nodes,
                    nodes in empty cells,
                    column sep=-\pgflinewidth, row sep=-\pgflinewidth,
                    nodes = {
                            rectangle,
                            draw = black,
                            text width = 5mm,
                            text height = 5mm,
                            align = center,
                            text = gray
                        }
                ]{
                    \node[kvbinhead] {};   & \node[kvbinhead] {00}; & \node[kvbinhead] {01}; & \node[kvbinhead] {11}; & \node[kvbinhead] {10}; \\
                    \node[kvbinhead] {00}; &                        &                        &                        &                        \\
                    \node[kvbinhead] {01}; &                        &                        &                        &                        \\
                    \node[kvbinhead] {11}; &                        &                        &                        &                        \\
                    \node[kvbinhead] {10}; &                        &                        &                        &                        \\
                };

                \node[] at ($(kv-1-1.north east) + (-6mm, +2mm)$) {AB};
                \node[] at ($(kv-1-1.south west) + (-1mm, +5mm)$) {CD};
                \draw[] ($(kv-1-1.north west) + (-3mm, 3mm)$) -- ($(kv-1-1.south east) + (-3.5mm, 3.5mm)$);

                \begin{pgfonlayer}{tl3}
                    \draw[thick, blue, ->, > = stealth] (kv-2-2.center) -- (kv-3-2.center) to[out = 180, in = 180] (kv-5-2.center) -- (kv-4-2.center);
                    \draw[thick, blue, ->, > = stealth] (kv-2-3.center) -- (kv-3-3.center) to[out = 180, in = 180] (kv-5-3.center) -- (kv-4-3.center);
                    \draw[thick, blue, ->, > = stealth] (kv-2-5.center) -- (kv-3-5.center) to[out = 180, in = 180] (kv-5-5.center) -- (kv-4-5.center);
                    \draw[thick, blue, ->, > = stealth] (kv-2-4.center) -- (kv-3-4.center) to[out = 180, in = 180] (kv-5-4.center) -- (kv-4-4.center);
                \end{pgfonlayer}
                \begin{pgfonlayer}{tl2}
                    \draw[thick, darkgreen, ->, > = stealth] (kv-4-2.center) -- (kv-2-3.center);
                    \draw[thick, red, ->, > = stealth] (kv-4-3.center) -- (kv-2-5.center);
                    \draw[thick, darkgreen, ->, > = stealth] (kv-4-5.center) -- (kv-2-4.center);
                \end{pgfonlayer}
            \end{tikzpicture}
        \end{center}
    \end{minipage}
    \hfill
    \begin{minipage}{0.45\linewidth}
        \begin{center}
            \begin{tikzpicture}
                \matrix (kv) [
                    matrix of nodes,
                    nodes in empty cells,
                    column sep=-\pgflinewidth, row sep=-\pgflinewidth,
                    nodes = {
                            rectangle,
                            draw = black,
                            text width = 5mm,
                            text height = 5mm,
                            align = center,
                            text = gray
                        }
                ]{
                    \node[kvbinhead] {};   & \node[kvbinhead] {00}; & \node[kvbinhead] {01}; & \node[kvbinhead] {11}; & \node[kvbinhead] {10}; \\
                    \node[kvbinhead] {00}; &                        &                        &                        &                        \\
                    \node[kvbinhead] {01}; &                        &                        &                        &                        \\
                    \node[kvbinhead] {11}; &                        &                        &                        &                        \\
                    \node[kvbinhead] {10}; &                        &                        &                        &                        \\
                };

                \node[] at ($(kv-1-1.north east) + (-6mm, +2mm)$) {CD};
                \node[] at ($(kv-1-1.south west) + (-1mm, +5mm)$) {AB};
                \draw[] ($(kv-1-1.north west) + (-3mm, 3mm)$) -- ($(kv-1-1.south east) + (-3.5mm, 3.5mm)$);

                \begin{pgfonlayer}{tl3}
                    \draw[thick, blue, ->, > = stealth] (kv-2-2.center) -- (kv-2-3.center) to[out = 90, in = 90] (kv-2-5.center) -- (kv-2-4.center);
                    \draw[thick, blue, ->, > = stealth] (kv-3-2.center) -- (kv-3-3.center) to[out = 90, in = 90] (kv-3-5.center) -- (kv-3-4.center);
                    \draw[thick, blue, ->, > = stealth] (kv-5-2.center) -- (kv-5-3.center) to[out = 90, in = 90] (kv-5-5.center) -- (kv-5-4.center);
                    \draw[thick, blue, ->, > = stealth] (kv-4-2.center) -- (kv-4-3.center) to[out = 90, in = 90] (kv-4-5.center) -- (kv-4-4.center);
                \end{pgfonlayer}
                \begin{pgfonlayer}{tl2}
                    \draw[thick, darkgreen, ->, > = stealth] (kv-2-4.center) -- (kv-3-2.center);
                    \draw[thick, red, ->, > = stealth] (kv-3-4.center) -- (kv-5-2.center);
                    \draw[thick, darkgreen, ->, > = stealth] (kv-5-4.center) -- (kv-4-2.center);
                \end{pgfonlayer}
            \end{tikzpicture}
        \end{center}
    \end{minipage}
\end{center}

Bei 5 Schaltvariablen wird die 5te Schaltvariable mit einer ABCD Matrix für $E$ und einer für $\not{E}$ dargestellt (2D!).


\subsection{Päckchen}

Orthogonal benachbarte Minterme (bzw. Maxterme) werden zu einem ''Päckchen'' zusammengefasst.

\begin{minipage}{0.48\linewidth}
    \hfill \includegraphics[width = 0.4\textwidth]{images/Packchen.jpg}
\end{minipage}
\begin{minipage}{0.48\linewidth}
    \begin{center}
        Implizite Anwendung des Nachbarschaftsgesetz: \medskip

        $\Rightarrow (\not{A} \land \not{B}) \lor (A \land \not{B}) = \not{B}$
    \end{center}
\end{minipage} \medskip

Es gelten folgende Regeln für Päckchen:

\begin{itemize}
    \item Päckchen sind rechteckig (Ausnahme: über Ecken)
    \item \emph{Umfassen möglichst grosse Zweierpotenz}.
    \item Dürfen über Ecken und Grenzen hinausgehen und sich überlappen.
\end{itemize}
\vfill


\subsection{Don't Care Zustände}

Redundante oder unmögliche Kombinationen der Eingangsvariablen werden mit einem 'X' im KVD markiert. Man \emph{darf} solche Zustände benutzen um Päckchen zu bilden!


\subsection{Hazard}

Hazards sind kurzzeitige, unerwünschte Änderung der Signalwerte, die durch Zeitverzögerung der Gatter entstehen.

\subsubsection{Strukturhazard (Statischer Hazard)}

Statische Hazards sind im KVD Stellen, an denen sich Päckchen orthogonal berühren, aber nicht überlappen.

\begin{center}
    \begin{minipage}{0.48\linewidth}
        \begin{center}
            \begin{tikzpicture}
                \begin{pgfonlayer}{bg}
                    \def\ppad{1.5pt}
                    \matrix (kv) [
                        matrix of nodes,
                        nodes in empty cells,
                        column sep=-\pgflinewidth, row sep=-\pgflinewidth,
                        nodes = {
                                rectangle,
                                draw = black,
                                text width = 5mm,
                                text height = 5mm,
                                align = center
                            }
                    ]{
                        \node[kvbinhead] {};   & \node[kvbinhead] {00}; & \node[kvbinhead] {01}; & \node[kvbinhead] {11}; & \node[kvbinhead] {10}; \\
                        \node[kvbinhead] {00}; & 0                      & 1                      & 1                      & 0                      \\
                        \node[kvbinhead] {01}; & 0                      & 1                      & 1                      & 0                      \\
                        \node[kvbinhead] {11}; & 1                      & 1                      & 0                      & 0                      \\
                        \node[kvbinhead] {10}; & 1                      & 1                      & 0                      & 0                      \\
                    };


                    \node[] at ($(kv-1-1.north east) + (-6mm, +2mm)$) {AB};
                    \node[] at ($(kv-1-1.south west) + (-1mm, +5mm)$) {CD};
                    \draw[] ($(kv-1-1.north west) + (-3mm, 3mm)$) -- ($(kv-1-1.south east) + (-3.5mm, 3.5mm)$);
                \end{pgfonlayer}

                \draw[blue] ($(kv-2-3.north west) + (1.5pt, -1.5pt)$) rectangle ($(kv-3-4.south east) + (-1.5pt, 1.5pt)$);
                \draw[blue] ($(kv-4-2.north west) + (1.5pt, -1.5pt)$) rectangle ($(kv-5-3.south east) + (-1.5pt, 1.5pt)$);
                \draw[darkgreen, thick, dashed] ($(kv-2-3.north west) + (1.5pt, -1.5pt)$) rectangle ($(kv-5-3.south east) + (-1.5pt, 1.5pt)$);

                \begin{pgfonlayer}{tl3}
                    \path[draw, <->, > = stealth, red] ($(kv-3-3.center) + (2pt, 0)$) to[in=45, out = -45] ($(kv-4-3.center) + (2pt, 0)$);
                    \path[draw, <-, > = stealth, red] ($(kv-5-3.center) + (2pt, 0)$) to[in=90, out = -45] ($(kv-5-3.center) + (5pt, -3mm)$);
                    \path[draw, <-, > = stealth, red] ($(kv-2-3.center) + (2pt, 0)$) to[in=270, out = 45] ($(kv-2-3.center) + (5pt, 3mm)$);
                \end{pgfonlayer}
                \begin{pgfonlayer}{tl2}
                    \node[text = red, fill = white, fill opacity = 0.8, text opacity = 1, rounded corners = 4pt] at ($(kv-3-3.south east) + (4mm, 0mm)$) {\small Hazard};
                    \node[text = red, fill = white, fill opacity = 0.8, text opacity = 1, rounded corners = 4pt] at ($(kv-5-3.south east) + (4mm, 0mm)$) {\small Hazard};
                \end{pgfonlayer}
            \end{tikzpicture}
        \end{center}
    \end{minipage}
    \hfill
    \begin{minipage}{0.5\linewidth}
        \emph{Lösung:} Berührendes \textcolor{blue}{Päck-}

        \textcolor{blue}{chen} mit zusätzlichem \textcolor{darkgreen}{Päckchen} (möglichst gross) verbinden.
    \end{minipage}
\end{center}

\subsubsection{Funktionale Hazards}

Wenn sich Päckchen diagonal berühren, dann wechseln mindestens zwei Variablen. Dies ist ein funktionaler Hazard und kann \emph{nicht} leicht behoben werden.