circuitikz / circuitikz

CircuiTikZ TeX/LaTeX package for drawing circuits
https://circuitikz.github.io/circuitikz
389 stars 60 forks source link

More examples of IC based circuits? like IC pin layout, breadboard diagrams #665

Open goyalyashpal opened 1 year ago

goyalyashpal commented 1 year ago

Current:

I want to be able to do:

Background:

Rmano commented 1 year ago

I'm sorry for your lack of time; probably this is a show-stopper. You can use some graphically oriented program, like for example XCircuit: http://opencircuitdesign.com/xcircuit/ (there is no https available, unfortunately).

If you still want to try with circuitikz: for the first problem (overlaying the circuit on the chip) I have an example that I can post (not now, I have no time --- but you can ask in https://tex.stackexchange.com/questions/tagged/circuitikz (be sure to read the rules and post a minimal example!).

For the second problem you can start from here: https://tex.stackexchange.com/questions/493239/alignment-of-dip-chips-in-circuitikz

I will close this issue now, because as stated in the README:

Please do not use the issue page for generic help on how to use the package. The manual has a (growing) set of examples; also the questions tagged circuitikz on https://tex.stackexchange.com/ are often answered promptly. You can also find help on matrix and on TopTeX.

Rmano commented 1 year ago

I found the code, pasting here with no comments...

documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\usepackage{mathpazo}
\usetikzlibrary{shapes.symbols, backgrounds, fit}
\usepackage{stackengine}
\DeclareSIUnit{\uF}{\micro\farad}
\DeclareSIUnit{\nF}{\nano\farad}
\ctikzsetstyle{romano}
\begin{document}

\begin{tikzpicture}[]
        \draw (0,0) node[dipchip, rotate=90, anchor=pin 8, circuitikz/chips/scale=1.5,
            no topmark, draw only pins={1,2,4,5,7,8}](AD835){}
            (AD835.north) node[above, rotate=90]{\texttt{AD835ANZ}};
        \begin{scope}[on background layer={color=gray}]
            \node [mixer, circuitikz/blocks/scale=0.7](M) at([xshift=-0.3cm]AD835.center) {};
            % 2.25 is 1.5*1.5 (chip scale * NL/2
            \node [muxdemux, muxdemux def={Lh=2.25, NL=3, Rh=0.8, NR=1, w=0.8, NB=1},
                external pins width=0, rotate=-90, anchor=blpin 3](DX)
                at ([yshift=-3mm]AD835.bpin 8){};
            \node [font=\tiny, below=-1mm] at (DX.blpin 3) {$+$};
            \draw (DX.blpin 3) -- (AD835.bpin 8) (DX.blpin 1) -- (AD835.bpin 7);
            \node [font=\tiny, below=-1mm] at (DX.blpin 1) {$-$};
            \node [muxdemux, muxdemux def={Lh=2.25, NL=3, Rh=0.8, NR=1, w=0.8, NB=1},
                external pins width=0, rotate=90, anchor=blpin 1](DY)
                at ([yshift=3mm]AD835.bpin 1){};
            \node [font=\tiny, above=-1mm] at (DY.blpin 1) {$+$};
            \node [font=\tiny, above=-1mm] at (DY.blpin 3) {$-$};
            \draw (DY.blpin 1) -- (AD835.bpin 1) (DY.blpin 3) -- (AD835.bpin 2);
            \node [muxdemux, muxdemux def={Lh=3, NL=3, Rh=1, NR=1, w=1, NB=1}, external pins width=0](A)
                at([xshift=0.7cm]AD835.center) {};
            \draw (DX.brpin 1) -- ++(0,-0.2) -- (M) (DY.brpin 1) -- ++(0,0.2) -- (M) (M.e) -- (A.left)
                (A.right) -| (AD835.bpin 5) (A.bbpin 1) -- ++(0,-0.2) -| (AD835.bpin 4);
        \end{scope}
    \end{tikzpicture}
\end{document}

image

Rmano commented 1 year ago

I'll add the previous example to the manual, reopening as a documentation issue.

goyalyashpal commented 1 year ago

For the second problem you can start from here: https://tex.stackexchange.com/questions/493239/alignment-of-dip-chips-in-circuitikz

... for overlaying the circuit on the chip ... I found the code, pasting here with no comments...

I'll add the previous example to the manual, reopening as a documentation issue.

wow, thanks a lot for these. this issue was meant as a documentation issue in the first place :cute_wink:

but you can ask in https://tex.stackexchange.com/questions/tagged/circuitikz


Continued:

  1. any book recommendation for learning Tikz & CircuiTikz? (preferably gratis and offline digital copy)
  1. update: refer: https://github.com/circuitikz/circuitikz/issues/213#issuecomment-497239564 [OPTIONAL] any thoughts on why the breadboard component is better not included?
goyalyashpal commented 1 year ago

I am making some progress using the example u provided. thanks a lot for that.

do u mind me posting my investigations on that here?

goyalyashpal commented 1 year ago

Investigations:

To-Do:

Current level of Abstraction: 4

Update: 2022.12.04 The further abstractions/cleanup/honing of the code are a bit more involving and mostly use concepts from Tikz, so, I will be mentioning those in a new comment: https://github.com/circuitikz/circuitikz/issues/665#issuecomment-1336343986

Input:

  1. Overlaying the circuit on the chip, on inspecting/isolating the code share above, is done just using the tikzlibrary and scope environment:
\usetikzlibrary{shapes.symbols, backgrounds, fit} % Have not tried to minimize further
...

\begin{tikzpicture}
    ...
    \begin{scope}[on background layer]
        ... <overlaying circuit content goes here>
    \end{scope}
\end{tikzpicture}
Rmano commented 1 year ago

Offsetting the pin labels to move them either outwards (preferably on the pin pads like in the IC manuals), or atleast off-centering

Like this?

\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\usetikzlibrary{backgrounds}
\begin{document}

\begin{tikzpicture}[]
        \draw (0,0) node[dipchip, rotate=90, anchor=pin 8, circuitikz/chips/scale=1.5,
            circuitikz/multipoles/external pins thickness=2,
            circuitikz/multipoles/external pad fraction=4, hide numbers,
            no topmark, ](AD835){}
            (AD835.north) node[above, rotate=90]{\texttt{AD835ANZ}};
        \foreach \i in {1,...,4} \node[font=\tiny\ttfamily, below] at(AD835.bpin \i){\i};
        \foreach \i in {5,...,8} \node[font=\tiny\ttfamily, above] at(AD835.bpin \i){\i};
        \begin{scope}[on background layer={color=gray}]
            \node [mixer, circuitikz/blocks/scale=0.7](M) at([xshift=-0.3cm]AD835.center) {};
            % 2.25 is 1.5*1.5 (chip scale * NL/2
            \node [muxdemux, muxdemux def={Lh=2.25, NL=3, Rh=0.8, NR=1, w=0.8, NB=1},
                external pins width=0, rotate=-90, anchor=blpin 3](DX)
                at ([yshift=-3mm]AD835.bpin 8){};
            \node [font=\tiny, below=-1mm] at (DX.blpin 3) {$+$};
            \draw (DX.blpin 3) -- (AD835.bpin 8) (DX.blpin 1) -- (AD835.bpin 7);
            \node [font=\tiny, below=-1mm] at (DX.blpin 1) {$-$};
            \node [muxdemux, muxdemux def={Lh=2.25, NL=3, Rh=0.8, NR=1, w=0.8, NB=1},
                external pins width=0, rotate=90, anchor=blpin 1](DY)
                at ([yshift=3mm]AD835.bpin 1){};
            \node [font=\tiny, above=-1mm] at (DY.blpin 1) {$+$};
            \node [font=\tiny, above=-1mm] at (DY.blpin 3) {$-$};
            \draw (DY.blpin 1) -- (AD835.bpin 1) (DY.blpin 3) -- (AD835.bpin 2);
            \node [muxdemux, muxdemux def={Lh=3, NL=3, Rh=1, NR=1, w=1, NB=1}, external pins width=0](A)
                at([xshift=0.7cm]AD835.center) {};
            \draw (DX.brpin 1) -- ++(0,-0.2) -- (M) (DY.brpin 1) -- ++(0,0.2) -- (M) (M.e) -- (A.left)
                (A.right) -| (AD835.bpin 5) (A.bbpin 1) -- ++(0,-0.2) -| (AD835.bpin 4);
        \end{scope}
    \end{tikzpicture}
\end{document}

image

(I reduced the dependencies, too).

any book recommendation for learning Tikz & CircuiTikz?

I learnt by perusing StackExchange and the TikZ manual. About circuitikz, I am pretty sure that the only book existing is the manual (which I heavily authored, but it's not just mine).

goyalyashpal commented 1 year ago
_(click me)_ Code for drawing the pin layout diagram of IC-`74x08`: **Update: 2022.12.04:** Further modifications to this code will be posted in a new comment after https://github.com/circuitikz/circuitikz/issues/665#issuecomment-1336343986 ```latex % Refer: % 2.4 A logic circuit % 4.25 Chips (IC) % Code shared by @Rmano % Tikz: 2.20, 88 Repeating Things: For-loops % 5.5.6 American Voltage Customisation (for specifying the style) % \documentclass[border=10pt]{standalone} \usepackage{circuitikz} \usetikzlibrary{backgrounds} \begin{document} \ctikzset{ logic ports=ieee, logic ports/scale=0.7, % ieeestd ports/height=1.5, } %% To define following globally, do: % copy the key without the circuitikz and paste it inside \ctikzset % Example: % \ctikzset{ multipoles/thickness=4, } % Define sizes in icpinlayout style \tikzset{icpinlayout/.style={% Defaults given in comments circuitikz/multipoles/thickness=4, % 2 circuitikz/multipoles/external pins thickness=2, % 1 circuitikz/multipoles/dipchip/pin spacing=0.8, % 0.4 circuitikz/multipoles/dipchip/width=2, % 1.2 circuitikz/multipoles/external pad fraction=4, % 0 circuitikz/multipoles/external pins width=0.3, % 0.2 circuitikz/logic ports=ieee, % circuitikz/logic ports/scale=0.4, % }} % Define labelling \newcommand*{\icpinlayout}[2]{%1 Pins, %2 Label IC number, % Draw 14 pin dipchip % This has to be the first command node[dipchip, rotate=90, num pins=#1, hide numbers, icpinlayout]% (ic08){\rotatebox{-90}{\texttt{#2}}}; % Draw Pin Numbers outside the bpin \foreach \i in {\inteval{#1/2 + 1},...,#1} \node[font=\scriptsize\ttfamily, above] at(ic08.bpin \i){\i}; \foreach \i in {1,...,\inteval{#1/2}} \node[font=\scriptsize\ttfamily, below] at(ic08.bpin \i){\i}; % Label VCC & GND \node[font=\small\ttfamily, above] at(ic08.pin #1){VCC}; \node[font=\small\ttfamily, below] at(ic08.pin \inteval{#1/2}){GND}; } % Define the IC for quad 2-input gates \newcommand*{\icGateTwoIn}[3]{%1 Label IC number, %2 gate % This has to be the first command \icpinlayout{14}{#1} % Define gate here to use the 2nd argument \def\gate{#2} % Begin Overlay Circuit \begin{scope}[on background layer={color=gray}] % Specify the parameters for gate % a = in 1, b = in 2, y = out, s = sign \foreach \a / \b / \y / \s in {% {1/2/3/+}, {4/5/6/+}, {9/10/8/-}, {12/13/11/-}}{% \draw (ic08.bpin \y) |- ++(-0.1,\s 0.7) node[\gate\space port, anchor=out, icpinlayout](1){}; \draw (ic08.bpin \b) |- (1.in 2); \draw (ic08.bpin \a) |- (1.in 1); } \end{scope} % End Overlay Circuit } % End IC definition \begin{tikzpicture}[] \draw (0,0) \icGateTwoIn{74x08}{and}; \draw (0,-5) \icGateTwoIn{74xxx}{xnor}; % Uncomment following line to verify the optional-ity of icpinlayout style for dipchip and gates % \draw (0,-10) node[dipchip, num pins=16](a){} (a.pin 15) node[and port, anchor=in 2, color=green]{}; \end{tikzpicture} \end{document} ```
Output Reference

The image preview of output here is scaled down to save space, and deliberately made for ANDs. Comparing with the reference/target image, it's awesome.


Further thoughts:

Any suggestions (code, implementation, or graphic, or anything else) is welcome

In the previous attempt with parametrization,

PS:

  1. How did you get the output in the image format - like did you convert the pdf into png, or directly output to png? In either case, how (just a brief summary like)?
  2. Remaining major things from my side is just the breadboard, and the alignment of these obtained figures on the page (the need might arise to use it with multi-column layout which i am not familiar with) - but i am positive that i'll figure those things out now 😜

For Inclusion in the documentation as example:

Rmano commented 1 year ago

I will get back to you with comments as soon as I finish the paper submission I'm in (for not having time, this is quite impressive 😉 on your side).

About the arithmetic, if you show me an example I can help. Often the problem is expandability... You can check \pgfmathsetmacro and/or the new LaTeX3 \fpeval, \inteval...

goyalyashpal commented 1 year ago

for not having time, this is quite impressive 😉 on your side

haha, thanks :smiley:

for clarification, i meant that - i can not get enough relaxed time to calmly dig through stuff for solutions, and do experiments with their validity and applicability to my use.

Mental Bandwidth or mental processing power would have pro'lly been a better term there instead of just time - but i guess that sounds a bit showoff i guess :sweat_smile:

goyalyashpal commented 1 year ago

plus, i gotta say, the documentation of Tikz is sometimes a bit - umh - ambiguous or unclear, for example,

detailed citations/quotes in the hidden comment below:

goyalyashpal commented 1 year ago

self hiding this comment as off topic:


Quotes:

Tikz 2.15 Specifying Coordinates (pg 40): +(0cm,1cm) means “1cm upwards from the previous specified position” ++(2cm,0cm) means “2cm to the right of the previous specified position, making this the new specified position”

CircuiTikz 3.1.3 Relative coordinates (pg 32): the +(x,y)-style coordinates (which are supposed to set a temporary relative coordinate and then going back to the starting point).

  1. The circuitikz one made it immediately clear - "going back to the starting point" , just the lack of "making this the new specified position" does not make it clear at all in case of tikz ones.

Tkz 2.21 Adding Text (pg 46): ... two (or even more) variables separated by a slash as in \x / \xtext ... the elements in the set over which \foreach iterates must also be of the form ⟨first⟩/⟨second⟩. In each iteration, \x will be set to ⟨first⟩ and \xtext will be set to ⟨second⟩

\foreach \x/\xtext in {-1, -0.5/-\frac{1}{2}, 1}

.

Tikz 88 Repeating Things - Multiple variables (pg 1003):

\foreach \x / \y / \r in {0 / 0 / 2mm, 1 / 1 / 3mm, 2 / 0 / 1mm}
  1. My brain got confused by a lot of things there: /-\ why minus in between?, / used only at one place here? and that with one more command (which further confused me)? \?, etc.
    • I admit that i was not relaxed, in a hurry, while reading this 2-4 days ago, but also, this is a, umh, quite direct application example
    • if there were redirect to more basic examples as provided aptly in Ch-88 in Tikz manual itself: - than I'd have no problem grabbing that.
    • On this matter, i'd like to applaud CircuiTikz documentation - as it always mentions relevant section containing more details (in both directions: next/previous chapters) - it was only because of those redirects/hyperlinks in CircuiTikz manual that I was able to read multiple sections relevant to me w/o much additional effort in searching through long ToC and scrolling.
Rmano commented 1 year ago

I'd love to follow up more, but you got me in a crossfire of deadlines in my job....

Yes, the TikZ manual is somewhat cryptic sometimes, but lately development is quite active so you can PR suggestions.... Once you untangle the source format, that is.

About the PNG conversion: mine are just bitmap copy and paste from okular (or screenshots from evince, when the antialiasing of the first one become unbearable).

Definitely I'd like to add your example to the manual!

goyalyashpal commented 1 year ago

I'd love to follow up more, but you got me in a crossfire of deadlines in my job....

it's okay, take your time to participate in real life.

Definitely I'd like to add your example to the manual!

thanks. aweesome. just for records, there's some more cleanup which i wish to do in this example update: done - most notably, defining the sizes in some style so that this specification of sizes is optional, rather than being forced onto; so that this can be used flexibly with normal dipchips too

Rmano commented 1 year ago

Definitely I'd like to add your example to the manual!

thanks. awesome.

...or if you want and you are in the mood, you can even do it as an "advanced tutorial". Whatever you prefer. I can just take the code (and attribution --- please tell me exactly how you'd like to be cited) and add to the examples, or wait for a PR on your side.

goyalyashpal commented 1 year ago

LaTeX3 \fpeval, \inteval - https://github.com/circuitikz/circuitikz/issues/665#issuecomment-1314950801

wow, they worked out of the box: \inteval{#1/2} , i thought it would require some additional settings to use LaTeX3

goyalyashpal commented 1 year ago

Status tracking for further and more involved abstractions/cleanups per the remark mentioned at comment: https://github.com/circuitikz/circuitikz/issues/665#issuecomment-1314236121

goyalyashpal commented 1 year ago

I have gathered quite a lot of good points on tackling a good amount of logic symbols.

'am very excited to put them in a tutorial. however, have exams at hand at the moment which will continue uptill 1 month at least. will do it thereafter.

goyalyashpal commented 1 year ago

just for records, i was thinking about TikZ styled tutorial - the walkthrough in a third person story type. it allows incorporating various "loose" tips and "reason behinds" as well.

but i was a bit unsure about how deep it will be, as i was thinking of starting from start, so before section 2.1 a current shunt (of Circuitikz tutorials), but its body will not touch much the contents of sections 2.1 to 2.3 transistor based amplifier, but then it will contain much more depth content than section 2.4 A logic circuit

the thing i am wondering about is how we will communicate regarding the order - ideation will require more commits, which will require cleanup. but i just know how to commit - that's pretty much all i know in git.

so, when we get to it, will you handle the commit cleanup part? the rebase / squash commit etc 😅 as i don't want to pollute the commit history...


anyways, that's enough rambling for now 😅 , i just wanted to put these thoughts out here

Rmano commented 1 year ago

so, when we get to it, will you handle the commit cleanup part? the rebase / squash commit etc sweat_smile as i don't want to pollute the commit history...

Yes, I can help --- as long as you do the changes on you branch, you can even reorganize it and force push --- until the thing is merged, no harm is done (I force push quite a lot when I am developing, you can see that). I am not a git-uber-user too, I just do the basic things (the interactive rebase is the best tool ever), especially if you want to "follow" the development.

One suggestion: you can develop it in a separate file --- I do the same when preparing part of the manual. You can add a file in your clone with the following content:

documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[siunitx, RPvoltages]{circuitikz}
\usepackage{ctikzmanutils}

\makeatletter
\makeatother

\begin{document}
\section{Dummy sec}
\subsection{Dummy subsec}
\subsubsection{Dummy subsubsec}

\begin{groupdesc}
    \circuitdesc*{bnc}{BNC connector}{}(left/135/0.6, right/45/0.6, center/-45/0.6, hot/0/0.6, zero/-135/0.6, shield/-90/0.4)
    \circuitdescbip[cuteopenswitch]{cute open switch}{Cute open switch}{cosw}(out/45/0.2)[out.s/-90/0.2]
\end{groupdesc}

\geolrcoord{bnc}

\begin{lstlisting}[varwidth=true]
    A one
    B two
    C three
\end{lstlisting}

\begin{LTXexample}[varwidth=true, basicstyle=\small\ttfamily]
\begin{circuitikz}[european]
    \draw (0,3) node[nand port](A){}
        (A.out) to[short, *-o] ++(0.5,0);
\end{circuitikz}
\end{LTXexample}

\end{document}

which load the same setup used in the manual, and then merge it when it is more or less finished in the main circuitikzmanual.tex.

Anyway, I will help with git if I am able to ;-)

Rmano commented 2 months ago

Hi @goyalyashpal, @gro1m --- I was thinking about all this, especially after seeing #784. While I think that adding a background image to a generic chip (like I implemented for muxdemuxes) could be a nice thing¹ for specific circuits, I now think that the full-fledged breadboard thing is quite out-of-scope for the package.

On the other hand, a package that extends TikZ for that specific usage would be a great thing. I do not know how much of the internals of circuitikz it would need (I hope very little), but I am willing to add interfaces where and when needed for the new package. Another advantage of a separate package is that, if the author(s) is(are) willing so, it can be made just LaTeX-specific, and so it could use the power of the latex3 programming layer, a thing that I can't do in circuitikz because it must be usable also in ConTeXt (or at least, it should).

Notes:

¹ really, it should be improved to be able to use generic, high-level tikz code for the drawings that can use the anchors of the component. Moreover, it should be added to chips. Again, I have little time on my hands now, and I am not sure on how to do it (tikzpictures can't be nested...).