Posts

Showing posts with the label ngspice

SPICE simulation in GNU Emacs (From schematics)

Image
Now you can design and run SPICE simulation for simple circuits in GNU Emacs. Since the circuit and graphs are in SVG format, you can easily annotate and share it on the web or embed it in a document.   Video tutorial for configuring the circuit diagram, running the simulation and plotting the results is below:  Video tutorial for drawing the circuit diagram using widgets is below:   Code:   https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/svg.el https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/spice-mode.el   Setup: Setup is covered in following blog posts. https://lifeofpenguin.blogspot.com/2021/10/svg-widget-in-gnu-emacs.html https://lifeofpenguin.blogspot.com/2021/10/spice-simulation-in-gnu-emacs.html Additionally, we need to make special spice plugin (defined in spice-mode.el) available to canvas-mode. This makes plugin keybindings available via C-x in canvas-mode. To do this, add following to .emacs (setq canvas-plugin-map spice-canvas-map)  ...

SPICE simulation in GNU Emacs

Image
Now you can manage and run SPICE simulation within GNU Emacs using ngspice. To visualize the output, the code uses ngspice control card to run gnuplot.   .emacs ;; Check the location of spice-mode.el (load "~/spice-mode.el") (setq spice-simulator "Ngspice"       spice-waveform-viewer "ngplot") ;; ngplot is a new custom viewer defined in elisp which uses gnuplot   Install ngspice and gnuplot # apt install ngspice gnuplot Download https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/spice-mode.el . Load the file (load "~/spice-mode.el") Open a new buffer and activate mode using M-x spice-mode . Select simulator Ngspice and waveform viewer ngplot via menu or by setting variables (same as in .emacs above). Enter circuit definition. Run the simulation using C-c C-r (spice-compile). Go to error, if any, using 'next-error' ( M-x next-error or M-g n ). Plot the results using C-c C-v (spice-plot). Enter the fields (e.g. int out) to be plotted. S...