Electronic circuit simulation with geda and NG-Spice by Example

Similar documents
Laboratory 4: Feedback and Compensation

Lab 7: Operational Amplifiers Part I

Experiment # (4) AM Demodulator

Lab 1: Introduction to PSpice

LAB4: Audio Synthesizer

Copyright 2011 Linear Technology. All rights reserved.

Op-Amp Simulation EE/CS 5720/6720. Read Chapter 5 in Johns & Martin before you begin this assignment.

EE 242 EXPERIMENT 5: COMPUTER SIMULATION OF THREE-PHASE CIRCUITS USING PSPICE SCHEMATICS 1

University of California, Berkeley Department of Electrical Engineering and Computer Sciences EE 105: Microelectronic Devices and Circuits

MATERIALS. Multisim screen shots sent to TA.

Electronics. Discrete assembly of an operational amplifier as a transistor circuit. LD Physics Leaflets P

Diode Applications. As we have already seen the diode can act as a switch Forward biased or reverse biased - On or Off.

Frequency Response of Filters

Low Cost Pure Sine Wave Solar Inverter Circuit

Rectifier circuits & DC power supplies

Lecture 24. Inductance and Switching Power Supplies (how your solar charger voltage converter works)

Accurate Measurement of the Mains Electricity Frequency

LAB 7 MOSFET CHARACTERISTICS AND APPLICATIONS

School of Engineering Department of Electrical and Computer Engineering

LABORATORY 2 THE DIFFERENTIAL AMPLIFIER

ANADOLU UNIVERSITY DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING

Output Ripple and Noise Measurement Methods for Ericsson Power Modules

PLL frequency synthesizer

Use and Application of Output Limiting Amplifiers (HFA1115, HFA1130, HFA1135)

Hands On ECG. Sean Hubber and Crystal Lu

Computer Aided Design of Home Medical Alert System

ε: Voltage output of Signal Generator (also called the Source voltage or Applied

Prepared by: Paul Lee ON Semiconductor

Introduction to LTspice IV Workshop

Lab #9: AC Steady State Analysis

See Horenstein 4.3 and 4.4

Lab 5 Operational Amplifiers

LH0091 True RMS to DC Converter

The full wave rectifier consists of two diodes and a resister as shown in Figure

PSPICE TUTORIAL (BASIC)

Pulse Width Modulation (PWM) LED Dimmer Circuit. Using a 555 Timer Chip

CHAPTER 2B: DIODE AND APPLICATIONS. D.Wilcher

Properties of electrical signals

1Meg. 11.A. Resistive Circuit Nodal Analysis

AC : MEASUREMENT OF OP-AMP PARAMETERS USING VEC- TOR SIGNAL ANALYZERS IN UNDERGRADUATE LINEAR CIRCUITS LABORATORY

Power Supplies. 1.0 Power Supply Basics. Module

Basics of Simulation Technology (SPICE), Virtual Instrumentation and Implications on Circuit and System Design

Experiment 2 Diode Applications: Rectifiers

LABORATORY 10 TIME AVERAGES, RMS VALUES AND THE BRIDGE RECTIFIER. Bridge Rectifier

Title : Analog Circuit for Sound Localization Applications

Final Project Report E3390 Electronic Circuit Design Lab. Automatic Phone-Alert Home Security System

Electronic WorkBench tutorial

Introduction to OrCAD Capture and PSpice

Lab 3 Rectifier Circuits

= V peak 2 = 0.707V peak

Diode Applications. by Kenneth A. Kuhn Sept. 1, This note illustrates some common applications of diodes.

Transistor Characteristics and Single Transistor Amplifier Sept. 8, 1997

LM 358 Op Amp. If you have small signals and need a more useful reading we could amplify it using the op amp, this is commonly used in sensors.

FREQUENCY RESPONSE ANALYZERS

Chapter 12: The Operational Amplifier

CIRCUITS LABORATORY EXPERIMENT 3. AC Circuit Analysis

LM1036 Dual DC Operated Tone/Volume/Balance Circuit

What you will do. Build a 3-band equalizer. Connect to a music source (mp3 player) Low pass filter High pass filter Band pass filter

ENGR-2300 Electronic Instrumentation Quiz 1 Spring 2015

Document Contents Introduction Layout Extraction with Parasitic Capacitances Timing Analysis DC Analysis

Pulse Width Modulated (PWM)

Hello and welcome to this training module for the STM32L4 Liquid Crystal Display (LCD) controller. This controller can be used in a wide range of

Lab Report No.1 // Diodes: A Regulated DC Power Supply Omar X. Avelar Omar de la Mora Diego I. Romero

STUDY OF CELLPHONE CHARGERS

EDEXCEL NATIONAL CERTIFICATE/DIPLOMA UNIT 5 - ELECTRICAL AND ELECTRONIC PRINCIPLES NQF LEVEL 3 OUTCOME 4 - ALTERNATING CURRENT

Reading: HH Sections , (pgs , )

FREQUENCY RESPONSE OF AN AUDIO AMPLIFIER

Figure 1. Diode circuit model

Understanding Power Impedance Supply for Optimum Decoupling

Circuit Simulation: Here are some of ADS analysis:

Step Response of RC Circuits

Pulse Width Modulated (PWM) Drives. AC Drives Using PWM Techniques

Series AMLDL-Z Up to 1000mA LED Driver

Homework Assignment 03

How to Create your own.lib File:

Application Note AN-1040

A Low-Cost VCA Limiter

Physics 623 Transistor Characteristics and Single Transistor Amplifier Sept. 13, 2006

ECEN 1400, Introduction to Analog and Digital Electronics

Experiment #11: LRC Circuit (Power Amplifier, Voltage Sensor)

LM118/LM218/LM318 Operational Amplifiers

SWITCH-MODE POWER SUPPLY CONTROLLER PULSE OUTPUT DC OUTPUT GROUND EXTERNAL FUNCTION SIMULATION ZERO CROSSING INPUT CONTROL EXTERNAL FUNCTION

DIODE CIRCUITS LABORATORY. Fig. 8.1a Fig 8.1b

POWER SUPPLY MODEL XP-15. Instruction Manual ELENCO

Welcome to this presentation on Driving LEDs AC-DC Power Supplies, part of OSRAM Opto Semiconductors LED Fundamentals series. In this presentation we

UNIVERSITY OF CALIFORNIA College of Engineering Department of Electrical Engineering and Computer Sciences

Current Loop Tuning Procedure. Servo Drive Current Loop Tuning Procedure (intended for Analog input PWM output servo drives) General Procedure AN-015

Power Electronics. Prof. K. Gopakumar. Centre for Electronics Design and Technology. Indian Institute of Science, Bangalore.

Audio Tone Control Using The TLC074 Operational Amplifier

MAS.836 HOW TO BIAS AN OP-AMP

Introduction to LTspice

Precision Diode Rectifiers

BASIC ELECTRONICS AC CIRCUIT ANALYSIS. December 2011

FEATURES DESCRIPTION APPLICATIONS BLOCK DIAGRAM. PT2248 Infrared Remote Control Transmitter

High voltage power supply (1 to 20 KV)

DIGITAL-TO-ANALOGUE AND ANALOGUE-TO-DIGITAL CONVERSION

Lock - in Amplifier and Applications

CONSTRUCTING A VARIABLE POWER SUPPLY UNIT

Measuring Impedance and Frequency Response of Guitar Pickups

Transcription:

Electronic circuit simulation with geda and NG-Spice by Example Andreas Fester May 25, 2004 Abstract This article describes how to simulate electronic circuits using the open source packages geda (GNU Electronic Design Automation) and NG-Spice. It was written after I spent some time to get involved with these packages, and especially NG-Spice needed some effort until the first circuit was ready for simulation. The article is meant to be a tutorial-by-example, not a reference manual; there is a detailed reference manual available in the NG-spice distribution. 1 Some SPICE history SPICE stands for Simulation Program with Integrated Circuit Emphasis. Originally, SPICE was implemented at the University of Berkeley. Other spice flavours have been derived from this implementation, and today there are several of them, for example winspice for the MS-Windows TM operating system, pspice, ltspice or tclspice. This article is about NG-spice, which has the goal to be a complete rewrite of the berkeley spice implementation. Currently it still contains code from berkeley spice, but has fixed a lot of bugs from the original code base. It is important to understand that each spice flavour might behave different in various areas; some of them are more compatible, others are less compatible. It is always necessary to read the documentation which came with the specific spice implementation. The NG-spice distribution comes with a detailed reference manual, but this article might help to learn where to start. It might be a good idea to have the NG-spice reference manual available when reading this article so that specific commands can be looked up in more detail. 2 Downloading and installing NG-Spice For the geda package, several binary packages are available. Many distributions already contain those binary packages. For example, for Debian installing geda is as simple as apt-get install geda. One of the packages from testing or unstable should be used, because they are much newer then the package in stable. The NG-spice package can easily be installed by compiling it from sources. After downloading the tarball, build a package for your specific distribution: % tar xvzf ng-spice-rework-15.tgz % cd ng-spice-rework-15 %./configure --with-readline=yes % make % checkinstall Make sure that the GNU readline library is enabled, this makes using the command line interface much more comfortable. More information on how to compile NG-spice can be found in the NG-spice user manual which is part of the NG-spice distribution.

3 Step by Step example This section contains a very simple step-by-step example to show how to simulate a circuit. Basically, the circuit will be drawn with gschem and then be simulated interactively with ngspice. 3.1 Drawing the circuit with gschem The circuit we want to simulate is a simple RC filter. This example was choosen because it contains a very limited and therefore manageable number of components: a voltage source, a resistor and a capacitor. Start gschem and draw the circuit shown in Figure 1. Using the schematics editor can be a littlebit confusing for the first time. Unlike other drawing applications, schematic editors tend to use an approach where the command has to be choosen first, and then the object on which the command is executed must be selected. Other graphics applications usually us an approach where the object is choosen and then the command to execute on these objects is selected. n0 C1 1 + - 2 V1 SIN(0 10 1kHz) 3,3nF R1 1k 0 Figure 1: A simple RC filter. The values which are shown in each corner are the netnames. They can be set by providing a value for the attribute netname for each net. A net can basically have any name, with one exception: There must be one net which is called 0. This is the reference (ground) net. V1 is an independant voltage source. Its value defines the wave form (SIN), the voltage offset (0), the amplitude (10V) and the frequency (1kHz). Save the schematic as rc.sch. 3.2 Creating the netlist The input for the spice simulation is a netlist. The netlist can be created from the schematics file using the command gnetlist. Create the netlist from the schematic file with the following command: $ gnetlist -g spice -o rc.net rc.sch geda/gnetlist version 20040111 geda/gnetlist comes with ABSOLUTELY NO WARRANTY; see COPYING for more details. This is free software, and you are welcome to redistribute it under certain conditions; please see the COPYING file for more details. Loading schematic [rc.sch] The netlist contains the following lines:

* Spice netlister for gnetlist * Spice backend written by Bas Gieltjes V1 n0 0 SIN(0 10 1kHz) C1 n0 3,3nF R1 0 1k.END The format of a netlist is quite simple: each line of the netlist file contains one device of the circuit. The first column in each line contains the name of the device, and the subsequent columns contain the netnames each pin is connected to and the value of the device. In our example, the third line contains the voltage source, which is connected to net n0 with pin 0 and to net 0 with pin 1. Its value is SIN(0 10 1kHz). The same applies to the capacitor and to the resistor. The first and the last line are special for NG-spice: when reading the netlist, NG-spice treats the first line as title or description of the circuit. The last line must contain the.end token. As the format of the netlist files is quite simple, it would even be possible to create those files manually with a text editor. Some articles about spice simulation even start with this approach, but I dont think that this is a suitable approach in general. Using a schematics editor, it is much easier to modify the circuit, and the schematic can also be easily printed or embedded into some documentation. For larger circuits it is really cumbersome to create the netlist manually. Furthermore, I like integrating tools in a tool chain. This simplifies work in most cases. 3.3 Simulating the circuit We are now ready to simulate the circuit. First, we need to decide which kind of analysis to run. SPICE can be used for different simulations, like transient, frequency (AC) and parameterized: A transient simulation is a time simulation. The result shows how the circuit behaves over time. An AC simulation is a frequency simulation. The behaviour of the circuit with varying frequency is described. A parameterized simulation can be both a transient or an AC simulation, but varies one or more values of the circuit. An example would be to simulate how a circuit behaves with a varying value for a specific capacitor. For the very first step, we want to see how the input voltage of our circuit behaves over time. We want to perform a transient analysis of the circuit and show the voltage between the nets 0 and n0. To start the simulation, launch ngspice: $ ngspice Note: can t find init file. ****** ** ngspice-15 : Circuit level simulation program ** The U. C. Berkeley CAD Group ** Copyright 1985-1994, Regents of the University of California. ** Please submit bug-reports to: ngspice-devel@lists.sourceforge.net ** Creation Date: Sun May 9 19:55:31 CEST 2004 ****** ngspice 6 -> We now need to load the netlist:

ngspice 6 -> source rc.net Circuit: * Spice netlister for gnetlist ngspice 7 -> Since we have defined a frequency of 1 khz for the input voltage, the time period is 1 ms. We want to see how the input voltage behaves during the first 5 ms. The simulation is started with the following command: ngspice 9 -> tran 0.01ms 5ms Doing analysis at TEMP = 300.150000 and TNOM = 300.150000 Warning: v1: no DC value, transient time 0 value used Initial Transient Solution -------------------------- Node Voltage ---- ------- n0 0 0 v1#branch 0 No. of Data Rows : 512 ngspice 10 -> The first parameter to tran determines the step to use, the second parameter is the end value. If no third parameter is given, the start time is 0, otherwise the start time is given by this third parameter. Well - thats all ;-) The simulation is now finished. What is still missing is to make the result of the simulation visible. 3.4 Viewing the results Spice has now generated tables with all calculated values (512 values for each of the nodes as shown above). To make the result visible simply type the following command: ngspice 10 -> plot n0 This plots the voltage transient of net n0. Note that plots always refer to two nets, that means the difference voltage between two nets is measured. If only one net name is given, the other net is automatically the reference net 0. This results in the following window opened: You should see the diagram with inverted colors on your monitor, i.e. what is white here is black in your image and vice versa. To make the image more readable and to save ink, I switched the colors before I made the screenshot. Close the plot window and enter the following commands in NG-spice: ngspice 11 -> set color0=rgb:f/f/f ngspice 12 -> set color1=rgb:0/0/0 ngspice 13 -> plot n0

Figure 2: Screenshot of the plot window The diagram shows the waveform of the input signal as we expected it, because we defined it so. But now, we are interested in the voltage across the resistor; additionally, we would like to compare the two signals! This can be simply achieved by adding the net name of another net to the plot command: ngspice 13 -> plot n0 V n0 10.0 0.0-10.0 0.0 1.0 2.0 3.0 4.0 5.0 time ms Figure 3: Input and output of the RC filter. There is almost no signal remaining at the resistor. The question now is: Are there frequencies which can pass the filter better? To check this, we will now perform an AC simulation. The general command to perform an AC simulation is ac ( DEC OCT LIN ) N FStart FEnd. FStart and FEnd are the start and the end frequency. The optional parameter DEC, OCT or LIN describes whether to vary the frequency linear, per decade or per octave. In the case of linear variation, N is the number of frequencies to generate. If octave or decade variation is choosen, N is the number of frequencies per decade or per octave. To perform the AC analysis, the voltage source must be changed: currently it is defined as a sine wave with an amplitude of 10V and a frequency of 1kHz. For the AC analysis, it must be an AC voltage source. Go back to gschem, load the circuit and modify the value of the voltage source to AC: Recreate the netlist, load the netlist into NG-spice and enter the following command to perform the AC analysis: ngspice 65 -> ac lin 1000 0.1 250kHz Doing analysis at TEMP = 300.150000 and TNOM = 300.150000

n0 C1 1 + - 2 V1 AC 3,3nF R1 1k 0 Figure 4: Filter for AC simulation. Warning: v1: has no value, DC 0 assumed No. of Data Rows : 1000 This command performs a linear frequency analysis from (almost) 0 Hz to 250kHz. The result can be viewed by plotting both the voltage source and the voltage on R1: mv 1000.0 800.0 600.0 400.0 200.0 0.0 0.0 50.0 100.0 150.0 200.0 250.0 frequency khz Figure 5: Frequency analysis of the RC filter. In the following sections, we are going to simulate more circuits to get better involved with NG-spice.

4 Simulating a full wave rectifier n0 D1 1N4148 V1 SIN(0 10 50Hz) 1 + - 2 D3 1N4148 D4 1N4148 R1 10k Vdd D2 1N4148 Vdd 0 Figure 6: A full wave rectifier. Figure 6 shows the typical full wave rectifier circuit. Both half waves of the input signal can be used, i.e. the negative half wave is mirrored upwards. This can be seen in Figure 7 which shows the spice simulation of the circuit. V v(,vdd) tran.v(n0) 10.0 5.0 0.0-5.0-10.0 0.0 5.0 10.0 15.0 20.0 25.0 30.0 35.0 40.0 45.0 50.0 time ms Figure 7: Source voltage transient and voltage across R1 Links to useful resources URLs

[1], TBD <http://www.ecircuitcenter.com/>. [2], GPL Electronic Design Automation <http://geda.seul.org>. [3], TBD <gnucap>. [4], TBD <gwave>. [5], NG-SPICE: The free circuit simulator <http://www.ngspice.org>.