SPICE simulation in GNU Emacs

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
 

  1. Install ngspice and gnuplot # apt install ngspice gnuplot
  2. Download https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/spice-mode.el.
  3. Load the file (load "~/spice-mode.el")
  4. 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).
  5. Enter circuit definition.
  6. 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).
  7. Plot the results using C-c C-v (spice-plot). Enter the fields (e.g. int out) to be plotted.

Sample circuit

* This is a comment
 
.title dual rc ladder
 
R1 int in 10k
V1 in 0 dc 0 PULSE (0 5 1u 1u 1u 1 1)
R2 out int 1k
C1 int 0 1u
C2 out 0 100n
 
.tran 50u 50m
* .plot in int out

.end

 

Note: Till I figure out a better way to override compilation-error rules, you need to apply the following patch to jump to error location via 'next-error' command. Also, if there's only one error, (next-error 0) should be called. However, (prefix-numeric-value arg) returns 1 and hence, error is not found.

modified   lisp/progmodes/compile.el
@@ -2186,7 +2186,7 @@ define-compilation-mode
    compilation-mode-font-lock-keywords
    compilation-page-delimiter
    compilation-parse-errors-filename-function
-   compilation-process-setup-function
+   ;; compilation-process-setup-function
    compilation-scroll-output
    compilation-search-path
    compilation-skip-threshold
 
modified   lisp/simple.el
@@ -333,7 +333,7 @@ next-error
     (when buffer
       ;; We know here that next-error-function is a valid symbol we can funcall
       (with-current-buffer buffer
-        (funcall next-error-function (prefix-numeric-value arg) reset)
+        (funcall next-error-function (if arg (prefix-numeric-value arg) 0) reset)
         (let ((prev next-error-last-buffer))
           (next-error-found buffer (current-buffer))
           (when (or next-error-verbose
 

Comments

Popular posts from this blog

GNU Emacs as a Comic Book Reader

Tinylisp and Multi-threaded Emacs

Data Visualization with GNU Emacs