3

I have to simulate the working of a jk flip flop. Using circuitikz to draw each gate individually and then simulating it is cumbersome, because I have to do complex circuits later on.

Searching online I found this solution: How do I embed vector graphics to LaTeX document

I.e draw the circuit in proteus, export it in svg format, then add it to the latex document using pdf_latex format.

But is there any way to simulate the circuit using a library or tool which can be exported to latex instead of manually going frame by frame?

edit: https://drive.google.com/open?id=0Bzi4BkL3Q2szUHBYMHNlM2Zzb2s this contains a slide with SR latch simulation.I want to do something similar to this

This is what i managed to do. The lines are not aligned and the circuit should be on the right of the page, which I also cant figure out how to do.

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usetheme{Madrid}
\usepackage[american]{circuitikz}
\usepackage{tikz}


\begin{document}
\maketitle

\begin{frame}{SIMULATION}
   \begin{circuitikz}

 \draw
(20,10) node[nand port](mynand1){}
(20,12) node[nand port](mynand2){}
(23,10) node[nand port](mynand3){}
(23,12) node[nand port](mynand4){}

(mynand1.out) -- (mynand3.in 1)
(mynand2.out) -- (mynand4.in 2);
\end{circuitikz} 
\end{frame}

\end{document}
4
  • Welcome to TeX.SX! What have you done so far? And how should it look like? Could you add an image of the desired result?
    – Bobyandbob
    Jul 12, 2018 at 5:51
  • I have done this so far sharelatex.com/project/5b46ef9027e0e16014dcc381, Im not getting the alignment right even.
    – afsara_ben
    Jul 12, 2018 at 6:15
  • Can you make a minimal working example (MWE), Its, posible to create gifs usign Imagemagic from a tikz drawing like this example
    – J Leon V.
    Jul 12, 2018 at 6:29
  • 1
    We can’t see your doc without login in to share LaTeX (at least I couldn’t). Pleas create a minimal working example (MWE) and add it to your question.
    – Tobi
    Jul 12, 2018 at 6:30

2 Answers 2

4

Here an attempt through a custom gate that allows coloring the pins, I have not worked much with the beamer class to make animations, but still generates a PDF output, which can be animated, using the imagemagic converter, in my case I have a rule in arara that allows me to automate the creation of the gif and visualize it in a browser.

RESULT: enter image description here

WIP MWE:

% arara: pdflatex: {synctex: yes, action: nonstopmode}
% arara: animate: {density: 200, delay: 100, other: -background white -alpha remove}
% arara: showanimate
\documentclass[tikz]{beamer}
\usetheme{Madrid}
\usepackage[american]{circuitikz}
\usepackage{tikz}
\usepackage{xcolor}
\definecolor{HIGH}{HTML}{ff0000}
\definecolor{LOW}{HTML}{0000ff}
\definecolor{SET}{HTML}{009900}
\definecolor{RESET}{HTML}{996600}
\definecolor{NC}{HTML}{000000}
\definecolor{INVALID}{HTML}{FE8637}
\usetikzlibrary{positioning}
\begin{document}

\foreach \C/\S/\R/\NS/\NR/\Q/\NQ/\STAT/\vC/\vS/\vR/\vNS/\vNR/\vQ/\vNQ in {
        LOW/LOW/LOW/HIGH/HIGH/NC/NC/No Change/0/0/0/1/1/Q_0/\overline{Q_0},
        LOW/LOW/HIGH/HIGH/HIGH/NC/NC/No Change/0/0/1/1/1/Q_0/\overline{Q_0},
        LOW/HIGH/LOW/HIGH/HIGH/NC/NC/No Change/0/1/0/1/1/Q_0/\overline{Q_0},
        LOW/HIGH/HIGH/HIGH/HIGH/NC/NC/No Change/0/1/1/1/1/Q_0/\overline{Q_0},
        HIGH/LOW/LOW/HIGH/HIGH/NC/NC/No Change/1/0/0/1/1/Q_0/\overline{Q_0},
        HIGH/LOW/HIGH/HIGH/LOW/RESET/SET/Reset/1/0/1/1/0/0/1,
        HIGH/LOW/HIGH/HIGH/LOW/RESET/SET/Reset/1/0/1/1/0/0/1,
        HIGH/HIGH/LOW/LOW/HIGH/SET/RESET/Set/1/1/0/0/1/1/0,
        HIGH/HIGH/LOW/LOW/HIGH/SET/RESET/Set/1/1/0/0/1/1/0,
        HIGH/HIGH/HIGH/LOW/LOW/INVALID/INVALID/Invalid/1/0/0/0/0/Q/Q',
        HIGH/HIGH/HIGH/LOW/LOW/INVALID/INVALID/Invalid/1/0/0/0/0/Q/Q'}{
\begin{frame}
\begin{tikzpicture}
\def\NAND(#1)#2[#3][#4][#5]{%CUSTOME NAND GATE TO ANIMATE PINS
    \begin{scope}[shift={(#1)}]
    % Draw the pins
    \draw[#3,line width=1pt] (-0.5,0.25) -- +(-0.25,0) coordinate (#2 IN1); % Pin 1 IN1
    \draw[#4,line width=1pt] (-0.5,-0.25) -- +(-0.25,0) coordinate (#2 IN2); % Pin 2 IN2
    \draw[#5,line width=1pt] (0.7,0) -- ++(0.25,0) coordinate (#2 OUT); % Pin 3 OUT
    \draw[#5,line width=1pt] (0.6,0) circle (2.5pt); % Pin 2 IN2
    % Draw the Discrete component body ANSI Symbol
    \draw[fill=blue!10,line width=1pt]
        (-0.5,0) |- ++ (0.5,0.5) arc (90:-90:0.5) -| cycle; % The body of IC
    % Label and component identifier.
    \draw[blue] (0,0) node []{\small\sf U-#2}; % IC LABEL
    \draw[blue] (0,0.7) node [align=center]{\sf\tiny NAND GATE}; % IC LABEL

  \end{scope}
}
\node[\Q, draw, anchor=west] at (3.5,-1.5) {\scriptsize\sf STATE: \STAT};
\NAND(0,0){1}[\S][\C][\NS];
\NAND(3,-0.25){2}[\NS][\NQ][\Q];
\NAND(0,-3){3}[\C][\R][\NR];
\NAND(3,-2.75){4}[\Q][\NR][\NQ];

%LOGIC C WIRE
\draw[color=\C,line width=1pt](-2,-1.5)
    node [anchor=south]{\sf C=\vC}
    to [short,o-*] ++(1,0) node(C1){} |- (1 IN2)
    (C1.center) |- (3 IN1);

%LOGIC S WIRE
\draw[color=\S,line width=1pt](1 IN1)
    to [short,-o] ++(-1.25,0) node [anchor=south]{\sf S=\vS};

%LOGIC NEG-S WIRE
\draw[color=\NS,line width=1pt](1 OUT)
    node [anchor=south]{$\mathsf{\overline{S}={\vNS}}$}--(2 IN1);

%LOGIC R WIRE
\draw[color=\R,line width=1pt](3 IN2)
    to [short,-o] ++(-1.25,0) node [anchor=south]{\sf R=\vR};

%LOGIC NEG-R WIRE
\draw[color=\NR,line width=1pt](3 OUT)
    node [anchor=south]{$\mathsf{\overline{R}={\vNR}}$}--(4 IN2);

%LOGIC Q WIRE
\draw[color=\Q,line width=1pt](2 OUT)
    to [short,-*] ++(0.5,0) coordinate (Q)
    to [short,-o]++(1,0)node [anchor=west]{$\mathsf{Q=\vQ}$}
    (4 IN1) -|++(-0.25,0.5) -- (Q |- 2 IN2) -- (Q);

%LOGIC NEG-Q WIRE
\draw[color=\NQ,line width=1pt](4 OUT)
    to [short,-*] ++(0.5,0) coordinate (NQ)
    to [short,-o]++(1,0)node [anchor=west]{$\mathsf{\overline{Q}={\vNQ}}$}
    (2 IN2) -|++(-0.25,-0.25) -- (NQ |- 4 IN1) -- (NQ);

\end{tikzpicture}
\end{frame}}
\end{document}
1

Using scopes you still have to copy and paste, but you don't have to rename the nodes each time.

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usetheme{Madrid}
\usepackage[american]{circuitikz}
\usepackage{tikz}


\begin{document}
\maketitle

\begin{frame}{SIMULATION}
   \begin{circuitikz}

\begin{scope}[yshift=0cm]
 \draw
   (0,0) node[nand port](mynand1){}
   (3,0) node[nand port](mynand2){}
   (mynand1.out) -- (mynand2.in 1);
\end{scope}
\begin{scope}[yshift=2cm]
 \draw
   (0,0) node[nand port](mynand1){}
   (3,0) node[nand port](mynand2){}
   (mynand1.out) -- (mynand2.in 2);
\end{scope}

\end{circuitikz} 
\end{frame}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .