Ask Sawal

Discussion Forum
Notification Icon1
Write Answer Icon
Add Question Icon

Kapil N




Posted Questions



Wait...

Posted Answers



Answer


Ngspice is the most popular free circuit simulator. Its available for most platforms including Linux. Whether you are an engineer or just want to play with electronics as a hobby, Ngspice can be a useful tool to simulate circuits and analyse their behavior before actually building them in the lab.

This quick tutorial shows you how to setup and use Ngspice on Ubuntu. The ngspice packages are available in the Ubuntu repository so you need to do any compilation.

Just install using the apt-get command and you are ready to go.

Install ngspice using the apt-get command.

Its should install in a few minutes. Next check the details of the installed version:

The above is how it showed up on my system. Yours might be a little different.

To learn more about the latest ngspice version available, check out their official site at:

Ngspice can be used as a stand alone command on the terminal or as an interactive shell. We shall be using the interactive shell. Inside the interactive shell we can do things like loading circuits, simulating them, and seeing the output in plots.

Running the ngspice command launches the shell with a welcome message.

Now that we have started the shell, its time to create and test our first circuit. Keep reading!

Lets take this simple circuit for example. It has a dc voltage source ( a simple battery ) and a resistor connected with it. It can't get any simpler.

The numbers 0 and 1 represent the node numbers. A node is a point which connects 2 or more components together. Be careful with node numbers. No 2 nodes can have the same number. Doing so would mean they are the same nodes.

To represent the above circuit in spice, we write the following piece of code. Type it out in a simple text file and save as "first.net"

You may ask, why the filename extension ".net" ? Because the circuit code is called a "net list" in spice terminology. You could use any extension for the file, but most popular extensions are .net and .cir

It doesn't matter!

:: First line is a comment - Its required !

The first line is a comment. Lines starting with an asterisk mark are treated as comments by spice. It is necessary to have a comment line at the starting of the file. Spice needs that! It is treated as the title of the circuit.

!! If you do not add a comment line, then the first circuit line shall be treated as the title and you shall get funky outputs.

:: The circuit

The Vin line specifies the voltage.

Note - When specifying the voltage nodes, the positive node must be specified first. If you specify the voltage as "Vin 0 1 dc 10", then spice will treat it as a negative voltage source. 0 shall be ground and 1 shall be 10volts below it.

However the node order is insignificant for passive components like resistors and capacitors. The resistor can be specified as "R1 1 0 5" or "R1 0 1 5". Its the same, as long as the nodes are correct.

:: Node 0 or GND must be there in the circuit

You must have a node named 0. The 0 node is absolutely necessary to be present in the circuit and it shall be treated as "Ground" by Spice. So make sure to have a node named 0 at the ground point.

If you do not have a 0 node in your circuit specification, you would see errors like these when trying to run the circuit program

You can also use gnd or GND in place of 0. The following syntax will also work

Spice will automatically replace gnd or GND with 0.

:: We are doing a TRANSIENT analysis in this circuit

Transient analysis is the the behaviour of the circuit over a period of time. This is what we would mostly do.

The .tran line indicates that we want to do a transient (time based) analysis of the circuit upto the time point of 1 second in increments of .05 seconds.

When doing a very basic analysis of the circuit to find out what would the current and voltage be at various places in the circuit at any time, we do a "transient" analysis inside of spice.

We tell spice to find the circuit behavior between 2 time points and spice calculates the data which can be used to draw a plot.

In the above code, we are analysing the circuit behavior between 0s and 1s and the calculation shall be done in increments of .05 seconds.

Now that we have written our first circuit program, its time to run it inside ngspice. Load the circuit file using the source command like this:

Now we shall simulate the circuit program written above. The ngspice interactive shell has a "run" command to make spice do the simulation and calculate values at different points in time.

Now the simulation is complete and all the date is ready for analysis.

To plot the voltage use the plot interactive command. First use the "display" command to see what all can be plotted.

Ngspice tells us that we can plot the voltage V(1) which is the voltage at Node 1, V(2) and the current through vin branch.

In the above example if you try to plot the current by plotting vin#branch, you will see that the current is being shown is negative. This is confusing. However that is how spice works.

Note: Plotting the current across a component in ngspice is a bit tricky.

The voltage is measured at a certain node. However currents cannot be measured at a node (since current entering any point it equal to the current leaving that point).

However current is measured through components. Spice by default measures current across voltage sources and certain components like inductor

:: Fake voltage source technique

To measure the current across a resistor add a fake 0 volt dc source in series and then spice shall calculate the current flowing through this voltage source which shall be equal to the current through the resistor itself!

Then spice will allow to plot the current across the voltage source on graph.

1. View the current circuit net using the listing command. The "listing" command shall display the circuit code as it is in the loaded file. There shall be however few extra lines.

1. You can skip the ".tran" statement in the circuit code and use the tran command from interactive terminal.

Run the transient analysis with the tran interactive command -

This way you can make the circuit file look neat and clean.

2. Use the .control statement in the code to run interactive commands inside the circuit code.

The above circuit program will run and plot immediately as you load it using the source command

The .endc marks the end of the control block. Instead of the run command inside the control block, you could instead write the tran command inside the control block which would also cause the simulation to run.

3. Run the interactive "help" command to launch the help window.

The previous circuit was too simple with a flat voltage and current plot. Now lets try plotting a different circuit that has a capacitor in it.

Here is what the graph would look like -

Now that we have done 2 circuits with a dc voltage source, lets try a different one with an ac voltage source. AC source is a varying voltage with changing amplitude and direction.

Here is the circuit code

Save the file as rc_ac.net Note that there is no .tran statement. We shall use the tran command instead.

Run it and plot the voltage and current

Now issue the tran command to calculate the time based behavior.

We want to plot the output of the circuit from 0s to 100us to be calculated in increments of .05 us.

To simulate a low pass RC filter with the above circuit, check out this tutorial -

Have a look at the following links for more examples:

https://possiblelossofprecision.net/?p=1384 https://ashwith.wordpress.com/2010/09/30/ngspice-interactive-mode/

Geda is a powerful circuit design tool for Linux. It can be used to design circuits and then you can create netlist files from these geda circuits.

Run from the applications menu on your desktop, or from the terminal like this -

Geda saves the circuits as sch files that can be converted to ngspice net files using the gnetlist command like this

Next you can use the .net file to simulate with ngspice or other tools like gspiceui

Gspiceui is a gui tool that can be used to simulate .net files and view the output or wave form. Once you have created your circuit ".net" file you can open it inside Gspiceui and run the simulation with various settings. Gspiceui can also directly import Geda .sch files and convert.

It has a menu option to reload the file quickly, if you are editing it in a text editor side by side. Just save the circuit file in the text editor and click Reload inside of gSpiceUI. And click Simulate and run again.

Besides geda and gspiceui, there are other free tools for linux like Kicad that can be used to draw and simulate circuits. We shall be talking about those in upcoming articles.

To try out ngspice programs inside your web browser, check out this site -

You can type in your netlist and view the plots in the browser, without having to install ngspice. It does not however save your netlist.

For a more powerful web based ngspice emulator check out partsim. It allows you to draw circuit visually and run them, and also save them and share them online.

http://ngspice.sourceforge.net/docs/ngspice-manual.pdf - The official Ngspice manual and guide you need to read up before using ngspice for the first time. However that's not compulsary!

http://bwrcs.eecs.berkeley.edu/Classes/IcBook/SPICE/UserGuide/analyses_fr.html - Explanation of the different kinds of analysis spice can perform on a ciruit.

http://www.allaboutcircuits.com/textbook/reference/chpt-7/spice-quirks/ - A practical guide explaining things that you need to careful about when simulating with spice.

http://www.allaboutcircuits.com/textbook/reference/chpt-7/example-circuits-and-netlists/ - Examples of circuit netlists


Answer is posted for the following question.

How to open ngspice in ubuntu?

Answer


With FlexSalary, you can avail a quick loan just within a few hours of approval or most probably on the same day of your application We offer quick loans for


Answer is posted for the following question.

Where can i get quick cash?

Answer


Nevada is one of the best places in the United States for boondockers You can camp for free on Bureau of Land Management ( BLM ) land,


Answer is posted for the following question.

Do you know best blm camping in Nevada?

Answer


After launching the Pokémon Trading Card Game Online it is possible, in rare circumstances, to experience an issue while loading the game


Answer is posted for the following question.

Why is my pokemon trading card game online not working?

Answer


If you’re hosting a meeting in Zoom but need to leave early due to unforeseen circumstances, you can pass off the host privileges to another member instead of ending the meeting. Here’s how.

Before we get started, there’s an important limitation you’ll need to be aware of. Zoom has a free version for all to use, but it also offers a couple of packages for businesses.

In the case of passing host controls to another user, if the original host is a licensed user, then the meeting can continue for an unlimited amount of time once the controls are handed off, even if the user who received the host controls is a free user. However, if the original host is a free user, the meeting will be limited to 40 minutes after the controls are passed—even if the new host is a licensed user.

Now that we’ve cleared that up, here’s how the host can pass the torch.

First, you (as the host) need to set up the Zoom meeting. You can do this by opening the Zoom app and selecting the “New Meeting” button from the home screen. Next, invite the participants to join the meeting. You can do this by selecting “Invite” at the bottom of the window.

RELATED: How to Hide Your Background During Video Calls in Zoom

Once the meeting is set up and all participants have joined, select the “Manage Participants” option at the bottom of the window where the video conference is being held.

Alternatively, press Alt+U (Windows) or Command+U (Mac).

The list of participants will appear in the right pane. Hover over the name of the participant you’re passing host controls to and then select the “More” button.

In the menu that appears, click the “Make Host” option.

A message will appear asking if you’re sure you’d like to change the host to . Select “Yes.”

In the pane showing the participants, you can now see the host controls have been passed to that user. The original host can now safely leave the meeting without interrupting the video conference.

RELATED: The 6 Best Free Video Conferencing Apps


Answer is posted for the following question.

How to change host on zoom?

Answer


  • Soft Tissue Injuries.
  • Broken Bones.
  • Traumatic Brain Injuries.
  • Spinal Cord Injuries.
  • Psychological Injuries.

Answer is posted for the following question.

What is a short term injury?

Answer


I suspect setting a RETURN-CODE, writing a message and then terminating the program via a STOP RUN or GOBACK is all that you really want to do. Causing an actual ABEND may not be necessary. In an IBM batch environment, the RETURN-CODE set by your program becomes the RC for the JCL job step the program was run under.


Answer is posted for the following question.

How to abend a cobol program?


Wait...