Silicon ChipLTspice – simulating and circuit testing, Part 1 - June 2017 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: SPICE streamlines circuit design
  4. Feature: The Flettner Rotating Sail and the Magnus Force by Ross Tester
  5. Project: All-new 10-Octave Stereo Graphic Equaliser, Part 1 by John Clarke
  6. Project: Arduino-based Digital Inductance & Capacitance Meter by Jim Rowe
  7. Feature: LTspice – simulating and circuit testing, Part 1 by Nicholas Vinen
  8. Serviceman's Log: Fixing the food processor that wouldn't by Dave Thompson
  9. Project: El Cheapo Modules, Part 7: LED Matrix displays by Jim Rowe
  10. Project: New Marine Ultrasonic Anti-Fouling Unit, Part 2 by Leo Simpson & John Clarke
  11. Feature: Getting Started with the Micromite, Part 4 by Geoff Graham
  12. Subscriptions
  13. Review: Keysight’s 9917A 18GHz Spectrum Analyser by Nicholas Vinen
  14. Product Showcase
  15. Vintage Radio: HMV’s 1951 portable model B61D by Associate Professor Graham Parslow
  16. PartShop
  17. Market Centre
  18. Advertising Index
  19. Notes & Errata: Micromite LCD BackPack V2 / ATmega-based Metal Detector with stepped frequency indication (Notebook Mar17)
  20. Outer Back Cover: Hare & Forbes Machineryhouse

This is only a preview of the June 2017 issue of Silicon Chip.

You can view 43 of the 112 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "All-new 10-Octave Stereo Graphic Equaliser, Part 1":
  • 10-Octave Stereo Graphic Equaliser PCB [01105171] (AUD $12.50)
  • Front panel for the 10-Octave Stereo Graphic Equaliser [01105172] RevB (PCB, AUD $15.00)
  • 10-Octave Stereo Graphic Equaliser acrylic case pieces (PCB, AUD $15.00)
  • 10-Octave Stereo Graphic Equaliser PCB pattern (PDF download) [01105171] (Free)
  • 10-Octave Stereo Graphic Equaliser front panel artwork (PDF download) (Free)
Articles in this series:
  • All-new 10-Octave Stereo Graphic Equaliser, Part 1 (June 2017)
  • All-new 10-Octave Stereo Graphic Equaliser, Part 1 (June 2017)
  • Completing our new Graphic Equaliser (July 2017)
  • Completing our new Graphic Equaliser (July 2017)
Items relevant to "Arduino-based Digital Inductance & Capacitance Meter":
  • 1nF ±1% polypropylene (MKP) or C0G/NP0 ceramic capacitor (Component, AUD $2.50)
  • 16x2 Alphanumeric serial (I²C) LCD module with blue backlight (Component, AUD $12.50)
  • Clear UB3 Lid for Arduino-based Digital LC Meter (PCB, AUD $5.00)
  • Firmware (Arduino Sketch) file for the Arduino-based Digital Inductance & Capacitance Meter [Arduino_LC_meter_sketch.HEX] (Software, Free)
  • Arduino-based Digital LC Meter front panel artwork (PDF download) (Free)
Items relevant to "LTspice – simulating and circuit testing, Part 1":
  • Software for the LTspice Tutorial, Part 1 (Free)
Articles in this series:
  • LTspice – simulating and circuit testing, Part 1 (June 2017)
  • LTspice – simulating and circuit testing, Part 1 (June 2017)
  • LTspice Part 2: Simulating and Testing Circuits (August 2017)
  • LTspice Part 2: Simulating and Testing Circuits (August 2017)
  • LTspice Tutorial Part 3: Modelling an NTC Thermistor (September 2017)
  • LTspice Tutorial Part 3: Modelling an NTC Thermistor (September 2017)
  • LTspice Simulation: Analysing/Optimising Audio Circuits (May 2018)
  • LTspice Simulation: Analysing/Optimising Audio Circuits (May 2018)
Items relevant to "El Cheapo Modules, Part 7: LED Matrix displays":
  • MAX7219 controller (SMD) with pluggable 8x8 red LED matrix display (Component, AUD $4.50)
  • MAX7219 controller (DIP) with pluggable 8x8 red LED matrix display and jumper leads (Component, AUD $2.50)
  • MAX7219 controller (SMD) with red 8-digit 7-segment display (Component, AUD $5.00)
  • Software for MAX7219 (Free)
Articles in this series:
  • El Cheapo Modules From Asia - Part 1 (October 2016)
  • El Cheapo Modules From Asia - Part 1 (October 2016)
  • El Cheapo Modules From Asia - Part 2 (December 2016)
  • El Cheapo Modules From Asia - Part 2 (December 2016)
  • El Cheapo Modules From Asia - Part 3 (January 2017)
  • El Cheapo Modules From Asia - Part 3 (January 2017)
  • El Cheapo Modules from Asia - Part 4 (February 2017)
  • El Cheapo Modules from Asia - Part 4 (February 2017)
  • El Cheapo Modules, Part 5: LCD module with I²C (March 2017)
  • El Cheapo Modules, Part 5: LCD module with I²C (March 2017)
  • El Cheapo Modules, Part 6: Direct Digital Synthesiser (April 2017)
  • El Cheapo Modules, Part 6: Direct Digital Synthesiser (April 2017)
  • El Cheapo Modules, Part 7: LED Matrix displays (June 2017)
  • El Cheapo Modules, Part 7: LED Matrix displays (June 2017)
  • El Cheapo Modules: Li-ion & LiPo Chargers (August 2017)
  • El Cheapo Modules: Li-ion & LiPo Chargers (August 2017)
  • El Cheapo modules Part 9: AD9850 DDS module (September 2017)
  • El Cheapo modules Part 9: AD9850 DDS module (September 2017)
  • El Cheapo Modules Part 10: GPS receivers (October 2017)
  • El Cheapo Modules Part 10: GPS receivers (October 2017)
  • El Cheapo Modules 11: Pressure/Temperature Sensors (December 2017)
  • El Cheapo Modules 11: Pressure/Temperature Sensors (December 2017)
  • El Cheapo Modules 12: 2.4GHz Wireless Data Modules (January 2018)
  • El Cheapo Modules 12: 2.4GHz Wireless Data Modules (January 2018)
  • El Cheapo Modules 13: sensing motion and moisture (February 2018)
  • El Cheapo Modules 13: sensing motion and moisture (February 2018)
  • El Cheapo Modules 14: Logarithmic RF Detector (March 2018)
  • El Cheapo Modules 14: Logarithmic RF Detector (March 2018)
  • El Cheapo Modules 16: 35-4400MHz frequency generator (May 2018)
  • El Cheapo Modules 16: 35-4400MHz frequency generator (May 2018)
  • El Cheapo Modules 17: 4GHz digital attenuator (June 2018)
  • El Cheapo Modules 17: 4GHz digital attenuator (June 2018)
  • El Cheapo: 500MHz frequency counter and preamp (July 2018)
  • El Cheapo: 500MHz frequency counter and preamp (July 2018)
  • El Cheapo modules Part 19 – Arduino NFC Shield (September 2018)
  • El Cheapo modules Part 19 – Arduino NFC Shield (September 2018)
  • El cheapo modules, part 20: two tiny compass modules (November 2018)
  • El cheapo modules, part 20: two tiny compass modules (November 2018)
  • El cheapo modules, part 21: stamp-sized audio player (December 2018)
  • El cheapo modules, part 21: stamp-sized audio player (December 2018)
  • El Cheapo Modules 22: Stepper Motor Drivers (February 2019)
  • El Cheapo Modules 22: Stepper Motor Drivers (February 2019)
  • El Cheapo Modules 23: Galvanic Skin Response (March 2019)
  • El Cheapo Modules 23: Galvanic Skin Response (March 2019)
  • El Cheapo Modules: Class D amplifier modules (May 2019)
  • El Cheapo Modules: Class D amplifier modules (May 2019)
  • El Cheapo Modules: Long Range (LoRa) Transceivers (June 2019)
  • El Cheapo Modules: Long Range (LoRa) Transceivers (June 2019)
  • El Cheapo Modules: AD584 Precision Voltage References (July 2019)
  • El Cheapo Modules: AD584 Precision Voltage References (July 2019)
  • Three I-O Expanders to give you more control! (November 2019)
  • Three I-O Expanders to give you more control! (November 2019)
  • El Cheapo modules: “Intelligent” 8x8 RGB LED Matrix (January 2020)
  • El Cheapo modules: “Intelligent” 8x8 RGB LED Matrix (January 2020)
  • El Cheapo modules: 8-channel USB Logic Analyser (February 2020)
  • El Cheapo modules: 8-channel USB Logic Analyser (February 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules (May 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules (May 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules, Part 2 (June 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules, Part 2 (June 2020)
  • El Cheapo Modules: Mini Digital Volt/Amp Panel Meters (December 2020)
  • El Cheapo Modules: Mini Digital Volt/Amp Panel Meters (December 2020)
  • El Cheapo Modules: Mini Digital AC Panel Meters (January 2021)
  • El Cheapo Modules: Mini Digital AC Panel Meters (January 2021)
  • El Cheapo Modules: LCR-T4 Digital Multi-Tester (February 2021)
  • El Cheapo Modules: LCR-T4 Digital Multi-Tester (February 2021)
  • El Cheapo Modules: USB-PD chargers (July 2021)
  • El Cheapo Modules: USB-PD chargers (July 2021)
  • El Cheapo Modules: USB-PD Triggers (August 2021)
  • El Cheapo Modules: USB-PD Triggers (August 2021)
  • El Cheapo Modules: 3.8GHz Digital Attenuator (October 2021)
  • El Cheapo Modules: 3.8GHz Digital Attenuator (October 2021)
  • El Cheapo Modules: 6GHz Digital Attenuator (November 2021)
  • El Cheapo Modules: 6GHz Digital Attenuator (November 2021)
  • El Cheapo Modules: 35MHz-4.4GHz Signal Generator (December 2021)
  • El Cheapo Modules: 35MHz-4.4GHz Signal Generator (December 2021)
  • El Cheapo Modules: LTDZ Spectrum Analyser (January 2022)
  • El Cheapo Modules: LTDZ Spectrum Analyser (January 2022)
  • Low-noise HF-UHF Amplifiers (February 2022)
  • Low-noise HF-UHF Amplifiers (February 2022)
  • A Gesture Recognition Module (March 2022)
  • A Gesture Recognition Module (March 2022)
  • Air Quality Sensors (May 2022)
  • Air Quality Sensors (May 2022)
  • MOS Air Quality Sensors (June 2022)
  • MOS Air Quality Sensors (June 2022)
  • PAS CO2 Air Quality Sensor (July 2022)
  • PAS CO2 Air Quality Sensor (July 2022)
  • Particulate Matter (PM) Sensors (November 2022)
  • Particulate Matter (PM) Sensors (November 2022)
  • Heart Rate Sensor Module (February 2023)
  • Heart Rate Sensor Module (February 2023)
  • UVM-30A UV Light Sensor (May 2023)
  • UVM-30A UV Light Sensor (May 2023)
  • VL6180X Rangefinding Module (July 2023)
  • VL6180X Rangefinding Module (July 2023)
  • pH Meter Module (September 2023)
  • pH Meter Module (September 2023)
  • 1.3in Monochrome OLED Display (October 2023)
  • 1.3in Monochrome OLED Display (October 2023)
  • 16-bit precision 4-input ADC (November 2023)
  • 16-bit precision 4-input ADC (November 2023)
  • 1-24V USB Power Supply (October 2024)
  • 1-24V USB Power Supply (October 2024)
  • 14-segment, 4-digit LED Display Modules (November 2024)
  • 0.91-inch OLED Screen (November 2024)
  • 0.91-inch OLED Screen (November 2024)
  • 14-segment, 4-digit LED Display Modules (November 2024)
  • The Quason VL6180X laser rangefinder module (January 2025)
  • TCS230 Colour Sensor (January 2025)
  • The Quason VL6180X laser rangefinder module (January 2025)
  • TCS230 Colour Sensor (January 2025)
  • Using Electronic Modules: 1-24V Adjustable USB Power Supply (February 2025)
  • Using Electronic Modules: 1-24V Adjustable USB Power Supply (February 2025)
Items relevant to "New Marine Ultrasonic Anti-Fouling Unit, Part 2":
  • New Marine Ultrasonic Anti-Fouling Unit PCB [04104171] (AUD $15.00)
  • PIC16F88-I/P programmed for the New Marine Ultrasonic Anti-Fouling Unit [0410417A.HEX] (Programmed Microcontroller, AUD $15.00)
  • One 40kHz 50W ultrasonic transducer (Component, AUD $55.00)
  • ETD29 transformer components (AUD $15.00)
  • IPP80N06S4L-07 high-current N-channel Mosfet (TO-220) (Component, AUD $2.00)
  • New Marine Ultrasonic Anti-fouling unit lid panel artwork (PDF download) (Free)
Articles in this series:
  • New Marine Ultrasonic Anti-Fouling Unit (May 2017)
  • New Marine Ultrasonic Anti-Fouling Unit (May 2017)
  • New Marine Ultrasonic Anti-Fouling Unit, Part 2 (June 2017)
  • New Marine Ultrasonic Anti-Fouling Unit, Part 2 (June 2017)
Items relevant to "Getting Started with the Micromite, Part 4":
  • Software for the Micromite Tutorial, Part 4 (Free)
Articles in this series:
  • Getting Started with the Micromite (February 2017)
  • Getting Started with the Micromite (February 2017)
  • Getting Started with the Micromite, Part Two (March 2017)
  • Getting Started with the Micromite, Part Two (March 2017)
  • Micromite Tutorial, Part 3: strings and arrays (May 2017)
  • Micromite Tutorial, Part 3: strings and arrays (May 2017)
  • Getting Started with the Micromite, Part 4 (June 2017)
  • Getting Started with the Micromite, Part 4 (June 2017)

Purchase a printed copy of this issue for $10.00.

LTspice Part 1: by Nicholas Vinen simulating and testing circuits SPICE is a powerful tool which allows you to use a computer to simulate how a simple or complex circuit will behave without actually having to build it. This allows you to experiment with different configurations and examine the internal operation of a circuit before building it, saving you time and effort. I n this series of articles, we’ll take you through installing and using LTspice, a free, easy-to-use and yet very powerful circuit simulation package. Once you’re familiar with LTspice, you can draw up a circuit and start simulating it. Testing circuits in LTspice is a lot cheaper and safer than building them – if you blow up components in LTspice you don’t have to buy new ones! Just modify the circuit and try again. Besides just figuring out whether a given circuit will do what you expect, you can also use SPICE (which stands for Simulation Program with Integrated Circuit Emphasis) to determine certain performance parameters such as stability, efficiency, distortion, noise, reaction time, overshoot, frequency response, power consumption and dissipation, and so on. Throughout this series we’ll show you examples of how to calculate all of these parameters. While SPICE isn’t perfect and may sometimes fail to simulate some complex analog circuits reliably, it is quite surprising how close the results of 38  Silicon Chip simulations can match the real-world behaviour of a circuit. Note that accurate simulation does rely upon accurate component models and these are not always available. Simulating a circuit starts with drawing it. During this process you will place component symbols on a sheet and “wire them up”. You will then need to tell the simulator the type code of each component so that it can select an appropriate model. In many cases, for components like resistors, capacitors and inductors, totally realistic behaviour is not terribly important and you can simply use a default “ideal” component. To get accurate results with devices like transistors and diodes, you would be better off picking one of the available component models which exactly matches the part you intend to use, or at least has similar characteristics. We’ll discuss this aspect in more detail later. Installing LTspice We’re going to use LTspice for Win- dows in this tutorial series because it’s free, easy to install and use and most importantly, is supplied with a fairly large and mostly complete library of component models so that you can get up and running right away. A component model defines its characteristics. For example, each type of transistor has a different curves for Vbe, Vce, hfe, maximum voltage and current and so on. The model provides coefficients so that the simulated component behaves similarly in these respects to an average, real component. To start off, download the latest version of LTspice from www.linear. com/designtools/software/ It's available for 32-bit or 64-bit Windows 7, 8 or 10; there is also an older version available for Mac OS X 10.7+. Simply download the executable file, run it and follow the prompts to install it. It’s a straightforward process. Once installed, run the program and you will see a blank window like in Fig.1. Now select the “New Schematic” option from the “File” menu. Not much will appear to have changed siliconchip.com.au Toolbar Icons Concentrate your gaze on the right-most section of the toolbar, blown up in Fig.1. From left-to-right, the buttons are: Wire – connects two or more component pins Ground – place a ground (0V) symbol on the circuit Label Net – assign a name to a “net” (more on that later) Resistor – place a resistor in the circuit Capacitor – place a capacitor in the circuit Inductor – place an inductor in the circuit Diode – place a diode in the circuit Component – place something else in the circuit, such as a transistor, IC, regulator, voltage or current source, etc Move – move something around in the circuit diagram Drag – same as Move, but keeps any wire connections to the selected component(s) intact Undo/redo – revert the last change to the circuit, or reinstate it Rotate component – rotates the selected component/components by 90° Mirror component – flips the selected component horizontally Text – add text to the circuit diagram SPICE Directive – add an instruction to the circuit diagram which tells the simulator how to behave Fig.1: how the LTspice window looks just after creating a blank simulation. The toolbar at top has been blown up to show the important buttons, which are (from left-to-right) Wire, Ground, Label Net, Resistor, Capacitor, Inductor, Diode, Component, Move, Drag, Undo, Redo, Rotate, Mirror, Text and Spice Directive. but you are now ready to start drawing your circuit. First though, it’s best to give it a name. Select “Save As” under the “File” menu, type in “tutorial1” and press Enter. Chances are that it will say that you don’t have permission to save the file into the “C:\Program Files” directory and it will ask if you want to save it in the User folder instead. That’s a good idea, so say Yes and then press Enter again to save your file. We’ll now draw up a simple mains power supply circuit. But first, let’s look at the toolbar at the top of the window. This is important since you will be using these buttons a lot. The description of each icon in the toolbar is under “Toolbar Icons” at the top right of the next page. You’ll find that you will need to use nearly all these icons when drawing up the circuit you want to simulate. We’re going to start by creating a source of 230VAC. Click on the Component button (which looks like a logic gate). You will then be presented with a list of components and folders (which are siliconchip.com.au in square brackets). Scroll to the right and click on “voltage”, then “OK” (or just double-click “voltage”). Click somewhere in the blank circuit to place your first voltage source. This will be simply shown as a circle with positive and negative symbols inside, corresponding to the two output terminals. Note that a voltage source will always take the same form, whether it is intended to produce AC or DC. Now right click your mouse or press escape, since we only want one voltage source for now. This is one of the most fundamental parts of a circuit to simulate; the voltage source can generate AC, DC, both AC and DC or a function such as a sinewave or pulse train and is used to feed other components in the circuit. Voltage sources can be combined in various ways. Voltage source mode setting There are three different kinds of voltage sources and we need to use the right one to simulate 230VAC mains; refer to the panel titled “Simulation Types” for an explanation. Having read that, right-click on the V1 element you have placed and then click Advanced. You can now select SINE from the list on the left, and enter 0V for DC offset, 325V for Amplitude (this is the peak value; not RMS), 50Hz for the frequency and leave the rest blank. Units in these values are optional, however, for clarity it’s usually best to include them. Click OK and the circuit updates to include these parameters. Now click on the Ground button in the toolbar and place a ground symbol directly below the "negative" end of your voltage source. You need to define 0V somewhere in the circuit if you want to simulate it and this (effectively, the incoming Neutral line), is as good as anywhere. As before, right-click your mouse or press escape to stop placing components. Now use the Wire tool (leftmost on the section of the toolbar described above) to draw a wire between the negative end of the voltage source and the ground symbol. Click at one end, then the other, then rightJune 2017  39 Simulation Types There are two common types of simulation you can perform, plus several other less common types. The two most common types are “transient” and “AC”. A transient simulation is essentially equivalent to hooking an oscilloscope up to various points in the circuit and then freezing its display to examine how the voltages and currents vary over time. An AC analysis is more like connecting a spectrum analyser with tracking generator up to a circuit. AC voltage sources in SPICE are primarily useful for AC analysis. For transient analysis, you need a combination of DC voltages or “function”based voltage sources which are generally one of the following: PULSE, SINE, EXP (exponential), SFFM (single frequency FM) or PWL (piecewise linear). Basically, if you want an AC voltage source in a transient analysis, you use the SINE function. If you try to use an AC voltage source in this situation, you’ll find it won’t do anything useful. click or press escape to stop drawing wires. Note that if at any point you make a mistake, you can press F9 or click the Undo button on the toolbar to revert to the previous state. Now we can run the simulation for the first time. Select the “Run” option under the “Simulate” menu. As this is the first time, you will need to set up the simulation conditions, using the dialog which appears (see Fig.2). “Transient” is the default simulation mode (tab) selected so all you need to do is enter a Stop Time (let’s use 100ms) and then click OK. A SPICE Directive automatically appears on the circuit, which reads “.tran 100ms”, and you will find a black box appears at the top half of the screen, with the circuit shrinking below. This is our virtual scope display. Move your mouse cursor down to hover just over the little square box at the positive end of the voltage source in the circuit diagram below and the mouse cursor should change to look like a probe. Click there and you should get a display like Fig.3. This shows our simulated mains voltage. Of course, the real mains sine40  Silicon Chip Fig.2: the Edit Simulation Command dialog comes up the first time you select the Run option from the Simulate menu. Select the simulation type from the tabs at the top and then fill in the details below. For a Transient analysis, the most important ones are: Stop Time; Time to Start Saving Data; and Skip Initial operating point solution. wave is nowhere near as clean as this but it’s a good start! Note the text reading “V(nc_01)” at the top. This indicates that the green trace is showing the voltage at the node labelled “nc_01” which is a name automatically generated for this part of the circuit, as we have not provided our own name yet. Hold down the CTRL key on your keyboard and click on this label. You will get a dialog box showing information about the “trace” including the start and end times, the average (which is very close to zero, as it should be) and the RMS value which is just under 230VAC; exactly what we wanted. You can now dismiss this dialog. By the way, if you want to change the parameters later, you can rightclick on the “.tran” directive to re-open the simulation dialog. Building the circuitry Note that if you already know how to build a circuit in LTspice, you can download the tutorial1.asc file from the Silicon Chip website and skip to the next cross-heading. If you find yourself confused by the following instructions, refer to Fig.4 to see how the finished circuit looks. Let’s start by adding a capacitor connected to the 230VAC “positive” terminal (effectively mains Active). Click somewhere inside the circuit diagram, then click the Capacitor button in the toolbar and place the capacitor above the voltage source. Right-click the capacitor to set its Capacitance value to 470nF. Set the voltage rating to 400V (peak) at the same time and the RMS Current Rating to 250mA. Use a similar process to add a resistor to the right of that capacitor and set its value to “10Meg”. Note that one of the traps when using SPICE is that “10M” would be interpreted as “10m” (ie, 10 milliohms) so you need to write it with “Meg” on the end. You can set the tolerance to 5% and power rating to 1W at the same time. Now use the Wire tool to wire the two components up in parallel and connect the common bottom end to the voltage source. Add a second resistor, in series with the capacitor/resistor combination, and set its value to 470 (ohms), tolerance to 5% and power rating to 1W. The next step is to add two diodes to form a half-wave rectifier. Click siliconchip.com.au on the Diode tool in the toolbar, then move the mouse down into the circuit. You will notice that if you place it, its cathode will face towards the bottom of the circuit but we want it at the top. So before placing it, move the mouse back up to the toolbar and click the rotate button twice (note that this button will be disabled before moving the mouse down into the circuit area, so after clicking the diode button, you need to move it down and then back up). Now place the diode above and to the right of the existing components. Right-click the diode symbol, which is currently configured as a generic (ideal) diode, and click the “Pick New Diode” button. You will now get a list of the diode models built into LTSpice, which includes silicon/switching/ Rectifier (standard) diodes, fast recovery diodes, schottky diodes, zener diodes, LEDs and transient voltage suppressors (TVS/varactor). Scroll down to where the “silicon” type diodes are listed and click on the MURS120 which is roughly equivalent to the 1N4002, then click OK. If the placement of the diode is not ideal, click the “Move” button in the toolbar (or press F7 on the keyboard) and click on D1 to move it to a better spot. Now we need a second, identical diode so the easiest solution is to clone the one we have. Press F6 on the keyboard, then click on D1 and place the new diode (D2) directly above it. Join the adjacent anode and cathode pins, then connect the free end of the 470W resistor to this junction, all using the Wire tool. Connect the free anode at the bottom to ground, as we did with voltage source V1. Now we need a zener diode. You can clone one of the two existing diodes, placing it immediately to the right of voltage source V1, then right-click on and select “Pick New Diode” to change its type. Scroll down to the zeners and you will find multiple 15V zener diodes in the list (look for 15 in the Vbrkdn(V) column). Pick the KDZ15B as this is a 1W type, then click OK. Move D3 if necessary, to avoid labels from overlapping. Now connect the zener’s anode (bottom end) to ground and the cathode (top end) to the free cathode of the rectifier diode above. Having done that, add a 220µF 25V capacitor in parallel with D3, with a 500mA ripple current rating and ESR of 0.1 (ohms). Also add a 1.5kW 10% 5W resistor, simusiliconchip.com.au Fig.3: the result of our first Transient simulation, showing the voltage at the top of voltage source V1 over a 100ms period. Note that the 325V figure selected defines the peak voltage, not RMS and that several parameters have been left blank and so default to zero, including the DC offset and phase values. Fig.4: now we’ve built up a basic mains power supply with a simple resistive load and can observe how the main 220µF filter capacitor charge increases every 20ms during the peak of each mains cycle. We can see that D3 (a 15V zener) begins to conduct after around 350ms, but some ripple remains. lating a power supply load, in parallel with both. When finished, your circuit should look similar to that shown in Fig.4. Making some measurements Right-click on the “.tran 100ms” directive and change the Stop Time to 500ms, then re-run the simulation (“Run” option under the “Simulate” menu). Click on the “wire” at the cathode of D3 to view the resulting voltage. Your result should be the same as shown in Fig.4. As you can see, it takes around 370ms from the application of mains June 2017  41 Fig.5: not only can we see the voltage across C2 but now we can also observe the current drawn from the mains as it charges – all without having to wire up a single component and without any test equipment! One of the benefits of using SPICE is how easy it is to make multiple voltage and current measurements. power before the 220µF capacitor is fully charged to 15V. You can drag a box around the waveform at the top of the screen to zoom in and examine it in more detail (right-click and select “Zoom to Fit” or press CTRL+E to go back to the normal view). Once zoomed in, you can see that the peak voltage across the capacitor is clamped to around 15.35V and with the 1.5kW load, the minimum voltage is around 14.85V, giving a ripple of around 0.5V. You can make reasonably accurate measurements by placing the mouse cursor over the trace and then reading the time and voltage values shown in the bottom-left corner of the LTspice window. Also, once you’ve zoomed in, if you CTRL-click the V(n001) text at the top of the screen, it will calculate average and RMS values for the time period displayed, in this case, both around 15.124V. Now click the mouse in the circuit window at bottom and move the cursor over capacitor C1. You will note that the cursor changes to what looks like a clamp meter. Click here and the current through this capacitor will also be shown in the top window. Note that it is essentially symmetrical and looks like a sinewave with zero-crossing artefacts. Note also that a new y-axis appears 42  Silicon Chip on the right-hand side of the plot, allowing you to see that the peak current through C1 is just below 50mA. You can CTRL-click the label at the top of the display to read off the RMS current which is 33.5mA (see Fig.5). Efficiency calculations The efficiency of this circuit is the power delivered to the load (R3) divided by the power drawn from the mains (V1). In both cases, we can compute power as V × I. We could use V2 ÷ R for R3 but then we could need to change the calculation if we changed the value of R3, and it would also make it harder to change the circuit to a more realistic load. To make it easier to calculate both power figures, let’s label the two voltages. Click the “Label Net” button in the toolbar and type in “VIN”, then press OK. Place the label at the junction of V1, C1 and R1. Similarly, label the junction of D1, D3, C2 and R3 as “VOUT”. Press the DEL key on your keyboard and click on the labels at the top of the simulation output to delete the traces, then re-run the simulation. Now right-click on the (now blank) top half of the window and select “Add Trace” (or, having clicked in this subwindow, press CTRL-A). It will prompt you for “Expression(s) to add”. Type in “V(VIN) * -I(V1)” and click OK. A new trace will appear showing the instantaneous power being drawn from V1. V(VIN) refers to the voltage at the node labelled VIN and I(V1) refers to the current through voltage source V1. “*” is the multiplication operator so giving us the product of the two. The minus sign before I(V1) just sets the polarity of the result and is something you’d normally need to determine experimentally. You will see that the instantaneous power goes positive and negative at different times in the mains cycle. This is because sometimes, current flow into C1 is in-phase with the mains voltage and sometimes it is out-ofphase. In other words, there are times when power is flowing from the mains into C1, and times when it is flowing out of C1 and back into the mains. If you CTRL-click the expression at the top of the window, you will see that the average is 712.21mW and its integral (ie, total energy consumed in the 500ms window) is 356.11mJ. But note that this includes the time that C2 is charging. So to get an accurate result, right-click on the “.tran 500ms” directive and change the “Time to Start Saving Data” to 400ms, then re-run the simulation. The average is now 783.93mW, which represents a steady-state value, and you will notice that the waveform is consistent across the five mains cycles (100ms) shown. By the way, if you want to change the expression used to plot the power, you can do this by right-clicking where it’s shown at the top of the window. Now, to compute the power consumed by R3, right-click in the top window (or press CTRL+A) and enter the similar expression “V(VOUT) * I(R3)”. If you CTRL+click the new expression which appears at the top of the window, you will see that the average power is 152.69mW (see Fig.6). This is in line with what you’d expect from 15V across a 1.5kW resistor (V2 ÷ R = 15 x 15 ÷ 1500 = 150mW). So we can calculate the efficiency as 152.69mW ÷ 783.93mW = 19.5%. That’s pretty lousy! That means that 80.5% of the energy drawn from the mains (630mW or so) is being dissipated elsewhere in the circuit, just turned into useless heat. Luckily, we can use LTspice to figure out where and improve the situation. First, let’s see how much power is siliconchip.com.au Helping to put you in Control Capacitive Oil Level Sensor 1000mm 4-20mA out. Level Sensor for non conductive liquids such as oil and diesel. The 1000mm probe can be cut to suit tank depth and easily calibrated. SKU: FSS-232 Price: $449.00 ea + GST 60W Ultra Slim DIN Rail Supply Meanwell HDR-60-12 measures only 53W x 90D x 55Hmm it supplies 12VDC 45A. SKU: PSM-0181 Price: $45.00 ea + GST H685 Series 4G Cellular Router Fig.6: plot of the product of the input voltage and current; LTspice automatically shows the result in watts and changes the Y-axis to suit. The area enclosed by the power curve below the horizontal axis is smaller than that above, with the net power consumption shown in the average (in the box to the right of the circuit). dissipated in D3, the zener clamp diode. We can simply plot the expression “V(VOUT) * I(D3)” and integrate it as before, to yield a figure of 73.282mW. Well, that’s barely more than 10% of the energy being wasted, so that isn’t the culprit; we may still be able to make some tweaks to reduce this figure and improve efficiency but let’s figure that out later. What about R2? To calculate the voltage across that, we need to label the wires (nets) at both ends. Let’s label the one junction of C1/R1/R2 as “VA” and the junction of R2/D1/D2 as “VB”. We can then plot the expression “(V(VB) − V(VA)) * I(R2)”, in other words, the difference between the voltage at points VB and VA (ie, the voltage across R2) times the current through R2. Integrating this gives us a figure of 529.33mW. Adding this to the power dissipated in D3 gives a result of 602.6mW, explaining over 95% of the power lost in the circuit (the other ~5% is probably in R1). So to improve the efficiency we need to do something about R2. Improving the efficiency R2’s purpose is to reduce the inrush current into C1 when the circuit is first connected to the mains, especially if that happens to be in the middle of a cycle. If we reduce R2’s value, that will siliconchip.com.au reduce its dissipation and improve the overall efficiency but we need to check that this won’t cause any problems and also quantify just how much of an improvement we can achieve. So let’s simulate the (almost) worst case, where the circuit is connected to the mains at the peak of 325V and C1 is discharged, and see how low we can make the value of R2 before we risk damaging something. To do this, rightclick on the body of V1 and enter 90 for “Phi(deg)”. We also need to make two changes to the simulation directive, which we can access by right-clicking on the “.tran 400ms 500ms” text. First, change the “Time to Start Saving Data” back to 0ms so that we can see the initial conditions, then also tick the “Skip Initial operating point solution” box towards the bottom. This tells the simulator to start with all capacitors and inductors fully discharged (although you can specify an initial charge on a case-by-case basis if necessary; we’ll explain how to do this in a future instalment). Re-run the simulation, clear all the traces and plot the current through C1; you can achieve the latter two simply by moving the mouse cursor over C1 until it turns into the clamp symbol and then clicking twice. The first time it will show the current plot for H685 4G router is a 4G cellular serial server and Ethernet and Wi-Fi gateway. It can act as an RS-232 serial cable replacement over the mobile phone network or as a serial server on the internet. It also shares the cellular internet connection out over an RJ45 port and Wi-Fi. SKU: OCO-002 Price: $495.00 ea + GST Waterproof Digital Temperature Sensor DS18B20 digital thermometer comes with waterproof 6 × 30 mm probe with 3 metre cable. -55 to 125 °C range with ±0.5 °C accuracy from -10 to 85 °C. SKU: GJS-003 Price: $16.00 ea + GST Pressure Transducer 0 to 25 Bar Firstrate FST800-211 pressure sensor features IP67, 3 wire connection, 0-5VDC output ¼” BSP process connection. ±0.3% F.S. accuracy. 0 to 25 Bar. SKU: FSS-1530 Price: $159.00 ea + GST Heating/Cooling Self Adaptive PID Controller 1/16 DIN Panel mount Heating and Cooling self adaptive PID controller. Features universal input 2 Relays, 2 Digital Input/Output and 24 VAC/DC powered. SKU: PID-048 Price: $299.00 ea + GST Eight 12VDC Relay Card Eight-way relay card on DIN rail mount allows driver direct connection to many logic families, industrial sensors (NPN or PNP) dry contacts or voltage outputs. Relay output load 10A(240AC) SKU: RLD-128 Price: $109.95 ea + GST For Wholesale prices Contact Ocean Controls Ph: (03) 9782 5882 oceancontrols.com.au Prices are subjected to change without notice. June 2017  43 Fig.7: by zooming into the early part of the current trace for C1, we see the inrush current is around 700mA for a fraction of a millisecond. The “uic” on the end of the “.tran” directive is critical; it stands for “use initial conditions” and without it, capacitors and inductors start in a “steady state” condition. Consider that in a real circuit, this would be an X2 capacitor which is designed for direct connection across the mains supply with no real current limiting whatsoever so it should be able to tolerate a high inrush current. So on that basis, let’s reduce R2 to 68W, giving an inrush current of just under 5A. The only other components which need to handle this current are R2 (which should be OK given how brief the spike is) and D1/D2 (which will handle much larger spikes as long as they’re short or non-repetitive). At the load end, how much of the initial spike will be borne by D3 and C2 depends on the polarity of the applied mains voltage (ie, whether D1 or D2 conducts) and C2’s ESL (equivalent series inductance). Typical ESL of a moderately-sized electrolytic capacitor appears to be pretty low at around 1nH so C2 should safely absorb the brief initial spike, but even if it doesn’t, it should not pose much difficulty for D3. We can now re-run the simulation, adjusting the time to start saving data back to 400ms and calculate the steady-state figures as input power: 327mW, output power: 152.7mW, efficiency: 46.7%. That’s a lot better but still not great. Let’s look again at the power consumed in D3, the zener diode. It’s virtually identical to before at 73.75mW but now this is around 50% of the power loss. We can reduce this by lowering the value of C1, so that it doesn’t deliver more current than the load requires and D3 will then only conduct rarely (eg, if the mains voltage is higher than nominal or the load is lighter than expected). Parameter stepping Fig.8: parameter stepping is a valuable method for optimising component values. Here we can see how varying the value of C1 between 220nF and 470nF affects circuit operation. You can also use this method to vary the simulated ambient temperature or to see how component tolerance affects circuit operation. C1 and the second time, it will erase all the other traces except for that plot. If you zoom into the first few milliseconds you can see that the peak current is around 700mA but this drops very rapidly, to just a few milliamps after 1ms or so (see Fig.7). In retrospect, we could have calculated the 700mA 44  Silicon Chip figure simply by assuming that C1 is initially a short circuit and doing the calculation 325V ÷ 470W = 0.7A. This suggests that whatever we do to reduce the value of R2 is inevitably going to increase the inrush current but the simulation shows that this is really very brief as C1 rapidly charges up. Now we consider whether changing the value of C1 will affect efficiency. It will because if the value is too high, D3 will shunt more of the current coupled through it, effectively wasting power whereas if the value of C1 is too low, the voltage across D3 will not rise to the desired value of ~15V. What we really want to do to figure out the ideal value is look at the effect of changing the value of C1 with everything else the same. We can do this by stepping its capacitance through different values. To do this, click on the SPICE Directive (“op”) button in the toolbar and then type in “.step param CV list 220nF 330nF siliconchip.com.au 470nF”. This creates a parameter called “CV” which steps through three different capacitance values. Now change the value of C1 from 470nF to {CV}. Re-run the simulation, with a start time of 0ms and finish time of 1500ms and plot VOUT. The result is shown in Fig.8. Unfortunately, LTspice doesn’t provide a colour-coding legend but it’s fairly obvious that the green curve is for C1=220nF, blue for C1=330nF and red for C1=470nF. 220nF is too low as VOUT doesn’t even reach 10V, while with both 330nF and 470nF it reaches the same final voltage, albeit after a different time delay. So it seems that 330nF is probably close to the ideal value. Let’s set the capacitance value of C1 back to 330nF, delete the step directive (press DEL on the keyboard, then click on the directive) and then re-run the efficiency calculations. Final results After changing the “Time to Start Saving Data” back to 1400ms and using the same steps as before, we can now compute the input power as 219mW and the power consumed by the load at 151.94mW, only a tiny bit lower than before, giving an efficiency figure of 69.4%. That’s pretty reasonable for such a simple circuit, and with a virtually identical load voltage. So we’ve barely sacrificed any performance for what is a pretty large improvement in efficiency, all thanks to the ease of simulating such a circuit. Compare this to the difficulty of measuring it, especially when you consider it would be directly connected to the mains! Apparent power consumption There are a couple of final issues to discuss regarding simulating this circuit. Firstly, our method of integrating the instantaneous power gives us the real power consumption of this circuit, as would be measured by your power meter (and which would be used to charge you for electricity). But note that the RMS current drawn from the “mains” (V1) is now 23.65mA with an RMS voltage of 230VAC. That gives an apparent power consumption of 0.02365A x 230VAC = 5.44W. That tells us that this circuit has a very low power factor. In fact, we can calculate it, it’s simply the real input power of 219mW divided by the apparent input power of 5.44W, giving a power factor of 0.04 or 4%. Note that because this is so low, many domestic power meters would have trouble giving any kind of reading at all and the power reading could range from zero all the way up to several watts. The low power factor is due to the fact that so much of the energy drawn from the mains goes into simply charging up C1 and this is returned later in the cycle, so the power moving into and out of the unit via the mains socket is much higher than the actual net consumption. Next Month Modelling relays in SPICE is a little tricky but it can be done, as we will demonstrate by building a fairly realistic relay model next month. We’ll also get into some more advanced techniques that are possible with LTspice. Secondly, there’s nothing to stop you from taking the simulation further and actually drawing up a real load instead of using resistor R3. This would give a more realistic depiction of the voltage regulation of this power supply circuit in the face of changing load demands. For example, this sort of circuit is commonly used to power a relay, either to act as a mains timer or some sort of load-detecting switch. Actually, if you look at our SoftStarter in the April 2012 issue, Soft Starter for Power Tools in the July 2012 issue and Mains Timer for Fans and Lights project in the August 2012 issue, you will see just this type of circuit. In those cases, the load current depends heavily on whether the relay is energised and it’s acceptable for the supply voltage to drop once the relay has latched, as a lower voltage is required to hold the relay than to switch it initially. So further simulation would definitely help optimise such a circuit. SC Radio, Television & Hobbies: the COMPLETE archive on DVD YES! A MORE THAN URY NT CE R TE AR QU ONICS OF ELECTR HISTORY! This remarkable collection of PDFs covers every issue of R & H, as it was known from the beginning (April 1939 – price sixpence!) right through to the final edition of R, TV & H in March 1965, before it disappeared forever with the change of name to EA. For the first time ever, complete and in one handy DVD, every article and every issue is covered. If you’re an old timer (or even young timer!) into vintage radio, it doesn’t get much more vintage than this. If you’re a student of history, this archive gives an extraordinary insight into the amazing breakthroughs made in radio and electronics technology following the war years. And speaking of the war years, R & H had some of the best propaganda imaginable! Even if you’re just an electronics dabbler, there’s something here to interest you. Please note: this archive is in PDF format on DVD for PC. Your computer will need a DVD-ROM or DVD-recorder (not a CD!) and Acrobat Reader 6 or above (free download) to enable you to view this archive. This DVD is NOT playable through a standard A/V-type DVD player. Exclusive to: SILICON CHIP siliconchip.com.au ONLY 62 $ 00 +$10.00 P&P Order now from www.siliconchip.com.au/Shop/3 or call (02) 9939 3295 and quote your credit card number. June 2017  45