www.elektor-magazine.com magazine June 2013 % Wi-Fi Controller Board i Recycle your ATX Power Supply Off to the EF Library | Lost Model Finder | Lithium -ion Battery Recycling Made Easy | Taming the Beast (5) | From BASIC to Python (2) • LCR Meter Shootout • Konrad Zuse's Z1 through Z4 US$9.00 - Canada $10.00 06 25274 24965 7 7 Human DATA LTD. www.hdl.co.jp/EL/ E-mail : s2@hdl.C0.jp Fax : +81 -72-620-2003 ullMANDATA ® FPGA / CPLD Boards from JAPAN SAVING C0ST=TIME with readily available FPGA boards ■ Basic and simple features, single power supply operation ■ Quality and reliability is provided by years of sales ■ Same board size and connector layout - AC M/XCM series ■ All stocked items are ready to be shipped immediately ■ Over 100 varieties of FPGA/CPLD boards are available ■ Customizing speed grade and/or any features are possible ■ Free download technical documents before purchasing ■ High quality and highly reliable FPGA/CPLD boards from Japan ■ Almost all products are RoHS compliance ALTERA FPGA Board Cyclone IV E F780 FPGA board ACM-204 series ^ Cyclone IV E SDRAM XILINX FPGA Board Spartan-6 FGG484 FPGA board XCM-018/018Z series [Spartan-6l( MRAM DDR2 EP4CE30F29C8N EP4CE40F29C8N EP4CE1 1 5F29C8N Credit card size (86 x 54 mm) RoHS compliant XC6SLX45-2FGG484C XC6SLX75-2FGG484C XC6SLX1 00-2FGG484C XC6SLX1 50-2FGG484C Credit card size (86 x 54 mm) RoHS compliant p Arria II GX F572 FPGA board ACM-025 series Virtex-5 FFG676 FPGA board XCM-109 series Arria II GX DDR2 SIF40 Virtex-5 SDRAM EP2AGX45DF25C6N EP2AGX65DF25C6N EP2AGX95DF25C6N EP2AGX1 25DF25C6N Credit card size (86 x 54 mm) RoHS compliant XC5VLX30-1 FFG676C XC5VLX50-1 FFG676C XC5VLX85-1 FFG676C XC5VLX1 1 0-1 FFG676C Compact size (43 x 54 mm) RoHS compliant Spartan-6 FGG676 FPGA board XCM-206 series CyclonelV GX F484 FPGA board ACM-024 series [Cyclone IV GX] Spartan-6 MRAM |( DDR2 DDR2 SIF40 XC6SLX1 00-2FGG676C XC6SLX1 50-2FGG676C Credit card size (86 x 54 mm) EP4CGX50CF23C8N EP4CGX75CF23C8N EP4CGX1 10CF23C8N EP4CGX1 50CF23C7N Credit card size (86 x 54 mm) RoHS compliant (5 ^ ■ TT IfffR f nm 1 1 m RoHS compliant gp Spartan-3A FTG256 FPGA board XCM-305 series [Spartan-3A][ MRAM XC3S700A-4FTG256C XC3S1 400A-4FTG256C Compact size (54 x 53 mm) RoHS compliant USB- FPGA Board Cyclone IV USB-FPGA Board EDA-301 ® Cyclone IV E][ USB Config.)(USB Comm. HI-SPEEP EP4CE15F17C8N Compact size (54 x 53 mm) RoHS compliant Spartan-6 USB-FPGA board EDX-301 ®i Spartan-6 USB Config. USB Comm. HI-SPEEP XC6SLX1 6-2CSG225C Compact size (54 x 53 mm) RoHS compliant ( ; 5" LCD Touch Panel Module 5 inch TFT full color LCD display with WVGA(800x480) resolution resistive touch panel UTL-021 3.3 V single power supply operation Piezo buzzer to beep Useful plastic bezel is included to assemble LTM-compatible pin assignment Easy and Quickly Mountable Module FPGA Module 1C socket mountable • 50 I/Os (External clock inputs are available) • 3.3V single power supply operation (Voltage converters for auxiliary power supply are built-in) • Separated supply-inputs: Core, I/O drivers • JTAG signal • All PLCC68 series have common pin assignment • Very small size (25.3 x 25.3 [mm]) • RoHS compliance • MADE IN JAPAN Wirpinmi - W Tr* i l.> 1 1 i f I ! IPli i i 1 1 XILINX PLCC68 Series Spartan-6 PLCC68 FPGA Module XP68-03 [Spartan-6] IJM468] XC6SLX45-2CSG324C 3.3V single power supply operation On-board oscillator, 50MHz RoHS compliant ALTERA PLCC68 Series Cyclone III PLCC68 FPGA Module AP68-04 [ Cyclone III ] B 6 8 EP3C25U256C8N 3.3V single power supply operation On-board oscillator, 50MHz RoHS compliant Universal Board (Type2) ZKB-106 r : ranai nir ■ ■ , * 1 - * I. I ■' * ■ One for general power(3.3V 3A max) and the Two variable outputs for Vccio(0.8V to 3.3, 3A max) > For ACM/XCM-2 series FPGA boards ■ Power Switch and LED ■ Power input:DC5V/2.1[mm] Jack / Terminal Block (option) • Board size : 156x1 84 [mm] ■ 4 Layers PCB, Thru-hole See all our products, A/D D/A conversion board, boards with USB chip from FTDI and accessories at : www.hdl.co.jp/EL/ Join the Elektor Community Take out a GOLD Membership now! Your GOLD Membership contains: 8 Regular editions of Elektor magazine in print and digital 2 Jumbo editions of Elektor magazine in print and digital (January/February and July/August double issues) Elektor annual DVD-ROM A minimum of 10% DISCOUNT on all products in Elektor.STORE Direct access to Elektor. LABS Direct access to Elektor.MAGAZINE; our online archive for members Elektor.POST sent to your email account (incl. 25 extra projects per year) An Elektor Binder to store these 25 extra projects Exclusive GOLD Membership card ALSO AVAILABLE: The all-paperless GREEN Membership, which delivers all products and services, including Elektor.MAGAZINE, online only. ektor membership Take out your Membership now at www.elektor.com/membersf S Contents Community 8 Elektor World • The Tube in the Lunchbox • Getting Control • DesignSpark 10 Day 1 — Make it just the way you want Getting started with DesignSpark PCB and configure it to your likings. This tutorial shows you how to set up your personal preferences in this latest release of PCB design software. 13 The Cat's Whisker Crystal Diode FRIHO D.R.P Projects 14 Wi-Fi Controller Board Control your home from your mobile phone with this universal Wi-Fi controller board. We show how to set the color of an RGB LED strip, but you can use it for a variety of other applications. 22 Recycle your ATX Power Supply This ATX bench top power supply adapter board converts any standard ATX computer power supply into a convenient supply for breadboarding and general workbench use. 26 Off to the EF Library! Using Elektor's 'Embedded Firmware Library', code for an embedded project can be generated swiftly without the need to know which type of interface will be used. This tool helps both beginners and old hands. 34 Lost Model Finder Build this radio detection finder and never lose your radio controlled plane again. Simply switch on the receiver and it points you straight to the crash location. 40 Lithium-ion Battery Recycling Made Easy Re-using Lithium-ion batteries can be tricky. Often they are charged inside the equipment, so there isn't a separate charger available. Luckily, a charger for used (or new) Li-ion cells is fairly easy to build. 44 Taming the Beast (5) Although FPGA applications can be designed using schematic diagrams with logic symbols, in practice this 4 | June 2013 www.elektor-magazine.com Volume 4 No. 54 June 2013 is usually done with a hardware description language. An advantage of the latter approach is that complex functions are often easier to express in algorithms than in schematics. Accordingly, in this installment we guide you through the process of programming an FPGA application. 54 From BASIC to Python (2) This second installment elaborates on graph plotting and Fourier synthesis. And without much effort we setup a graphical user interface. 62 Beefing up DAC Resolution Improve the resolution of ordinary, cheap digital/analog converters by using the output of one as a programmable voltage reference for the others. Labs 64 LCR Meter Shootout A quick comparison between Elektor's 500 ppm LCR Meter and two other LCR measurement devices • Industry 66 New Performance Require- ments for Resistors Today's aircrafts are increasingly fuel efficient and need to conform to anti- pollution regulations. The humble resistor can be helpful, provided some of its key specifications are given close consideration. 70 News & New Products A selection of news items received from the electronics industry, labs and organizations. • Magazine 74 Retronics: Konrad Zuse's Z1 through Z4 and beyond Ever since the earliest days of mathematics and logical thought, people have tried to find ways to simplify the repetitive work involved. This article takes a tour of Konrad Zuse's impressive contributions to the development of the computer. Series Editor: Jan Buiting. 78 Hexadoku Elektor's monthly puzzle with an electronics touch. 79 Gerard's Columns: In the Clouds A column or two from our columnist Gerard Fonte. 82 Next Month in Elektor A sneak preview of articles on the Elektor publication schedule. www.elektor-magazine.com | June 2013 | 5 Community No. 54, ''Oune 2013 ISSN 1947-3753 Elektor Magazine is published 10 times a year including double issues in January/February and July/ August at $80 per year, Canada add $15 per year; by Elektor International Media LLC 111 Founders Plaza, Suite 300 East Hartford, CT 06108. Phone: 860.289.0800 Fax: 860.461.0450 www.elektor.com Elektor is also published in French, Spanish, German and Dutch. Together with franchised editions the magazine is on circulation in more than 50 countries. Memberships: Elektor USA P.O. Box 462228 Escondido, CA 92046. Phone: 800-269-6301 E-mail: elektor@pcspublink.com Internet: www.elektor.com Head Office: Elektor International Media b.v. PO Box 11 NL-6114-ZG Susteren The Netherlands Telephone: (+31) 46 4389444, Fax: (+31) 46 4370161 Advertising: Strategic Media Marketing Peter Wostrel 2 Main Street Gloucester MA 01930. Phone: 978-281-7708, Fax: 978-281-7706 E-mail: peter@smmarketing.us Advertising rates and terms available on request. A Case for Boards Looking at our readers' main interests, PCB design and production rank pretty high. Elek- tor PCBs are famous the world over not just for their quality, but also their consistent look and feel. How did that come about? Here at Elektor, the change from manual artwork design using masking tape and pho- tographic reproduction techniques to a 100 % PC-driven process was gradual, and took place in the early 1990s. The use of a PC to draw a schematic and then run a PCB design program was not forced or even suggested by the publishers at the time. Back then, some of the younger lab designers boldly set out to discover the advantages of the PC route, eventually supplying files instead of drawings to their colleagues in the PCB design department. Others stuck to pencil, paper and rubber with equally good results particularly in RF and space critical designs. No matter how the final artwork got produced, Elektor never actually mass-produced their circuit boards— this was always farmed out to PCB manufacturers. We did, however, handle the storage and packaging of what must have amounted to hundreds of thousands of those blue and green boards. Also, to this day Elektor Labs have their own PCB etching and drilling facilities. The equipment is used to make prototypes and one- offs of any board, single or double sided, TH or SMD. I do recall the excitement in the lab and editorial offices about 20 years ago when a parcel arrived containing 500 or so boards for a recently published project. At last, the proud designer was able to see the fruit of his design efforts. More importantly however, readers all over the world were able to construct circuits on superbly produced circuit boards with a component overlay and silk screen finish! Today, there is still the satisfaction not only of publishing these wonderful designs and getting response from you, but also of holding a perfectly machined printed circuit board with an Elektor production number printed to aid identification. Copyright Notice The circuits described in this magazine are for domestic use only. All drawings, photographs, printed circuit board layouts, programmed integrated circuits, disks, CD-ROMs, DVDs, software carriers and article texts published in our books and magazines (other than third- party advertisements) are copyright Elektor International Media b.v. and may not be reproduced or transmitted in any form or by any means, including photocopying, scanning and recording, in whole or in part without prior written permission from the Publisher. Such written permission must also be obtained before any part of this publication is stored in a retrieval system of any nature. Patent protection may exist in respect of circuits, devices, components etc. described in this magazine. The Publisher does not accept responsibility for failing to identify such patent(s) or other protection. The submission of designs or articles implies permission to the Publisher to alter the text and design, and to use the contents in other Elektor International Media publications and activities. The Publisher cannot guarantee to return any material submitted. © Elektor International Media b.v. 2013 Printed in the USA Jan Buiting, Managing Editor The Team Managing Editor: Jan Buiting Publisher: Hugo Van haecke Membership Manager: Shannon Barraclough International Editorial Staff: Harry Baggen, Thijs Beckers, Eduardo Corral, Wisse Hettinga, Denis Meyer, Jens Nickel, Clemens Valens Laboratory Staff: Ton Giesberts, Luc Lemmens, Tim Uiterwijk, Clemens Valens, Jan Visser Graphic Design & Prepress: Giel Dols, Jeanine Opreij, Mart Schroijen Online Manager: Danielle Mertens Managing Director: Don Akkermans 6 June 2013 www.elektor-magazine.com Our network f§ i=^ USA Hugo Van haecke + 1 860-875-2199 h.vanhaecke@elektor.com United Kingdom Wisse Hettinga +31 46 4389428 w.hettinga@elektor.com Germany Ferdinand te Walvaart +49 241 88 909-17 f.tewalvaart@elektor.de France Denis Meyer +31 46 4389435 d.meyer@elektor.fr Netherlands Harry Baggen +31 46 4389429 h.baggen@elektor.nl Spain Eduardo Corral +34 91 101 93 95 e.corral@elektor.es Italy Maurizio del Corso +39 2.66504755 m.delcorso@inware.it Sweden Wisse Hettinga +31 46 4389428 w.hettinga@elektor.com Brazil Joao Martins +55 11 4195 0363 joao.martins@editorialbolina.com Portugal Joao Martins +351 21413-1600 joao.martins@editorialbolina.com India Sunil D. Malekar +91 9833168815 ts@elektor.in Russia Nataliya Melnikova +7 (965) 395 33 36 Elektor. Russia@gmail.com Turkey Zeynep Koksal +90 532 277 48 26 zkoksal@beti.com.tr South Africa Johan Dijk +31 6 1589 4245 j.dijk@elektor.com China Cees Baay +86 21 6445 2811 CeesBaay@gmail.com Connects you to Supporting Companies AP Circuits www. apcircuits. com Beta Layout www. pcb -pool, com 33 39 ElPololu Sebctiei * f iscirwilct Pololu www.pololu. com 33 Saelig www. saelig.com 73 ctsvar Cleverscope www. cleverscope. com DLP Design www. dlpdeslgn.com 39 33 ExpressPCB www. expresspcb. com EzPCB www.ezpcb.com . . . . FabStrvnm Fabstream www. fabstream.com 71 53 9 uUMANDATA HuMANDATA www. hdl. co.jp/EL/ 2 Not a supporting company yet? Contact Peter Wostrel (peter@smmarketing.us, Phone 978-281-7708, Fax 978-281-7706) to reserve your own space for the next edition of our members' magazine www.elektor-magazine.com June 2013 7 Community The Tube in the Lunchbox: reader comments Elektor readers like you, consistently demonstrate the true spirit behind the magazine, enhancing and extending the editorial content with your own investigations and experiments. Component related articles remain the most popular and in last April's Elektor World we showed the 'Tube in the Lunchbox' and asked for more details. Among others, Christopher Kessler from Germany and Jan Swenker from The Netherlands dug out more information on this. Christopher found the specs of this tube in the "Valvo Fotovervielfacher 1978-79 In total he found 6 pages of information on the device and figured that its current price tag was around 30 dollars. Jan's information confirms the date of origin: 1978. He pointed us also to the Hamamatsu Photomultiplier Tubes book from 1986 (you can find the PDF on the internet). The book has the specs of a replacement tube, the model R1450... It is time to get our hands dirty getting this tube to work! Many thanks to Jan and Christopher Elektor World Compiled by Wisse Hettinga Getting control "In engineering, control system theory focuses on how to manipulate a system's inputs to change its behavior. DIYers are familiar with many simple, open-loop control systems — such as those in basic stepper motors. But today, project kits for everything from robotic sumo cars to auto-piloted model aircraft demand DIYers learn more about the theory behind complex, closed-loop control systems", Brian Douglas says in his "Tech the Future" essay in Circuit Cellar magazine's June 2013 edition. "DIYers aren't going back to the classroom, they're going online — educating themselves on websites and turning to open-source software and hardware". Douglas should know. The Seattle-based control systems engineer has a YouTube site dedicated to fostering a practical understanding of control system theory, www.youtube.com/ user/ControlLectures . Douglas is one of the essayists featured in CC's recurring "Tech The Future" section, which focuses on developing trends and breakthroughs in technology. Visit circuitcellar.com/ category/tech-the-future to read more of Douglas's essay, and others. 8 June 2013 www.elektor-magazine.com Order Introducing FabStream... An integrated approach that combines FREE PCB design software with industry-leading PCB manufacturers -- , — - - >V — j| . . . _ : 7 CB Design Software Our Solo PCB Design® software is a free, full-featured schematic capture, layout and autorouting tool suite. It's customized specifically for each of our manufacturing partners to automate design setup right from the start and design within your chosen manufacturer's capabilities to minimize defect or delay. We've created a global network of industry-leading PCB manufacturers to give you a variety of manufacturing options. Choose your manufacturer based on your design specs, geographic location, budget and delivery needs, then use the integrated SoloPCB ordering wizard to automatically price your PCB order and extract and upload all the necessary manufacturing data directly to your chosen manufacturer 24/7/365* Get Started Now at FabStream.com A DownStream Technologies Solution ©2013 Downstream Technologies, ILL All rights reserved. Fab stream is a trademark of Downstream Technologies, ULC. DESIGNSPARK Day 1 - Make it just the way you want By Neil Greunding The good folks at RS Components have just released version 5.0 of DesignSpark PCB and the first thing I like to do with a new tool is to get it configured just the way I like it. DesignSpark lets you configure everything on a per file basis or globally. Figure 1. Schematic with default parameters. Figure 2. Default Fonts set to Arial. Today I will walk you through how to make global setting changes using DesignSpark technology files so that you can make DesignSpark work just the way you want. Getting started But before we start configuring DesignSpark it's important to know that DesignSpark uses styles to specify the formatting rules for design primitives like shapes, text and tracks. Each style has a name to make it easy to reference, just like in a word processor. I normally try to give styles meaningful names so that you can know what the style is without checking its properties directly. For example, having a style named "Via" is ok if you only have one via but calling it "Via (0.45 mm x 0.95 mm)" makes it immediately obvious that the via has a 0.45 mm drill and a 0.95 mm copper pad. You are free to add custom styles to the technology files but this discussion we will be focusing on the system default styles like "[Symbol Names]" which is the style name used for reference designators and component names. Also, don't forget to double check the DesignSpark technology file path which can be changed on the General tab in the Settings->Preferences menu. In my installation I had to change it to C:\ Users\Public\Documents\DesignSpark PCB 5.0\ Technology. If this path is incorrect DesignSpark won't find any technology files automatically which makes it harder to use. You can check if the directory path is correct if it contains .ptf and .stf files. Schematic technology files Schematic technology files are where you can configure: • The line styles used for terminal and junction connections • Predefined text styles used in the schematic (font, size, etc.) • How various line elements are drawn (solid, dashed, etc.) • How the connection line elements are drawn 10 June 2013 www.elektor-magazine.com TIPS & TRICKS (solid, width, etc.) • Any predefined electrical nets, although I would do this in the schematic instead • Any predefined electrical net classes (ground, power, etc.) • The colors used to draw various elements You can change these parameters from the Settings->Design Technology menu and in the View->Colors menu. You can see what the default parameters look like by loading an example project. The chipKit Max32 project schematics should appear as shown in Figure 1. I personally find that the stroke fonts look old fashioned and so I like to change them to Arial since it's a standard true type font. After playing around for a few minutes this is what I came up with Figure 2. So how do we implement this in the schematic technology file? The first thing you need to do is open the default. stf schematic technology file which is normally located in C:\Users\Public\ Documents\DesignSpark PCB 5.0\Technology which will open as a blank schematic document. Now open the Settings-> Design Technology menu and change the Net Names, Pin Names, Pin Numbers and Symbol Names text styles to use an Arial font with a height of 80. I also changed the Normal text style to Arial as well but with a size of 120. I then went into the View->Colors menu and changed the Pin Names and Pin Numbers fields to black. Once you've made all of your changes, save the technology file so you can use it for new schematic pages by selecting "default. stf" in the new document menu window PCB technology files PCB technology files are one of the best DesignSpark features because they let you combine all of your basic design rules and layer stackups into files that are easily reused. For example, I have a file for simple low cost 2-layer boards and another for 4-layer boards. I can then choose which file I want to use when creating a new PCB document. This feature isn't common with other PCB design packages. PCB technology files let you configure: • The design units (mm, mils, etc) and the resolution. • The design grids, especially the working grid • The layer stackup and colors • The track spacing and clearance rules • The pad and track styles, although you would usually specify the pad styles in your library components and only specify the default track styles in the technology file • The default net classes, but I usually specify them in the schematic instead • Autorouter and autoplacer rules • Basic design elements like board shapes, mounting holes, etc. Let's see how this works by working through an example for a simple 2-layer board. The first step is copy and existing technology file so we don't have to start from nothing, so let's start with C:\ Users\Public\Documents\DesignSpark PCB 5.0\ Technology\metric.ptf to and save it with a new name like my2layer.ptf. The first thing to modify is the design units in Settings->Units menu. I always use mm with a precision of 4 decimal places, but if you prefer imperial units choose in or mil instead. You can then set up your preferred design grids in the Settings->Grids menu. Configuring the layers in done on the Layers tab in the Settings->Design Technology menu. By default the metric technology file has a Top Silkscreen, Top Copper, Documentation, Bottom Copper and Bottom Silkscreen layers already defined. Since all my boards are surface mount, I added a Top Paste, Top Solder Mask, Bottom Solder Mask and a Bottom Paste layer. You can add layers by clicking on the Add button and entering the layer parameters as shown in the example of the Top Solder Mask layer in Figure 3. Figure 3. Configuring the layers. POWERED BY Figure 4. Configuring the layers. Figure 5. Design rules. Once you've added all the layers you want, you can order them properly in the layer stackup by moving them up and down in the Layers window. When you're done you should see something like Figure 4. Next, let's configure the spacing rules by clicking on the Spacings tab. Here you will see a matrix of all the spacing rules between the different object types. For a basic 2-layer board with 10-mil tracks and 10-mil spacing, the rules could look like in Figure 5. Also don't forget to click on the Rules tab. The important parameters are the minimum annular ring and the component spacing. After that it's time to set the default track widths in the Track Styles tab. For a 10 mil/10 mil board I would set the minimum and normal signal track widths to 0.25 mm. The power track widths can be anything you want for the normal width, but I recommend making the minimum 0.25 mm so that you can route the power traces onto the component pads. The final step is to edit the via styles in the Pad Styles tab. For a basic technology 2-layer board I would use a via with a 0.45 mm drill with a 0.95 mm pad. You can also define other via styles if you like to use a variety of different via sizes. At this point you have a set of basic design rules and constraints for a basic 2-layer board that can be easily reused with future 2-layer boards. When you create a new PCB design, select the appropriate technology file when prompted in the PCB Creation Wizard. Conclusion Now that we have configured DesignSpark's default parameters the next steps are to configure DesignSpark's libraries and to create some documentation templates. Fortunately DesignSpark comes with a large set of libraries which makes getting started much easier. ( 130172 ) Hi, I'm Neil Gruending and I have used numerous different PCB CAD packages as an electronics design engineer over the years. I'm pretty particular about my tools and I like to learn how to maximize my productivity with them whenever possible. I also enjoy sharing what I've learned on my website at www.qruendinq.net and on Twitter as @ngruending. 12 June 2013 www.elektor-magazine.com WEIRD WORLD OF COMPONENTS The Cat's Whisker Usually when I start writing an article, for inspira- tion I look at what's around on my desk. For this edition of Weird World of Components a Crystal Diode type FRIHO D.R.P. caught my eye. It is mentioned in an old Radio Bauer Katalog from 1926 — we are talking old stuff here — and it is one of the main components of old crystal radio systems. To be honest, I have no idea how or when I acquired this component, but in my early years I used to spend a lot of time browsing stuff in a renowned shop called Quakkelstein in Vlaardin- gen, The Netherlands. Most likely this was where I picked it up and since then it had been living on my desk or in my drawer. Now this component takes us back to the early days of Radio. It is an automated 'cat's whisker' diode. Turning the knob changes the position of a small wire (the whisker) on the galena crystal, allowing you to find the best spot for the diode to be doing what a diode should do: pass current in one direction only. This is what listening to the Radio encompassed those days. To get a decent signal you needed to twist and tweak the inductor, the capacitor and the rectifier diode. But how good where these diodes compared to what we have today? To measure the character- istics of a diode is really simple. Basically, if you want to do a decent job getting the I-V charac- teristic, all you need is a power supply, a voltage meter and an ammeter. Getting this diode to work properly is challenging to say the least. You need to fiddle around a bit to find the right spot where the diode effect peaks. I started out trying to find that spot with an ohmmeter, but soon I had to conclude that wasn't going to work. The mea- surement results were all over the place. I was ready to give up when I decided to give it a final shot and bring in some more equipment. An HP generator, a Hameg HM01522 oscilloscope and a 330-ohm resistor finally gave me some promis- ing results. In Figure 2 the oscilloscope displays a very fuzzy signal, but with some imagination you can see the FRIHO cutting of the sinusoidal input signal. Figure 3 shows the characteristic of a present-day diode in the same measure- ment setup. Looking at the results I am amazed a component like the FRIHO D.R.P. actually worked! Today a huge variety of diodes exists for all kinds of appli- cations. Small signal diodes, zener diodes, vari- cap diodes or varactors, tunnel diodes, and all of them are available in a variety of packages. It is interesting to realize they all relate to this very old Cat's Whisker diode in some way. ( 130169 ) Wisse Hettinga (Elektor) •Projects Wi-Fi Controller Board Control RGB LED strips, motors, relays & stuff, but no wires With Wi-Fi modules pervasive it's high time to start thinking about adding household appliances to your home Wi-Fi network. Controlling your home from your mobile phone has never been easier thanks to the universal Wi-Fi controller board presented here. Although we used it to set the color of an RGB LED strip, you can use the board for a plethora of other applications. By Clemens Valens (Elektor.Labs) The project you are about to encounter took a while to complete. It all started a year ago with a Home Automation system [1] originally devel- oped by two trainees at Elektor Labs, Koen and Jesper. One part of their system was an RGB LED strip controlled over Ethernet, i.e. with a cable. The idea was nice, but I felt that a wireless connection would be a more appealing solution. Also, I wanted a web browser based application, compatible with most browsers, and that used sliders to control the color of the strip. So Koen set out to develop the lot, but unfortunately his trainee period ended before he could finish the project and he went back to college. Before he left Elektor, Koen had explained to me the prob- lems he had run into, some of which still needed 14 June 2013 www.elektor-magazine.com Wi-Fi Controller Board addressing. I then took it on me to finalize the project, and so it spent the next few months on my desk gathering dust! When I finally found the time and energy to dive into it, I failed to recall most of what Koen had told me, and basically I had to start all over. Koen's circuit was essentially an ATmega328 AVR microcontroller (MCU) controlling three MOSFETs with PWM signals to regulate the intensity of the three colors. For the Wi-Fi connection a WizFi220 module from WIZnet was used that communicates with the MCU over a simple serial link. Since I was in possession of an Arduino shield sporting this very Wi-Fi module [2] and since an Arduino Uno board is based on an ATmega328, I decided to build my prototype as an Arduino application. All I needed was a second shield with the MOS- FETs on it so that I could drive the LED strip. This was quickly slapped onto a piece of prototyping board (Figure 1). Then it was programming time. Parsing the HTTP commands received from the Wi-Fi module and sending back the required answers was not so complicated, but when I wanted to change the web page I ran into Koen's problems. First of all there were the sliders that control the LED strip's color from within a browser that I had so light- heartedly requested. As I then learned, there are no sliders in standard HTML. Searching the Internet I discovered that HTML 5 may be aware of sliders, but only very few browsers support it, so HTML 5 was not an option. Koen had solved this by using the JavaScript libraries JQuery and JQuery-UI [3]. These are online libraries for web pages to use to implement all kinds of nifty con- trols and other functions. Some inconveniences of these libraries are that they are online, mean- ing that you need an Internet connection to use them, and also that they are too large to put them in the MCU's program memory. Since I had no other solution, I decided to stick to the use of the online JavaScript libraries. Looking through Koen's web page code I suddenly remembered the problem he had mentioned before he left: for some reason the Wi-Fi module closed the connection after receiving a command, disal- lowing the browser to send more commands. Con- sequently you could change the color of the LED strip just once, unless you rebooted the module. Koen had found a workaround using a complicated JavaScript that made the browser change its com- munication port before it would send a command. This workaround also involved using the HTTP GET command to send the color data, whereas this com- mand is actually meant to get data from a server (who would have guessed that?). To send data you are supposed to use the POST (or PUT) command. Figure 1. The prototype based on an Arduino Uno, an Elektor Wi-Fi shield (120306) and a piece of prototyping board. A much more elegant solution however is to add the line "Connection: close" to the server's reply to a GET command. Now I could delete the workaround script, making the web page much smaller, and I could switch to using the POST command, which, I felt, was more appropriate. This is what the POST command looks like when it is send by Firefox (the color data is at the end): POST / HTTP/1.1 Host: 192.168.2.15 User-Agent: Mozilla/5.0 (Windows NT 6.1; W0W64 ; rv : 17 . 0) Gecko/17.0 Firefox/17.0 Accept: */* Accept-Language: en-US, en ; q=0 . 5 Accept-Encoding : gzip, deflate DNT : 1 Connection: keep-alive Content -Type : application/x-www-form- urlencoded; charset=UTF-8 Content-Length: 23 www.elektor-magazine.com June 2013 15 •Projects Origin: null Pragma: no-cache Cache-Control: no-cache red=79&g reen=10&blue=20 The next step was to make the web page look pretty on mobile devices. On my smartphone the sliders were shown very small, making it impos- sible to move them with any precision. The solu- tion was to add the viewport meta tag to the header of the web page, like this: With this line added to the HTML code of the web page it now nicely filled the screen of my Android phone while looking good on a PC as well. (On an iPad it occupied only about a quarter of the screen and I have not tried to improve that.) Meanwhile I had also optimized the size of the rest of the program and now my goal was to make it all fit in as little memory as possible. An important improvement came from compress- ing the web page. You can do this with gzip and then add the line "Content -encoding : gzip" to the server's reply. Most, if not all, browsers will know how to handle zipped web pages. The disadvantage of doing this is that it is now a bit more complicated to change the web page; there- fore you only do this when its design is finished. At that point I had a fully working prototype based on Arduino compatible hardware with software that compiled within the Arduino IDE. If you want the details, please visit [4]. I could have stopped here, but I wanted better hardware; a stack of three PCBs for such a simple circuit just didn't feel right. Looking for an MCU with fewer pins I found that I could not stay on Atmel's AVR platform because the parts that would be suitable are difficult to get. However, I did happen to have a couple of Microchip PIC18F14K50 devices lying around. This is a 20-pin MCU with USB, which was interest- ing because that would allow for comfy PC-based configuration of the Wi-Fi module (see also [2]). Another interesting feature is the USB bootloader Microchip provides (for free), which enables easy firmware development without a special program- mer. Unfortunately, this MCU has only one PWM channel, so I had to implement the three-channel PWM color control in software. Porting the AVR code to the PIC should have been an easy and straight forward exercise, but it wasn't. Of course I had complicated things a bit by wanting to include a bootloader and USB func- tionality, but Microchip could have made it a bit easier. I was using my super-duper full-featured XC8 compiler that Microchip is raving about but found it impossible to get the USB code to com- pile, let alone to work. I got this code from the Microchip Application Libraries V2012-10-15 and only after many hours of fruitless fiddling with compiler settings and pragmas did I find a state- ment somewhere on the internet saying that XC8 is not (yet) compatible with the Microchip Appli- cation Libraries. Duh! I needed another compiler. Again internet came to the rescue and within fif- teen minutes I had an official full-featured C18 compiler up and running without shelling out a dime. Another fifteen minutes more and I had the USB serial port example up and running. Now it was time to add my Wi-Fi code — which went pretty smoothly except for fitting all the data in the PIC's segmented RAM — and try it out. And of course it worked. Not. Actually, it worked a bit. I could change the color of the strip once or twice, but then Wi-Fi communica- tion would stop. When I controlled the strip over the USB serial port, it all worked fine. So, back to the debugging table where I discovered that the USB interrupt seemed to hold up the serial port interrupt, causing data loss. By this time I was pretty fed up with it all and decided to sim- ply disable the USB port in Wi-Fi mode instead of going to the bottom of the problem. (I suggest you give it a try if it really interests you. Please let me know if you find the solution.) Building it Now my second — PIC-based — prototype was functioning as intended with the parts I wanted to use (Figure 2); the time to design a nice PCB had finally come. Since the goal was to control an LED strip, I decided to build it into a small, discreet enclosure. The PCB is designed in such a way that the enclosure requires minimal tool- ing, especially when you use the blue transpar- ent version that allows you to view the status LEDs inside. In that case no drilling is needed at all; you only have to trim some standoffs inside. Even with a 20-pin MCU several pins remained unused so I added some extra functionality to the board. In combination with the bootloader 16 June 2013 www.elektor-magazine.com Wi-Fi Controller Board this made the board into a much more versatile platform that you can use for other applications as well. It can be used as: • Wi-Fi RGB LED (strip) controller; • three-channel controller to switch relays or control motors over Wi-Fi or USB (or both); • USB to serial port adapter; • rapid prototyping system with Wi-Fi, expan- sion port and three power channels; • FlowBoard compatible with FlowStone 3 [5]; • something I have not imagined yet. To make these different applications possible the board has been equipped with a switched mode regulator so it can be powered from a 7 V to 40 V DC power supply without wasting too much calories. The board can also be powered from +5V TP2 IC2 +3V3 MCP1 825S-3302E/AB tps +5V jpi ICSP fo O 0 3x 1N5819 * ,h HTS ^>11^)1C^> 9 22p ^2p ^ IC1 VDD VSS RA5/OSC1 D+ RA4/OSC2 D- RA3/MCLR VUSB RC5 RCO RC4 RC1 RC3 RC2 RC6 RB4 RC7 RB5/RX RB7/TX RB6 20 19 18 17 16 X HI C3 ??~fl LO CD “1 D1 N5819 M-7 JP3 K1 lOOn 15 14 13 VBUS D- D+ GND USB-B JP2 O RXD TP5 EXPANSION 120718 - 11 Figure 2. Circuit diagram of the Wi-Fi Controller Board. Did you ever notice how people always connect the barrel jack the wrong way around? The center pin is supposed to be the common connection. I was wicked here on purpose because of PCB layout considerations. www.elektor-magazine.com June 2013 17 •Projects Figure 3. A typical RGB LED strip with an adapter cable salvaged from a PC power supply. the USB port, but keep in mind that the Wi-Fi module may consume quite a lot of power when it is transmitting. A large 3.3-V linear regula- tor provides power for the Wi-Fi module (due to current requirements you cannot use the 3.3 V regulator integrated in the MCU). The module is accompanied by three status LEDs indicating if the module is connected to an access point or not, and if data is being exchanged. Because the MCU is powered from 5 V and the Wi-Fi module from 3.3 V, level converter circuitry was added for the inputs of the Wi-Fi module. The MCU can handle 3.3 V-level input signals directly. The MCU is clocked from a 12-MHz crystal oscil- lator to get the USB timing right. The pushbut- ton connected to the reset pin (MCLR) will serve mostly to activate bootloader mode (the external reset input must be disabled for this to work, fuse MCLRE=0FF). If the bootloader is not needed, this pushbutton can function as a reset button or it can be used for some other function. The three conservatively rated MOSFETs feature an R DS ( on) of 0.077 ft, can switch up to 100 volts and are protected by flyback diodes so they can handle inductive loads too. As an output con- nector I have opted for a standard 4-pin .2" (5.08 mm) pitch PCB terminal block even though most of the LED strips I have seen are equipped with a smaller pitch connector. However, since I do not know how standard these connectors are or if they are all wired in the same way, I preferred a more flexible solution. You can easily make an adapter cable from, say a floppy disk drive power cable (Figure 3). For the power connector you can either use a center-pin barrel jack or a standard 2-pin . 2 " pitch PCB terminal block. A diode provides a basic protection against polarity inversion. A 5-pin extension header allows the use of the free MCU ports for custom purposes. A row of test points extends this connector in one direc- tion; the in-circuit serial programming (ICSP) connector extends it in the other direction. All together they give access to ten MCU pins and all the power supplies. An LED connected to RC4 and a pushbutton are available too. Because the application program can be changed easily thanks to the bootloader and the USB interface, these options make the board into an excellent rapid prototyping platform. All parts (except the Wi-Fi module) are standard through-hole parts so it should not pose any problems to assemble the board. I suggest you mount the Wi-Fi module first as it is a bit fiddly to position properly because of its many connec- tions. Note that the voltage regulators should be mounted lying on their belly (see Figure 4, or on the solder side of the board). The reason for this is that if you don't use the proposed enclosure and you mount them standing up, they can eas- ily be screwed to a heat sink (not that you really need one). The MOSFETs should lie on their back to fit in the enclosure. If the LEDs must stick through the enclosure you should drill the holes first to get the length of their leads right. LED D5 (connected to RC4) and the pushbutton each have been positioned exactly under a standoff so that you can drill holes for them without tedious measuring first, just drill through the standoffs. The enclosure has a battery trap allowing you to mount Wi-Fi status LEDs on the solder side so you can see them only when you open the trap. The pushbutton needs a cap of the right height. The 16-mm model will be almost flush with the top side of the enclosure. To fit the PCB in the enclosure you need to trim in the top cover the four standoffs that keep the enclosure together. An easy way to do this is with a large drill bit. Do not trim too much or the screws won't have any material left to bite into. You should also break away the two bits of plastic meant to keep the battery in place. The Wi-Fi module has a small connector for a better antenna (Figure 5). If you use it, just leave it dangling. 18 June 2013 www.elektor-magazine.com Wi-Fi Controller Board Programming the board The firmware you can download for this project [6] contains the bootloader, the RGB LED strip application and the fuse settings in a single HEX file. Burn the HEX file into the MCU using an appropriate programmer (PICKIT, ICD or other) and you're set. With the bootloader programmed in the MCU you're ready to upload your own appli- cations. The procedure is as follows: • do not power the board, make sure JP3 is not in place; • connect the board to a free USB port of your PC; • press pushbutton SI and keep it pressed while you place JP3. Actually, instead of JP3, I used a normally-closed (NC) pushbutton (microswitches are perfect for this). In this case, while you hold down SI, briefly press the microswitch to enter bootloader mode; • The PC (Windows, Linux or Mac) should now detect the board as an HID. If this is the first time on a Windows PC, you have to show it the .INF file that comes with the download; • on the PC launch the HIDBootloader tool provided in the download (Windows, down- load the Linux or Mac version from the Microchip website) (Figure 6). It should dis- cover the board instantly; • browse to your executable (HEX file) and click the program button; • to quit bootloader mode and to start the application, click the Reset button or toggle the power supply of the board without hold- ing down SI. Configuring the Wi-Fi module In [2] I showed you how to configure the WizFi220 module over a serial port using AT commands. This technique is useful if, for instance, you want the MCU to reconfigure the module on the fly. It also allows configuration of options not accessible in another way. The board presented here has a special mode to allow this way of configuring the module. The Wi-Fi module offers an easier way if all you want to do is connect to an existing Wi-Fi network. In this case you have to put the module in so-called Limited Access Point (LAP) mode. The board can do this as well. For both methods you have to put the board in USB-to-serial mode first. To do so, connect RC2 to +5 V (for example, with a wire on the exten- sion connector) and then connect the board to a free USB port of your PC. LED D5 starts blink- ing and you can send AT commands to the new virtual COM port (the number or name of which you will have to get from your operating system). If the Wi-Fi module is connected to an AP (i.e. when status LEDs 'LINK' and 'OK' are both on) type "+++" in a serial port terminal program to force the module into command mode (the 'OK' LED should be switched off). Now refer to [2] to configure the module. Figure 4. The almost finished board, revision 1.0, fully assembled. Rev. 1.1 is identical except for some parts that have been moved slightly for a better fit with the enclosure. To put the Wi-Fi module in LAP mode instead requires some dexterity. Watch the blinking LED closely, and get into its rhythm. When you feel ready, press pushbutton SI when the LED is off and keep it pressed during two full blinks. Release the button only when the LED goes off after the second blink. If you managed to do this properly then after a second or so the three Wi-Fi status Figure 5. Three 2.4 GHz antennas, one from Winizen (top) and the two others kindly provided by the girls from 2J (www.2j-antennae.com). www.elektor-magazine.com June 2013 19 •Projects Figure 6. Use this tool to upload a new application to the Wi-Fi Controller Board. Figure 7. The WizFi module's configuration page that's accessible in Limited Access Point mode makes life very easy. Figure 8. The Wi-Fi Controller Board web page as seen from an Android smartphone. Is blue semi On or semi Off? Elektor Wi-Fi RGB LED All off All on max max max min min min LEDs will suddenly flash rapidly several times and the module enters LAP mode. (If you count three blinks the module will restore its factory defaults, it's a quick way to get you out of trouble.) If you have the board connected to a serial port moni- tor you will see the message: IP SubNet Gateway 192.168.1.1: 255.255.255.0: 192.168.1.1 [OK] Now make sure that the module is in range of the AP you want to use with the board. Check for new access points with a PC, a smartphone or a tablet. If all is well you should see one labeled "WizFiAPxxxx" where xxxx is a number. Con- nect to it — it is an open AP so you don't need any pass phrases — and point a web browser to the address 192.168.1.1. You should see a page similar to Figure 7. Click on the link "Find Avail- able Wireless Networks". A list will appear with the networks in range from which you can pick the one you want. Click "Save And Continue". This will take you back to the first form, which now shows the details of the selected network. Depending on the security settings of this network you can enter a pass phrase. Click the "Save" button to store the configuration. Click the link "Network Settings (TCP/IP)" and fill in the form. I prefer to use a static IP for the module so I always know its address, but this is up to you. In the field "S2W Connection method " type "1,1, ,80". This will turn it into a serial gateway listening on port 80, the default HTTP port used by web browsers. Again, feel free to use another value. When done click the "Save" button. The "Administration Settings " link allows you to enter a password for the module. I have not used this option. When done configuring click the " Logout " link. Now you will see the message "Rebooting..." and the Wi-Fi connection will be lost. The WizFi mod- ule will restart and try to connect directly to the selected network. If all goes well the LEDs "LINK" and "OK" will light up, meaning that you can now connect to the board. Enter the IP address of the module in the browser and wait until you get the page from Figure 8. When the page loads cor- rectly you are ready to play. 20 June 2013 www.elektor-magazine.com Wi-Fi Controller Board It was fun to be able to control the lights in my house from the outside with my mobile phone. However, this is not how I plan to use the board. My intention is to hook it up to the motorized garage door so a smartphone becomes the key. It will then also be possible to give access to our home to someone even when we are (far) away. Indeed, this board has many possibilities, use your imagination! ( 120718 ) Internet Links [1] Elektor Home Control: www.elektor-labs.com/node/2325 [2] Wi-Fi/Bluetooth shield: www.elektor.com/120306 [3] JQuery(UI): http://jquery.com & http://jqueryui.com [4] Arduino version: www.elektor-labs.com/node/2373 [5] FlowStone (in this issue): www.elektor.com/130064 [6] Firmware, Eagle PCB files, BOM; ordering: www.elektor.com/120718 COMPONENT LIST Resistors (5%, 0.25W) R1,R2,R3,R4,R5,R8 = lkft R6,R7 = 47kft R9 = lOkft Capacitors C1,C2 = 22pF, ceramic, 50V, 2.5mm pitch C3,C5,C7 = lOOnF, Z5U, 50V, 5mm pitch C4,C6 = lOpF 63V, radial, 2.5mm pitch C8 = 330pF 16V, radial, 3.5mm pitch C9 = lOOpF 50V, radial, 3.5mm pitch Inductors LI = 330pH 1A, 5mm pitch, e.g. Wurth Elektronik type 7447452331 Semiconductors D1,D3,D4,D9,D10,D11 = 1N5819 D2 = 3V zener diode, e.g. BZX79-C3V0 D5,D6,D7,D8 = LED, green, 3mm IC1 = PIC18F14K50-I/P IC2 = MCP1825S-3302E/AB IC3 = LM2575T-5.0/NOPB T1,T2,T3 = IRL540 T4 = BC547 Miscellaneous MODI = WizFi220 w. antenna, Elektor # 130076-92 JP1 = 6-pin pinheader, 0.1" pitch, vertical JP2 = 5-pin pinheader, 0.1" pitch, vertical JP3 = 2-pin pinheader, 0.1" pitch vertical Jumper for JP3 K1 = USB-B receptacle K2 = Connector 1x4, 90deg, 0.2" pitch, e.g. MSTBA4 K3 = DC socket 20-way DIP socket for IC1 SI = Multimec type RA3FTL6 w. cap type S09-16.0 XI = 12MHz quartz crystal, HC49/S case Enclosure, Hammond type 1593QGY PCB, Elektor # 120718-1 120718-1 vl.l Elektor' TP8 GPI029 MODI dO com c\iZ> voQ ir)Q D-Z CL 3 am ax aX ~ m •—CO ^-CO I-+ '-a. a. a I3SE3 JP3 www.elektor-magazine.com June 2013 21 •Projects Recycle your ATX Power Supply Elegant adapter board makes it easy By Ben Jordan (USA) This ATX bench top power supply adapter board allows you to convert any stan- dard ATX computer power supply into a convenient supply for breadboarding and general electronics workbench use — simply and elegantly. Features • Outputs for ±12 V, 5 V, 5 V Standby and 3.3 V • No ATX power supply hacking necessary • Easy on and off switching of the connected ATX power supply • LED status indication • Capable of handling heavy supply currents • Binding posts for each voltage output • Slots for easy connection of alligator clips For any electronics or embedded system tin- kering, you have to have a good power supply. Now I don't know about your personal lab equip- ment budget, but mine is rather, well... let's just say that I'm married to the head of the finance department and she's not exactly an electronics engineer. You've probably crafted a few linear regulated power supplies over the years, but it's no trivial task to design and build a variable high powered lab supply. And also, if you're anything like me, the majority of what you tinker around with is digital circuits and low-voltage analog stuff, like audio preamps and such. In most cases, I am messing around with a micro- controller and a few opamps, so typically it's handy for me to have a 5 V rail for the controller (and any glue logic I might have) and +/-12 V rails for the opamps. Increasingly, the sample devices I'm working with (for example the Fre- escale DSP56367 DSP or the NXP LPC2101 ARM-7 microcontroller) require low voltage rails for inter- nal core and 10, namely 1.8 V and 3.3 V. This is a pain in the butt if you have to build a supply with all these rails for each project, but most of them (except 1.8 V) can be obtained from off- the-shelf PC ATX switching power supplies. This is great, because somehow (I don't exactly know how) over the years I have accumulated several of them. They all have 3.3 V, 5 V, 5 V Standby and ±12 V supply outputs. Granted, on many, cross regulation of the 12 V rails is not fantastic. But for the vast majority of opamp circuits it is more than adequate. Design considerations So, why not just put a bunch of banana jack bind- ing posts directly on the power supply, as I've seen so many people do across the web? Good question! Here's why: • ATX PSUs are designed with extremely tight clearances inside them. If you go putting binding posts in there, you may be closing in on safety clearances (and these are important. The AC power input side of most switching supplies sees voltage spikes over 1000 volts and DC busses around +370 volts. It's not worth risking life and limb!) • You have a perfectly good computer power supply, and if you're anything like me you may want to use it to power op amps one day, and a computer motherboard the next. Why modify it beyond its original use? I wanted a more elegantly designed solution, that not only had the binding posts, but also some clip points I could clip alligator leads onto. So I set about designing a PCB for adapting the ATX supply to bench top use. As with any- thing, a good place to start is to define some specifications. 22 June 2013 www.elektor-magazine.com ATX power supply adapter The adapter shall: • not alter the power supply itself; • use an ATX connector; • have binding posts for each ATX power supply voltage and standby; • have a matching return (GND) binding post for each voltage output; • be capable of handling heavy supply currents; • have a switch circuit to make use of the ATX on/off controller; • have LEDs to monitor standby and Power Good signal, and • use through-hole PCB design, so you, dear reader, can make one for yourself easily. 120619 - 11 Figure 1. The schematic shows how simple this power supply add-on actually is. www.elektor-magazine.com June 2013 23 •Projects I had also considered a built-in panel meter so you could monitor the output voltage of each output, but I quickly realized this would be unnecessary feature-creep for this applica- tion, since the outputs are fixed and fairly well regulated, and most users (like me) can plug in their multi-meter and get a more accurate measurement anyway. No complex circuit Figure 1 shows the circuitry for this design. The switching circuit is a simple latch based on two Figure 2. The component layout leaves no room for misinterpretation. Note that the ATX connector should be mounted on the bottom side of the PCB. COMPONENT LIST Resistors R1,R4 = 2200 . R2,R3 = lOkft Capacitors C1-C8 = lOOnF Semiconductors D1 = LED, 3mm, yellow D2 = LED, 3mm, 2-pin bicolor IC1 = TC4049B Miscellaneous K3-K7,K10-K14 = binding post (socket) for banana plug J1 = ATX connector for PCB mounting S1,S2 = tactile push button 24 June 2013 www.elektor-magazine.com ATX power supply adapter inverters from a 4049 HEX CMOS inverter, pow- ered from the ATX standby 5 V rail. The other gates in the inverter are used to drive the power on control signal to the PSU and the LEDs. Press- ing S2 turns on the power supply while SI turns it off again. D2, a bi-color LED, indicates standby mode (green) or powered-on mode (red). ATX power supplies have built-in protection, but there's also a Power Good output that tells the motherboard when the PSU is ready, or if there's a fault condition. It would be nice to have this displayed on an LED. I used a yellow LED for D1 which indicates when Power Good goes high (Power Good is an active low signal). This way, you get some warning of ATX power supply fault conditions. In general, any continuous flashing is bad and your power supply probably has a problem. All the capacitors provide a bit of decoupling for the different supply outputs, except C3 which is for de-bouncing the on-off circuit. All the capaci- tors are ceramic 100 nF types. R1 and R4 are LED dropping resistors and R2/R3 form the feedback paths for the on/off dual-inverter latch. I have seen others converting ATX power supplies to bench top lab supplies and putting minimum load resistors in them. In my experience this is not necessary since the cooling fan is generally enough of a minimum load and most modern switching power supplies are designed to run down to zero load anyway. But if it makes you feel better, you can attach a 10 or 20 W resistor to the 5 V rail (10 Q. will usually suffice) by sol- dering the power resistor between the 5 V and GND binding posts at the rear. Board design This adapter board acts as a break-out board with an ATX header and the necessary on/off circuitry as well as standard-spaced binding posts for plug- ging in single or dual banana plugs. The silkscreen overlay as a guide for placement is shown in Fig- ure 2. Note that the ATX power supply socket must be mounted on the rear side of the PCB, with all other components on the front side. An additional novelty of this board is the unique plated slots around its edge, which are used to clip on 'alligator' style test leads as well. The silkscreen text indicates the output voltage of each one. The board layout is available as a PDF download from [2]. The plated-through holes designated K3 to K14 are for bolting the back conductive end of the banana socket binding post onto. Notice the use of multiple vias in a circle around each of these and also around the mounting holes. These offer increased strength for tightening up screws over them and also for the binding posts a good low- resistance current path through the PCB. In practice This ATX adapter board offers standard 0.75" jack spacing for dual-banana plugs and has color- coded binding posts for each of the voltage rails: 5 V standby, 3.3 V, 5 V, +12 V and -12 V. I have now been using this board extensively at work and at home, powering several development kits off a single ATX supply. At work I have an Altium Nanoboard-II and two Altium Nanoboard 3000 FPGA development boards all running at once from one power supply, as well as a few other things. It has really simplified things well for me! ( 120619 ) Internet Links [1] http://jordandsp.com/ATX-bench-top-power- supply-adapter.php [2] www.elektor.com/120619 I want it This project is available in limited supply as a complete kit, with the PCB, all components including binding posts, components and an ATX connector, plus comprehensive assembly instructions which include the schematic diagram and PCB assembly diagram, as well as drill templates for panel mounting. Visit [1] for more information on price and ordering. www.elektor-magazine.com June 2013 25 •Projects Off to the EF Library! Controlling hardware jb HTermOait Received Data IN ITALY httOM'trOOirHS II I -r -V DIGITAL (PWM~) P S POWER using a UART or SPI interface J CT3 (low control ££ :: Parity . lone Show newine charset ers Newline at Couit Reset □R Newine alter ... ms receive pause (0=off) New sme every ... characters r Clear at [✓ Autoscroll □ Show errors 0 LED LED BOTTOM CONNEC DART ADC : £ ANALOG Ihi © wi cn m ^ m" <<<<<< By Jens Nickel (Elektor Germany Editor) If a suitable protocol is defined, hardware connected to your PC can be controlled using a terminal emulator program. The necessary firmware can be rustled up quickly using Elektor's 'Embedded Firmware Library' (EFL), and the code can be written without knowledge of whether a UART or some other interface will be used for the connection. The protocol described here is ideal for experimentation and development purposes. In the previous edition we described our modular 'Embedded Firmware Library' (EFL), written in the C programming language. This helps begin- ners and old hands alike to develop code for an embedded project that is independent of the underlying hardware and which can therefore easily be ported from board to board and from microcontroller to microcontroller. This is achieved using a hardware abstraction layer consisting of a code file for the board and a code file for the microcontroller. Flowever, the idea of modularity is taken even further in the EFL. Protocol libraries allow pro- grams that communicate to be written without knowledge of the communication channel that will be used: it makes no difference whether com- mands and data are transferred using a UART and 26 | June 2013 www.elektor-magazine.com EFL RS-232 or RS-485 connection, or using TCP/IP over Ethernet. Just a couple of lines of the appli- cation program code need to be changed to use a different interface. In this article we will look at this in more detail and present a protocol that can be used in simple hardware control applica- tions and for development. Mini protocol When trying to get code up and running simple tests such as turning a LED on and off or reading a digital input can be very helpful. Often, how- ever, a microcontroller board will not have any buttons to help you carry out such tests. One alternative option is to control the board from a PC, for example over a serial interface. If the protocol is restricted to ordinary printable ASCII characters it is easy to use a terminal emula- tor program to send commands to the board, avoiding the need for special-purpose software on the PC. Our mini protocol (called 'BlockProtocol') is designed to let us set and clear pins on the microcontroller from the PC terminal. If there is an LED connected to the pin in question, this gives immediate feedback; otherwise a multi- meter or oscilloscope can be used. There are also simple commands for obtaining the status of digital inputs and for reading ADC conversion results from the analogue inputs (see the text box 'BlockProtocol'). The code in the accompa- nying library module can of course be extended in many ways as required. Perhaps a reader will be inspired by the control protocols designed by Andreas Eppinger [2] and Uwe Altenburg [3], which offer a much wider range of facilities. hie Options View Help Disconnect Port COM lb 0 Baud w Oats 8 * Stop 1 - Parity None -| □ CIS Flow control : R* Rwr T* 10 Rwr ■ Cant 0 qIH 0 Rwt ■ NmArwnt CR _ , btiow nt* v* dear received sequence overview j/ Ascii QHex tjDcc x Bn : output - dear at Ncvtfcn* «y«y ... C"a'3CT*ri 1/ Autoscroll Show errors Nentncahcr ... ms r * calva PSUS4 (0-cH * krrnvnl llata 1 *v h h h b h b b n b b n b h b b h OK 5 10 15 70 7. 5 30 01 UART 0/ 0 03.00 DO 1) ADC 0/ 0 07.00 CO 2) ADC 0/ 1 02.01 Cl 31 T/C 1/ 0 01.00 DO (12) (13) (14) (15) (+ 0 ) (+ 1 ) (+ 2 ) (+3) (+4) (+5) (3) (4) (5) ( 6 ) (7) ( 8 ) (9) 35 f t [ r t 40 01 1] 2] 31 «] 5] 45 LCD ir.D BUTTON COHHEC DART ADC 50 55 < 0 1 - { 11 <12)-<15) < 2 > - « 3> < 4 1 - { 31 ( 10 ) { 0 ) { l)-l 2) 70 0 1 2 3 4 5 € 7 8 3 1 0 11 12 13 14 15 75 03.04 03.06 03.05 03.07 07 .00 02.01 02.02 07 .03 02.04 02.05 03 .07 03.03 02.02 02.0 3 02.04 02.05 60 D4 D6 D5 D7 CO Cl C2 C3 C 4 C5 D7 D3 C2 C3 C 4 C5 [4] [ 0 ] [ 2 ] 120668- 16 Map, blocks and board pins The BlockProtocol includes the 'x' command spe- cially designed for use in development with the EFL. The command causes the board to send a dump of the EFL tables to the PC. The tables are used by the hardware layer to determine the microcontroller pins and registers that need to be changed in response to a function call. The entries are specific to the board and any expan- sion board that might be attached. The screenshot in Figure 1 shows what appears in the terminal window when the board shown alongside is used. On the left is the 'map' including the features of the microcontroller such as the UART and ADC that are set up by the board initialization code. The peripheral blocks are shown in the middle, while on the right is a list of the pins on the board. This is particularly important information for any- one planning to adapt or write an EFL board file for a new board. More extensive documentation on the internals of the EFL are given in the extra document that can be downloaded at [1]. Control via UART We shall now show by example how easy it is to use the protocol in your own microcontroller appli- cations. We will use an experimental node, famil- iar from our series on the ElektorBus. This is a very compact board based on an ATmega328. As usual we will connect the node to the PC using its Figure 1. Dump of the EFL tables as seen in the terminal emulator. On the left is the map with the microcontroller features in use (red numbers in the board block diagram); in the middle is the block table (blue numbers); and on the right are the board pins (green numbers). www.elektor-magazine.com 1 June 2013 27 •Projects In this case the code is the same as in the EFL example software from the previous issue, as we are using the same board and the same microcon- troller. The 'Libraries' directory includes the files UARTInterface.h and UARTInterface.c, which form the library for the UART interface on the board. Here this is our RS-485 driver (corresponding to the 'physical layer' of our communications). There is also a module implementing our proto- col (BlockProtocolEFL.c and BlockProtocolEFL.h). Together these two library modules provide a defined software interface which we will now look at. A little code In the main source file of the application code itself we need to include the library header files as follows. Figure 2. Our small microcontroller board can be controlled over a UART/RS-485 interface with the help of a simple ASCII text-based protocol and a terminal emulator program. RS-485 interface and a USB-to-RS-485 converter (Figure 2). Instead of the ElektorBus protocol we will use our new text-based BlockProtocol. The necessary firmware for the microcontroller can be downloaded at [4]; the application can also be found in the EFL code base at [5]. An overview of the files is given in the extra doc- umentation mentioned above. Double-clicking 'ExperimentalUART.atsIn' opens the project in Atmel Studio: see the screenshot in Figure 3. On the right-hand side is a list of the files in the project. The files Controller.h, Controllers, Board. h and Board. c form the hardware layer. Listing: Basic structure of an EFL application. int main (void) { Controller_Ini t() ; Board_Init() ; Extension_Init () ; ApplicationSetupQ ; whi le (1) { ApplicationLoopO ; } }; #include “UARTInterfaceEFL . h” #include “BlockProtocolEFL.h” The main function in an EFL-based project is always structured in the same way: see List- ing 1. In the application set-up function, which is called whenever the application starts up, we initialize the libraries: UARTInterface_LibrarySetup() ; UARTInterface_SetBaudrate(0 , 38400) ; BlockP rotocol_ Li bra ry Setup (UARTIn ter face_ Send, 0, UARTInterface_GetRi ngbuf fer (0) ) ; Here the second line sets the baud rate of UART interface block 0 (which is where we have our RS-485 driver connected) to 38400 baud. The third line needs a bit more explanation. We are telling the BlockProtocol library that it should use the function UARTInterface_Send when it wants to send data from the board. The second param- eter is the number of the UART interface block to be used (even though on the experimental node there is only one UART interface). The third parameter is a pointer to a 'ring buffer' (or 'circular buffer') to be used to store received bytes. Here the required pointer is obtained as the return value of the function UARTInterface_ GetRingbuffer(O), which is also implemented in the UARTInterface library. In the main application loop function, which is called regularly when the application is running, 28 | June 2013 www.elektor-magazine.com EFL we need just a single line: BlockProtocol_Engi ne() ; This is the main function in the BlockProtocol library. It checks whether characters from the PC have been received in the ring buffer, and as soon as a (ASCII 13) is seen it is interpreted as the end of a command and the command is then carried out. A response is assembled, which is either simply 'Ok' or a value such as 'HIGH' or 'LOW', or information about the EFL variables in table form. Let's try it Having compiled the code and flashed it into the board we can try it out using a terminal emula- tor program such as HTerm [6]. First we have to specify which COM port to use and the baud rate. In the 'input control' window we have to set the program up so that the character is sent when the Enter key is pressed (see Figure 4). We will first use the library at its lowest level to demonstrate direct access to to the output port pins of the microcontroller. From the circuit dia- gram of the experimental node [7] we can deter- mine that the red LED on the board is connected to port pin PD4. Port D on the AVR microcontroller corresponds to port index 3. And so we simply type into the terminal emulator p 3 4 + Filr Fdrt Vi rw YAtutfX Project RiwW Debug Tools Window Help ; J’4] w A d -J - p. - 0 - s ^ Otbuj - Jt bSendmg ^ ► u ^ ^ 3 •* h« ; ja,:a buaidbH.i. PnXucutbH.C. MjptH-h MjpiH..c lunlru4te»tFUi BluckPruluculbH.!. ^ Application Setup ^ void AppIkationSetupfJ _T void ButtonEvent(uint8 Block Type, uint8 BlockNiafcer, uinLB BultonPusition, uinl8 EventZndex); Bint aain(unid) j{ tontroller_mit() ; M.ZnitO; Extenslon_Init(); ApplicationietupO; while(l) < Appl i cot iani oop () j ) > I // This function is rnllrd before entering the uin loop // Use it for setup of your application (device-dependent) - void ApplicetionietupO [< LEDButton_l ibrarySctup( ButtonEvent ) ; UART Interf ace_Libreryietup( ) ; UARTInterf ace~5etB«udrete( 0 . 3S4«0); BlockProtocol l ibrary^etup(liAPTTnterface ^eod, 0, UAATInterfnce GctRingbuffer(O)); [) void ApplicetiomoopO |< ButtonPoli(B); BlockProtocol Fngine()j l> 100 % * • Output I Show output from: Build - ^ 3 Build succeeded. r *^ - AlmegaiiSP j CunLiullerbFL.i Kin^BulfefbFL.i jh) Solution Evpefimrnt xlUART (1 prefect) a | j FvperifnentalUART k _Mt Dependencies a jS Output Files s J) Common j] BoardpinCFt c 3] BoardpinCfL-h CemmenfFlr CcnrvwonfR.h jO MepfcFLc MaptfLh ProtocoCR C j] ProtocoCRh RingBufferfFL.c j) RingBufferfFL.h a & Hardware 7 $J BoatdbFL.c BcatdbFL.h j] ControlleifFl.c ControlltfCFL.h FutensionFFL.c FutensionFFL .h a & Libraries jg] BlockProtocolEFl.t BlockPretocolEFl.h LEODuttonCFl.c L£0«utton£FL.h UARTthterfacefR-c UARTthterfaerfR Ji cj IxpefimentalUARTx character sequences given above. Higher-level commands Directly controlling port pins is not the main rai- son d'etre of the EFL. If we want to port our device control program to use a different micro- controller board with different wiring, we would have to change the character sequences given above inside the PC or Android software. For this reason the mini-protocol also allows hardware-independent control of digital inputs and outputs, just like when writing code to run Figure 3. Code to control hardware over a UART interface. Figure 4. The HTerm terminal emulator lets you choose what is sent when the Enter key is pressed. and the red LED on the board will light. As another example, using commands like 'p 2 0 +' or 'p 2 0 -' we can set and clear pin PCO on the expansion connector. If an expansion board, such as the sensor/LED board form the previous issue or the relay board from the Elek- torBus series [8], is fitted this gives us a simple way to control external hardware devices from the PC. Instead of the terminal emulator program we could run a dedicated program on the PC to send commands like 'p 2 0 +' to the appropriate COM port in order to switch the relay. Alternatively we could connect a smartphone to the experimental node using the Andropod RS- 485-UART bridge board [9] and write a small Android app. The software at [10] could be used as a starting point for such a project, replacing the bytes of the ElektorBus protocol with the File Optiom View Help I Ottconnect Pert C0M14 Baud 38*00 » Stop l ^ Parity None » CTS flow eon»d Rx *871 R«e: TX 8 Reset Court Oeer received Overview 0 Reset : Neatne at CR_ nex Dec am : s*v touBut H ; OevM 0 : -*a ... craraom o : ! J fcJtWffOl $tW««rror* ... ■wav® h.m fOwaif o : ;CJ deceived Dal a 1 S 10 IS 20 25 30 35 40 45 SO 55 <0 IS TO ?5 10 £5 >3 »S 100 a* b l 0] UART 0/ 0 03.00 DO i t 01 CCHHEC ( 01- < *» b ( 01 02 . 00 CO v b < 11 ADC 0/ 0 02.00 CO i i 11 LED ( 61- < 3| b f 1) 02.01 Cl u b < 2) ADC 0/ 1 02.01 Cl i i 21 LED (121 - <1SI b t 2) 02.02 C2 u n ( 3) T/C 1/ 0 01.00 80 i i 3) BUTTON ( ej- ( 91 b < 3) 02.03 C3 V h i t «) UART (10) ( 0) b ( *) 02.04 C4 V h i i 31 ADC < n- ( 2) b ( S| 02.0$ C$ V b 1 b ( <1 03.04 D4 V b 1 b ( 3) 03.01 Cl V b 1 b ( t) 03 . OS cs V b 1 b ( 9) 03.07 D7 u b 1 b <101 03.02 D2 u h 1 b (111 03.03 03 V h 1 b (12| 02.03 C3 V h 1 b (13) 02.02 C2 V b i b (141 02.es cs V b 1 b (111 02 . 04 C4 V CT$ OSft RT DCD 115 - Input coned X lnputopeervi 1 Our trancmtttd /Am m*x Dte B/i Send on enter CR w ferrifle Dm ] | RTS.] Type A5C - | xj L"-rJ Tranemtted data X 1 5 Xu www.elektor-magazine.com ] June 2013 29 •Projects on the microcontroller itself as described in the previous issue. With the string L 0 l + we can switch on LED 1 in LED block 0 (which on our board is the yellow LED). With B 0 0 ? we can request the status of the test button (but- ton 0 of button block 0). And with R 0 0 + we can turn on a relay. Three-wire interface The approach described above assumes that we have external access to a UART on the microcon- troller, for example via RX and TX pins brought out on the board. We also need a more-or-less complete EFL microcontroller description file which describes not only the I/O pins and ADC functions but also the UART functions that are available. When starting out with a new microcontroller (for example because you want to develop an EFL microcontroller description file for other read- ers to use) it is probably simplest to start with the I/O functions. The first major hurdles are to study the datasheet to determine how to go about setting the level on the I/O pins and reading their status, and to find at least three general- purpose I/O pins that are brought out to con- venient points: fortunately most boards satisfy this condition. It will then be possible to control the board using the protocol described above, over a three-wire SPI interface implemented in software. One of the wires is a clock signal, the second carries bytes from the master (the PC) to the slave (the board), and the third carries bytes in the opposite direction. The SPI specification allows for the further pos- sibility of having communications over the three- wire interface initiated by the slave rather than by the master. In this case each participant takes its 'out' line high and waits for the other partici- pant to do the same. Then communication can begin, with, as usual in SPI systems, the mas- ter providing the clock and data bytes flowing in both directions simultaneously. When there are no more data to send a 'stop character' (, ASCII 10) is sent. When both participants have sent this byte, the communication is complete. We have encapsulated this protocol in the EFL module called 'ThreeWirelnterfaceEFL'. With the help of this module it is easy to set up communi- 30 | June 2013 www.elektor-magazine.com EFL cations using the software SPI interface in place of the UART interface. The code required in the application set-up func- tion is now as follows: ThreeWi relnterf ace_ Li brarySetupQ ; BlockProtocol_ Li brarySetup (ThreeWi reInterface_Send , 0 , ThreeWi relnterf ace_GetRi ngbuf fer (0) ) ; These lines tell the BlockProtocol library that we will be using the three-wire interface to send and receive data: compare them with the code for setting up the UART interface above. In the main application loop we need the command ThreeWi relnterf ace_Li sten (0) ; Figure 5. Communication with an Arduino Uno over a three- wire interface. which checks whether the other device has taken its data line high to indicate a request to send data. If so, the communication is set up. When using the UART for communication we do not need a listener function like this, as in that case a microcontroller interrupt can be used to detect when characters arrive and automatically store them in the ring buffer. Making contact with an Arduino To demonstrate the EFL concept we selected an Arduino Uno board. The code for this board can be found in the project ArduinoUnoEFL [4] [5] . We decided to use general-purpose I/O pins PBO, PB1 and PB2 to access the board: these are brought out on the 'digital' I/O connector as Digital8 to Digital 10. A simple three-way cable (for exam- ple using Conrad order code 741221) provides a practical solution (see Figure 5). Of course we also need a connection to the PC at the other end, and that will also need to have a three-wire interface. We pressed an experimen- tal node board into service as a gateway, con- verting from three-wire format to RS-485 (and thence to USB) and back again. The firmware involved can also be downloaded at [4] or [5]: the Atmel Studio project can be found in the directory 'ExperimentalSPI'. The gateway function has its own library mod- ule called OneToOneGatewayEFL. With a call to OneToOneGateway_Engi ne() ; inserted in the main application loop the processor will regularly check whether a string, terminated with a character, has appeared in one of the input ring buffers. If so, then its contents are sent out on the other communication chan- nel. Then the other input ring buffer is similarly checked, and so on. It should almost go without saying that the gate- way module itself is programmed in a manner independent of the underlying communication channels and can therefore easily be used to per- form other similar gateway functions. The func- tion OneToOneGatewayJJbrarySetup takes two triples of parameters to specify the two com- munications channels being connected. In this example the call appears as follows: OneToOneGateway_ Li brarySetup (UARTIn ter face_Send , 0, UARTInterface_GetRi ngbuffer (0) , ThreeWi reInterface_Send , 0 , ThreeWi reInterface_GetRi ngbuf fer (0) ) ; We now just need to plug the cable into the experimental node's expansion connector (pins PCO to PC2, see Figure 6) and flash the appro- priate hex file into its microcontroller. The pins used to form the three-wire interface have to be specified separately for the two dif- ferent boards. The three-wire interface on each device is a separate peripheral block: recall that www.elektor-magazine.com | June 2013 31 •Projects Figure 6. The experimental node acts as a gateway between the three-wire interface and the UART/RS-485 interface. the board file encapsulates the mapping between peripheral blocks and microcontroller pins. The configurations for the three-wire interface, includ- ing these pin assignments, can be found in the Board_Init function in the file BoardEFL.c. It rocks! In the terminal emulator program we first issue the V command. The Arduino board responds directly, sending the ELF variables out over the three-wire interface, albeit at a rather more lei- surely pace than before (the speed is comparable to that of a 9600 baud serial port). The command C 0 13 + can be used to set pin 13 of the Arduino's 'digi- tal' connector high: this pin drives an LED on the Arduino Uno board, and so we get immedi- ate visual feedback. ( 130154 ) Internet Links [1] www.elektor-magazine.com/120668 [2] www. elektor-magazine. com/100576 [3] www. elektor-magazine. com/1 20296 [4] www. elektor-magazine. com/1 301 54 [5] www.elektor-labs.com/efl [6] www.der-hammer.info/terminal/index.htm (in German only) [7] www. elektor-magazine. com/1 10258 [8] www. elektor-magazine. com/1 10428 [9] www. elektor-magazine. com/1 10405 [10] www.elektor-magazine.com/1 20097 In the next installment we will take the EFL proj- ect further: suggestions and contributions are more than welcome. The most recent version of the EFL code can be found on the Elektor.Labs pages at [5]. 32 | June 2013 www.elektor-magazine.com \ ■ ■ ^ rj Add USB to your next project. UOD It's easier than you might think! DLP-USB1232H: USB 2.0 UART/FIFO HIGH-SPEED 480Mb/s • Multipurpose: 7 interfaces • Royalty-free, robust USB drivers • No in-depth knowledge of USB required • Standard 18-pin DIP interface; 0.6x1 .26-inch footprint DLP-I08-G 8-Channel Data Acquisition Only $29.95/ • 8 I/Os: Digital I/O Analog In Temperature • USB Port Powered • Single-Byte Commands DLP-IOR4 4-Channel Relay Cable DLP-THIb Temp/Humidity Cable DLP-RFID1 HF RFID Reader/Writer DLP-FPGA USB-to-Xilinx FPGA Module www.dlpdesign.com AP CIRCUITS PCB Fabrication Since 1984 As low as... each! Two Boards Two Layers Two Masks One Legend Unmasked boards ship next day! www.apcircuits.com VISA IPC MEMBER ASSOCIATION CONNECTING f ELECTRONICS INDUSTRIES* BBS ■ !■ ElPololu Robotics & Electronics Zumo Robot Arduino-controllable tracked robot small enough for mini- sumo (less than 10 cm x 10 cm) and flexible enough for you to make it your own. Maestro USB Servo Controllers Compact, versatile servo controllers that offer USB, serial, and internal scripting control. Metal Gearmotors Available in a wide range of motor types and gear ratios that let you choose the right combination of size, torque, and speed for your application. AltlMU-10 Gyro, Accelerometer, Compass, and Altimeter Provides ten pressure, rotation, acceleration, and magnetic measurements that can be used to calculate absolute orientation and altitude. Finding the right parts for your robot can be difficult, but you also don't want to spend all your time reinventing the wheel (or motor controller). That's where we come in: Pololu has the unique products — from actuators to wireless modules — that can help you take your robot from idea to reality. Find out more at www.pololu.com •Projects Lost Model Finder By Robert Budniak (Australia) io control plane flyer at some time has had a plane go down outside of the airfielcPboundaries. Sometimes the location of the pre- cious plane is easy and at other times they are hard to find. High grass, trees or even uncertainty where the plane went down all make it hard to find that elusive plane. So let's build a radio direction finder (RDF) that ideally takes you straight to the crash location. There are a number of systems around used to locate lost R/C models. I considered that I could build a system that was a little bit better. The concept specifications were: • Lightweight transmitter for the plane Features • low cost design • TX board in SMD, RX board in T/H technology • Suits most 315/433 MHz ISM short range radio modules • Programmable personal callsign on each TX • Minimum range: 600 ft (200 m) • Maximum range: depends on terrain and TX and RX modules used • 4-element Yagi directional antenna on RX • Battery backup in case of disconnection of the main battery • Using commercial, type approved UHF ISM band radio modules • Range at least 600 ft. (200 m) • Receiver to be handheld and able to use radio direction finding (RDF) to locate the model. From this I was able to put to together the design described here. If you're strong in model building and flying, but not in electronics, consider doing this project as a club activity. Transmitter Every country has a series of radio frequencies allocated to the Instrument, Scientific and Medi- 34 June 2013 www.elektor-magazine.com Lost Model Finder cal Band (ISM), sometimes combined with 'Short Range Devices' (SRD). These frequencies vary between countries. While in the USA 315 MHz is used, in Australia and most of Europe we find 433 MHz. Because there is a demand for sim- ple and cheap transmitters, there are a number of manufacturers supplying RF modules to this market. The type of module used in this project uses Amplitude Shift Keying (ASK), and these types of modules seem to have a standardized pin configuration from different manufacturers. So that's the RF transmission part taken care of. Note that the parts list for the project indicates suggested types only. As you can see in the schematic in Figure 1, the RF module just needs to have a data stream applied its 'DATA' pin, and for this project I used a simple PICAXE08M chip. I chose this microcon- troller as it was readily available, the program- ming language was easy to learn, and the chip did not require any special equipment to program it. Really an ideal system for low volume and low complexity projects. The code is only a few lines (Listing 1), and in the sample code for this project the coded gener- ates three short 500-Hz tones and then a pause of about 2.5 seconds. Whilst the code can be copied, I would recommend that the line where the tones are generated is changed if you use a number of these transmitters near each other (like in a club environment). The transmitter is normally powered off the plane's receiver. However sometimes the plane's battery gets disconnected in an accident, so a backup battery is provided. The backup battery is a small Li Po battery (around 130 mAh capac- ity) that usually powers small indoor planes. This battery is available cheaply from online suppliers. Usually you'd use steering diodes to automati- cally select the power supply. However with the low voltages used in this project (5 volts and 3.7 volts) even the 0.4 volt drop of a Schottky diode was a sizable proportion of the voltage. Looking through some online databases, I found some small signal transistors type DTB123YK (Tl, T2), which also had base-emitter and base resistors in the chip. They work quite well in steering the volt- ages of the batteries, and the voltage drop across the transistor is just 100 millivolts. The only down side is that when the main battery is disconnected the backup battery takes over. Hence the backup battery needs to be disconnected when the plane Figure 1. Circuit diagram of the transmitter, which is not much more than a programmed PICAXE microcontroller. Listing 1. PICAXE TX code main : sound 4,(0,10,120,10,0,10,120,10,0,10,120,10,0,10) high 4 pause 2300 goto main is not in use, or it will run down. So that the Lost Model Finder can be left per- manently in situ (it's cheap enough that one can have one for each plane), it's designed with a charging port combined with an on/off switch. This is achieved by using the switch in a 2.5-mm jack socket that's operated by a 2.5-mm jack. With the jack inserted, the backup battery is dis- connected. If a jack that is connected to a char- ger is inserted, then you can charge the battery. Figure 2. A possible charger circuit for the LiPo/Li-Ion battery in the transmitter. It's either externally powered (6.5- 15 VDC), or USB powered as selected on JP1. www.elektor-magazine.com June 2013 35 •Projects Figure 3. Build this inverter circuit if you use an FTDI TTL- to-232 adapter between the transmitter's TX/RX pins and, say, a microcontroller. Figure 4. The Lost Model Finder receiver uses an old faithful, the LM3914 LED bar graph indicator. The 433 MHz (315 MHz) receiver (RX) module gets plugged onto the MODI connector. Charger A suggested circuit for a charger is shown in Fig- ure 2. Two inputs control the mode the charger is operating in. One input selects the regulating volt- age, 4.1 V or 4.2 V (jumper JP2, SELV). The other input sets the charge current, 100 mA or 500 mA (jumper JP3, SELI). A nice feature of this IC is the ability to precondition a near-dead battery before charging. The enable input (EN) is not used and thus permanently connected to the power supply. The general description in the datasheet states specifically it can be powered from a USB port and can handle input voltages as low as 4.35 V, the minimum of a USB port. With higher input voltages (the MAX1811 can handle 6.5 V max.) and with the high current set the IC will limit the charge current to keep the die temperature at a safe level. In case only a power source with a higher voltage is avail- able a low-dropout 5V regulator is added (IC2). A jumper selects the input voltage for the MAX1811 (JP1: AUX or USB). Do not connect an input volt- age to the regulator if the USB port is selected as input source. The input decoupling of the MAX1811 (C2) doubles as the regulator output decoupling. This was done to save space. PICAXE PE interface At some point you'll need to burn the plane ident program to the PICAXE chip. In case you are using an FTDI TTL-to-RS232 adapter to interface with the TXD/RXD pins of the PICAXE in combination with the PICAXE Programming Editor, you need an additional inverter circuit as shown in Figure 3. Receiver The receiver is based on a complementary module to the transmitter. However a little more care is needed in the selection of the receiver, to ensure it supplies the right signals to our circuit. Referring to Figure 4, the first output of the receiver module is from the DATA pin, 14. This passes to a small-signal FET T1 and the output goes to a piezoelectric transducer Bzl (not a piezoelectric buzzer). What you will hear from this transducer (hopefully!) is the tones and pauses generated by the transmitter. In use you listen for your personal 'call sign' that was embedded in the transmitter. The second output from the transmitter is the RSSA output (pin 13). Basically this is a voltage that is proportional to the signal strength and used as part of the automatic gain control (AGC) in these receivers. This signal is applied to the input of an LM3914 LED driver. The RSSA sig- nal on the prototype was found to vary between 0.4 volts and 2 volts, so the upper and lower limits of the LED driver have been set to those values. I won't go into the design of the circuit around the LM3914, since the IC has been used a zillion times in DIY electronics projects over the past decades. If you want a more detailed tuto- rial then point your web browser to [1] and enjoy Dave's EEVBIog #204. Say Hello to Dave for us. The receiver is powered from four AA or AAA batteries, rechargeable or dry, although three dries should also work. Despite the transmit- ter's datasheet claiming a maximum voltage of 5 volts, the module has been tested to work up right up to 7 volts. The only other major item associated with the receiver is a 4-element 'Yagi' directional antenna. This antenna was chosen for its simplicity and its directional properties, a feature which will becomes obviously necessary in the how to use section. 36 June 2013 www.elektor-magazine.com Lost Model Finder Building The transmitter is built on a double-sided PCB using SMD components (Figure 5). It uses 0.1" pitch pinheaders for all external connec- tions except possibly K3. The artwork may be downloaded free from [2]. The PICAXE may be soldered in but also mounted in a DIL-8 socket. Only solder in the two transistors if using the battery backup version. Do not connect the RF module yet to the footprint marked K3. At this stage you can test the transmitter driver by connecting a piezoelectric transmitter between the data and ground pins that go to the RF mod- ule. After applying power you should be able to hear your callsign. The RF module may be connected to the board with a short length of 4-way flatcable and using pinheaders and mating IDC sockets. Alternatively, it may lie flat over the microcontroller board as shown in Figure 6 (433 MHz version built by Elektor Labs). Make sure the solder sides of the board do not touch. The final part is the installation of a quarter-wave antenna. A piece of stiff wire about 173 mm in length will do (I use one core of an Ethernet cable). When using a 315 MHz TX module the antenna length becomes 240 mm — remember, from (300/0-F4. The microcontroller board, RF module and backup battery (if used) may be wrapped in a short length of shrink wrap tube. The receiver PCB design is also shown in Fig- ure 5. This is a single sided board forTH compo- nents so it should be plain sailing. Insert and sol- der all the parts into the PCB. The radio module is mounted vertically. The board and battery holder for three (or four) AA(A) cells may be mounted on the Yagi boom behind the reflector. The radiator (dipole) elements of the Yagi antenna should be connected to the input of the radio module with a length of thin 50-ft coax cable like RG174/U or /CU. Keep the length to an absolute minimum to prevent excessive losses. Resist the temptation to use screened audio cable. The (optional) charger is built on the board shown in Figure 7. Do not forget to fit the jump- ers according to your requirements. The 4-element antenna is all-homebrew. Var- ious designs are around on the Internet, and mechanically skilled members of your local model COMPONENT LIST Transmitter Resistors R1 = lOkft 1%, SMD0805 R2 = 22kft 1%, SMD0805 Semiconductors IC1 = PICAXE-08M2, programmed T1,T2 = DTB123YK Miscellaneous K1,K2,K5 = 3-pin pinheader, 0.1" pitch K3 = 4-pin pinheader, 0.1" pitch (optional, see text) K4,BT1, 2-pin pinheader, 0.1" pitch Transmitter module (on K3), ASK, 433MHz ISM band, type approved, e.g. Quasar Electronics type QAM- TX1 (433 MHz), Farnell/Newark # 1304024. USA readers, use 315MHz equivalent LiPo battery, 3.7 V, 130mAh PCB # 120139-1 Receiver Resistors R1 = lkft R2 = 620ft 1% R3 = 360ft 1% R4 = 2.7kft Figure 5. The Transmitter board is double-sided and takes SMD parts; the Receiver board is a single-sided design for through-hole parts. TX board shown at 150 % of true size. Capacitor Cl = lOOnF, 5mm or 7.5mm pitch Semiconductors D1-D10 = LED, orange, 2.5x5mm rectangular, 20mA T1 = 2N7000 IC1 = LM3914 Miscellaneous BZ1 = (not on board) piezo transducer, flying leads, Farnell/Newark # 1193640 K1,K2,(BZ1) = 2-pin pinheader, 0.1" pitch (MODI) = 15-pin pinheader, straight, SIL, 0.1" pitch MODI = AM SuperHet Receiver, QAM-RX3 (433MHz), RS Components # 742-4484. USA readers, use 315MHz equivalent Battery holder for 3 or 4 AA(A) batteries, see text PCB # 120139-2 building club may be persuaded to produce a few sophisticated antennas for members. The author made the radials from coat hanger wire, although any stiff wire will do, like electrical installation wire. Try to cut the radials to the lengths shown in the drawing in Figure 8 (dimensions for 433 MHz). The author's prototype was made from some 3-mm (1/8 in.) corrugated plastic sheet (corflute; corriboard; Polyflute), with the radi- als inserted into the cores. The spacing does not work out exactly, but works well in practice. Elektor Labs built their Yagi antenna from a 570 x 53 x 12 mm piece of wood and lengths of 2.5 mm 2 www.elektor-magazine.com June 2013 37 •Projects Figure 6. LiPo Charger board (left) and TX assembly (right). The PICAXE board and the transmitter module may be connected without a cable, simply by bending and soldering the four pins straight to K3. csa electrical installation wire (introductory pho- tograph) fitted at the exact positions from Fig- ure 8. The boom is long and wide enough to hold the RX board and the battery holder. This antenna should have about 7 dB gain, allowing the TX to be found at a distance of about 1,000 feet (300 m) in a built-up area as Labs were able to measure in and around their location at Elektor House. Connect the dipole elements of the antenna to the receiver via the previously installed cable. Sticklers for nanovolts may want to add a balun for proper matching of the symmetrical radiator to the asymmetrical coax cable, but in this case the work and cost may defeat the purpose. COMPONENT LIST LiPo Charger (optional) Figure 7. The charger board is a double-sided design for surface mount components. Resistor R1 = 1.5kft SMD 0805 Capacitors Cl = lOOnF SMD0805 X7R C2,C3 = lOpF 10V, SMD 0805, X7R C4 = lOpF 25V, SMD 1206, Y5V Semiconductors D1 = LED, red, SMD 0805 D2 = PMEG2010AEH, Farnell/Newark # 1510673 IC1 = MAX1811ESA+, Farnell/Newark # 1593327 IC2 = NCP1117ST50T3G, Farnell/Newark # 2112617 Miscellaneous K1 = mini USB receptacle type B, SMD K2,(BT2) = 2-pin pinheader, 0.1" pitch JP1,JP2,JP3 = 3-pin pinheader, 0.1" pitch, with jumper PCB # 120139-3 Testing Fortunately there is no calibration required. Leave the transmitter off at this stage. Turn on the receiver and you should hear white noise with the occasional pop. The LED indicator should be showing the lowest LED on. Turn on the transmitter. You should now hear your callsign, and the bar graph should be moving up and down in synchronization with the tones of the call sign. The bar graph should go to full scale when the transmitter and receiver are within 10 feet or so (3 m) of each other. In use It's going to take a little practice in order to successfully use the Lost Model Finder. It's best to initially have a friend hide the transmitter in a park or garden and then try and find the transmitter. The antenna is directional and the 'sharp' end is the end with the greatest sensitivity. When looking for the transmitter, hold the antenna in front of you and rotate a full circle. Listen for your call sign to make sure you're chasing your transmitter. The bar graph will indicate where the maximum signal is. Walk in the direction of maximum. Continue doing this, stopping occa- sionally to check your bearings. You should see that the bar graph increases. At some point you will get close to the transmit- ter and the bar graph will be at maximum. Now point the insensitive ('blunt') end of the antenna in the direction where you think the transmitter is. Now when you rotate the antenna around you, you are not looking for the maximum signal but the minimum signal. You're sort of sneaking up from behind. You can also change whether you hold the antenna radials parallel to the ground, or per- pendicular, or any other orientation. The last few ten feet or so are the hardest in finding a plane, especially one lost in vegeta- tion or scrub. Also don't forget to look up to the tree top canopy! You never know where these models are hiding. ( 120139 ) [1] Dave's EEVBIog # 204: www.youtube.com/watch?v=iIKGvHjDQHs&fe ature=player_embedded) [2] Project page: www.elektor-magazine.com/120139 38 June 2013 www.elektor-magazine.com Lost Model Finder E F G A = 30 mm B = 124.4 mm C = 138 mm E = director #2, 307.9 mm* F = director #1, 310.8 mm* G = radiator, 2 x 163.5 mm* h H = reflector, 338 mm* I = boom, 570 mm * 2.5mm 2 / AWG 13 wire Figure 8. Experimental Yagi antenna with the receiver electronics attached on top of the wooden 'boom', behind the reflector. The directors, radiator and reflector were made from electrical installation wire (c.s.a. around 2.5 mm 2 / 13AWG) and secured to the wooden boom with tie wraps — after carefully centering on the boom, of course. For safety, the radial ends should be covered with a blunt object or some putty. Gain is approximately 7 dB. For 315 MHz use, the element spacing and lengths should be scaled up by a factor 1.37. Advertisement THE ORIGINAL SINCE 1994 PCB-PnQL 8 Beta LAYOUT FREE Stencil with every prototype order Xfi, Embedded RFID authenticate, track & protect your product www.magic-pcb.com Call Tyler: 1 707 447 7744 sales@pcb-pool.com PCB-POOL® is a registered trademark of www.pcb-pool.com / LAYOUT create : electronics CS328A-XS 100MHz Mixed Signal Oscilloscope + Signal Generator EASY AS! + Copy & past? + Signal generator + USB or Ethernet + 8M samples storage + 10Q MHz sampling + Dual 14 bit ADC + Ext Trigger, 8 Digital Inputs + 1.5 lYISaj'sec HD streaming 1 4 Bits 1 00 MSPS MSO uuww.cleverscope.com www.elektor-magazine.com June 2013 39 •Projects Lithium-ion Battery Recycling Made Easy meaning: without a microcontroller By Fons Janssen (Maxim Integrated, The Netherlands) It can be quite tricky to reuse Lithium-ion batteries from discarded equipment since these cells are often charged inside the equipment, meaning that there won't be a separate charger that can also be reused. Luckily, it turns out to be fairly easy to build a charger for used (or new) Li-ion cells. Like most people, you probably have some old equipment lying around that uses a Li-ion battery for the supply. This type of battery has been used in most portable equipment produced in the last few years because it can be easily made in various sizes and shapes, whilst it also has a relatively large capacity (compared to NiMH and NiCd). What can you do with that old MP3 player or mobile that's been replaced by a newer, better version? The electronics can usually not be used for any other purpose, but that battery can still come in useful, even if it's for use in a toy. Since electronics hobbyists tend to be an inventive lot they will usually find a way to incorporate and connect a recycled battery. The author, for exam- ple, has built a Li-ion battery into a Lego train to replace three penlight cells (see the main photo). This still leaves the need to charge the battery. The original equipment usually contains a special charger circuit for the battery, most likely on a small part of the PCB in the equipment. It is dif- ficult to figure out which components are part of the charger circuit since no circuit diagram is normally made available for portable equip- ment. In that case we'll just have to build our own Li-ion charger! The circuit The charger circuit described in this article is built around a Li-ion charger IC made by Maxim (MAX8677A, see the block diagram in Figure 1). This IC works completely autonomously so that there is no need for a microcontroller (and hence no software!). A number of LEDs is used by the IC to indicate the state of the charging process. The IC is very flexible and contains a 'smart 40 june 2013 www.eIektor-magazine.com Li-ion-charger power selector' (see Figure 2), which consists of three electronic switches that direct the charge and load currents according to the situation. With an external power source, the IC can use the available power to both charge the battery and supply the load. Should the load require more power than the charger can deliver then the IC can make the battery supply the extra current. When there is no external power source avail- able the load is obviously powered solely by the battery. The IC can be powered from a USB port via pins 15 and 16 (USB). In this case the current drawn is limited to 500 mA (the maximum for a USB2.0 port). The IC can also be powered from an adapter via pins 2 and 3 (DC), where the current limit can be increased up to a maximum of 2 A. In the circuit for the charger in this article (Figure 3) we make use of the DC input, which gives us greater flexibility in setting the vari- ous limits. The operating voltage at the input is between 4.1 to 6.6 V. If the voltage becomes too high, the IC turns off the input to prevent it from overheating. The IC can survive voltage spikes up to a maximum of 14 V. The charging status is provided by Dl, D2 and D3. The following three states are indicated: Figure 1. Block diagram of the internal circuit of the MAX8677A. Figure 2. The 'smart power selector' splits the charge and load currents according to the demand. Figure 3. The complete charger circuit consists mainly of the MAX8677 and a mini-USB connector. www.elektor-magazine.com june 2013 41 •Projects Figure 4. Most Li-ion batteries with three connections have an internal NTC connected as shown. NTC BAT- BAT+ maximum charge current can never be reached as it can not go higher than the maximum input current. Both these limits are set using a resistor: Maximum charge current: Ichgmax = 3000/K iset = 3000/R9 = 3000/5. 6k Q = 535 mA Maximum input current: I D cmax = 3000/R pset = 3000/R6 = 3000/3. 3k Q = 909 mA Figure 5. The PCB designed for this charger has been kept as small as possible to make it easier to build it into existing equipment. The battery is being charged (LED D3), the bat- tery is fully charged (LED Dl), or the battery is faulty (LED D2). There are two current limits that can be set with this IC: one for the maximum charge current and one for the maximum input current. It's clear that the second value should always be larger than the first. If this isn't the case, the programmed Component list Resistors (default: SMD0603) R1,R2,R5 = 4.7k Q R3,R4 = 560kft R6 = 3.3kQ R7 = 10k Q. R8 = lOkft (only if NTC in battery) R9 = 5.6kQ Caoacitors (default: SMD0603) C1,C3 = 4.7pF (SMD0805) C2 = lOOnF C4 = 68nF Semiconductors Dl = LED, green, 3mm D2 = LED, red, 3mm D3 = LED. yellow, 3mm IC1 = MAX8677AETG+ (24-pin TQFN) Miscellanous USB1 = mini USB connector, PCB mount, SMD, (e.g. Molex 67803-8020, RS Components # 720-6618) FS1 = fuse, SMD, rating dependent on battery (e.g. LittleFuse nanofuse 3 AT, Farnell/Newark # 1596930RL) Print artwork # 130117-1 from [2] You can obviously select more suitable values depending on the power rating of the adapter, the power consumption of the device and the desired load current. The IC can provide a maxi- mum charge current of 1.5 A. We've used a mini-USB connector, which makes it easy to power the circuit with contemporary mains adapters. This also ensures that we're using a 5 V supply. The maximum input current should be adjusted according to the rating of the adapter. The circuit will function just fine when the adapter can provide a current of at least 1 A. Is there an NTC? Batteries are often provided with an NTC, which is used to prevent them being charged at tem- peratures that are too high or too low. The bat- tery therefore has three connections: a positive terminal (BAT+), a negative terminal (BAT-) and a connection for the NTC (see Figure 4). You should be aware that some batteries with three connections have only a normal resistor inside that is used for identification. Its value will be constant, so won't vary with the temperature of the battery. When an NTC is used it should be connected between the THM pin and ground (via the BAT- connection). A resistor (R7) is also connected between the THM pin and a reference voltage (\/ L) , which creates a potential divider. The value of the resistor is chosen such that it has the same value of the NTC at a temperature of 25 °C. The voltage at the THM pin at 25 °C will then be equal to 0.5 V L . When the temperature rises/falls, the resistance of the NTC falls/rises as will the volt- age at the THM pin. The IC will only charge when this voltage is between 0.28 \/ L and 0.74 \/ L . With contemporary NTCs this corresponds to a tem- perature between 0 °C and 50 °C. When no NTC is available you should add R8, which causes the voltage at the THM pin to be 0.5 \/ L . 42 june 2013 www.elektor-magazine.com Li-ion-charger Connection tips If you're reusing a cellphone battery it will already have a protection circuit as standard, which pro- tects the battery from overloads and from being discharged too deeply. However, if you want to use a single cell, for example from a battery pack from an old laptop, then you will have to make your own protection circuit. The circuit inside the pack will have been designed to protect the whole pack and can therefore not be used to protect a single cell. A simple fuse (shown in the circuit diagram as FS1; this is an SMD fuse on the PCB) offers suf- ficient protection from overloads, which means that separated cells are perfectly usable. How- ever, a fuse doesn't offer any protection against deep discharging. When these types of cells are discharged too much it is possible to damage them. This can happen when an ohmic load is attached for too long a period, such as a small incandescent light bulb. Most devices will stop working once the supply voltage has dropped below a certain value, which stops the cell from discharging further. Whether or not a fuse offers enough protection therefore depends very much on the type of device that is connected. Construction A compact PCB has been designed for this proj- ect, which uses a large number of SMDs (see Figure 5). This keeps the PCB very small, which makes it easier to build into the device. The board layout (made using DesignSpark) is available as a free download from [2]. You will need some dexterity and soldering expe- rience in order to mount the SMDs. For the TQFN packaged IC you should ideally use a reflow oven, since the pins and the exposed pad are on the underside of the 4x4 mm package. However, the author has thought of a method that can be used to solder the IC by hand, which is described in detail in the inset. There are holes on the PCB for the connections to the LEDs, battery and the load, so they can be connected easily via wires. The mini USB connector has two plastic pins that fit in the associated holes on the PCB, providing alignment of the socket. If you don't want to use the mini USB connector you can use these two holes for connecting the power. In this case you have to make sure that the supply voltage is 5 V. ( 130117 ) Soldering a TQFN by hand Mounting the IC with a hot air soldering iron is possible if you're experienced enough, although a reflow oven makes life much easier. The method described here shows how to use an ordinary soldering iron to mount the IC, even though the home made PCB is not through-plated. Locate one hole in the center of the IC's exposed pad instead of 9 like in the PCB design shown. Drill this hole using a drill bit with a diameter of 1.5 mm (a). Position the chip on the PCB (b) and solder all contacts along the sides of the chip (c) . Use Litze wire to tidy everything up again (the author used a stereoscopic microscope to get a good view of everything). When all contacts on the top side have been soldered properly we turn over the board and drop a few pieces of solder into the hole (d). Find a piece of solid copper cable that fits snugly in the 1.5 mm hole (one of the cores in a solid core mains cable would be a good choice) and use a file to make one of the ends completely flat. Put this end through the hole and heat it up using the soldering iron (e). At some point the piece of copper wire gets so hot that the pieces of solder in the hole start to melt. The copper wire will then drop down slightly and makes contact with the exposed pad of the chip. Then solder the piece of wire to the ground plane on the solder side of the PCB (f). You will now have a good electrical and thermal connection between the exposed pad of the chip and the ground plane on the solder side of the PCB. Internet Links [1] http://datasheets.maximintegrated.com/en/ ds/MAX8677A.pdf [2] www.elektor.com/130117 www.elektor-magazine.com june 2013 43 •Projects Taming the Beast (5) Programming an array of 250 Kgates A ■ • ■ • • • ■ ■ ■ • • ■ ■ ■ ■ • • • • ■ ■ • • ■ • By Clemens Valens (Elektor.Labs) Although it's perfectly possible to design FPGA applications using schematic dia- grams with logic symbols, in practice this is usually done with a hardware descrip- tion language. An advantage of the latter approach is that complex functions are often easier to express in algorithms than in schematics. Accordingly, in this in- stallment we guide you through the process of programming an FPGA application. In the previous installment [4] we took a cautious initial look at the hardware description languages VHDLand Verilog fortesting an application. In this final installment we delve into hardware descrip- tion languages more extensively - in this case, to define an application. However, working with two languages is too difficult, so I had to make a choice. After many sleepless nights and consult- ing dozens of experts, I ultimately decided to cast my lot with VHDL. There are various reasons that can be given for this choice. One is that VHDL should require less simulation time because it is more difficult to arrive at a synthesizable design. That might sound like a reason for choosing Ver- ilog instead, but it reflects the fact that simula- tion often takes longer than synthesis, so in the end you're done faster. To draw an analogy with computer programming (Verilog fans should look the other way and plug their ears at this point), instead of just throwing together a bit of code and then using the debugger to turn it into a working algorithm, you can first spend some time thinking about your algorithm and then use the debugger to make sure it works properly. The application I have chosen here is a DCF77 decoder. I can hear the snide remarks already, but there are good reasons for this choice. The radio signal from the DCF77 atomic clock broad- 44 | June 2013 www.elektor-magazine.com FPGA cast station near Frankfurt in Germany can be received on 77.5 kHz easily in virtually all of Europe with an inexpensive module. The signal coding is fairly simple - it consists of a sequence of 59 pulses (one per second) which can have two different lengths (100 ms for "0" or 200 ms for " 1 "), which collectively represent the bits of the time code. The end of the code sequence is marked by omitting the final pulse (number 60, corresponding to bit 59). A new code is sent every minute. The date and time are in BCD for- mat, and there are several check bits that can be used to verify the validity of the data. This signal is a good starting point for a project with VHDL (or Verilog) because it is relatively easy to show the results on a 7-segment display with simple logic. For those of you who do not have a DCF77 receiver or who cannot receive the signal because they live too far away from Frankfurt, we have written a DCF77 simulator program for Arduino [5]. That way everyone can join in. Let's start with a functional design for a DCF77 decoder. Here we take the 'naive' approach, which means we assume that the input signal will usu- ally be good and will stay nicely within specifica- tions. Thanks to this assumption, the design can be fairly simple. As previously mentioned, the input signal consists of pulses with lengths of 100 ms and 200 ms, which represent zeros and ones respectively. If you sample the input signal at a point 150 ms after the rising edge of each pulse, you will thus see either a '0' or a '1' (Figure 1). If you also measure the time between two successive rising edges, you can detect the missing pulse and therefore iden- tify the start of the time code. The bits that are found in this manner are fed into a shift register. Then the BCD sequences that encode the various date and time units are extracted from the shift bit string in the shift register and presented on the 7-segment display. In the C-based pseudocode, this looks roughly as follows: do for each clock pulse { counter = counter + 1 if (counter == 150ms) { shiftregister = ( shiftregister « 1) + inputsignal ; } if ( risingedge(inputsignal) == true) { if (counter >= 1750ms) { showcontent ( shiftregister) ; } counter =; } } The counter is incremented on each clock pulse. When the counter reaches 150 ms, the input sig- nal is sampled and the sample is fed to the shift register. When a rising edge is detected in the input signal, a test is made to see whether the counter has exceeded the maximum value. If it has, the shift register is full and the data can be displayed. After this the counter is reset to 0. That's all there is to it. You could add all sorts of bells and whistles to this, such as error detection and more robustness, but that falls outside the scope of this introductory example. How do you do this in VHDL? Doing the same thing in VHDL is fairly easy because translating pseudocode into VHDL is straightforward. The result is the following code fragment: 1 process (clock) is 2 begin 3 if risingedge(clock) then 4 counter <= counter + 1; 5 if ( counter=tl50ms ) then 1 1 1 1 DCF77 0 1] 1 ■“1 1 SAMPLE 1000 ms — — 2000 ms 6 100 150 200 — ~t[ms] 130066-12 Figure 1. The DCF77 signal and sampling points. www.elektor-magazine.com | June 2013 | 45 •Projects 6 bits <= input & bits(58 downto 1) ; 7 end if; 8 if input_rise=' 1 ' then 9 if (counter>=tl750ms) then 10 data <= bits; 11 end if; 12 counter <= 0; 13 end if; 14 end if; 15 end process; The definitions and a bit of VHDL syntax are miss- ing here, but the algorithm is there. I added the line numbers here because they make it easier to explain how the code works. In this code, coun- ter is self-explanatory and bits are the stages of a 59-bit shift register. Let's start at the top with line 1. This is a process, which means that it will be executed by the FPGA. Nothing happens without a process. There can be multiple processes, and they are all executed at the same time. Within a process, the order of execution is normally top to bottom. Our process is dependent on the sig- nal clock, which means that the process is only executed when the value of clock changes. The process starts after line 2 and runs until line 15. Line 3 causes everything in the process to be synchronized to the rising edge of the clock sig- nal. This is made possible by the function ris- ing edge. You will often see the following con- struction in VHDL code: if clock'event and clock='l' then ■ ■ end if; This does the same thing as rising edge, but it is a bit old-fashioned. Here we use rising edge. There is also a function called fallingedge. The counter is incremented by 1 in line 4. Easy, isn't it? Yes, but you should be careful because whenever you use the increment function, which is represented by the "+" sign, you have to include the numericstd library in the list of libraries to be used (as described elsewhere in this article). In line 5 the counter value is compared to a con- stant that corresponds to an interval of 150 ms with a clock frequency of 8 MHz (the FPGA clock rate). If the counter is at 150 ms, the current value of the input signal is fed into the bits shift register in line 6. This is done from the left end of the shift register, unlike the pseudocode where it is done from the right. We chose this approach because the time code starts with the least significant bit, so the bits are fed into the shift register in the right order for our purpose. After 59 pulses, bit 0 is at position 0. The shift operation looks a bit strange because the con- catenation function is used for this purpose. This function simply joins the left part of the expression to the right part. Here the right part consists of the 58 bits from 1 to 58 (in reverse order, without bit 0), which are shifted to posi- tions 57 to 0. The left part is the 1-bit input sig- nal, which now ends up in bit 58. The details of what ISE (or actually XST) does with this con- struction are not so important here; what mat- ters is that it works (and it does). Line 8 checks to see whether a rising edge has been detected in the input signal. Exactly how that works is not obvious from the code fragment (I'll explain this later), but if a rising edge has been detected, line 9 checks whether the counter has exceeded the maximum value of 1750 ms. If it has, the content of the shift register is copied to a data register for further processing, which is done in another fragment described below. Line 12 resets the counter to zero. It is not nec- essary to flush the shift register, since it is com- pletely filled every minute. The lines not specifically mentioned here are only there to conform to VHDL syntax rules. To complete this fragment, all you need is an edge detector, some VHDL syntax glue, and the specifications of the input and output signals for this process. In the final design I also added a couple of signals that blink the LEDs on the FPGA board so you can see whether something is actu- ally happening inside the FPGA. Edge detection The edge detector is a key part of this design. At first I used a simple scheme that compared the current value of the input signal with the value during the previous clock pulse. This was not reliable and caused problems, with the result that synchronization was occasionally lost. The solution turned out to be adding another flip-flop so that instead of comparing the current value with the previous value, we compare the previ- ous value with the one before it. In other words, 46 | June 2013 www.elektor-magazine.com FPGA instead of comparing t = n with t = n - 1, we compare t = n - 1 with t = n - 2. You may be asking yourself whether the func- tion risingedge could have been used for this purpose, but unfortunately the answer is that this won't work. If you try this, the XST synthe- sizer will think that a clock signal is involved, but since this isn't the case, XST doesn't know what to do and therefore generates an error message. I included the edge detector in the project as a separate module (a function in VHDL; see List- ing 1), but this is not mandatory. However, it has the advantage that you can easily use the function in another project. The module starts with a library instruction, followed by a use instruction. The purpose of these instructions is to ensure that the module can access the appropriate standard functions and signals. If necessary, you can also add other libraries here, such as numeric std (for "+", as you may recall). Unlike most programming lan- guages, these instructions do not apply to the entire file in which they appear, but only to the first entity block and associated architecture block(s) appearing after the instructions. This means that each entity block is normally pre- ceded by library statements. Now let's have look at the entity block. It can be regarded as essentially equivalent to a symbol in a schematic diagram. This is where the inputs and outputs of the component are defined in the port section. Here you see that all the signals are of type stdlogic from the std_logic_1164 library, which means that they are logic signals that can assume various states defined in the library, including "0", "1", and quite a few others. The signals with the suffix in are the inputs of the module, while the signals with the suffix out are the outputs. After the entity block there is an architecture block that defines the function. The latter block has a name (behavioral) and is an implemen- tation of the specified entity (in this case edge_ detector). The name behavioral is assigned when you let ISE create a VHDL module. Another frequently seen name is rtl, which stands for Register Transfer Level (the level where VHDL code is compiled), but you can also choose your own name. The edge detector is implemented as a pro- cess that is dependent on the signal clock. The instructions in the process are executed each Listing 1. An edge detector module in VHDL. library ieee; use ieee. std_logic_1164. all; entity edgedetector is port (input : in stdlogic; clock : in stdlogic; rise : out stdlogic); end edgedetector; architecture behavioral of edgedetector is begin process (clock) variable history : stdlogicvector ( 1 to 3); begin if risingedge(clock) then rise <= history(2) and not history(3); history := input & history(l to 2); end if; end process; end behavioral; time the value of this signal changes. After the process declaration, there is a list of variables that are needed inside the process but not outside. Here there is only one: history, a 3-bit shift register. This variable is a vector, which means that it consists of several bits. Note that The fully assembled and tested FPGA development board is available in the Elektor Shop for just $66.89 plus shipping. www.elektor-magazine.com ] June 2013 | 47 •Projects Listing 2. DCF77 timecode decoder with edge detector, library ieee; use ieee. std_logic_1164. all; use ieee. numericstd .all; entity dcf 77_decoder is port ( input : in stdlogic; clock : in stdlogic; data : out stdlogicvector (58 downto 0) ); end dcf77_decoder; architecture behavioral of dcf77_decoder is component edgedetector is port (input : in stdlogic; clock : in stdlogic; rise : out stdlogic); end component edgedetector; constant tl750ms: integer := 14000000; -- 1750 ms (a 8 MHz constant tl50ms: integer := 1200000; -- 150 ms @ 8 MHz signal counter : integer := 0; signal bits : std_logic_vector(58 downto 0) := (others => '0'); signal inputrise : stdlogic := '0'; begin edgedetect: edgedetector port map (input => input, clock => clock, rise => inputrise) ; process (clock) is begin if risingedge ( clock) then counter <= counter + 1; if ( counter=tl50ms ) then bits <= input & bits(58 downto 1); end if; if input_rise=' 1' then if (counter>=tl750ms) then data <= bits; -- Transfer data. end if; counter <= 0; -- Clear counter. end if; end if; end process; end behavioral; here the vector is defined as (1 to 3), while the shift register in the DCF77 decoder is defined as (58 downto 0). Both of these definitions are valid, but you must be careful to avoid acciden- tally getting the bits confused when you use the two together. The edge detector is only active after a rising edge of the clock signal. When that happens, it determines the value of the output signal rise from bits 2 and 3 of history, and then feeds the current value of the input signal into the shift register in the same way as the code fragment for the DCF77 decoder. As you can see, each block ends with an end statement (or perhaps end if), possibly followed by the name of the block concerned, so your fin- gers will be busy on the keyboard. This is one of the drawbacks of VHDL: it requires a lot of typing. Figure 2 shows what ISE thinks the edge detec- tor should look as a schematic diagram. I person- ally find this interpretation somewhat strange, but maybe I'm missing something. Let's just say that ISE is not the world's best draftsman. I discussed this module in so much detail to illus- trate what a VHDL module looks like. All modules follow this pattern of library, entity and archi- tecture, including the DCF77 decoder module. Using modules If you want to use the edge detector in the DCF77 decoder, you have to somehow make XST aware of its existence. There are various ways to do this, such as using a library, but here we use the component method. Listing 2 shows the details of how this works. This listing also shows the complete DCF77 decoder module, including the entity block and the associated architecture block, the input and output signals, and the local variables and constants. Just have a good look at it, take your time, and use the Web for help if necessary - it's not all that difficult. You include the edge detector in the module by declaring it as a component at the top in the architecture block. Then you copy the entity block and replace the word entity by compo- nent. The next task is to link in this block, which you do after the start of the architecture block by generating an instance of the block. For this purpose, you have to specify a label and then 48 | June 2013 www.elektor-magazine.com FPGA Figure 2. This bizarre schematic is the result of letting ISE's RTL Viewer draw the schematic diagram of the edge detector described in this article ( Design tab, Synthesize - XST -► View RTL Schematic). The signal input is not connected to anything, and the operation of this circuit is a complete mystery to the author. Maybe he got something wrong? use a port map to indicate which signals (ports) of the DCF77 decoder on the right in the folder must be linked to the signals (ports) of the edge detector on the left in the folder. The clock and input signals are already taken care of because they are inputs (ports) of the DCF77 decoder as part of the entity block. You have to add a local signal of the same type for the edge detec- tor output signal rise. Here I gave it the name inputrise. Now you can use this signal in your process. It will assume the value " 1 " for one clock period when a rising edge is detected in the DCF77 signal. If you forget to map an input signal of a com- ponent, you will see a rather baffling error mes- sage. It tries to explain that the forgotten signal does not have a default value and may therefore remain unconnected. Don't say I didn't warn you. Display Articles of this sort tend to be long because I try my best to explain everything properly, but m ISE Project Navigator (P.28xd) C:\workVFPGA\part5\part5.wsc hllNM File Edit View Project Source Process Tools Window Layout Help ! 0 * U 6M <*, r X | ■*> cx | »|j jp sP 3 l**|i - B 3 t> i >• *? i ► e * 9 Desgn ** □ ff X UJ Ww: a lirrtpmpntatinn ^ 1 an damn Kaatthy 53 part5 FI Q xt3v250c-4vql00 Q Ran top * Behavioral (top.vhd) B f%| display - twodigrtdisplay - Behavioral (twodigitdisplay.vhd) B digl - hrd_to.7tprjmpnt - Behavioral (hrd_to.7epgmpnt.vhd) DU dig2 - bod to 7 segment - Behavioral (bod to 7segment.vhd) B R| dot// - dct//_recerver - behavioral (dct//_receiver.vhd) — [\j| pdgp_dptprt - edge_rl erect or - Behavioral (edge_detertor.vhd) - P3 top.ucf fi No Processes Rtmvng tup - Bchaviuial Oesign Summary/Reports Design Utilities User Constraints Synthesize - X5 I View RTI Schematic View Technology Schematic Check Syntax fienerafe Post- Synthesis Simulation Model Implement Design Translate Map Place fit Route Generate Proqramminq File Configure Target Device Geneiate Target PROM/ACE File Manaqe Configuration Project (iMPACT) Analyze Design Using ChipScope ^ Start [=*] tv.o_digit_dicplay.vhd □ ii a A A 'A A 33 nrr.hlr.pcr.iirp Rehavlnral nr r.wo digit <11 spiny In 40 41 component bed to 7 segment 42 Port ( bed : In STD_TXXSTC_VTCTOR (3 dnwntn 0); 43 segmeuts : uut 3TD_LOGIC_VECTOR (6 dowutu 0) ); 44 end component; 45 46 begin 47 Instantiate digit 1. 48 dxgi: bcd_to_7 segment port map (bed *> bcdl, 44 segments •> digitl) ; 50 Instantiate digit 2. 51 dig2: bed to 7segment port map (bed “ > bcd2, 32 segments “> dlglr.2); S3 end Dehavioral; r 1 iri r hcd_tn_7segment vhri S3 edgedetector.vhd — nrlr.hsipr.le funer.l nnn with —use IEEE.HUMERIC_5TD.ALL; — rmenmsipnr. r.hp rol lowing 11 — any Xiliux primitives in L library UNISIM; — use UNISIM. vcomponent s .all; — Producing a synchronous ed — edges ul a lung (many clot entity edge detector is Port (input : In 3Tn_TlXlTr clock : in 3TD_LOGIC rise s out STD LOGIC mil : nut STIW-OGTC end edge detector; S= R A •A A A © 9 37 architecture Behavioral of bed to 7seumcnt is A 30 begin 39 with bed select 40 — A-biLO. G“biL6 41 segments <“ "0111111" when "0000", 42 "0000110" wnen "0001", 43 "1011011" when "0010", 44 ■1001111" when "0011", 45 ■1100110" when "0100", 4b "1101101" when "0101 ", 47 ■1111101" when "OHO", — | 48 ■0000111" when "0111", 49 ■1111111" when "1000", 50 "1101111" when "1001", 51 ■1000000" when others; pnrl Rehavlnral; 4 m ► architecture Behavioral of ed begin process (clock) variable history : std lo begin if rising_cdgc (clock) the — detect rising and ta rise <“ history (2) and fall <“ history (3) and — update history shift history : *= input l hint end if; end process; pnrl Rehavlnral; Design IQ Flee ||Q I hranes 2E Design Stxmwy (New) Q [=] r1rf77_r vHhri [j | prigp_riptprtnr. vhri • 1^1 hrr1_tn_7s«jm*nr.vhd Q [Pi two_digt_dsplay.vhd Q In 44 Col 17 VHDI Figure 3. An ISE screenshot showing the code for the display and the project hierarchy, along with the green check marks which prove that it's possible to compile the project and generate a bit file. www.elektor-magazine.com 1 June 2013 | 49 •Projects my editor is not especially fond of long articles. Nev- ertheless, I want to explain in an article how you can produce a working VHDL design, since otherwise the task is a bit frustrating. As I still have a lot to explain, I am omitting the code for the 7-segment display from this article. I used the same two-digit display as in the third installment [3], with a BCD to 7-seg- ment decoder as described there. This is a standard textbook exercise, so there is no need to explain it in detail. Have a look at the project for this installment [5] to see how it all works. Figure 3 also shows a few details. Back to the top As in the previous install- ments, everything comes together at the top, but now the top is a VHDL module instead of a sche- matic diagram. This detail must be communicated to ISE in the Design Prop- erties. First create a new project based on the previ- ous one, in the same way as described at the start of the third installment [3]. Then delete all schemat- ics, but keep the UCF file. Next, open Design Proper- ties (e.g. at the bottom of the Project menu) and set Top-Level Source Type to "HDL" and Preferred Lan- guage to "VHDL" (if this isn't already done). Listing 3. The top level of the final DCF77 decoder. library ieee; use ieee. std _logic_1164. all; entity top is port ( dcf77_input : in stdlogic; clkin : in stdlogic; hourmonth : in stdlogic; timedate : in stdlogic; ledl : out stdlogic; led2 : out stdlogic; tsample : out stdlogic; digitl : out stdlogicvector (6 downto 0) ; digit2 : out stdlogicvector (6 downto 0) ) ; end top; architecture behavioral of top is component twodigitdisplay is port ( bcdl : in stdlogicvector (3 bcd2 : in stdlogicvector (3 digitl : out stdlogicvector digit2 : out stdlogicvector end component; downto 0) ; downto 0) ; (6 downto 0) ; (6 downto 0) ) ; component dcf 77_decoder is Port ( input clock tick sync data end component; in stdlogic; in stdlogic; out stdlogic; out stdlogic; out stdlogicvector (58 downto 0) ); signal data : stdlogicvector (58 downto 0); signal bcdl : stdlogicvector (3 downto 0); signal bcd2 : stdlogicvector (3 downto 0); signal tick : stdlogic; begin display: twodigitdisplay port map (bcdl => bcdl, bcd2 => bcd2, Now you can start adding new source files. To do this, open the Project menu or right-click the Design tab and select New Source.... Then select VHDL Module, enter the file name (e.g. top), ver- ify that Add to project is ticked, and click Next. Now you will see a form that you can fill in if you know which input and output signals you need. If you don't know, leave the form blank. When you're done, click Next and then Finish. ISE will create a file for you, containing the template where you have to add your VHDL code. Add as 50 | June 2013 www.elektor-magazine.com FPGA digitl => digitl, digit2 => digit2) dcf77: dcf77_decoder port map (input => dcf77_input, clock => clkin, tick => tick, sync => led2, data => data) ; process (clkin) is begin tsample <= tick; ledl <= tick; if risingedge(clkin) then if time_date=' 1' then - - Show time . if hour_month=' 1' then -- Show hours, bcdl <= data(32 downto 29); bcd2 <= “00" & data(34 downto 33); else - - Show minutes . bcdl <= data(24 downto 21); bcd2 <= "0" & data(27 downto 25); end if; else - - Show date . if hour_month=' 1' then - - Show month . bcdl <= data(48 downto 45); bcd2 <= "000" & data(49 downto 49); else - - Show day of month . bcdl <= data(39 downto 36); bcd2 <= "00" & data(41 downto 40); end if; end if; end if; end process; end behavioral; of the input and output signals in top, which are the signals named in the entity block of the top module, must match the names in the UCF file, because this is how the pins of the IC are linked to the VHDL code. All of the signals in the UCF file must appear here, as oth- erwise ISE will complain. A new feature here is the use of vectors for the dis- play pins. You can do this in the UCF file by using an index with the name of the vector - for example, digitl(0) corresponds to bit 0 of the digitl vector in the top module. many files as the number of modules you intend to generate. In the present project there are five: top, DCF77 decoder, edge detector, BCD to 7-segment decoder, and 2-digit display. The top module is shown in Listing 3. The names Two components are called in the architec- ture block of the top module: two digit dis- play and dcf77_decoder, and one instance of each of them is used. With a larger display, such as six digits, you could generate and link three instances of twodigitdisplay, each with its own label. For linking the two com- ponents, I defined several additional signals that are not needed outside the top module. For example, the tick signal is used to blink LED1 each time a bit is received. Since this LED is not connected to a pin on the FPGA board, it is also linked to the t sam- ple signal, which in turn is linked to pin P86 in the UCF file. This makes it easy to view the sampling points on an oscilloscope relative to the DCF77 input signal. The process of the top module does not do any- thing especially remarkable. It is actually a mul- www.elektor-magazine.com | June 2013 51 •Projects MODI Figure 4. The schematic of the DCF77 decoder is virtually identical to the one in the third installment [3]. Since the FPGA is not especially comfortable with 5-V signals, a Zener diode is used to limit the input signal level to approximately 3 V. tiplexer that shows the hours, minutes, day of the month or month number on the two-digit 7-segment display, depending on the levels of the two control signals time date (P94) and hour_ month (P95). With a but of cutting and pasting ("&"), the right bits are extracted from the shift register string to form 4-bit BCD codes, which in turn are converted into 7-segment signals by the BCD decoders. Here it should be noted that it is not necessary to explicitly route the vectors bcdl and bcd2 to the display component, since this is done implicitly by the port map. When you synthesize this design, you will see a number of warnings. They are caused by the fact that some of the bits of the DCF77 shift register are not used, and that bit 3 of the vector bcd2 is always "0" because the design does not use eight-bit data (only the year number component encompasses eight bits, but it is not used here). You will also see that a nicely ordered hierarchy has been generated on the Design tab (Figure 3), just as when you entered the design in sche- matic form. Everything is therefore restored to the way it was. As already briefly mentioned, ISE has an RTL viewer that is able to portray VHDL code in schematic form (more or less; see Figure 2), which emphasizes the underlying duality: a schematic is the same as VHDL code, and VHDL code is the same as a schematic. Figure 5. The test circuit being driven by an Arduino acting as a DCF77 simulator. The display shows the simulated hours figure ('17'). The FPGA board is powered from the Arduino board. Despite my efforts to keep things short, it has been a long journey. I have tried to convey all the essential information, but a bit of self-reliance and determination to build this project yourself are probably still necessary. Good luck! ( 130066 ) Web links [1] Part 1: www.elektor.com/120099 [2] Part 2: www.elektor.com/120630 [3] Part 3: www.elektor.com/120743 [4] Part 4: www.elektor.com/130065 [5] Part 5: www.elektor.com/130066 52 | June 2013 www.elektor-magazine.com 4 ww.ezpcb .coll: Free Shipping! New Webs ^ ^ Better Design More Powerful Easier to Use s Onli . LKsiy I / 1 to 40 Layers i-i' ■ ■ Prototype to Production lal order now http://>v>v>v.ezpcb.c©iii Retronics 80 tales of electronics bygones This book is a compilation of about 80 Retronics installments published in Elektor magazine between 2004 and 2012. The stories cover vintage test equipment, prehistoric computers, long forgotten components, and Elektor blockbuster projects, all aiming to make engineers smile, sit up, object, drool, or experience a whiff of nostalgia. The latest on electronics and information technology Videos, hints, tips, offers and more Exclusive bi-weekly project for GREEN and GOLD members only Elektor behind the scenes In your email inbox each Friday elektor post The- beginning of a &eaul«tii friendship Sitol ,ire ^ms of the World, unite! W * fl m DaUKKCT rn me . rt more- im * mow mu .. .***" a 1 J, 'W »t SW Ihd v* prr.y . w av ir..Tf>Qrs iv DMA or Firkm mti ' v w ,V9 * W Wkj < yvrj v 11 uf W ifii iv ’jpi! H 1 it tpn ( lektor Q* Ele-lwia.:- ii :■! , 9«i Hfcit . Irinn*^ Elektor. TV goes Linux Du Lnj . lit—, f*r»i**x $mrtn- WATCH IT ON ELEITTfflftJY •Projects From BASIC to Python (2) A field report By Jean-Claude Feltes (Luxembourg) the first part of this series we looked at how Python differs from BASIC. We went over the installation process and got our first program running. Now we go a little further with graph plotting and Fourier synthesis. Finally with not much effort we use a graphical user interface. The Python language is particularly suited to engi- neering environments. Often it is advantageous to represent data graphically. The saying that a picture is worth a thousand words is also true in the world of mathematics; an engineer can interpret so much more from the plot of a curve compared to a column of sterile mathematical values. As a rule popular programming languages already feature tried and tested library routines to ease the writing process. Python is no excep- tion to this rule. Plotting graphs In Python the standard library for 2D graph plot- ting is 'Matplotlib'. Part of the Python philosophy is summed up in its motto There is only one way' suggesting that there should only really be one obvious way to achieve something in Python. This does not unfortunately apply to the mod- ules written in the additional libraries, a discov- ery that has already cost me many hours work. Notably in Matplotlib there exist simple proce- dural interfaces and complicated object orientated interfaces. Examples given in books and on the Internet use either one method or the other so it is quite easy to get confused. The simple interface 'pyplot' facilitates very sim- ple programming. The program in Listing 1 pro- duces a damped sine wave oscillation. The curve it describes is shown graphically in a display win- dow (Figure 1). The first line of the listing imports the interface 'pyplot' as the object 'pit'. 'Numpy' is an exten- sion to python providing support for mathematical functions. The second line shows three functions imported from the Numpy extension. The 'linspace' routine can be used with an interval (here from 0 to 7) divided into an equal number of parts (1,000 here) and represented as a vector (array). This enables a fast and simple calculation of the value of the function. Numpy functions can also handle vectors. Using just the line: y= sin(5*x)*exp(-x) Calculates all 1,000 values of the y vector. This relieves you of the more usual 'For' loop constructs and makes the code both fast and understandable. The command 'plt.plot(x,y)' plots the data as a curve on the graph and 'pit. show' is used to show it on the graph. To display more than one curve on the chart as shown in Listing 2 it is necessary to call the plot function again. The graph window (Figure 1) automatically shows a toolbar which allows you to zoom and save the chart. Apart from this it also indicates the cur- sor coordinates. Should you want to spice up the graph with some GUI elements then it will be necessary to proceed using an object oriented approach. Example: frequency response As an example we can plot the transfer function of a simple RC low pass filter. The transfer function shown here is a result of an RC voltage divider network consisting of a resistor and capacitor which has a complex impedance: 54 | June 2013 www.elektor-magazine.com Basic to Python F=l/(l+jcoRC) The frequency response is given by a plot of the value of F as a function of frequency (Fig- ure 2). This is a good example to demonstrate how Python handles complex variables. In this program (Listing 3) the Array 'f' is calcu- lated with frequency steps incremented logarith- mically. For plotting against linearly incrementing values use 'linspace()'. An array for the complex F values is calculated along with an array of the absolute values Tabs'. Numpy is useful here with its vector functions. There is no requirement for a Tor' loop in the calculation and the code is both short and understandable. Finally the plot is displayed, showing a logarith- mically scaled frequency axis. For a professional looking result it is important to define the grid lines: ax.grid(True, which = "both", linestyle _ a n j The grid lines are defined with "both" indicating the same line style for both major and minor subdivisions. Lastly a solid line style is selected. By adding the following lines of code: # plot phi = f(f) phi = angle( F) *180 . 0/pi ax2 = f ig . addsubplot (212) ax2.plot(f, phi) ax2 . grid (True, which = "both", linestyle _ // // j ax2 . setxscale ("log") ax2 . setxlabel ( "f /Hz" ) ax2 . setylabel ("phi/degrees") We can show the phase shift introduced by the filter. Example: Fourier synthesis Engineers quite partial to some mathematics will be pleased to learn that some of the more useful advanced engineering concepts such as Fourier synthesis are also catered for in Python. The example given in Listing 4 shows how a square wave can be synthesized by summing 30 weighted harmonics of a fundamental sine wave. Figure 3 shows quite an impressive output waveform from what is a relatively short program listing. More or fewer harmonics can be used to Listing 1: Sinewave.py import matplotlib . pyplot as pit from numpy import sin, exp, linspace x=linspace(0 . 0, 7.0, 1000) y= sin(5*x)*exp( -x) pit . plot ( x , y) pit . show( ) Listing 2: Multigraph. py mport matplotlib . pyplot as pit from numpy import sin, exp, linspace x=linspace(0 . 0, 7.0, 1000) yl = sin (5*x) *exp( -x) y2 = yl* 0.5 plt.plot(x, yl) pit. plot (x, y2) pit . show( ) Figure 1. The plot of a damped oscillation given in Listing 1. Figure 2. The frequency response of an RC low pass filter given in Listing 3. www.elektor-magazine.com 1 June 2013 55 •Projects Figure 3. Fourier synthesis of a square wave, see Listing 4. Figure 4. Data plotter: Terminal window showing list of values and their XY plot. 1400 1200 1000 800 400 200 p PLOTTfR - e]f*T F* ■ Data •10.0 50.0 A 'i.ytYiYiYir* 44.17304815686 HJ./U/U/U/U/UU 30.6134067952 -;5 18181818182 33.4710743802 7 -5757575757 ft 78.6*50514733 -6 9696969697 24.289377924 7 •6.36363636364 25.2479338843 5.7575757575ft 16.5748393071 -5.15151515152 13 2690541701 -4.54545454545 10.3305785124 3.93939393939 7.75941730487 - 2.72727272727 S.55W5W5656 3.71900626446 M7I7I7I2121 2.74977043199 V -10 fcjojol+l -1B| make the plot by altering the number of harmon- ics defined in the code. To GUI or not to GUI? Dyed in the wool Linux users will tell you that any system with a GUI is not a serious operat- ing system and that the computer mouse is in fact the work of the devil. Despite this view there are still many people who can appreciate easy to use, well designed software. Surely the graphical method of file selection is both convenient and these days almost indispensable? Anyhow Python allows the combination of both graphical and non-graphical elements in the same program. The program in Listing 5 functions as a data plotter. Input data is displayed as both text in a terminal window using the Print command and also as a plot in a graphic window (Figure 4). Looking at the functions available in the GUI libraries you really are spoilt for choice. I began with the 'Tkinter' library because it was already supplied with the Python interpreter and proved easy to understand. However a problem occurred copying a graph to the clipboard so I moved on to use the 'wxPython' library in these examples. There are also other alternatives available such as 'PyQt' and 'GTK'. This data plotter program is a useful example of the use of GUI elements in a program. It shows how measurement values stored in a text file can be edited and then displayed. The values Listing 3: RC.py import matplotlib . pyplot as pit from numpy import pi, linspace, loglO, logspace from numpy import complex, abs # these allow vector operations # EDIT R = 1O.0E3 C = 1O0.0E-9 # END EDIT RC = R*C # create f values equally spaced on a log scale f = logspace ( 1, 4, 100) # 100 values from 10**1 to 10**4 # calculate F (complex) and absolute value Fabs F = 1 / (1 + lj* 2 * pi * f * RC) Fabs = abs(F) # plot Fabs = f(f) fig = plt.figureO ax = fig . addsubplot ( 111) ax.plot(f, Fabs) ax . g rid (True, which = "both", linestyle = "-") ax. setxscale ("log") ax . setxlabel ( "f /Hz" ) ax . setylabel ( "U2/U1" ) ax. set_title("RC low pass frequency response") pit . show( ) 56 | June 2013 www.elektor-magazine.com Basic to Python are plotted on a two dimensional graph. The X and Y values are also displayed in the form of two columns. In this example I have abandoned pure 'Pythonic' object orientated style for the sake of simplicity. After the necessary modules are imported all the functions are defined and 'main' is at the end of the program listing. The main program begins with an instance 'app' of the App objects. Next a Frame object creates a window for the application. This window will have a menu and text box to enable editing and display of the data. The Text-Box is essentially a small editor: here you can edit data or enter new values, and the clipboard can be controlled using the standard key-sequence shortcuts. A right-click on the mouse pops up the classic edi- tor functions. Listing 4: Fourier.py """FOURIER SYNTHESIS OF A SQUARE WAVE""" # # EDIT HERE n = 30 nb_points=1000 frequency = 100.0 amplitude =2.0 # END OF EDIT AREA #--- print "Importing modules" import matplotlib . pyplot as pit from numpy import sin, exp, linspace, pi from numpy import zeros #--- def calc_amplitude(amplitude, i) : """ Calculate amplitudes of harmonics""" # take only odd harmonics if i % 2 == 0: ai = 0 else : ai = (4/pi) *amplitude / i return ai # def calcharmonics (nbpoints , n): """ Calculate harmonics and resulting voltage returns uharm = array nbpoints * n ug = array nbpoints // n n # init arrays for resulting voltage and harmonics ug = zeros (nbpoints) uharm = zeros ( (nbpoints , n+1)) # harmonics and total voltage for i in range( 1, n+1) : ai = calc_amplitude(amplitude, i) fi = frequency * i uharm[:,i] = ai * sin(2 * pi * fi * t ) ug = ug + uharm[ : , i] return uharm, ug # """ Main program""" T=l/f requency # equally spaced time array for 1 period t = linspace(0 . 0, T, nbpoints) # plot harmonics uharm, ug = calcharmonics (nbpoints , n) for i in range ( 1, n+1) : pit. plot (t, uharm[:,i]) # plot resulting voltage pit. plot (t, ug) s=str(n)+" harmonics, "+str(f requency)+"Hz , ampl .="+str( amplitude )+"V" pit . title("Fourier synthesis RECT\n"+s) pit .xlabel ("t/s") pit . ylabel ( "u/V" ) # make plot visible pit . show( ) # number of harmonics # horizontal resolution #Hz #V www.elektor-magazine.com 1 June 2013 57 •Projects Listing 5: Dataplot.py #! /us r/bin/env python """ Plot data from file """ import w x import os. path import matplotlib . pyplot as pit def create_menu(f rame) : # create menu menubar = wx.MenuBar() # main menus mnuFile = wx . Menu ( ) mnuData = wx . Menu ( ) menubar .Append (mnuFile, "&File") menubar .Append (mnuData , "&Data" ) # submenus mOpen = mnuFile. Append( -1, "&0pen") mnuFile . AppendSeparator( ) mExit = mnuFile. Append( -1, "&Exit") mPlot = mnuData .Append( -1, "&Plot") # attach menu to frame frame . SetMenuBar (menubar) # bind menu events to procedures frame. Bind (wx. EVTMENU, OnExit, mExit) f rame . Bind (wx . EVTMENU , OnOpen, mOpen) f rame . Bind (wx . EVTMENU , OnPlot, mPlot) # # Event handlers def OnExit (event ) : frame . Close( ) def OnOpen(event) : # ask for filename dig = wx. FileDialog (None, "Open data file", os.getcwdO wx.OPEN) dig . ShowModal ( ) filename = dig .GetPath( ) # open file, get data and put it into textbox t ry : f = open (filename, "r") data = f . read ( ) f . close( ) textbox. Set Value (data) except : wx . MessageBox( "Could not open file!") 58 | June 2013 www.elektor-magazine.com Basic to Python def OnPlot (event ) : # plot data x,y = f illxywithvalues (textbox) plotxy (x, y) # - - def f illxywithvalues (textbox) : # """ get values from textbox # returns arrays x, y and number of data points""" text=textbox.GetValue( ) lines=text . splitlines ( ) x=[] y=[] for line in lines : columns = line. split () #separator can be one or more " " or "\t" x. append (float (columns [0] ) ) y. append (float (columns [1] ) ) return x,y # def plot_xy( x, y) : """ Plot arrays x, y with matplotlib""" pit . figure(l) pit . subplot ( 111) # 1 row, 1 col, plot nb. 1 pit . grid (T rue) pit . plot ( x , y) pit .xlabel ("x") pit . ylabel ( "y" ) pit . show( ) # # Main #--- app = wx. App( ) # create frame frame = wx. Frame (None, title= ' PLOTTER' , pos=(350, 300) ) create_menu (frame) # editor textbox for data textbox=wx .TextCt rl (frame, style = wx .TEMULTILINE) # show frame and run event loop frame . Show( ) app.MainLoop( ) www.elektor-magazine.com 1 June 2013 59 •Projects The Author Jean-Claude Feltes lectures in electronics at the Lycee Technique des Arts et Metiers in Luxembourg. This college caters for both arts and technical students and provides professional qualifications for apprentices and technicians. He spends much of his free time pursuing his interests in electronics and programming [2]. The 'frame. Show()' function displays a window and 'app.MainLoopO' is used to begin an event loop. The program waits for an event (mouse click or keyboard key press) and then branches to the event handler (the function called when an event occurs). The first function defines the menu and binds menu events to the 'On' prefixed event han- dling procedures. Functions 'OnExit', 'OnOpen' and 'OnPlot' are called from the menu or when the corresponding key is pressed. 'OnOpen' calls the file selection dialog 'wx.FileDialog'. This also uses 'os.getcwd' (get current working directory) to find the file in the current directory. When the file name is selected an attempt is made to open the file. A 'try - except' statement is used to detect any file opening error. When the file can be opened the contents are read into the variable 'data' and put into the text box. Now the values can be edited, copied or pasted. Other values can of course also be added instead of storing them from a file. The 'OnPlot' function displays the data as a graph. The functions 'fill_xy_with_values' and 'plot_xy' are also called here. The former reads data from the textbox and splits it into an array of lines. The 'for' loop is next iterated on all the lines which are split again using 'line.split()'. The individual values are then stored in the arrays 'x[]' and 'y[]'. These are then returned as the function values. The function 'plot_xy' draws the graph (Figure 4). This small program is of course still a little rudi- mentary, but an equivalent in Visual BASIC would require much more work. It would be quite easy to add a menu option here to store edited data. Coming up By now you should have a basic appreciation of how powerful Python is and also how easy it can be to use. Python has a growing band of devotees, if you wish to explore there are many resources that will take you further than we have shown you in these examples. Python is well suited for tasks such as classic data collection and processing. Things like filters and FFTs are really no obstacle for Python and you have the possibility to upgrade your own project with a graphical user interface. In the next installment we look into the program- ming intricacies of data acquisition and control via the RS485 Elektor Bus. ( 120143 ) Internet Links & Literature [1] Listings etc.: www. elektor. com/120 143 [2] The author's homepage: http://staff.ltam.lu/feljc/home.html [3] Python documentation: https://pypi.python.org/pypi/RPi.GPIO [4] Python tutorials: www.awaretek.com/tutorials.html [5] Introduction: J.M. Hughes: „Real World Instrumentation with Python" [6] Modules available in the Python package: http://pypi.python.org/pypi [7] Python for engineers: Andrew Pratt: 'Python Programming and GUIs for Electronic Engineers' www.elektor.com 60 | June 2013 www.elektor-magazine.com ELEKTOR Preferred Suppliers Tel. 1-978-281-7708 Email ElektorUSA@smmarketing.us 8 & 32 bit M i croco n trol [ e rs MC9S0SAC12B MCF51AC25& Mt:h L .lCTJly'U MC9S OSJM&Q MCF5 UH12S MC3508QE1Z8 MO-biqMJiS Communications Bluetooth, KF r USB LEARN Programming with BASIC ON BOARD CREATE Your own projects with EXemplar kits EXPLORE Peripherals Microcontrollers 2x20 LCD 4x4 Keypad Powei Supply Motor Control Real Time Clock Microcontroller Kits Application Notes Schematics— Data Sheets ATRIA Technologies Inc www, AtriaT ech nologies .com Ultrasonic Distance Sensing Made EZ www.maxbotix.com HRUSB-MaxSonar^-EZ ,H l2CXL-MaxSonar*-EZ™ - Multi-sensor operation -USB interface - Easy integration - 1 mm resolution -MSRP $49 95 Incredible noise immunity ISC interface 1cm resolution UAV‘s and robotics Automatic calibration Starting at $39.95 HRXL-MaxSonar-WR ™ - IP67 rated - Low power - Multi-sensor operation - Easy to use - Great for lank and bin - IVtSRP $1 09. 95 measuring From Si 19 Ethernet RLCs for OEMs Bui It ’in Ethernet MODBUS TCP/IP Digital and Analog I/Os PWM/PlD/Stepper Control TRIANGLE RESEARCH INTERNATIONAL Tel : 1 377 TRE-PLC5 ■web : www.tri-plc.ccim/eK, htm AP CIRCUITS PCB Fabricalio-n Since 1994 Two Boards Two Layers Two Masks One Legend Unmasked boards ship next day! www.apcircuits.com As low as... A \ i 9.15 each' VIS A : Ipc " r « , “ See what's brewing @ Elektor Labs 24/7 Check out www.elektor-labs.com and join, share, participate! elektor@labs Sharing Electronics Projects I Heme Ntwt Fropouli TD “O J "™jl . r r- rial L .TL [1 ©lektor Limited Time Offer for GREEN and GOLD Members! 13°/o DISCOUNT 4- FREE SHIPPING www.elektor.com/june OS Hard- and Software for Electronics Applications . Open Source 1 Electronics on Linux If you have ever wanted to take advantage of the expanding field of open source software for electronics and everyday applications, this book is for you. Using the Linux OS, Warwick A. Smith guides you through the world of open source hardware and software, teaching readers to use EDA tools and software that is readily available online, free to download. The hardware projects inside can be built using easily obtainable parts, in the comfort of your own home, on single sided PCBs, or professionally manufactured with output files generated by you. Open Source Electronics on Linux is about changing today's electronics enthusiast into empowered, savvy, discerning engineers capable of building and modifying their creations, be it solely on Linux or in tandem with your current operating system. 272 pages • ISBN 978-1-907920-19-6 $47.60 Programming step-by-step E Android Apps This book is an introduction to programming apps for Android devices. The operation of the Android system is explained in a step by step way, aiming to show how personal applications can be programmed. A wide variety of applications is presented based on a solid number of hands-on examples, covering anything from simple math programs, reading sensors and GPS data, right up to programming for advanced Internet applications. Besides writing applications in the Java programming language, this book also explains how apps can be programmed using Javascript or PHP scripts. When it comes to personalizing your smartphone you should not feel limited to off the shelf applications because creating your own apps and programming Android devices is easier than you think! 244 pages • ISBN 978-1-907920-15-8 $56.40 A whole year of Elektor magazine on a single disk El DVD Elektor 2012 The year volume DVD/CD-ROMs are among the most popular items in Elektor's product range. This DVD-ROM contains all editorial articles published in Volume 2012 of the English, American, Spanish, Dutch, French and German editions of Elektor. Using the supplied Adobe Reader program, articles are presented in the same layout as originally found in the magazine. An extensive search machine is available to locate keywords in any article. With this DVD you can also produce hard copy of PCB layouts at printer resolution, adapt PCB layouts using your favorite graphics program, zoom in / out on selected PCB areas and export circuit diagrams and illustrations to other programs. ISBN 978-90-5381-273-0 • $37.90 Display, buttons, real time clock and more , Elektor Linux Board Extension This extension board was developed to further propel our Embedded Linux series of articles and the matching GNUblin board. It has a display, buttons, a real time clock and 16 GPIOs. Linux devotees, switch on your solder irons. The Linux extension board includes everything needed to provide the user interface for a wide variety of projects! Module, SMD-populated and tested board, incl. LCD1, XI, K1-K4, BZ1, BT1 for home assembly Art.# 120596-91 • $50.20 Taming the Beast Ei FPGA Development Board FPGAs are unguestionably among the most versatile but complex components in modern-day electronics. An FPGA contains a maze of gates and other circuit elements that can be used to put together your own digital circuit 80 | June 2013 www.elektor-magazine.com Books, CD-ROMs, DVDs, Kits & Modules E on a chip. This FPGA developiment board (designed in the Elektor Labs) shows how easy it is for any electronics enthusiast, whether professional or amateur, to work with these programmable logic devices. Module, ready build and tested Art.# 120099-91 See www.elektor.com/fpgaboard LabWorX 2 - Mastering Surface Mount Technology This book takes you on a crash course in techniques, tips and know-how to successfully introduce surface mount technology in your workflow. Even if you are on a budget you too can jumpstart your designs with advanced fine pitch parts. Besides explaining methodology and equipment, attention is given to SMT parts technologies and soldering methods. Many practical tips and tricks are disclosed that bring surface mount technology into everyone's reach without breaking the bank. A comprehensive kit of parts comprising all SMT components, circuit boards and solder stencils is available for readers wishing to replicate three projects described in this book. 282 pages • ISBN 978-1-907920-12-7 $47.60 Sound Secrets and Technology E Electric Guitar What would today's rock and pop music be without electric lead and bass guitars? These instruments have been setting the tone for more than forty years. Their underlying sound is determined largely by their electrical components. But, how do they actually work? This book answers many questions simply, in an easily-understandable manner. For the interested musician (and others), this book unveils, in a simple and well-grounded way, what have, until now, been regarded as manufacturer secrets. The examination explores deep within the guitar, including pickups and electrical environment, so that guitar electronics are no longer considered highly secret. With a few deft interventions, many instruments can be rendered more versatile and made to sound a lot better - in the most cost- effective manner. 287 pages • ISBN 978-1-907920-13-4 $47.60 10 captivating lessons n. PIC Microcontroller Programming Using the lessons in this book you learn how to program a microcontroller. You'll be using JAL, a free but extremely powerful programming language for PIC microcontrollers. Assuming you have absorbed all lessons you should be confident to write PIC microcontroller programs, as well as read and understand programs written by other people. You learn the function of JAL commands such as include, pin, delay, forever loop, while loop, case, exit loop, repeat until, if then, as well as the use of functions, procedures and timer- and port interrupts. You make an LED blink, build a time switch, measure a potentiometer's wiper position, produce sounds, suppress contact bounce, and control the brightness of an LED. And of course you learn to debug, meaning: how to spot and fix errors in your programs. 284 pages • ISBN 978-1-907920-17-2 $47.60 Further information and ordering: www.elektor.com/store Elektor US 111 Founders Plaza, Suite 300 East Flartford, CT 06108 USA Phone: 860.289.0800 Fax: 860.461.0450 E-mail: order@elektor.com www.elektor-magazine.com | June 2013 | 81 •Magazine Next month in Elektor Elektor Project Generator Edition 2013 Extra-thick edition with an extra bunch of circuits Next month we publish the 37 th edition of Elektor's famed double edition for the months of July and August. This loved & collected issue offers a bulk of ideas, projects and practical software in a mix of small and large articles. Our editors and designers are now burning their midnight oil to make sure you can enjoy lots of pages with detailed descriptions and inventive electronics applications. Don't miss it, this jumbo edition of Elektor packed with articles and projects like: CAN-checker - ElektorBus-steppermotor control - CDI-ignition for mopeds - Inrush current limiter - Class-D audio amplifier with 555 - Servo checker - ECG-monitor for Android - USB-power pack - Numitron Ardui no clock - Parking help - Multi-channel temperature logger - IR remote for Android - Extremely accurate digital clock - Universal precision measurement interface - AVR-USB-keyboard-stick Article titles and magazine contents subject to change; please check www.elektor-magazine.com Elektor July & August 2013 edition published June 26, 2013 See what's brewing @ Elektor Labs 24/7 Check out www.elektor-labs.com and join, share, participate! dp ¥ m V ^1 aCV Sharing Electronics Projects A m. — M Home JUTiLV Papular Active ropular ACflUC r'npiiihr r 'f Create a Project Cr-^te a r>jr» &r cite* * Jtnliwf a> fcEl title, fcH&BtK ft wMM Wm tf-c* v a ^ i tiv = ir ■■ 'tm u m hi it i to post a project but you .-ire not a member? c ikk bfrrt to *end « dwcrlptton of you^ project Including a circuit diagram and a ptiotwjna ph for evaluation and mayt^ you t^iii C* grtrusd 82 | June 2013 www.elektor-magazine.com Ordering Information ORDERING INFORMATION To order contact customer service: Phone: 860.289.0800 Fax: 860.461.0450 Mail: Elektor US 111 Founders Plaza, Suite 300 East Hartford, CT 06108 USA E-mail: order@elektor.com On-line at www.elektor.com/store Customer service hours: 8:30 AM-4:30 PM EST Monday- Friday. Voice mail available at other times. When leaving a message please be sure to leave a daytime telephone num- ber where we can return your call. PLEASE NOTE: While we strive to provide the best possible information in this issue , pricing and availability are subject to change without notice. To find out about current pricing and stock , please call or email customer service. COMPONENTS Components for projects appearing in Elektor are usually available from certain advertisers in the magazine. If diffi- culties in obtaining components are suspected, a source will normally be identified in the article. Please note, however, that the source(s) given is (are) not exclusive. PAYMENT Orders must be prepaid. We accept checks or money orders (in US $ drawn on a US bank only), VISA, Mastercard, Discover, and American Express credit cards. We do not accept C.O.D. orders. We also accept wire transfers. Add $20 to cover fees charged for these transfers. TERMS OF BUSINESS Shipping Note: All orders will be shipped from Europe. Please allow 3-4 weeks for delivery. Shipping and handling via airmail: $20.00 per order. Returns Damaged or miss-shipped goods may be returned for re- placement or refund. All returns must have an RA #. Call or email customer service to receive an RA# before returning the merchandise and be sure to put the RA# on the outside of the package. Please save shipping materials for possible carrier inspection. Requests for RA# must be received 30 days from invoice. Patents Patent protection may exist with respect to circuits, devices, components, and items described in our books and maga- zines. Elektor accepts no responsibility or liability for failing to identify such patent or other protection. Copyright All drawing, photographs, articles, printed circuit boards, programmed integrated circuits, diskettes, and software car- riers published in our books and magazines (other than in third-party advertisements) are copyrighted and may not be reproduced (or stored in any sort of retrieval system) without written permission from Elektor. Notwithstanding, printed circuit boards may be produced for private and personal use without prior permission. Limitation of liability Elektor shall not be liable in contract, tort, or otherwise, for any loss or damage suffered by the purchaser whatsoever or howsoever arising out of, or in connection with, the supply of goods or services by Elektor other than to supply goods as described or, at the option of Elektor, to refund the purchaser any money paid with respect to the goods. MEMBERSHIPS (US & CANADA ONLY) Order memberships on-line at www.elektor.com/members All memberships begin with the current issue. Expect 3-4 weeks for receipt of the first issue. Membership renewals and change of address should be sent to: Elektor US P.O. Box 462228 Escondido, CA 92046 E-mail: elektor@pcspublink.com Memberships may be paid for by check or money order (in US $ drawn on a US bank only). We accept Mastercard, VISA, Discover and American Express credit cards. For gift memberships, please include gift recipient's name and address as well as your own, with remittance. A gift card will be sent on request. Memberships may be cancelled at any time for a refund of all unmailed issues. Does your membership expire soon? Renew it on-line at www.elektor.com/members www.elektor-magazine.com | June 2013 | 83 Ft lmt-"‘M>Cr A lifetime of electronics engineering projects, tips, and analysis, packed onto a portable, USB flash drive. Keep your archive current with a digital subscription and download new issue PDFs directly to the drive! Plus, with 32 GB of storage, there's plenty of room for your own notes and projects. Offer ends 6/30/13 ^Complete archive includes all issues in print through time of purchase. Visit www.cc-webshop.com to purchase. You’ll have plenty of summer reading with Circuit Cellar’s CC Gold issues archive. CIRCUIT CELLAR ROBOTICS H-sl.il f tnvnrr-'-H 1 'Lrduh.i-i W97i:h?r [ I -.-!.!. .- . IJv n fci'jl I ■ in < it i' GLkte rtNduril Hit-It LCidiiiij fr#- f nglnrerc