www.elektor-magazine.com magazine March 2013 | £4.90 10?.69 o L&K'ia ItHf MO ter Witt Mtllll T R Th The luxury of precision within everyone's reach 0#?* W/j n JIM - J0J4 rry ITA * » ko U*e iwr s 0 $ JvHi • Raspberry Pi Prototyping Board | The 7-uP Alarm Clock | USB-I024 Cable I FPGA Programming | Simple Servo tester | Battery Indicator *1956 Audion Kit * Frontline Breaking Newsi prototype Howlers *0pen Data * 'hue' Lighting 0 3 770268 451 73 9 p r*j*tf5 fpc^ **■ 7 . u ? M^ 1 ^m**J an nift i*# -1 ** ALSO AVAILABLE: The all-paperless GREEN Membership, which delivers all products and services, including Elektor.MAGAZINE, online only. 0 T 2 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 1 0% 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 Arduino AC Grid Aira|y Ser Frequency analysis on a mini ctrfour display * IMf«i k.t«. * IHnyrip ■ U L , , #m li li i ipih y ^ *r M If.. fpfc*. Join the Elektor Community Take out a GOLD Membership now! Crystal-free 8-bit USB PIC® microcontrollers cut system costs and power consumption 0.25% clock accuracy enables USB connectivity, eliminating the need for external crystal Microchip's lowest-cost and smallest-form-factor USB microcontrollers (MCUs), feature pin counts of 14 to 100 pins and are the first 8-bit MCUs to integrate LCD control, battery-backed RTCC, and USB on a single chip. Microchip's latest USB PIC® MCUs feature internal clock sources with 0.25% clock accuracy to enable USB connectivity with no external crystal. They are also the first USB MCUs to combine pin-counts ranging from 14 to 100, with high peripheral integration and up to 128 KB of Flash. The extreme Low Power (XLP) technology also keeps power consumption down to 35 pA/MHz in active mode and 20 nA in sleep mode. Lowest-cost and smallest-form-factor The PIC16F145X MCUs give you USB connectivity and capacitive touch sensing, in addition to a wide range of integrated peripherals with footprints down to 4x4 mm. High-performance touch-sensing with USB With an integrated Charge Time Measurement Unit (CTMU) and 1 .8 V to 5 V operation, PIC18F2X/4XK50 MCUs are pin-compatible with legacy PIC18 MCUs, giving an easy migration to higher-performance. USB plus LCD control and a RTCC with Vbat The PIC18F97J94 family gives you USB connectivity with LCD control, and a battery-backed real-time clock calendar (RTCC), all on a single 8-bit PIC® microcontroller. GET STARTED IN 3 EASY STEPS: 1. Choose a peripheral mix and pin count to suit your application 2. Use the free USB stacks and software drivers for faster design 3. Start developing with low-cost development kits For more information, go to: www.microchip.com/get/eu8bitUSB Microchip Microcontrollers • Digital Signal Controllers • Analog • Memory * Wireless The Microchip name and logo, MPLAB and PIC are registered trademarks of Microchip Technology Incorporated in the U.S.A., and other countries. PICDEM is a trademark of Microchip Technology Incorporated in the U.S.A., and other countries. All other trademarks mentioned herein are the property of their respective companies. © 201 2, Microchip Technology Incorporated. All Rights Reserved. DS31039A. ME1049Eng09.12 Contents Community 8 Elektor World • What is Mickey Mouse doing on a chip? • In front of the camera, behind it, and behind the wheel • CC25 • Download your free Raspberry Pi Poster Projects 12 500 ppm* LCR Meter (1) High quality analogue parts, a microcontroller totally suited to the job, and careful design have resulted in an LCR Meter that achieves remarkable precision considering it can be built at home. Make room on your workbench! 24 The 7-uP Alarm Clock / Time Switch (2) In this second and concluding instalment Michael J. Bauer discusses the schematics and the assembly of his 'zero-compromise' alarm clock. 30 Raspberry Pi Prototyping Board Everyone between 8 and 80 seems to be doing RPi software 'and stuff', but few have the courage to start designing hardware extensions. To do so, you'll find this prototyping board an excellent helper. 36 USB-I024 Cable This cable, which is actually a circuit, effectively puts 24 lines at your disposal for controlling individually over your computer's USB port. The lines are highly configurable for digital, analogue, PWM, RC, counter, or even servo use. 46 Simple Servo Tester Servos are critical electromechanical parts in many applications, so it makes sense to have a tester available to reveal any risk of error or breakdown. 48 Battery-Nearly-Empty Indicator This design can be configured for almost any battery end voltage. 50 Taming the Beast (3) This month we set up a hierarchical FPGA project structure with components you develop yourself. As an example, let's do a simple up/down counter with a two-digit seven-segment LED display. And learn to use the User Constraint File (UCF) along the way. 4 | March 2013 | www.elektor-magazine.com Volume 39 No. 435 March 2013 Raspberry Pi , » J ■* iCT ^ 1 ■: ^ i, in? t-:*~ II rvrsi i*^a. ■rflm hi £D cars jrid hj !: p tia i ui Pr.r c^itnJnr rJ prr-p Iters Sri WQ*Hc <1 1 -3 ZuUlutt I'-il’j;- Itri .«*h a-vi In-. n for hie-ir Labs • Industry • Magazine 56 Frontline Breaking News What's brewing, growing and being researched at Elektor labs. 60 Power supply issues How the guys at Elektor Labs eliminated a construction blooper in one of their benchtop PSUs. 60 7805 replacement grilled Testimony of a number of gruelling tests on our November 2012 switch-mode 7805 replacement. 61 Prototype howlers Can you discover what's wrong here without turning the mag upside down? 62 Philips 'Hue' 'Personal colour tone' is a fast becoming a buzzword in the lighting industry. Here's what enlightened engineers at Philips in Holland have developed. 66 News & New Products A monthly selection of new electronics products, components and technologies. • Tech the Future 68 Open Data In many ways the next step to Open Source, Open Data is freely available for use by everyone. It's not copyrighted, easy to find, and provided in machine-readable format. Series Editor: Tessel Renzenbrink. 72 Hexadoku Elektor's monthly puzzle with an electronics touch. 74 Retronics: 'Radiomann' Audion Kit (ca. 1956) Raise your hands everyone hooked on electronics after being given a 'radio experimenter's kit' by a kind father, uncle or Santa. Series Editor: Jan Buiting. 82 Next Month in Elektor A sneak preview of articles on the Elektor publication schedule. ~M/W www.elektor-magazine.com | March 2013 | 5 Community Volume 39, Number 435, March 2013 ISSN 1757-0875 Publishers: Elektor International Media, 78 York Street, London W1H 1DP, United Kingdom. Tel. +44 (0)20 7692 8344 www.elektor.com The magazine is available from newsagents, bookshops and electronics retail outlets, or by membership. Elektor is published 10 times a year with a double issue for Januaiy & Februaiy and July & August. Memberships: Elektor International Media, 78 York Street, London W1H 1DP, United Kingdom. Tel. +44 (0)20 7692 8344 Internet: www.elektor.com/member Email: service@elektor.com Head Office: Elektor International Media b.v. P.O. Box 11 6114 ZG Susteren The Netherlands. Telephone: +31 (0)46 4389444 Fax: +31 (0)46 4370161 Distribution: Seymour, 2 East Poultry Street, London EC1A, England. Telephone:+44 (0)20 7429 4073 UK Advertising: Elektor International Media b.v. P.O. Box 11 6114 ZG Susteren The Netherlands. Telephone: +31 (0)46 43 89 444 Fax: +31 (0)46 43 70 161 Email: j.dijk@elektor.com Internet: www.elektor.com/advertising Advertising rates and terms available on request. 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, 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 Publishers cannot guarantee to return any material submitted to them. Disclaimer Prices and descriptions of publication-related items subject to change. Errors and omissions excluded. © Elektor International Media b.v. 2013 Printed in the Netherlands Bridging the gaps bit by bit Here's an assumption up for consid- eration if not for revision: microcon- trollers and microvolts (and -amps, -henries, -farads...) are separated by a big gap; they are two sepa- rate worlds, each with their own fan club, its members easily discernible by activity: the digital pundits 4ver eliminating bugs, the analogue guys, always chasing and combatting noise of the electric variety, and corporate too at times. Jean-Jacques Aubry's 500 ppm (that's 0.05%) LCR Meter in this edition should be a feast for LSB manipulators and microhenry addicts alike, as it successfully combines some of the best digital and analogue design tech- niques I have seen so far, at least in the DIY scene. Even if you do not intend to build this sophisticated instrument, there's a lot to be learned from the descrip- tions on how it got designed, both in terms of hardware and software. Another apparent gap in the current electronics / embedded scene is not just revealed but also eliminated by the Raspberry Pi Extension Board article on pages 30-35. While I was easily able to find a mass of RPi software and ready-made hardware out there, I saw preciously little in the way of e-prototyping from the ground up with that nifty little computer. Tony Dixon's article I am convinced will redress the balance, literally challenging you to develop your own hardware for the Rpi, starting on a prototyping area with all bus signals and supply rails eas- ily available on connector pins. Along the way, hopefully you'll have the stirring experience of reducing component count by clever software. If you do it bit by bit, in a low noise environment, success is assured. Please tell me and the Elektor community how you get along LCR'ing, RPi'ing and Elektor'ing. Jan Buiting, Managing Editor The Team Managing Editor: International Editorial Staff: Design staff: Membership Manager: Graphic Design & Prepress: Online Manager: Managing Director: Jan Buiting (editor@elektor.com) Harry Baggen, Thijs Beckers, Eduardo Corral, Wisse Hettinga, Denis Meyer, Jens Nickel, Clemens Valens Thijs Beckers, Ton Giesberts, Luc Lemmens, Raymond Vermeulen, Jan Visser Raoul Morreau Giel Dols, Mart Schroijen Danielle Mertens Don Akkermans 6 March 2013 www.elektor-magazine.com Our network United Kingdom Wisse Hettinga +31 (0)46 4389428 w.hettinga@elektor.com USA Hugo Vanhaecke + 1 860-875-2199 h.vanhaecke@elektor.com Germany Ferdinand te Walvaart +31 46 4389417 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 +27 78 2330 694 j.dijk@elektor.com China Cees Baay +86 21 6445 2811 CeesBaay@gmail.com VOICE 111 COIL CIRCUIT CELLAR Connects you to Supporting Companies AudioXpress www.audioamateur.com 77 Beta Layout www.pcb-pool.com 45 Eurocircuits www.elektorpcbservice.com 59 Labcenter www.labcenter.com 84 BeIK - „ Microchip y Microchip www.microchip.com/get/eu8bitUSB ... 3 pi co Pico Technology www. usb3 scope. com/TRll 1 §* reichelt Hr Reichelt www. reichelt. co. uk Schaeffer AG www. schaeffer-ag. de 83 11 76 Not a supporting company yet? Contact Johan Dijk (j.dijk@elektor.com, +27 78 2330 694) to reserve your own space for the next edition of our members' magazine www.elektor-magazine.com March 2013 7 Community Compiled by Wisse Hettinga Elektor World Every day, every hour, every minute, at every given moment designers and enthusiasts are thinking up, tweaking, reverse-engineering and de- veloping new electronics. Chiefly for fun, but occasion- ally fun turns into serious business. Elektor World connects some of the events and activities — for fun and for business. What is Mickey Mouse doing on a chip? Last month's Elektor World topic on deep IC explorations using an acid bath drew a nice response from Peter van de Wetering in Holland. His hobby is to inspect the architecture of old chips designs. At some point Peter had revealed the insides of a Mostek type MK5017AA IC - a clock chip capable of driving 7-segment displays. Peter remembers: "a very nice design, but not terribly accurate, and also quite sensitive to all sorts of AC powerline distortions". When his brother was busy welding in the shed outside, the IC suddenly shortened 3 days to about 3 minutes! When inspecting the 4x4 mm design of the actual silicon chip, Peter noticed a small spot. Put under a magnifier glass he discovered a developer's joke; Mickey Mouse stretching his arms between '7' and '12'! Searching for more information on Mostek and why Mickey Mouse was etched in the design we found out the company got sued by Disney lawyers due to a publication in Electronics Magazine. Elmer Guritz, former Mostek employee, says; 'We used to put all sorts of designs on chips , i.e. Woodstock on an HP calculator chip , a rat on a Magnavox Chip and of course Mickey on that clock chip that some foolish person published in Electronics Magazine...' Mostek was purchased in 1979 by United Technologies Corporation, which ended up purchased by Thomson France, so the story is fading, but perhaps there are people out there wanting to help us find this rat on a Magnavox chip .... have a close look! 8 March 2013 www.elektor-magazine.com All Around the World ... g^S agjga Hi In front of the camera, behind it, and behind the wheel Filmed at Elektor HQ in Holland in a studio not unfit for David Letterman, the Retronics — Best Of webinar held on January 24 was remarkable in a few ways. For one, a webcast like this allows antique electronic equipment to be dropped in the App Age at the flick of a few switches and using a trifling amount of bits on the web. Second, young people marvel at the old gear shown, while older viewers suddenly confirm that the Internet is useful. During his 30-minute talk to registered attendees all over the globe (check the picture of the notebook in de passenger seat, it was taken in South Africa by Brian Tristam Williams on his way home from work), Elektor's resident e-vintage & boat anchor expert Jan Buiting showcased some of his favourite items discussed since 2004 in his 7 Retronics ' column — you know, those nostalgic pages towards the back of the magazine. Jan's 80+ instalments are now in a book, too! The webinar was canned and may be viewed at your best time: start at elementl4.com/webinars. For the next webinar on February 21, sign up at www.elektor.com/webinar CC25 Over a year ago during a lunchtime conversation in San Jose, CA, Circuit Cellar staffers began preparing the Circuit Cellar 25 th Anniversary Issue. Today, the team is happy to announce that the issue is ready for the world to read (http://circuitcellar.com/25th-anniversary/home/). Circuit Cellar magazine was founded in 1988 by Steve Ciarcia, who had previously authored the "Ciarcia's Circuit Cellar" column in BYTE magazine. Today, Circuit Cellar is an Elektor International Media publication supplying articles, tutorials, and design projects covering professional electrical engineering and state of the art embedded systems design. The purpose of the Circuit Cellar Anniversary Issue is to commemorate 25 years of Circuit Cellar magazine, as well as document the history of embedded technology since the late 1980s. The issue is divided into three main sections: • The Past : articles about the last 25 years of Circuit Cellar magazine (memorable design projects from past issues), as well as essays and interviews about early embedded technologies. • The Present : essays on present-day electrical engineering top- ics (essential embedded design principles, user interface design, embedded security, and more). • The Future : prognostications about the future of embed- ded electrical engineering, embedded technology, and the microcontroller industry. The issue features the following articles, essays, and interviews: • Steve Ciarcia (Founder, Circuit Cellar) on the magazine's history; • Dave Tweed (Engineer/Editor, Circuit Cellar ) on 25 years of embedded design projects; www.elektor-magazine.com March 2013 9 Community • John Regehr (Professor, University of Utah) on the future of small RAM microcontrollers; • Limor Fried (Founder, Adafruit Industries) on the future of the DIY revolution; • Simon Ford (Director of Online Tools, ARM) on the future of rapid prototyping; • and many more. There are also interviews on the future of technology with Steve Sanghi (CEO, Microchip Technology), Stefan Skarin (CEO, IAR Systems), and Jeff Kodosky (Co-Founder, National Instruments). Go to www.cc-webshop.com/CC25-Anniversary-Issue-FI-20 13-CC25.htm for more information about the unique issue. bSB Port- °*vm w-Of ^ T'-s-i. *’*'■■ * t ■ m. ^ ** , 3J 3s£-s,'.^ssar. — • ir?S,*;~S — s ask* ~^gaa ag «w. * SKSShs****. . £=.*:jp • -T^r ; ' ****** *^ '*“*** 4 y** *. ■*«■ IX ( 1 , *-<’ViiL, , *^%5T5£5 i ’■‘m r-j /•f'Hd'H *^**'u, nSTS 2 i ’*« * '**-*r. ^aspb erry p/ Download your free ^ crsdit-rir* Options f 0r ""*J" *1 SO eardtnn t 11 «*W*W; « '-an-.,,' • l ‘ ru! • « rtw • 1*5 Sf ** 9 mm. P**-'* 1 PO**r** B* e :r- Xm*Ornl n 51 m... -- _ , ■^ rwx . £ 5 £*—um f* reichelt M _ ■ _ ■ - _ *5*3? <, f, *-^/-?-r_ r * ± - 1 P* 15 . *■ \ TjiS -r v _ jjk _■ " JtV 5 -Si, * :?- - •co.uk * «& a\ Vir « elektronik ^raa; *A« more than 40 years experience ^ more than 40000 products in stock S no minimum order charge fast 24 hour shipment / +49 (0)4422 955-333 +49 (0)4422 955-360 Workshop equipment Professional quality @ discount prices! Network & PC technology Switch Relay Programming devices \P Light technology APEM JOYSTICK MS Development tools SAT and TV technology @ finder FIN 49.52.9 24V 7, 15 (~ £16,96) Micro switch joystick (~ £5,82) with micro switches and two-way contact, 6A, 25V' 1 -pole • 2 axes* tapered handle bushing: 22mm • incl. 4 diverse links All switches: /"? http://rch.lt/85 Push button, IP 65 016mm, 2 A, 36 V Illuminated ring configuration: 1N01NC ©NP©H r Colour VSGQ16F-GN 6,60 (~ £5,37) green VS GQ16F-RT 7,55 (~ £6,14) red Vled 2,8 1,7 V Miniature toggle switch • 1 -pole, welded / plug-in connections 6 A - 125 V AC MS 500A MS 500B MS 500C 1,65 (~ £1,34) on • on 1,75 (~ £1,42) on - (on) 1,85 (~ £1 ,50) on • off - on 3 A - 250 V AC MS 500 D MS 500E 1,85 (~ £1,50) on • off -(on) 1,85 (~ £1,50) (on) - off -(on) ( ) = touch function Dip coding rotary switch • 0.4VA at 20V • for printed circuits • 1 0 and 1 6 switching positions, respectively vertical position KDR10 1,45 (~ £1,18) 10-pole KDR16 1,10 (~ £0,90) 16 pole b 5 C * ci __f Q fo il i horizontal position KDR10H 1,80 (~ £ 1 >46) 10 pole KDR16H 1,45 (~ £1-18) 16 pole Couple relay, two-way contact, 8A • completely assembled with FIN 40.52 relay • 24 VDC • 900 Q Rl • for DIN bus bar • switching capacity: 250 V/1 250 VA GALEP V All relays: 17 http://rch.lt/84 fir

so we'll just have to accept right away the idea of breaking it up into manageable chunks. You will only have seen the whole thing once the series of two or three instalments have been published — please excuse this inconvenience. * see detailed specifications 12 March 2013 www.elektor-magazine.com 500 ppm LCR Meter Technical specifications Display Dominant parameter: value Secondary parameter: value Equivalent circuit: series or parallel (manual or automatic selection) Q-D (can be reversed with respect to the automatic choice) \z\ 0) either Rs + Xs, \/x + lx, or ADCU + ADCI Sort function On the main parameter of a control component ( R , L, or C) after adjustment of the central value. Tolerances: 1 % 2 % 5 % 10 % 20 % Measurement scope Parameter Value L 0.1 nH - 100 H C 0.1 pF - 100 mF R, \z\ 0.1 mil - 1,000 Mil (lGfi) Q or D 0 - 10,000 (p -90.00° to +90.00° Rs, Xs 0.1 mil - 1,000 Mil (1 G£l) U x and I x U x 0 - 500 mV I x 0-5 mA ADC U and ADC I 0 - 5 V Test frequencies 50 Hz supply 100 Hz, 1 khlz, 10 khlz 60 Hz supply i20 Hz, 1 khlz, 10 khlz Power consumption Without display 5 V - 100 mA With backlit display 5 V - 180 mA PC software For Windows, Linux, MacOSX Test conditions Off-load test voltage 0.4 V rms ± 5 % Ranges 8, automatic Measuring speed Around 2 measurements per second. It is possible to take the average of several measurements (1-9), at the expense of speed. A green LED indicates the end of each sequence. Accuracy of the main parameter ( R , L, C) Conditions* Warmed up for 10 minutes, 25°C ± 2°C Use of 0.01 % resistors (100 ft, 1 kft, 10 kft, 100 kft) in the current/voltage converter. Ranges 3, 4, 5, and 6 < ±500 ppm (0.05 %) (down to 200 ppm **) ±1 on the final digit Ranges 2 and 7 < ± 1000 ppm (0.1 %) (down to 800 ppm) **) ±1 on the final digit Ranges 1 and 8 < ± 3000 ppm (0.3 %) ±1 on the final digit ** The accuracy (±1 unit in the last figure on the right) is greatest when the post-amplification ranges are the same for U and I. Miscellaneous Miscellaneous Measurement connections 4 Kelvin wires on BNC connectors Compensations "OPEN" / "SHORT" "SHORT" limit \z s \ < ion "OPEN" limit \Z S \ > 100 k£l Supply voltage 5 V DC ± 5 %, via the USB connector www.elektor-magazine.com March 2013 13 •Projects Figure 1. Analogue and digital techniques are closely intertwined within the sub- assemblies of the 500 ppm LCR Meter. 110758 - 14 An LCR meter isn't usually seen as indispensable in an amateur electronic enthusiast's workshop. However, with the proliferation of SMD compo- nents with no markings, like chip capacitors, or the increasingly common use of chokes in switch- mode PSUs, the use of an LCR meter is becom- ing more and more frequent. Let's not forget too that this device doesn't stop at just giving a passive component's 'value' in the usual sense — inductance L , capacitance C, or resistance R — but also its secondary component, defining its 'quality' (see specifications box), which can be defined in several ways: • O - phase angle between voltage and cur- rent: tan O = |X S | / R s • Q - quality factor = tan CD, used to charac- terize an inductor. • D - dissipation factor = 1/Q, used to charac- terize a capacitor. This duplicity in our components, innocent enough as to be most usually ignored in low-frequency circuits, does need to be taken into account in high-frequency work, and more generally in pre- cision circuits. We have to go back more than 15 years in the Elektor archives to find a precision LCR meter [1]. My project, the fruit of which you're going to be discovering here, has itself been in ges- tation for four years; the first version, battery- operated, with a modest 2x16 LC display, has become a bench model, mains powered, with a 128x64 graphic display. My exchanges with Elektor Labs have led to the version published here, which benefits from all the accumulated experience. Did we have to choose between two concepts, either a computer used as a display and control peripheral (USB link) associated with an LCR meter that was reduced to being just a measuring interface, or a true self-contained LCR meter? No. To keep everyone happy, I'm pro- posing a no-compromise variable configuration, designed to combine accuracy and convenience at the highest level: • A measuring head that dialogues with a PC (for displaying the results and sending com- mands), but is also present on an extension connector; • An optional extension comprising a display and a mini keyboard, which when connected to the previous element converts it into a standalone unit; Figure 2. An enlargement of the section within the dotted line in Figure 1: this is the measuring head, which most of this article is about. 14 March 2013 www.elektor-magazine.com 500 ppm LCR Meter A little bit of theory The complex impedance to be measured is equal to the ratio between the vectorial dimensions U x and L x representing the voltage across the device under test (DUT) and the current flowing through it: U X X Each vector can be broken down into phase and quadrature components with respect to some fixed reference: Zv = _ V p + jV q !„ + J ' q Hence again, using the series representation of an impedance Z x = R s + j X s V I +V I I 2+1 2 p q V I -V I X - 4 p p JL S 1 2 + I 2 p q Some LCR meters go down the analogue route (phase detectors) to obtain the phase and quadrature components of the voltage and current to be measured, the final measurement being performed by an ADC, often of the dual-ramp type for good accuracy, as the DC voltages to be measured are in fact 'contaminated' by a not-inconsiderable residual voltage, if one is looking for a fast response time. The "all digital" method does not suffer from this drawback, and the mathematical operation of discrete Fourier transformation (DFT) makes it possible to obtain the phase and quadrature values for the voltage (U p U q ) and current (ip J q ) from N samples d t of one period of the signal to be measured 1 N - 1 U n = — V d: x cos P M ^ 1 7=0 r Ini ^ k~N~ , 1 N-l U n = — T d: x sin q N " ly 7=0 r Ini ^ k~N~ y This requires just a fast, accurate ADC, and a little bit of calculating power. • Software, within the measuring head, capa- ble of handling both these modes. Before we take a detailed look at the complete circuit of the unit, I propose first taking a quick look at the block diagram, which gives a good idea of the whole project (Figure 1). It would be tempting to immediately examine each element in detail as we usually do. Sadly, we wouldn't under- stand a great deal of it without first taking a look at the problems posed by these measurements. All in all, they are fairly complex, and the preci- sion requirement we've set for ourselves places the bar pretty high. Rest assured, though, that all I'm using for this is grey matter — there are no other hard-to-find components. Principle and operation In the "A little bit of theory" box, I provide a few details about the measurement principle. Let's take a look here at its practical implementation in the measuring head (Figure 2), which comprises those elements enclosed by the dotted line in Figure 1. The analogue section of the LCR meter uses the conventional technique of a self-balanc- ing bridge to determine the unknown impedance of the device under test (DUT) by measuring the voltage across its terminals together with the current flowing through it when driven by a variable-frequency sinewave signal. We can see from Figure 2 that the current flow- ing through the DUT also flows through the cur- rent sensing resistor R seuse (this simplified dia- gram doesn't show that the value of this sens- ing resistor changes with the impedance range, which we'll see in the full circuit diagram). The potential at the inverting input of the current/ voltage converter ( IU converter ) is maintained at 0 V (virtual ground) so as to maintain the balance between the current through R sense and that through the DUT. As the frequency is never more than 10 kHz, a fast opamp is suitable for this converter, which must introduce only a mini- mum of phase error into the signal path. The complex impedance of our unknown compo- nent will thus be obtained from the voltage meas- ured across the DUT and that across R sense (an image of the current through the DUT), applied to a differential amplifier (INA128) via the I/U switch. Before being digitized by the microcontroller, the signal undergoes further amplification (PGA103), multiplication (by means of the DAC8811 fast converter), and filtering. The remainder of its path is handled by the software, which will first determine the basic series parameters of the unknown impedance R s and X s (where X s is an inductive or capacitive component, depending on the nature of the DUT) and then lastly the www.elektor-magazine.com March 2013 15 •Projects Table 1. Combined gain: variable from 1 to 866 in 48 steps PGA gain 1 10 100 CNA gain 1 1.155 ■ ■ 7.50 8.66 1 1.155 ■ ■ 7.50 8.66 1 1.155 ■ ■ 7.50 8.66 Total gain 1 1.155 a m 7.50 8.66 10 11.55 a a 75.0 86.6 100 115.5 a a 750 866 Table 2. Measuring Ranges Range IU converter resistor U gain I gain Measuring Range (resistance) Measuring Range (L or C - impedance) 1 ioo n 100 1 < o.i n < 1 ft 2 ioo n 10 1 o.io a to n n 1 ft to 10 ft 3 ioo n 1 1 11 ft to 900 ft 10 ft to 995 ft 4 1 kft 1 1 900 ft to 9.9 kft 996 ft to 10 kft 5 10 kft 1 1 9.9 kft to 99.9 kft 10 kft to 100 kft 6 100 kft 1 1 99.9 kn to 1 MS2 100 kfl to 1 MS2 7 100 kft 1 10 1 Mft to 10 Mft 1 Mft to 10 Mft 8 100 kft 1 100 > 10 Mft > 10 Mft other parameters derived by calculation: Z, Z_, C, R, O, Q, D. The conformity of the successive stages is deter- mining. In order to avoid problems of drift, the same chain is used for both the voltage and cur- rent measurements after the IU converter. The high precision of the programmable gain ampli- fiers used and the compensation for the stray differential phase error, which is a function of the gain of the chain, ensure a basic accuracy practically equal to that of the precision resistors used in the current/voltage converter. You could be forgiven if you now rushed ahead to look at the circuit, without reading what follows. How- ever, do be aware that in order to understand everything, you will have to come back to the next two essential paragraphs, which may at first reading seem a bit hard going... Better watch that gain To obtain extended measuring ranges (see para- graph "Measuring ranges" below), the amplitude of the signals to be measured must be adjusted before they are digitized. This is achieved by: • Selecting the appropriate value of R se nse , according to the impedance of the DUT. The values adopted are: 100 ft, 1 kft, 10 kft, and 100 kft (we'll see these later on the cir- cuit diagram). • Modifying the gain of the measuring chain so as to drive the analogue/digital converter (ADC) with a voltage that's as high as pos- sible, without overloading it. Using the same amplifying chain for the current and voltage measurements makes it possible to avoid a good part of the drifts and uncertainties about the global gain value. In point of fact, as the impedance value can be written: z V_ p±j\ x G iR ms e X I p + jl q Gv Where G; and G v are the current and voltage gains of the amplifier channel; R sens e is the IU converter resistor; V and I are the voltages measured by the ADC; the ratio Gj/G v will only keep the variable parts of the gains. The linearity error of a successive approxima- tion ADC (SAR) is at best ±1-2 LSBs. Now since the zero-crossing of the sinewave signal to be measured is the region where the digitizing error is greatest, the higher the amplitude of the sig- nal, the more accurate will be the measurement. Most LCR meters, like for example the one described in Elektor\r\ 1997 [1], use a program- mable gain amplifier (PGA in Figure 1) using a step of xlO between values (gain of 1, 10, or 100). It is quite simple to use a high-precision integrated PGA, such as the PGA103 from Texas Instruments. 16 March 2013 www.elektor-magazine.com 500 ppm LCR Meter Compensating the phase shifts in the IU converter and PGA103 The software measures reference capacitors The phase shifts introduced by the IU converter are compensated for by the software. The phase shift to be compensated is determined by measuring components whose behaviour is known, such as SMD capacitors with NPO dielectric, considered as 'perfect' (at these low frequencies). The advantage of this method: the stray capacitance of the connections is in parallel to the capacitance proper and hence is no longer of any importance. We will be aiming for a -90° phase shift. To do this under the best conditions, the amplification gains must be identical for U and J; this implies that @ 10 kHz the impedance of this DUT must be practically equal to R sen se : 159 nF for 100 ft, 15.9 nF for 1 kft, etc. To make things simpler, these capacitors are wired onto the PCB, but they are only brought into service manually via a jumper during the compensation procedure. After that, they are not used for anything at all! The software measures low-value resistors In order to compensate, via the software, the PGA103's phase shift for ranges 1 and 2 (not for range 7 and 8, as this would require high impedance with a great many stray components), we use low-value resistors (the influence of stray capacitance and/or series inductance is negligible), here too wired as closely as possible to the board, and aiming for a zero phase shift. These are only brought into use during the compensation procedure and are not used for anything else afterwards! In this respect, adjusting the gain in this way means the voltage to be measured will change by steps in a ratio of 10. If this voltage had to be used "as-is" by the ADC, not only would the operating conditions not be ideal, but above all the measurements of the current and voltage by the ADC could be dissimilar, to the point of introducing a (severe) relative digitizing error. To avoid this, we need to have intermediate gain values — without compromising the accuracy of the overall gain value! Using a multiplying digital/analogue converter (DAC) ( DAC8811 in Figure 1) in conjunction with an operational amplifier (Buffer in Figure 1) allows us to obtain a gain that can be varied from zero to 1 (actually -1, but the phase is irrelevant here), in as many steps as the resolution of this DAC allows, and with the same precision as it! An ingenious bit of wiring makes it possible to make the gain of this stage variable between 0 and k (k constant >1): it involves applying only a proportion of the output signal to the DAC8811's built-in feedback resistor. If 16 gain values are used for the multiplying DAC, the basic gain variations will be selected in a ratio of 1 $\0 , i.e. 1.155, with the maximum gain being 1.155 15 , i.e. 8.66. This will allow us to have a combined gain that is variable from 1 to 866 in 48 steps (see table 1). If the gain control program is well designed, it will provide the ADC with a voltage to digitize whose maximum amplitude is close to its full- scale capacity for both the voltage and current parameters of the DUT, with a maximum ampli- tude difference in a ratio of 1.15. Under these conditions, knowing that the imped- ance is equal to the quotient (give or take a coef- ficient) of the two measurements, and if the ADC has high resolution (ideally 16 bits), then digitiz- ing errors will be practically eliminated. And there you have it as far as the gains are concerned. Stray phase shifts The accuracy also depends on the compensa- tion for the stray phase shifts introduced by the measuring chain. Two elements must be considered: • The phase shifts introduced by the IU con- verter , as this is found only in the current measurement path. To achieve this, we're going to be using measurements of multi- layer ceramic SMD capacitors with lossless dielectric (NPO or COG) — the compensation will be adjusted to obtain a phase shift as close as possible to the theoretical -90°. The appropriate capacitors are fitted to the PCB and brought into circuit by jumpers J6-J9. • The differing phase shifts in the PGA103 when it is programmed for a gain of 10 or 100 in one of the measuring paths and 1 in the other: ranges 1, 2, 7, and 8 (see table below). In this case, we'll be using two SMD www.elektor-magazine.com March 2013 17 •Projects resistors of 1 ft and 10 ft (R19 and R16), brought into circuit by J3 and 32, to achieve zero phase shift. Measuring ranges (see table 2) For the voltage and current meas- urements of the DUT impedance, eight ranges are defined from the value of R sense 0- e - the IU con- verter resistor) and the gain of the main amplifier (PGA103). The final amplification (DAC8811 multiplying DAC) between 1 and 8.66 is performed in 16 steps, denoted 0 to F, for both voltage and current measurements. Analysing the circuit Before looking at the circuit proper, I just want to point out that digitiz- ing the sinewave signal directly by the microcontroller's ADC obliges us to use DC coupling from one end of the amplification chain to the other. Without such DC cou- pling, we'd have to wait for the ADC input to stabilize at the mean value of the signal every time the gain was changed or when switch- ing between the current (7) and voltage ( V) measurements. As the intended accuracy is < 500 ppm (0.05 %), this stabilization time would be a problem. Considering the DC coupling, any offsets super- imposed on the sinusoidal signal will need to be compensated so that the mean value of the signal is close to 0.000 V, even at maxi- mum gain. The main circuit diagram (Fig- ure 3) breaks down into four sections, some of which we are already familiar with: at top left, the microcontroller; bottom left, the measuring bridge; bottom right, the amplification chain with the sinewave generator above it; and lastly, top right, the power supply and the interface with the outside world. 18 March 2013 www.elektor-magazine.com 500 ppm LCR Meter U16 VIN SW LT1611 SHDN NFB GND TP13 R80 0 HWW- 20k C73 I ■ In it 5% ■ ■ NPO D7 ^1BR0520 2u2 C69 C70 33u 6V3 U17 IN OUT TPS72325 EN NR GND C72 2u2 TP14 0 -2V5 C71 lOn U18 IN OUT TLV70030DDC EN GND GND TP15 O 2 C75 + ■ r 2u2 R84 wwv- R85 2R2 Hww 2R2 C76 470u 6V3 • J17 SET FOR FIRMWARE UPDATE AT POWER-ON R87 56R ^077 C79 Cl -@AVDD -@AV+ C80 4u7 I lOOn ^OC R86 HWW 2R2 R89 H/WV 2R2 3 Jc85 Jci -0 VDD -@+3VD +5VA 0 - IC20 = TLC2274 IC20 ^^53 T oon i\ JC 61 V I 2u2 I 10 T C86 lOOn 0- -5VA lOOn Figure 3. Complete circuit diagram of the 500 ppm LCR Meter. Almost everything happens inside the microcontroller, but the development of the analogue part needed the greatest care in order to avoid compromising its accuracy in any way. www.elektor-magazine.com March 2013 19 •Projects Figure 4. The Kelvin measuring principle uses two separate wires for current flow and voltage measurement. Measuring bridge Having read the foregoing, you will have under- stood that the IU converter (U6, R18, R20, R21, R22) at the bottom left of the circuit diagram is a critical part of the device. The accuracy of the values of R18 and R20-R21-R22 determines the accuracy of the whole device. The resistor R sense is selected using one half of analogue switch IC U3. The buffer amplifiers U4C and D measure, at high impedance, the voltage across the R sense resistor selected: • U4D for the voltage at the junction of the resistors; • And U4C, via the second half of U3, at the // To check it would be possible to use the C8051F06x, I bought the development kit (C8051F060-DK) and obtained a sample of the MAX7400 (8 th -order hi ter). I wired up the latter on prototyping board. I wanted to measure a capacitor. But how could I do this simply , using just the kit's two analogue inputs (referenced to ground)? The solution was to use two series R sense + C branches , as identical as possible , connected in parallel between the filter output and ground. One with the capacitor on the ground side , the other with the resistor on the ground side. Measuring at the junction of R sense and C gave the C voltage measurement on one branch and on the other the measurement of the R sense voltage - and hence , of the current flowing through C! other end of these resistors (allows us to compensate for the R on resistance of the switches in U3). Hence the differential voltage between the out- puts of U4C and D is equal to the voltage across the feedback resistor selected via U3. The voltage across the DUT is measured using a 4-wire Kelvin connection: the DUT is connected between J 1 1 and J12, i.e. the lines High Drive and Low Drive through which flow the current, while the voltage is measured, at high imped- ance, via J10 and J13 (the High Sense and Low Sense lines) and buffer amplifiers U4A and B. The internal resistance of a single cable would introduce an error in the measurement result. The Kelvin clip, with its twin insulated cord, lets us perform the voltage measurement without its being interfered with by the voltage drops caused by the current flowing in the other wires (see Figure 4). The dual diodes D1-D5, with very low reverse leakage current, provide overload protection. All this is of course prone to stray capacitance, which is going to introduce phase shifts. It's essential to choose a very wide bandwidth ampli- fier for the IU converter, so as to maintain the linear relationship between phase shift and fre- quency. Knowing this phase shift at the maxi- mum operating frequency (10 kHz) will enable us to calculate it at the intermediate frequencies. The very wide bandwidth of U6 means we have to include a network to stabilize the gain at very high frequencies; this is the role of R26 and C19. Its offset is compensated using DACO in the pC U9: the DACO output voltage is programmable between 0 and 2.5 V; this is taken to a value between about -75 mV and +75 mV via the resistor network R47, R46, and R45, which will let us inject a programmable current (via R42 and R34) into U6's inverting input so as to cancel out its output voltage. Amplification chain Up front comes the analogue switcher U8 (Fig- ure 2, bottom left on right-hand page) which makes it possible to select the output voltages of either U4A and B for the voltage measurement (l/), or U4C and D for the current measurement (7). After this, the amplification chain is common, thus avoiding the influence of offsets and stray phase shifts; but this does mean we must use amplifiers with stable, well-defined gain. 20 March 2013 www.elektor-magazine.com 500 ppm LCR Meter Automatic bridge for measuring the impedance of passive components between 1 mQ and 1000 Mft Differential amplifier U5 lets us go from a float- ing value to a value referenced to the 0 V power rail (ground). Its gain is set at 2 by R32||R93, i.e. 50 kft. The gain of the precision amplifier U7 can be selected to be 1, 10, or 100 via two control lines. Then come U12, the DAC8811 multiplying digital/ analogue converter amplifier, and its fast opamp U14. Taking the feedback voltage (RFB) from the divider R65/R67 rather than directly from U14 output allows us to obtain the quoted gain of 8.66. It is programmed in serial mode using 3 command lines. In order to make the most of their performance, the ADCs in the pC U9 are used in differential mode. To this end, amplifier Ull inverts the phase of U14's output signal. As each of the ADCx inputs can only accept a voltage between 0 and V REF (2.5 V), a DC cur- rent is extracted from the summing point so as to obtain an offset voltage of (+l/ ref / 2) and thus a differential DC voltage of 0.000 V (adjustable via preset R75, at the very bottom on the right- hand side of the circuit). Sinewave generator The DUT is driven by a sinewave signal that can be set between 100 Hz and 10 kHz. I use three frequencies: 100 Hz or 120 Hz (i.e. twice the AC supply frequency), 1 kHz, and 10 kHz. Other fre- quencies are possible (with certain restrictions). To get the most out of the microcontroller's ADCs, the digitizing process is carefully synchro- nized with the sinewave signal. Timer2 in the pC supplies a squarewave signal at the desired frequency, applied to the (8 th order) switched- capacitor filter U2. This filter requires a clock signal (CLK) at lOOx its cut-off frequency, which is provided by Timer4. At U2's output, we have a perfectly sinusoidal signal, but we do still need to remove residual clock frequency components from it. This is the job of the two active 4 th -order filters built around U20, one with a cut-off frequency of 1.1 kHz, www.elektor-magazine.com March 2013 21 •Projects Operates in standalone mode with display and mini-keyboard or in USB satellite mode with a computer (OSX, Windows, Linux) used for the frequencies < 1 kHz, and the other with a cut-off frequency of 11 kHz, for the fre- quencies > 1 kHz. The amplitude of the 1 and 10 kHz signals is adjusted using R7 and R100. Analogue switch U13 selects which filter is used. AC coupling (C3, C9) to buffer U1 eliminates the signal's DC component. Offset compensation for U1 is performed using DAC1 in the pC U9, in a similar way to the offset compensation for U6. Powering The device's supply arrives via J19 (USB-B), with +5 V on pin 1 (V bus ) and return on pin 4. It will come either from a USB cable connected to a computer, or from a USB power supply such as a smartphone (max. 6 V pp off load). Our device draws more than 100 mA. So if it is powered via a computer USB interface, this will have to be a 'high power' one, capable of sup- plying up to 500 mA and guaranteeing a mini- mum V bus voltage of 4.75 V. It is possible to indicate the nature of our peripheral (high-power bus-powered device) by modifying the Max Bus Power parameter of the USB_Config_Descriptors in the FT245R's EEPROM, to set it to 500 mA (see the documentation for the FT_Prog utility on the FTDI website [2]). Low-dropout linear regulator U15 supplies a volt- age of +4.60 V (typ.) when its input 5 (EN) is high. Its 470 mA current limit ensures we respect the USB standard specification for a bus-powered high-power USB device. Table 3. PWRN State LCD_RES State Action low high display on computer low low display on computer or standalone mode if any key of the extension's mini-keyboard is pressed during boot. high high ERROR! neither a computer nor the display extension is connected high low standalone mode The switching regulator U16 supplies -4.60 V (typ.). It is wired in accordance with the LT1611 data sheet [3], using a double-wound inductor LI. Regulator U18 supplies +3 V, and lastly U17, -2.5 V. Note: On the circuit diagram, the indications +5 V and -5 V actually correspond to the +4.60 V and -4.60 V rails. Microcontroller The C8051F061 from Silicon Labs™ is an 8-bit analogue/digital mixed-architecture microcon- troller. I chose it for the quality of its 16-bit successive-approximation ADCs ADC0 and ADC1: • Sampling up to 1 MS/s and direct memory access (DMA); • Max. ± 1 LSB inherent linearity in different mode; • ± 0.5 LSB differential linearity (guaranteed monotonicity). The rest is just as good: • Improved-architecture 8051 core (70 % of instructions are executed in just 1 or 2 clock cycles) • Clock frequency up to 25 MHz • 2 12-bit DACs • 1 10-bit, 200 kS/s ADC and 8-channel multiplexer • 4,352 bytes of RAM and 64 KB reprogram- mable flash memory • 5 16-bit timers • 2 serial ports (UART); data rate up to 115,200 baud (24 MHz clock) • SMBus and SPI interfaces • CAN 2.0 bus • 24 general-purpose inputs/outputs • Numerous interrupt sources • JTAG interface, etc. The test frequencies of 100 Hz, 120 Hz, 1 kHz, and 10 kHz are derived from the crystal-controlled 24 MHz clock. The 2.50 V reference voltage for the A/D and D/A converters is provided by U10 (to right of the pC). Its accuracy has no effect on the overall 22 March 2013 www.elektor-magazine.com 500 ppm LCR Meter accuracy of the device, as its value is eliminated in the calculations. When fitted, jumper J17 notifies the boot program of an unconditional firmware update request. LED D6 lights at the end of each valid measure- ment to indicate that everything's OK. USB interface Communication with the PC is entrusted to the well-known FT245R USB/UART converter from FTDI (U19). It's configured for 115,200 baud, 8 bits, no parity, and 1 stop bit (8 N 1) and no handshaking. LEDs D8 and D9 light when data is being transferred. Between 25 ms and 200 ms after applying power, this IC sends its SLEEP/ pin high. If SW1 is open, U15 is then validated and all the regulated volt- ages are supplied to the rest of the electronics. If the device is connected to a computer via a USB cable, the PWRN/ pin, which is high when power is applied, goes low after around 300 ms. The pC's internal program tests the status of this pin during the boot sequence, along with the sta- tus of pin 6 (LCD_RES/) on extension connector J16; if this pin is low, it indicates the presence of the Display/Keyboard extension. From these two statuses, we get four possibilities (see table 3). Temporary conclusions This is where our initial overview of the 500 ppm LCR Meter ends. In the next part, we'll be dis- cussing the measurement accuracy and the error or uncertainty factors (gain, calibration, phase). We'll learn about the extension with its display and keyboard, which will turn it into a standalone device, together with the computer software for the Windows, Mac, or Linux platforms), which is going to enable us to make the most of its accu- racy. But you've got plenty to think about while you're waiting. And if here or there you still find some things a bit unclear, don't despair — read through it all again, check out the documenta- tion, and things will soon become clearer. ( 110758 ) Links and References [1] Elektor April 1997 p. 12; May 1997, p. 12; June 1997, p. 32 All three articles can be found on the Elektor 90-99 DVD, www.elektor.com/dvd90-99. [2] FT245R User Guide from FTDI www.ftdichip.com/Support/Documents/App- The fruits of passion Born in 1943, Jean-Jacques Aubry, drawn at an early age to the phenomenon called Radio, developed an interest in listening-in to radio amateurs, using tube receivers. Graduating as a radio-electrical engineer in 1968, he joined a small electronics firm, where he stayed for 36 years. He discovered computing with the ZX80 kit from Sinclair (commandeered from his young son) and taught himself programming, first with a stock management program in Turbo Pascal, then the software for various test benches in Visual BASIC. Moving on to the Mac in 1990, he applied himself to C and then C++, and discovered Qt with a Software Defined Radio (SDR). Once retired, to keep busy, Jean-Jacques set out to design a high- performance LCR meter. Notes/AN_124_User_Guide_For_FT_PROG. pdf [or] http://goo.gl/USPOS [3] LT1611 data sheet http://cds.linear.com/docs/Datasheet/1611f. pdf [4] www. elektor-magazine.com/1 10758 // I initially noted a discontinuity in the measured value when changing range (modifying R sense or the PGA103 gain). In the end , I realized that one of the reasons was that I'd used capacitor with X7R dielectric for C30 (filter between U5 and U7), C52, and C59 (ADCO and ADC1 input capacitors). With the signal's alternating voltage applied , the non-linearity of this dielectric introduced noticeable distortions! The solution was to use capacitors with NPO (COG) dielectric. // During my initial testing , I couldn't get the right frequencies for the timers. In the C8051F06x documentation , for the square-wave output mode, it gives (p. 298 , equation 24.1) .-equation 24.1) p Ftclk sq 2 (65535 -RCAP„) RCAPn being the value to be loaded into a Timer n register. In actual fact > you need to perform the calculation using 65,536 and not 65,535! www.elektor-magazine.com March 2013 23 •Projects Part 2 The 7-uP Alarm Clock/ Time-Switch The main board schematic shown in Figure 3 gives the impression of a very simple industrial controller with minimal external I/O interface connections. A notable exception is the audio generator circuitry, which is more complex than you would expect on a general-purpose program- mable controller, for example. The choice of micro-controller chip has already been explained in the technical introduction (above). The At89c5131 is a derivative of the Intel 8051 family and thus has many 8051 core characteristics, including the inexplicably bizarre By Michael J. Bauer (Australia) Figure 3. Circuit diagram of the main board electronics. ♦Vex © +V| N © FI 500mA TP1 — O (+VIN) VBUSD R15 1 1 [R14 HW\Ar-| C05 3k0 II ^MkO II 4n7 5 4 R12 HWW 47k +V E X © PWRON / T Q1 RIO D5 10k '4V7^ L > R11 BC547 C13 lOOn TP2 GND0V RESET / SI RESET HI "USB STATUS" R02 +5V +5V © 1N5817 VBUS / VRXD 20 V TXD 29 \INT0 30 V DE/RE 31 ^CANCEL 32 33 \ENCA 35 S.ENCB 39 VSSDISP 1 ^SSEXTI 2 VSSEXT2 3 VFREQO 9 VFREQ1 10 VFREQ2 11 ^ALMOUT 14 VDOUTA 15 16 TP5 ALE RA1 17 EA VDD P3.0/RXD P3.1/TXD P3.2/INT0 P3.3/INT1/LED0 P3.4/T0 P3.5/T1/LED1 P3.6/WR/LED2 P3.7/RD/LED3 U1 AVDD ALE P4.0/SCL P4.1/SDA P0.0/AD0 PO. 1/ADI P0.2/AD2 P0.3/AD3 P0.4/AD4 P0.5/AD5 P0.6/AD6 P0.7/AD7 P1.0/T2/KIN0 P1.1/T2EX/KIN1/SS P1.2/ECI/KIN2 P1.3/CEX0/KIN3 P1.4/CEX1/KIN4 P1.5/CEX2/KIN5/MISO P1.6/CEX3/KIN6/SCK P1.7/CEX4/KIN7/MOSI AT89C51 31 A-S3SUM PLCC-52 SKT RST NC 10k 10k 7 scl / 8 , SDA/ 52 3MPIN0 / 45 CMPIN1 / 44 CMPIN2 / 42 CMPIN3 / 40 DOUT1 / 38 DOUT2 / 37 DOUT3 / 36 DOUT4 / 47 PWRON / 48 VBUSD/ 1 49 MUTE/ 50 PWMO / 51 PWM1 / 4 MISO/ 5 SCK/ 6 MOSI / 43 RESET / NLiAAA/U, M°!EL2aaaa^ 8x 22k +5V © ON/OFF , x P6 BT1 (+) 3V6...4V5 (3x AA) i 2 3 4 C-T D4 1N5817 © +Vbatt \ DE/RE MOD-6P4C +5V +V E x © © \ TXD SIL-4 SERIAL INTERFACE (INTERNAL) C16 @ (l Z U4 U ioo n (7) q D ® 8 U5 P? +\ G • 1 ^IN p ► SIL-2 SPEAKER 1N5817 V. V. V V. V. V V V V V V V V \_ V 24 March 2013 www.elektor-magazine.com Alarm Clock/Time-Switch Description of the main board, the display board, and assembly I/O port configurations. Port 0, for example, is open-drain and therefore requires external pull- ups on pins to function as outputs. Other ports have internal weak pull-ups (~25 kft) which do not provide sufficient output drive capacity for most purposes. Nevertheless, the 89c5131 has many redeeming features including a very fast processor core. With a 24 MHz crystal and 'X2' clocking mode, the MCU core runs at 48MHz! The device incorporates many extra peripheral modules, e.g. USB, Timer T2, PCA (used for PWM outputs), SPI, and TWI (IIC). The At89c5131 provides a separate flash program memory block (4 KB) for a bootloader. The device ships with a USB bootloader pre-programmed into this 'boot block', allowing user program code to be loaded into the main flash program area (32 KB) via the USB port, i.e. requiring no addi- tional flash programming hardware. If the pro- cessor is reset while the PSEN# pin is pulled low (using the ISP button), the bootloader is started instead of the user application code. The UART TX and RX signals are routed to the expansion header (PI), also to a 4-pin header (P5), in case the user wants to attach an RS232 serial interface adapter. The UART signals are also routed to an RS422/485 transceiver (U3 = SN75176) to support external accessories via a serial bus. The initial release of clock firm- ware does not include any feature which uses the RS422/485 serial bus, so the transceiver (U3) and bus port connector (J3) may be omitted until such time as might be needed. Circuitry is provided to monitor the external DC supply voltage (+V EX ). If it drops below about 6 V, transistor Q1 will turn off and the logic sig- nal PWRON# will be in the High state due to a pull-up resistor in the MCU. The firmware moni- tors this signal and turns on an enunciator (PF) if the supply drops below minimum required volt- age. The signal PWRON# is also routed to the 5V switch-mode regulator IC (U2 = LM2594) EN# (enable) pin. If the external 9V power supply is removed, the 5 V regulator is shut down, allow- ing the +5 V rail to be energized either by USB power or battery power. The USB 'V bus ' line is sensed by the circuit of transistor Q2. If USB power is not present, Q2 turns off and signal VBUSD# will float High. The firmware reads this signal and adapts its operat- ing mode accordingly. The state of the USB V bus signal can also be used by the firmware to control one (or more) of the accessory control outputs. www.elektor-magazine.com March 2013 25 •Projects SI S2 S3 S4 TIMER CLOCK S5 MENU EXIT rill ©-IL RA1 HWW7 -WWV7 - J WW 7 ^rwwvf "-VWV7 "- j WWt- "“VWVf- ^ww 1 ALARM CHECK S6 SET OK ON/OFF ST H « SW8 SW7 SW6 SW5 SW4 SW3 TIME- SWITCH S8 w » +5V 0 SW2 SW1 8x 22k 16 Jo vcc SH/LD U1 CLK QH OH 74HC165 SER CLK INH GND U2.A TP1 O PI O Cd E < 2 O LL. CQ o- SIL-8 +5V 0 +5V +5V 0 EN PWMO (CEXO) MISO SCK SCK U2.C EN 10 MOSI SSDISP SENSOR +5V 0 AMBIENT (14) LIGHT SENSOR BPW85C R1 U2 0 U2.D C2 lOOn 12 EN U2 = 74HC125 +5V 0 PWMO MOSI SSDISP , U2.B EN V > 13 +5V 0 13 16 ^C3 ^ToOn RST SDI VCC U3 SCLK LCLK 74HC595 OE QA QB QC QD QE QF QG QH SQH GND 15 +5V 0 1 ASEG1 2 ASEG2 3 ASEG3 4 ASEG4 5 ASEG5 6 ASEG6 7 _ ASEG7 9 16 15 3 2 1 18 17 4 11 10 8 6 5 12 7 9 16 15 3 2 1 18 17 4 11 10 8 6 5 12 7 9 <1X10 0 CM CM CM moo 0" 0 nr-LL CC1 CC2 13 L 4 TlOOn ASEGO <0300 o :: o DSP-523E U CM CM CM moo o~o CC1 CC2 14 13 14 16 RST SDI U4 SCLK LCLK OE VCC QA QB QC QD QE QF 74HC595 QG QH SQH GND 15 1 1 2 2 3 3 4 4 5 5 6 6 7 Jl COM > U5 slL iiL ULN2003 17 07 GND .16 02 OL OO P2 a 1 2 1 J a sil-: 3 B T ! S9 ROTARY --> ENCODER K.- ! SWITCH 100149 - 12 r 0 0 ASEG7 H08 ASEG6 H07 44. H06 ASEG5 ASEG4 44 H05 0 ASEG3 0 ASEG2 ^j H04 „ 44_ H03 >4. ^ ASEG1 H02 ASEGO ^ H01 "PF" " SU " "SA" "FR" „TH" "WE" „TU" "MO" /~ /~ /~ ASEG7 H16 ASEG6 H15 ASEG5 44 H14 ASEG4 44. H13 ASEG3 4* 4k ASEG2 _ ^ H11 44_ H10 ASEG1 0 ASEGO >1 44_ ho9 colon 1 colon 2 "AL" "ON" "OFF" "PM" "24h" "sec" r 0 0 ASEG7 H24 ASEG6 H23 44_ H22 ASEG5 ASEG4 44. H21 ASEG3 /“ ASEG2 ASEG1 ASEGO 0 H2 ° ^j H19 „ H17 "S4" "S3" "S2" "SI" "A4" "A3" "A2" "A1" 2^ 3^ 5^ 6^ 7^ A Figure 4. Circuit diagram of the display board. Accessory logic inputs and outputs Six logic outputs are provided on the accessory sockets J4 and J5. The four time-switch outputs are active low (current sinking) control signals which can sink up to 50 mA each. These are intended to drive optocouplers (isolated inputs) in a solid-state AC power board. The alarm-switched 9V DC output is active high (current sourcing) and can source up to 500mA (limited by the resetta- ble fuse FI). The corresponding MCU output port pins are buffered with a CMOS hex-inverter (U4) because the port pins cannot source enough cur- rent to drive the inputs of the peripheral driver IC (U5 = ULN2003A). Two logic inputs are implemented by comparators U6C and U6D. The logic threshold is set to +1.6 V. The external inputs are buffered and filtered by RC networks to protect the MCU input port pins from nasty external transients (e.g. ESD). Analogue inputs The AT89c5131 MCU does not provide analogue (ADC) inputs. The clock application needs two ana- logue inputs to monitor the ambient light sensor and backup battery voltage. Analogue-to-digital conversion is implemented by a firmware algorithm, making use of a pulse-width modulation (PWM) out- put from the MCU to provide a variable reference voltage. A low-pass filter (R26, C21) removes the AC component (47 kHz) from the PWM pulse train, so that the DC level is controlled by the PWM duty. The PWM reference voltage is fed into the (-) inputs of two comparators U6A & U6B. The ana- logue input voltages to be measured are fed into the (+) inputs of U6A & U6B. By changing the reference voltage at periodic intervals, the firm- ware can determine the input voltages. Conver- sion accuracy is limited by the resolution (and linearity and noise) of the PWM-generated ref- erence voltage. About 1% error is the best we could hope for. Due to the filter time-constant, it takes a few milliseconds for the reference voltage to stabilize after a change in PWM duty. Conse- quently, the conversion time is quite slow com- pared to a hardware ADC. Fortunately, in this application, speed is not an issue. 26 March 2013 www.elektor-magazine.com Alarm Clock/Time-Switch Audio generator and power amplifier A square-wave oscillator is realized with a CMOS tinner IC (U7 = TLC555). The frequency of the timer audio output signal is controlled by switch- ing the resistance and capacitance of the RC tim- ing network. Eight different frequencies in the range 500Hz to 2kHz (approx.) are selectable by MCU logic output signals FREQ2, FREQ1 and FREQO. A CMOS quad analogue switch (U8 = CD4066B) is used to switch the resistors (R27, R29) and capacitor (C25) in or out of circuit. The chosen frequencies are harmonically related. Audio amplitude is controlled by a PWM signal generated by the MCU (CEX1), fed to the control input of analogue switch (U8D) which 'chops' the square-wave audio signal. The duty cycle of the PWM signal determines the effective audio output level. The PWM frequency is about 47 kHz; well out of range of human hearing and out of range of the speaker too. (The speaker itself acts as a filter to remove the 47 kHz PWM signal.) The PWM pulse duty is variable over a 256:1 range using the 8-bit duty register in the MCU. This is an adequate dynamic range for the application, but a 10-bit (or higher) resolution would have been really nice. The audio signal remains a square-wave (chopped at 47 kHz), right up to the speaker driver transis- tor Q6. Hence, the power amplifier is a class-D design. Transistor Q5 is necessary to boost the base drive current required to turn on Q6. The PWM analogue switch (U8D) is not capable of passing currents higher than about 2 mA. Using a class-D power amplifier not only provides higher audio output power level than a linear amplifier, but it has another major advantage in this appli- cation. When the audio generator is "muted" (by firmware putting the MUTE signal High), the PWM switch (U8D) is off and hence the output transis- tor Q6 is off, so there can be no current whatso- ever flowing in the speaker, no matter how much noise is present on the supply rail (+V IN ). This is a very important consideration for an appliance which may be sitting closer than 3 feet to your ears while you are trying to sleep. The audio level is updated by the firmware 'sound synthesizer' driver routine every two milliseconds. The firmware driver is capable of synthesizing an amplitude 'envelope' for the alarm sounds. User-settable parameters determine the attack (slope), sustain (time), release (slope) and hold- off (time), in similar manner to the analogue sound synthesizers of the 1970s (for which the author has a fond nostalgia). The hold-off time determines the interval of silence between suc- cessive plays of an alarm sound. (This is not the same as the 'snooze interval', which is indepen- dently settable.) In addition, the firmware provides a means to modulate the audio amplitude and/or frequency with (virtual) modulating signals, the period of which can be set to any integer multiple of two milliseconds (i.e. 2, 4, 6, 8 ... ms), up to 500 ms. In summary, a simple low-cost audio genera- tor circuit in combination with a smart firmware driver routine delivers a diverse range of appeal- ing sound effects (and some not so appealing!). Circuit description - display board The display uses a 4-digit 7-segment LED display because it is a low-cost solution giving adequate readability, and because the technology lends itself to variable-brightness capability. A white or multi-color backlit graphical LCD panel would have been more aesthetic, but the extra cost was considered unjustified, and continuity of supply of LCD panels can be an issue. Figure 4 shows that the 4-digit numeric display is realized using two 2-digit devices (Avago HDSP- 523X), available in three colours: red, green or yellow. Pin-compatible parts are made by other optoelectronics manufacturers. Backlit enuncia- tors are realized by 24 discrete LEDs, 5 mm round diffuse lens, of various colours. The 7-segment display and enunciator LEDs are multiplexed in a common cathode 7x8 matrix. The cathodes are driven (active low) by a 7-ele- ment peripheral driver IC (U5 = ULN2003A), which is just an array of seven Darlington tran- sistors with TTL/CMOS logic compatible inputs. The anode (segment) lines are driven by an 8-bit CMOS shift-register. Looking at the display sche- matic, astute readers will notice there are no current-limiting resistors in series with the anode lines. The design relies on the source resistance of the CMOS outputs (approx. 60 ft) to limit the LED current. The ULN2003 outputs have a minimum low-state voltage near 1 V (because of the Dar- lington configuration). The LEDs' forward voltage drop is about 2 V. That accounts for 3 V, which when subtracted from the 5 V supply, leaves 2 V on the CMOS outputs' equivalent resistance (60 ft). The LED peak current is therefore limited to about 33 mA (= 2 V/60 ft). Keep in mind the LEDs are multiplexed 8:1, and dimmed using PWM, so the peak current is www.elektor-magazine.com March 2013 27 •Projects Figure 5. Top view of completed main board. Figure 6. Top view of completed display board. allowed to be near the LEDs' maximum rating. The average LED current will be much lower than this — about 2 mA in normal viewing conditions. Variable brightness is achieved by applying a vari- able duty 47 kHz pulse waveform (PWM) to the Output Enable (OE#) input of the LED cathode driver register (U4). The range of PWM duty, and hence brightness, is 256:1. At minimum duty (1/256), the display is still bright enough to be readable in low lighting conditions. By the way, don't be tempted to fit blue or white LEDs for any of the enunciators. Their forward voltage drop is too high (typically about 4 V) to be used in this circuit design. 1 1 1 III i| 28 March 2013 www.elektor-magazine.com The LED display requires two 8-bit output ports and the push-buttons need an 8-bit input port. MCU I/O port expansion is realized by 8-bit CMOS shift-registers with parallel data latches and serial data transfer logic. The shift-registers are (almost) directly compatible with the MCU 'SPI' (serial peripheral interface) bus. With a tiny sprin- kling of "glue" logic, implemented by a quad tri- state buffer (U2 = 74HC125), the display output registers (U3, U4 = 74HC595) and button input register (U1 = 74HC165) connect easily to the SPI bus. Note that buffers U2A and U2B are wired to function as inverters, with the aid of pull-down resistors on their (tri-state) outputs. Inverting the polarity of the SPI clock signal (SCK) to the display registers allows the same SPI clocking mode to be used for simultaneous read (slave input) and write (slave output). Using the SPI bus minimizes the number of sig- nals required to interface the display board to the main board. The display and button regis- ters share a common SPI 'slave-select' signal (SSDISP#). The display registers are written and the button register is read in the same 2-byte SPI data transfer cycle. Since the button input register is only one byte wide, the second byte of the received data is ignored by the firmware. The slave-select signal SSDISP# is inverted to obtain a shift/load signal SH/LD#. While the input port is de-selected (SSDISP# High), parallel data are accepted by the input latch. During an SPI transfer, SSDISP# is put Low, SH/LD# goes High, so the input latch is inhibited and the serial clock is enabled, i.e. the input data is held constant while being shifted out. Output registers (74HC595) are comprised inter- nally of an 8-bit serial-in/parallel-out SR with an 8-bit D-type latch. Output pins are driven from the latch bits. Whenever the latch clock signal (LCLK) is pulsed, the rising edge causes the 8 bits in the internal shift register to be transferred to the output latch. While LCLK remains High, the bits in the output latch remain unchanged. Bits in the internal shift register change whenever any SPI transfer cycle (read or write) is executed, regardless of whether the SPI slave select signal is asserted or not. In other words, the shift reg- ister data will change when other devices on the SPI bus, if any, are selected and written to. This doesn't matter, so long as LCLK remains static while there is garbage data in the internal shift- register. Connecting LCLK to the display slave- select, SSDISP#, ensures the desired behaviour. Alarm Clock/Time-Switch The display board has a phototransistor (Q1 = BPW85C) which senses the ambient light level. The current flowing in the emitter resistor, and hence the voltage across it, increases with increasing illumination of the transistor junction. The emitter voltage is monitored by a comparator on the main board using a primitive analogue- to-digital conversion technique, as noted earlier. Provision is made on the display board for mount- ing a rotary encoder switch (S9). Project build- ers who choose to deviate from the 'standard' enclosure arrangement might want to relocate the encoder switch. This is easily done by cutting the display board into two pieces, separating off the smaller piece with the encoder switch. For this reason, wiring terminations to the encoder switch are separate from the other display board connections (8-way pad strip). Internally, the encoder switch has two sets of contacts which make and break as the shaft is rotated. Using pull-up resistors to the +5 V sup- ply rail, the two switch outputs (A and B) gen- erate square pulse trains in a quadrature phase relationship (i.e. 90 degrees out of phase with each other). Each output produces 24 pulses per revolution of the shaft, but the relative phases of the two pulse outputs is different (by 180 degrees) depending on the direction of rotation. A firmware decoding routine removes noise from the signals and keeps track of changes in the encoder shaft position. Assembly The assembly of the clock is described in detail in a document called Assembly Instructions which may be downloaded free of charge from the Elektor website [1]. The documentation package also contains BOMs. Due to space limitations, we are limited here to printing photographs of the assembled main board (Figure 5), display board (Figure 6), the connector line-up at the rear of the clock (Figure 7), and how the display board is mounted upright in the casing (Figure 8). You're invited! The firmware is richly annotated, and could serve as a useful example to Electronics Engineering, IT and Embedded Technologies students developing embedded real-time firmware projects, whether or not they build the 7-uP Alarm Clock. This project has the potential to spawn a number of spin-off projects, not only as accessories for the alarm-clock, but which could be used inde- 9V DC BATT. RESET LED USB RS422 ALARM TIME-SWITCH ISP INPUT ON/OFF ACCESSORY ACCESSORY pendently. Examples: Four outlet solid-state relay (TRIAC) AC power board; Low-voltage dimmable LED bed-side lamp; IR remote-control interface (forTV/AV equipment); PCM/MP3 add-on sound- effects board (with SPI link to MCU). The last three of these examples would require firmware updates for use with the clock. Also, Elektor readers active at the ElektorLabs community website [2] are expressly invited to develop a Windows GUI software application for use with the clock, e.g. for the purpose of edit- ing, saving and restoring alarm and time-switch schedules, option parameters, etc. Windows GUI software developer, please step forward. Note: The clock operates stand-alone — it is not dependent on Windows software. Please feel free to suggest any changes you think might enhance the appeal or utility of the project. Express yourself at ElektorLabs and be heard. (100149) Figure 7. There's an impressive array of connectors at the back of the 7-uP Alarm Clock. Internet Links [1] www.elektor.com/100149 [2] www.elektor-labs.com Figure 8. Showing how the display board is held vertically in the Pactec CM6-225 case. www.elektor-magazine.com March 2013 29 •Projects By Tony Dixon (UK) Raspberry Pi Prototyping Board Make the RPi do things... Your Thing! One of the more interesting aspects of the Raspberry Pi, unlike most conventional personal computers, is that it has a small and simple expansion header connector to which a user can directly connect their own interfaces and circuits. To aid in this, this article presents a prototyping board which can be used to make building your own interfaces and circuits for the Raspberry Pi easier. Figure 1. Not much of a circuit, this, but quite essential for serious prototyping with your Raspberry Pi. The Raspberry Pi is a bold and exciting develop- ment from the Raspberry Pi Foundation charity based in Cambridge in the UK. The Raspberry Pi Foundation [1] wants to bring tiny and afford- able computers to the children of today, with the jpi EXT INT JP2 REG INT 3.3V_rpi Q~ K2 5 V O * 3.3V_rpi 3.3V O- 1 SDA 3 SCL 5 ' GPI04 7 / 9 GPI017 11 ' GPI027 13 ' GPI022 15 / 17 MOSI 19 ' MISO 21 ' SCK 23 3.3V JRPI Q~ K3 5 V O 1 SDA ~r TxD RxD GPI018 GPI023 GPI024 GPI025 CEO CE1 3.3V O- SCL GPI04 GPI017 GPIQ27 GPI022 MOSI MISO SCK 11 13 15 17 19 21 23 T TxD RxD GPI018 GPI023 GPI024 GPI025 CEO CE1 3.3V < oooooooooooooooooo oooooooooooooooooo oooooooooooooooooo oooooooooooooooooo 120483 - 11 intention to re-ignite their interest in computer programming and all things technical. The Foundation have enjoyed enormous interest, support and help from both the educational insti- tutes (such as Cambridge University), electronic companies (RS and Farnell) and the software and maker development communities. "The Pi" (pronounce /pai/, not /pi/) has been said to be "the beeb" (BBC Micro) of the Inter- net age. Elektor was quick to spot not only the RPi's potential, but also one of its makers, Eben Upton, as you can read in an interview [2]. Circuit description The RPi Prototyping Board is a simple board, designed to break-out the expansion signals from the Raspberry Pi board and provide additional power for any circuit built in the prototyping area. Its pleasantly simple schematic is shown in Figure 1. The first thing the RPi Prototype board provides is an additional 3.3 V DC power supply source. The 3.3 V from the RPi expansion header can only provide a small current at around 50 mA, so if you want to build any circuits which need more than 50 mA, an additional 3.3 V power source will be required. On the RPi Prototyping Board, this is provided by IC1 which is an LD1117 linear 3.3 V regula- tor. This can be either powered from an external or internal DC power source, with the selection made on jumper on JPI. The LD1117 can pro- 30 March 2013 www.elektor-magazine.com RPi prototyping board vide up to 800 mA if needed with an appropriate heatsink secured to it. If jumper JP1 is set to 'INT' (internal then IC1 is powered from the 5 volts line directly from the Raspberry Pi board. If JP1 is set to 'EXT' (external), then external power from a 9-12 V DC power adapter ("wall wart") is fed to IC1 through a standard 2.1 mm jack plug (center pin positive, outer sleeve 0 V) through diode Dl. Jumper JP2 will need to be set to 'REG' (regulator) position. Capacitors Cl and C2 act as noise suppression devices on IC1, and C3, as a small reservoir. The second thing the RPi Prototyping Board pro- vides is an easy means to access the signals from the Pi's expansion header connector. A second connector K2, breaks the Raspberry Pi signals out, allowing the user designed (yes, your!) cir- cuit to easily connect to them. One final note on the circuit, if a small circuit design is being prototyped that doesn't need more than 50 mA from the 3.3 V supply then jumper JP2 allows the 3.3 V prototyping power rail to be connected directly from the Raspberry Pi board itself. To do this set JP2 to 'INT'. With the capacitors and power connector sol- dered, solder he regulator IC1 next. Finally sol- der the connector K2. This needs to be mounted on the solder side of the PCB to allow the RPi Prototyping Board to be mated with a Raspberry Assembly Assembly for the RPi Prototyping Board is straightforward. Using the PCB layout pictured in Figure 2, solder the small components first, that's Dl, Cl, C2, JP1 and JP2. The slightly larger components K1 and C3 should be soldered next. Figure 2. A prototyping board is like a tennis lawn: just waiting to be played on. www.elektor-magazine.com March 2013 31 •Projects & k0 d U © V K? W i 1 U -i b|Doe&«esaeeflfl ~ ( O L I i?k E O' ^ ^ (J 0 O © Q G O G @ O : ' 1 20^93- L COOOOQQOOOQQ i it n - + ■ U 000000000 0-00 OOOOOGoooqoo 00-0 000000000 ooooooooooooooo OOOOOOOOOOOOOOO ooooooooooooooo ooooooooooooooo ooooooooooooooo ooooooooooooooo ooooooooooooooo ooooooooooooooo ooooooooooooooo ©GOQOOGOQOOOOODGOO ooooooooooooooo ooo T flOflOOOOOOOOQOOOOOO 1 oooooooooocooooooc ooaooooooooooooooo ooooooooooooo o o o~j” ■ 1 ' GOO e o « o o o ooe Q o O ODD o o o goo ooo o o o o o o ooo AAA Gee Sfi « ooo o & a ooo ooo ooo o o o ooo ooo ooo u - * ■ 5 I y m O O - j yy spc hose rm i-?-" &<■+ nlM JiJ Mw *a, D D; 2 j Q, Ll O. 0 , (J. • • • DO O 0003# ill ex; ios , iK-Wi a-L CCC MS ID-' IDl Jo* * 0 *, 1-L 3 jic: * 5 y PCI Figure 3. Impeccable construction courtesy of Luc @ Elektor Labs. Note that the PCB silkscreen pertains to Rpi Revision 2. Pi. K3 is not a connector but a set of solder pads where you connect the signals you need for your experimental circuit. Feel free to solder pins in the relevant holes. The choice of component for connector K2 is important. The Raspberry Pi is a very compact board and has a number of raised components, namely the RJ45 Ethernet connector (height = 13 mm), RCA Composite Video connector (height = 13 mm) and Dual USB connectors (height = 17 mm), which have the potential to mechani- cally interfere with any expansion boards con- nected to it. Therefore, for the RPi Prototyping board to be mated successfully with a Raspberry Pi, connector K2 should have a total height of not less than 10 mm. The connector specified for K2 has a height of 10.8 mm, this together with the height from the standard 0.1" pinheader fitted to the Raspberry Pi brings the standoff height to 13 mm. This is sufficient to just clear the RJ45 and RCA connector of the Pi. A rectangular clear- Figure 4. Circuit diagram of the RPi Blinking LED Demo hardware. All the real power is in the software! GPI017O GPI018O GPI022O GPI023O GPI024O GPI025O GPI027O GPI04 O IC1 +vs 10 VEE 18 R1 17 R2 16 R3 15 R4 14 R5 ww A/WV m m D1 13 R6 ft M dTjJ dTjJ dTJJ 3.3V © 12 R7 11 R8 A/WVJ . AM/V^i* A/WV 8x 330R 9 ULN2803 + * 120483 - 12 ance is provided on the RPi Prototyping Board to avoid mechanically interfering with the Raspberry Pi's USB connector. All done with your soldering? Then compare your work with the proto - prototyping board pictured in Figure 3. Using the board — generalities A couple of things to remember about the Rasp- berry Pi expansion header are, firstly, the sig- nals from the RPi expansion header are 3.3 V only and are not 5 V compatible, so be careful what you connect in the way of voltages to them. Secondly, the current the RPi signals can sink or source is small, at around 8 mA, so again be care- ful what you connect, don't connect anything that needs a lot of current because it's not going to get it. If you need to source or sink more, then use a buffer chip such as 74LVC245 to provide additional source/sink current capa- bilities, or just provide 5 V compatibility. An RPi LED blinking demo Whenever Elektor publishes about microcon- troller boards, readers appear to be divided in two camps. A typical Camp #1 member says: "I am invariably smarter than you, but I've never published anything myself. No example applica- tion for me." From Camp #2 may be heard: "I'm not buying or building anything micro without a fully illustrated application, so yes, please show it to me". To complicate things, both Camp #1 and #2 members may choose to a) not tell anyone, b) tell their peers only, or c) widely disseminate their opinion in forums, tweets, etc. Add vari- ables like language, print or online, age 16 or 66 — and you get an interesting matrix. The following example is for all of you who want to delve into the basics of controlling stuff with an RPi, be it a few LEDs, as shown in Figure 4, or a minibar in a girls-only limousine with GPS tracking, slowly cruising Lower Manhattan. Your imagination is the only restricting factor. Why? Because software is involved. This project shows a ULN2803 8-channel Dar- lington Array driving a set of LEDs. Just as it's the tradition for your first program on a new sys- tem to display "Hello World", so it's the tradition on any new hardware project to flash an LED to show it all works. So keeping up with these tradi- tions Listing 1 shows a simple Python program to control the LEDs. 32 March 2013 www.elektor-magazine.com RPi prototyping board Says Eben Upton, Raspberry Pi co-creator & prophet Q: Whence the name? A: We wanted to have a computer especially for Python, and there is a great tradition of naming computers after fruit: like Apricot, Acorn and even today there are computers named after fruit. So Raspberry is following the line of a rich tradition with the Pi, and yes, we wanted this connection with Python. That is where the Pi comes in. Q: The Raspberry Pi is a bare PC board; no keyboard, no HD, no screen... how will this product become successful? A: Basically, there is no reason why a computer has to cost more than $50. The peripherals like a screen and keyboard and stor- age will create a higher price, but with the Raspberry Pi we have taken another route — a normal TV can be used as a screen. Combine that with a 'charity shop' keyboard for a few dollars and you have a full working system. The Raspberry is specifically aiming at youngsters learning to program. (reproduced from Elektor, April 2012) This program uses a Python GPIO library to give us access to the GPIO pins. If you've not already downloaded the Python development tools or Python GPIO library, then using an LX Terminal on your Pi, we'll type the following commands. First, however, we'll download the Python devel- opment tools by typing sudo apt-get install python-dev In order to access the Raspberry Pi GPIO port we need to download and install the GPIO package. Type the following: wget http : //pypi . python . o rg/packages/ sou rce/R/RPi.GPIO/RPi. GPIO -0.4. la . tar . gz Once downloaded, we'll need to extract the files. Type tar -zxf RPi.GPIO-0.4. la.tar.gz Once extracted a new a directory will be created with the Python files in. Now type cd RPi.GPI0-0.4. la Now we'll install the package by typing sudo python setup. py install Once that's done we should have the Python GPIO library installed. On your Pi, using either IDLE Listing 1: Blinky.py # !/usr/bin/python import time import RPi. GPIO as GPIO # Configure Pi's GPIO pins GPIO.setmode(GPIO.BCM) pins = [17,18,22,23,24,25,21,4] for pin in pins: GPIO. set up (pin, GPIO. OUT) # Program loop while True: for pin in pins GPIO. output (pin, True) time . sleep(0 . 01) GPIO . output (pin , False) time . sleep(0 . 01) www.elektor-magazine.com March 2013 33 •Projects More RPi circuits and applications shortly in the Elektor.POST newsletter type the program as shown in Listing 1. Looking at the program, Setmode defines the numbers used to address individual pins. The instruction GPIO . setmode(GPIO . BCM) employs the sym- bolic names assigned to the RPI's I/O lines. In this case the following eight pins are employed in the array called 'pins': GPI017, GPI018, and GPI022 through GPI04. Note that the alloca- tion follows the RPi PCB Revision 1. Here, schematic label GPI027 is indicated as '21' , i.e. the older I/O numbering. Next, GPIO. setmode(GPIO. BOARD) sets up a direct link between the 10 lines and the physi- cal numbering of expansion connector on the Rpi board. Using this setting, the pin array looks like this to achieve the same effect on the LEDs: pins = [11,12,15,16,18,22,13,7] Once you've typed the program, save it as 'Blinky.py', switch to an LX Terminal and type the following command to make your program an executable: Raspberry Pi Expansion Header Table 1. Expansion Header Pin Out Pin Name Pin Function Alternative Pl-02 5.0V - Pl-04 5.0V - Pl-06 GND - Pl-08 GPI014 UART0_TXD Pl-10 GPI015 UART0_RXD Pl-12 1 GPI018 PWMO Pl-14 GND - Pl-16 GPI023 Pl-18 GPI024 Pl-20 GND - Pl-22 GPI025 Pl-24 GPI08 SPI0_CE0_N Pl-26 GPI07 SPI0_CE1_N Pin Name Board Revision 1 Board Revision 2 Pin Function Alternative Pin Function Alternative Pl-01 3.3V - 3.3V - Pl-03 2 GPIOO I2C0_SDA GPI02 I2C1_SDA Pl-05 2 GPIOl I2C0_SCL GPI03 I2C1_SCL Pl-07 GPI04 GPCLKO GPI04 GPCLKO Pl-09 GND - GND - Pl-11 GPI017 RTSO GPI017 RTSO Pl-13 GPI021 GPI027 Pl-15 GPI022 GPI022 Pl-17 3.3V - 3.3V - Pl-19 GPIOIO SPIO_MOSI GPIOIO SPIO_MOSI Pl-21 GPI09 SPIO_MISO GPI09 SPIO_MISO Pl-23 GPIOll SPI0_SCLK GPIOll SPI0_SCLK Pl-25 GND - GND - Notes: 1. GPI018 (Pin 12) supports PWM output. 2. 12C0_SDA0 and I2C0_SCL0 (GPIOO & GPI01) have 1.8K pull-up resistors to 3.3 V. Referring to K2 in the schematic, the Raspberry Pi expansion interface is provided by a simple double row, 0.1" (2.54 mm) pinheader connector giving the little computer 26 expansion signals. These signals fall into one of three categories: 34 March 2013 www.elektor-magazine.com RPi prototyping board chmod +x blinky.py Once done, you can run your program by typing the following command: sudo ./blinky.py With a little more code we could just as easy show CPU temperature or Network activity on the LEDs. Conclusion The Raspberry Pi PC offers enormous program- ming and software development potential for lit- tle money. The prototyping board described in this article allows the more hardware oriented electronics enthusiast to make the RPi do useful things in the real world. If you develop an RPi application everyone should know about, then do not hesitate to e-publish at www.elektor-labs. com. And don't forget to download that free Rpi poster from www.elektor.com/poster. ( 120483 ) Internet References [1] Raspberry Pi site: www.raspberrypi.org [2] Eben Upton interview: "What are you Do- ing?", Elektor April 2012; www.elektor-magazine.com/120228 [3] www.elektor-magazine.com/120483 Figure 5. The experimental circuit laid out in the prototyping area and connected up to the RPi through expansion signal connector K2. Table 2. P5 Header (Revision 2 Boards only) Power: +5 V DC and 3.3 V DC* as well as 0 V Input/Output: General Purpose Input/Output (GPIO) signals Communications Interfaces: Serial UART, SPI and I 2 C * Note: 3.3 V can only provide about 50 mA of current. There are 17 general purpose input / output (GPIO) signals on the expansion header. Most of these can have alternative function. These alternative functions provide a UART, SPI and I 2 C interfaces. Each GPIO pad can source between 2 and 16 mA depending on its drive strength configuration. The drive strength is set in a configuration register and by ^ default after reset the source current is set to 8 mA. In addition to the PI Expansion Header, Revision 2 of the Raspberry Pi saw the introduction of a second, smaller expansion header, designated P5 (see Table 2). This adds another four GPIO signals but more importantly allows access to the PCM audio interface of the Broadcom 2835 chip. Also, the signals for PI Expansion Header were slightly revised on the revision 2 boards, see Table 1. Notably, the I2C0 interface was replaced by the I2C1, a small but important thing to remember if you are planning to interface I 2 C devices. Pin Name Pin Function Alternative P5-01 5V0 P5-02 3.3V P5-03 GPI028 PCM_CLK P5-04 GPI029 PCM_FS P5-05 GPIO30 i — i Q 1 U CL P5-06 GPI031 PCM_DOUT P5-07 GND P5-08 GND www.elektor-magazine.com March 2013 35 •Projects Use your PC for measurement, control and data conversion tasks the easy way By Dr. Ing. Uwe Altenburg (Germany) Transferring up to 24 digital signals using your com- puter's USB interface is simple with the multifunction cable described here. You can also sample up to eight analogue signals, generate PWM and servo signals and more besides. This article offers a simple protocol for controlling the cable and covers PC programming in the C# language as well. USB-I024 Cab e These days you can get computers in every imaginable form — be they desktops, laptops or tablets. A welcome side effect is that prices have fallen, meaning that people who a few years ago would employed a redundant Mini-Tower computer to control the lighting of their beloved aquarium can now do the same with a micro-sized Box PC and develop a neat control panel with touch-screen control. Having said this, hooking up your homebrew electronics to a PC using USB connectivity is not exactly child's play and a computer would not be one's first choice for generating time-critical signals. On top of this you will need to select a communications protocol and find a suitable programming language. 36 March 2013 www.elektor-magazine.com USB-I024 Cable COMPONENT LIST Resistors (SMD 0805, 5%) Rl= lOOkft R2 = 4.7kft R3 = 100ft Capacitors C1,C2,C5 = lOOnF 50V, 10%, X7R, SMD 0805 C3,C4 = 22pF 50V, 5%, NPO, SMD 0805 Semiconductors D1 = LL4148 (Minimelf) IC1 = R8C/25 (SMD TQFP52) Miscellaneous USB/TTL Adapter cable TTL-232R-5V-WE, Elektor # 080213-71 [6] K1 = 25-pin Sub-D socket (Amphenol type 77SD B25S) K3 = 10-way MicroMatch connector, with under- side solder connections (TE Connectivity/Am p type 8-215079-0) XI = 18.432MHz quartz crystal, 18pF, 50ppm Shell for 25-pin Sub-D connector, flip top (Assmann type A-FT 25) Optional 10-way MicroMatch plug (8-215083-0 TE Connectivity/Amp) Figure 1. There's more than enough room for the PCB inside the housing of the Sub-D connector. No problem — all these challenges are solved here! Circuit For some years a USB/TTL converter cable (the TTL-232R-5V-WE [1]) has been sold by FTDI. It is also available from Elektor [2]. Using this cable, which besides RxD, TxD, RTS and CTS signals also provides a 5 V supply voltage, it is extremely easy to connect a microcontroller to a PC. The cable contains an FT232R USB-to- serial converter, located within the epoxy-potted USB connector. The idea springs to mind that you could attach a 25-pin Sub-D socket at the other end of the cable, with a second micro- controller inside the connector housing there. The 8-bit microcontroller employed here is a derivative of the R8C family, which has been featured already in Elektor many times. The R8C25 [3] has adequate memory resources with 64 KB Flash and 3.5 KB RAM. Its 10-bit analogue converter and high-performance timer structure make it ideally suited for control tasks. The 25 connections of the Sub-D connector are sufficient to make all the pins of three controller I/O ports and the necessary ground connection available externally. There is sufficient room in the connector shell to install a small PCB with the dimensions 37x20 mm (Figure 1). Besides the microcontroller there is little else on the board: only an 18.432 MHz crystal, a programming con- nector and a handful of discrete components. The plan is to offer the PCB ready-assembled (more about this on the web page for this article [6]). All you do with the PCB is solder it onto the FTDI cable and then fit this assembly inside a suitable connector housing. In terms of circuitry (Figure 2) there are few items of note. The microcontroller takes its power over the USB cable. The RTS wire of the USB- Characteristics • 24 digital in/outputs or alternatively up to • 8 analog inputs (10-bit resolution) • 8 PWM outputs (10-bit resolution) • 8 RC servo signals (10-bit resolution) • 4 counter inputs (16-bit up/down) • 2 ICs MAX7219 selectable for up to 128 LEDs www.elektor-magazine.com March 2013 37 •Projects +5V Figure 2. Besides the microcontroller you need just a crystal and a few discrete components. serial cable is connected via diode D1 to the reset pin of the microcontroller. This enables you to initiate a hardware reset of the microcontroller over the USB interface. The TxD and RxD signals of the USB-serial cable are used for communica- tion between the PC and microcontroller. Ports PO to P2 of the microcontroller are taken to the Sub-D connector (Figure 3). This makes all the essential signals of the microcontroller available for use. The pins of PortO can be configured as analogue inputs, enabling up to eight analogue signals to be sampled. In line with standards, the reference voltage input of the analogue-to-digital converter is linked via an R-C combination to the 5 V sup- ply, which provides a measurement range from 0 to 5 V with adequate accuracy. However, for situations when you place a value on higher accu- racy in the measurement of analogue signals, an LM4040 reference voltage source IC can be fitted in addition. Alternatively Portl offers up to four interrupt inputs, which would enable, for example, high- speed counters to be realized. There is addition- ally a serial interface on Portl that can be used in UART and SPI modes. The outputs of the two 16-bit timers of the R8C25 are on Port2. These enable you to generate up to eight PWM signals simultaneously. A PWM signal can be used, for example, for rotational control of DC motors or to generate analogue signals. Altogether our USB 1024 cable provides a mul- titude of possibilities! Right then, how does the software check out now? Firmware The author has produced firmware for the control- ler that makes driving it with a PC very straight- forward (the controller on the ready-built PCB is preprogrammed with this firmware). Data trans- fer between PC and microcontroller take place at a data rate of 115,200 baud with 8 data bits, 1 stop bit and no parity (115200, 8, N,l). Instead of a binary data protocol with a fixed for- mat (comprising, for example, type and length of data plus checksum) we use simple text com- mands for communication. This approach is flex- ible and simple to understand, rendering the com- munication extremely Transparent' and obvious. To compose commands we need nothing more than a simple terminal program, which makes the whole affair independent of the operating system used. Following reset, the microcontroller begins with initialization. There is not a lot to do at this stage 38 March 2013 www.elektor-magazine.com USB-I024 Cable because the exact function of the ports and tinner is determined later on by the commands. All that needs to be initialized right now is the clock gen- eration and naturally the serial interface for con- nection to the PC. Beyond this the main program consists only of an endless loop — the Command Interpreter (Listing 1). In this a command is formed of a sequence of ASCII characters, followed finally by a CR (Carriage Return). More precisely, sev- eral commands can follow one another and only the last one needs to be finalized with a CR. This provides greater flexibility for applications. The character string X10 PO.O=l P0.0=0 is therefore a valid command and means: "Set PortO. 0 to 1 and back again 10 times". The function ReadCmdO reads in a command sequence up to the CR. All blank characters are removed from the sequence using SkipBlanksO and following this, the function Execute () is otherwise a null. According to the outcome either invoked. If the function of each command can OK or ERROR is then transmitted back to the PC. be executed successfully, a positive value is given, Execution of a command sequence can take some Listing 1. Main routine with command interpreter. // — Main — VOID main( ) { InitCrystal ( ) ; // init crystal InitUartO; // init uart El; // ints SendString("\xCPIOCable VI . 5\r\nOK\r\n") ; // version for ( ; ; ) // endless . . { ReadCmd( ) ; // read command SkipBlanks ( ) ; // remove spaces if (ExecuteO) // execute commands SendSt ring ("\r\nOK\r\n" ) ; else SendSt ring ( "\ r\nERR0R\ r\n" ) ; } } Listing 2. Interpretation of port commands. // — Macros — #define Digit(p) (*p++ - '0') // get a digit #define Getlf(p,c) (*p == c ? p++, 1 : 0)// get if char // — Read port — BYTE GetPort (BYTE nPort) { switch (nPort) { case 0: return pO; // P 0 input case 1: return pi; // Pi input case 2: return p2; // P2 input } } // — Write port — VOID Set Port (BYTE nPort, BYTE nBits , BYTE nMask) { BYTE nSet = nBits & nMask; switch (nPort) { case 0: pO = p0 & -nMask | nSet; break; // p0 output case 1: pi = pi & -nMask | nSet; break; // pi output case 2: p2 = p2 & -nMask | nSet; break; // p2 output } } // — Port command [Pn | Pn=v | Pn . b | Pn . b=v | Pn~ | Pn . b~] — BOOL PortCmdO { BYTE nPort = Digit(pCmd); // port BYTE nMask = OxFF; BYTE nPin = 0; if (Getlf (pCmd, ' . ' ) ) { nPin = Digit ( pCmd ) ; nMask = 1 « nPin; } if (nPort <3 && nPin < 8) { BYTE nValue; if (Getlf (pCmd, '=' ) ) { nValue = GetValueO « nPin; Set Port (nPort , nValue, nMask) ; } else if (Getlf (pCmd, '-') ) { nValue = GetPort (nPort ) ; Set Port (nPort , -nValue, nMask) ; } else { nValue = GetPort (nPort ) & nMask; nValue = nValue » nPin; SendValue(nValue) ; } return TRUE; } return FALSE; // // pin // mask // check // ' = ' // value // set port // // get port // set invert // get port // get value // send value www.elektor-magazine.com March 2013 39 •Projects Table 1. Summary of commands supported A to An n = 0 to 7 Configure Pin An as analogue input. Analogue values returned in the range 0 to 1023. C to Cn, C n - x n = 0 to 3 Return/set current value of counter CNTn, in the Cr?+, Cn- x = 0 to 65535 range 0 to 65535. Use + or - to determine count direction. P to P n, P n = x n = 0 to 2 Read/write to an 8-bit wide Port (or an individual P n.b, P n.b = y P n~, P n.b~ b = 0 to 7 x = 0 to 255 y = 0 to 1 Pin). Use ~ to select between Port and Pin modes. S to Sr?, S n = x n = 0 to 7 x = 0 to 1023 Program one of the PWM Pins as output of the RC servo signal. Mid-position of the servo is when x = 512. W to Wr?, \Nn = x n = 0 to 7 x = 0 to 1023 Program one of the PWM Pins as output of a pulse- width signal. The pulse-width has a range from 0 to 1023. D to Dr? = n = 0 to 1 Control a MAX7219 device, to which up to 64 LEDs x,x,x,x,x,x,x,x x = 0 to 255 can be connected. Simultaneously 8 data bytes y x' are sent. R to Rr?,Rr? = x n = 0 to 6 x = 0 to 255 Rec R0 R1 R2 R3 R4 R5 R6 R7 ad/write to the access control register: Data flow direction from P0, 0=Input,l = Output Data flow direction from PI, 0=Input,l=Output Data flow direction from P2, 0=Input,l = Output reserved PWM frequency, 0=1 kHz, 1=2 kHz, 2=4 kHz PWM time delay, from 0=none to 99=slow Brilliancy 1. MAX7219, from 0=dark to 1 5 = brig ht Brilliancy 2. MAX7219, from 0=dark to 15=bright. T to T n n = 0 to 6500 Time delay of n * 10 ps. X to Xn n = 0 to 65535 Repeat all instructions in the command line following the X symbol n times. ? ? Display a summary of all commands implemented. time. During this period additional characters can already be transmitted across the serial inter- face by the PC, however. With the baud rate of 115200 baud set, transmitting a character takes a mere 90 ps! For this reason reception takes place in an interrupt routine that deposits the characters in a ring buffer. ReadCmdO then reads the characters out of the ring buffer. The commands that are possible are distinguished or differentiated by their first character. So the port command starts with a P, polling the ana- logue inputs with an A, setting a counter with C and so on, with either capital or small letters allowable in each case. For each command there is a special function in the code that recognizes the syntax feasible. Listing 2 gives the functions for the port command. In the most straightforward case the current state of a port is sampled using PO , PI or P2. The inter- preter sends back the result as a numeric value from 0 to 255. To alter the state of a port you can also assign a value to it (PO = 0 to 255). The function PortCmdO knows whether it is in assign- ing or sampling mode by the " = " symbol. This also makes it possible to address individual bits of a port. To do this you suffix the port number with the pin number PO.O, P0.1 to P0.7. Another function here is the symbol, which indicates 40 March 2013 www.elektor-magazine.com USB-I024 Cable whether the entire port is intended or just one pin. Finally the command can also toggle a port pin — this is done by including (P0.0~). Command set The port commands already described provide an extremely effective means of controlling a digital I/O card with relays and optocouplers. However, we have not yet configured the data flow direc- tion of the individual pins of the USB 1024 cable. Following a reset all pins are programmed to be inputs. This factor needs to be taken into con- sideration at the outset when developing your own hardware — the output stages must take up a fixed state unconditionally. The command R allows various control registers to be addressed (written to). Registers RO, R1 and R2 contain the data flow direction of the three ports. Bit 0 of RO determines the data flow direction of pin PO.O, Bit 1 determines that of pin PO.l and so forth. Digit 1 indicates output and a 0 signifies input. The command RO = 15 switches the data flow direction of the lower four pins of PortO to output. Alternatively you can also write RO = $OF or RO = %00001111. The dollar symbol indicates hexadecimal numbers and the percent sign binary figures. Table 1 sets out all currently supported com- mands for the USB 1024 cable. As well as the commands for ports and registers already mentioned there are also further, rudimentary commands. For sensor applications the command A is defi- nitely vital for sampling the analogue inputs. Up to eight analogue values can be digitized. The corresponding pins AIO to AI7 do not have to be configured additionally — they are automatically programmed as analogue inputs the first time you type the command An. Since it is in principle possible to transmit several commands at once, it is also possible to sample multiple analogue inputs with a single command. The command sequence AO A1 A2 polls the first three analogue inputs and sends their value as the response. Multiple values in a response are always separated by empty spaces. The equivalent of an analogue input would be an analogue output. It is true that the micro- controller employed does not support analogue outputs directly but we can generate up to eight analogue values nevertheless by using the work- around of producing PWM signals. PWM signals are turned on with the command Wn. As with the analogue inputs, no extra configuration is required; however, you can also set the PWM frequency in control register R4. To derive an analogue value from a PWM signal we need a low-pass filter. An R-C combination is sufficient in the simplest of cases but it is better to use an opamp to construct a higher order low-pass, for example a Butterworth filter. Using the commands presented so far it is already feasible to cover many standard applications with digital or analogue in and outputs. If you reckon that theoretically up to 127 USB 1024 cables could be connected to a computer, this would provide 127 x 24 = 3,048 digital inputs and outputs! All the same, every once in a while special solu- tions are required for those challenges that occur occasionally in the realm of DIY electronics. For those alone additional powerful commands are implemented, which we will deal with shortly along with sample applications. Instructions for RC servos Servo motors, used widely by radio-controlled model aircraft hobbyists and available with all manner of power capabilities, have recently met approval also for robotics projects, model rail- roads and other mechanical applications. They regulate their position against a predetermined set point. The set point for RC servos is coded as a pulse with a width of 1 to 2 ms, repeated every 20 ms (Figure 4). To produce this pulse sequence is a task that cannot be handled directly by a PC. The timing is extremely critical — particularly the pulse width. Even slight jitter causes clearly audible buzzing in the servo (and tied up with this, raised power consumption). For this reason we have a special 20ms - A <-> - 1...2ms >t K1 PO.l /All 2 -o r\ P0.2/AI2 3 U r\ P0.3/AI3 4 u r\ P0.4/AI4 5 yj r\ P0.5/AI5 6 U r\ P0.6/AI6 7 u r\ P0.7/AI7 8 yj r\ P1.0/CNT0 9 U r\ P1.1/CNT1 10 u P1.2/CNT2 11 r\ P1.3/CNT3 12 U r\ GND 13 u -o o- A 15 P2.6/PWM6 yj A 16 P2.5/PWM5 U A 17 P2.4/PWM4 U A 18 P2.3/PWM3 yJ A 19 P2.2/PWM2 U A 20 P2.1/PWM1 U A 21 P2.0/PWM0 yJ A 22 PI. 7 U A 23 P1.6/ DATA U A 24 P1.5/CLK u o- 25 PI .4 /LOAD SUB-D 25 Figure 3. Pinout of the Sub-D connector. Figure 4. Pulse sequence for RC servos. www.elektor-magazine.com March 2013 41 •Projects Figure 5. PIOCable-Tool PC software Figure 6. Demo application in C#. command Sn, which can generate up to eight servo signals as an alternative to PWM signals. It is also possible to produce both PWM and servo signals simultaneously. However, the timer struc- ture in the R8C25 means that four pins of Port2 must always share the same timing — so that pins P2.0 to P2.3 generate PWM signals, whilst pins P2.4 to P2.7 take care of servo signals. The newer RC servo motors are distinguished by their very fast setting speed. In principle this ly/i < - i III V i-a __ OWJiVuta UpdHn Hufe Abwt PTOC Jhlp” Ik rWFF riK rJL*itiO Update... * L> software reran... ■0K <1*. | ’ JuAtJ PEOQWi VI. 5 P'-lpipi' nn: p'S-Yiaioisio •0* pCI pi iro o i? TfiT OK ■ Bilk IJi.Tt j »| Canfcnl nOQbit nD^NictJ .ti uM? is an advantage, although not for intentionally slow movements, where very many set points need then to be provided. Doing this produces a kind of judder in the servo mechanism, how- ever, leading to substantial oscillations in a robotic arm for instance. For this reason con- trol register R5 allows the setting speed to be reduced specifically. The delay is introduced directly into the pulse generation process and reduces the amount of judder in the servos quite significantly. The value set in R5 affects the generation of PWM signals simultaneously. Position or rotational speed The control of low-power DC motors, as used in many projects, is a wide subject. At the simplest level a bipolar (or for higher currents, a field effect transistor) will suffice, and if the direction of travel needs to be reversed, also a relay or a bridge rectifier. The rotational speed can then be varied with the help of a PWM output. Difficulties begin when we want to control the rotational speed or advance to a precise position. This requires us to provide a feedback pulse generator on the motor shaft, for example an optical timing disk that interrupts a light beam. The pulses (leading edges) must then be counted. Aggregating this count delivers the position or, referenced against a time interval, the rotational speed. Both can be determined using the com- mand Cn. The USB 1024 cable possesses four inputs CNTO up to CNT3, which in each case can be linked to a 16-bit counter internally within the controller. The command CO+ activates the counter input CNTO, with the counter counting upwards), whereas CO- causes it to count downwards. The counter position can be read out using CO. The direction of count can be toggled at any time, without affecting the current count. This makes it possible for the counter to always reflect the current position of a motor shaft. All you need do is change the direction of count before revers- ing the motor direction. On the other hand, to determine the rotational speed, you reset the counter to 0 with CO =0 and read out the counter again after a suitable time. The count value is then a measure of the rotational speed of the motor. LED displays In the MAX7219 [4] Maxim provides universal circuitry for controlling up to 64 LEDs. Apart from a resistor this requires no other wiring. Elektor has already produced a 7-segment display for general application using this chip [5], although people frequently produce matrix displays as well. Two of these chips can be connected to our USB 1024 cable cascaded in series. This makes it pos- sible to control up to 128 individual LEDs (or two 8-element numeric displays or even combinations of the two). The data is transmitted to the dis- plays serially. To achieve this all we need do is 42 March 2013 www.elektor-magazine.com USB-I024 Cable connect the three DATA, CLK and LOAD wires to the pins of the same name on the MAX7219. The command Dn then transmits eight data bytes at once — e.g. D0=48, 109, 121,51,91,95,38, 105. The MAX7219 deposits the bytes sequentially in its Digit 0 to Digit 7 registers; each bit corre- sponds to an LED connected. The exact correla- tion can be found in the data sheet for the chip. PlOCable Tool How tricky is it to commission the cable? Where do you find the necessary drivers? To test the functions do you need to write a program first? These are all typical questions when you want to hook up some new hardware to your PC. Luckily putting our USB 1024 cable to work is extremely easy. When you connect the USB plug into the PC, Windows searches for a suitable driver. With the drivers provided by FTDI you generally don't need to take any further action (assuming you are connected to the Internet) because they are installed automatically. In case of difficulty the FTDI website has some instructions for install- ing the VCP drivers necessary (VCP = Virtual Com Port). Next you start up the PC program PIOCable-Tool, which was produced specially for commissioning and testing all of its functions (Figure 5) and can be downloaded from the web page for this article [6]. The source code for PIOCable-Tool can be found here too. The tool was produced using Delphi XE2 — essentially you should also be able to interpret the code with earlier ver- sions of Delphi. When you activate the software and click on the Connect button, a search for the cable is made automatically. If the search is unsuccessful you will need to look in Device Manager to find out which COM port addresses the cable and then enter this manually in the PIOCable-Tool program. The PIOCable-Tool software is fundamentally a so-called terminal program. All inputs are trans- mitted direct to the USB 1024 cable's microcon- troller, which for its part responds immediately. This means you can enter all commands manu- ally and at the same time check the reactions on each pin (using a 'scope for example). The development of the cable firmware is ongo- ing, meaning it is possible to install new software versions on the microcontroller using PIOCable- Tool. The microcontroller on the ready-built PCB is equipped with a bootloader. Further software updates will be found both at Elektor [6] and also on the author's TinyBasic website [7]. If you wish to run firmware that you have devel- oped yourself, the bootloader can of course do this for you likewise. The High-Performance Embedded Workshop development environ- ment together with the matching C compiler can be downloaded from the Renesas website [8]. The controller can also be programmed with- out a bootloader, given a suitable program- mer. In this case you will need to make up a small adapter cable that is fitted with a MicroMatch connector (see Optional sec- tion of compo- nent list). The bootloader (and the orig- inal firmware) are naturally overwritten by conventional programming. Demo application For simple applications (perhaps like a servo tester) entering the commands with the aid of PIOCable-Tool would be adequate. For all other applications it would of course be sen- sible to produce suitable PC software that then transmitted the corresponding commands to the USB 1024 cable. For the Delphi programmers among us, using the source code of PIOCable- Tool is recommended as a starting point. However, self-written applications can also be produced extremely easily using Microsoft's pro- gramming language C# for .NET (a free 'Express' www.elektor-magazine.com March 2013 43 •Projects version of the development environment is avail- able). As well as the usual control elements like menus, buttons or labels, .NET also provides com- plete serial interface components, with which our cable can be addressed very easily. First we drag some components in the SerialPort category onto a task list. The components need to be given a name, e.g. "PlOPort". All other set- tings are then made in the source code. To do this we add a button to the schedule and type in its OnClick routine the following lines: PlOPort . ReadTimeout = 100; PlOPort . BaudRate = 115000; PlOPort .NewLine = "\r\n"; PlOPort. PortName = "C0M5"; PlOPort . Open( ) ; ton onto the schedule and write the following line into the OnClick routine: PlOPort . Writ el_ine("r0=lp0. 0=1") ; The command first sets the pin into output mode and then immediately to High — job finished! It would be a bit more complicated if you wanted to read analogue values for example. Then you would first need to await the response and then read this in using PlOPort. ReadLine () . To see how this works, look in the code of the demo application. Now nothing stands in the way for you to start programming your own measurement and con- trol software! (120296) For PortName we enter the port by which the cable is currently addressed. If everything works, the connection to the hardware is established. The author has produced a demo application in C# [6] and you can see a screenshot in Figure 6. In the code the lines shown above are invoked when the user selects one of the available inter- faces in the drop-down box. The setting PlOPort . NewLine = "\r\n" informs the component PlOPort that the invocations of PlOPort .WriteLine( ) and PlOPort . ReadLine ( ) that follow should always end with the charac- ter sequence . When writing a com- mand you must not enter an extra and when reading a response, this is read as far as the end of the line. As an example let's now write a simple function that sets port pin PO.O to 1. Again we drag a but- Internet Links [1] www.ftdichip.com/Products/Cables/USBTTL- Serial.htm [2] www.elektor.com/080213 [3] www.renesas.com/products/mpumcu/r8c/ r8c2x/r8c25/index.jsp [4] www.maximintegrated.com/datasheet/index. mvp/id/1339 [5] www.elektor.com/081154 [6] www.elektor.com/120296 [7] www.tinybasic.de [8] www.renesas.eu/products/tools/ide/ide_hew/ index.jsp 44 March 2013 www.elektor-magazine.com THE ORIGINAL SINCE 1994 PCB-PnOL Beta LAYOUT eSTnRE Beta LAYOUT create : electronics ■ Develop, assemble, solder FREE Stencil with every PCB Prototype order Assembly service From as little as one component Embedded RFID authenticate, track & protect your product www.magic-pcb.com Free Phone UK: 0800 389 8560 salescppcb-pool.com j-fil i H i. 1-1 LtLUl£j^jpV i D cedEnce RS-274-X □ P'JLfON'H »i- Dii-Ti^ct www.pcb-pool.com Beta create: electronics Arduino Mega (ATMega I280-I6AU) compatible UHF RFID Starterkit create : electronics Create complex electronic systems in minutes using Flowcode 5 flowcode Design - Simulate - Download Flowcode is one of the World’s most advanced graphical programming languages for micro- controllers (PIC, AVR, ARM and dsPIC/PIC24). The great advantage of Flowcode is that it allows those with little experience to create complex elec- tronic systems in minutes. Flowcode’s graphical development interface allows users to construct a complete electronic system on-screen, develop a program based on standard flow charts, simulate the system and then produce hex code for PIC AVR, ARM and dsPIC/PIC24 microcontrollers. Convince yourself. Demo version, further information and ordering at www.elektor.com/flowcode (Mr/MS PC: -U eSTORE® is a registered trademark of Beta LAYOUT GmbH •Projects By Cederique Prevoo (Netherlands) Simple Servo Tester Nice SMD soldering exercise This small test circuit is a handy aid for anyone who frequently works with servos. It is often sufficient that you can connect a servo to this circuit and try with a potentiometer whether the servo operates properly over its entire range. The control of a servo is done with a PWM-sig- nal (Pulse Width Mod- ulation). The period is generally around 20 ms. The exact value is not that important, as long as the frequency is constant. The duration of the high-pulse determines the position of the servo. The minimum and maximum duration of this pulse are nominally 1 and 2 ms (with the occasional exceptions in some types). At 1.5 ms the servo is in the centre position. K1 + 8V...15V o o C5 47u 25 V w B0530WS-7-F MC7805BDTRKG IC3 l> * Cl lOOn C2 lOOn +5V -© C6 lOu 50V 120542 - 11 This circuit generates such a PWM signal, where the pulse-width can be set with the aid of a potentiometer. In contrast with most simple servo test circuits, a 555-timer is not used here, but instead a Voltage-Controlled Pulse Width Modulator IC from Linear Technology, the LTC6992, was selected. In this IC the pulsewidth can be set using an analogue voltage and the frequency is set with a few resistors. This IC is a member of the so-called TimerBlox series made by LT. LT supplies a program to select the component values around the IC, where you only need to enter the desired function, range and frequency. The control range for the positioning pulse was selected to be from 0.5 to 2.5 ms, to ensure that all servos can be tested to the full extents of their operating ranges. To achieve this the LTC6992 requires a control voltage between 0.12 and 0.2 V. To prevent influence between compo- nents, potentiometer PI and attenuator resistors R1/R2/R3 are not directly connected to the MOD input of the LTC6992, but via a buffer instead. An MCP6002 from Microchip was chosen for this purpose, an opamp with a rail-to-rail input and output range, so that the relatively small voltage of the potentiometer is reproduced accurately. The output signal and the power supply con- nections for the servo to be tested are available on K2. Because there is a spare opamp in the MCP6002, we have used this as a buffer for a second output signal on K2. This allows for the possibility of controlling two servos simultane- ously or for connection to an oscilloscope to look at the output signal. Note that the pin-out of K2 does not correspond to the standard plugs of most servos. This requires making an adapter cable with suitable connectors. A 7805 regulator provides a stable power supply voltage for both the circuit and the servo. The 46 March 2013 www.elektor-magazine.com COMPONENT LIST Resistors (all SMD 0805) R1 = 24kft, 5% R2 = 1 kft, 5% R3 = 15kft R4 = 243 kQ R5 = 681k£> R6 = 1MQ PI = 10kC> linear potentiometer Capacitors C1,C2,C3,C4 = lOOnF C5 = 47pF 25V (e.g. Panasonic EEEFT1E470AR) C6 = lOpF 50V (e.g. Panasonic EEEFT1H100AR) Semiconductors D1 = 30V 0.5A Schottky diode, SOD323 case (e.g. Di- odes Inc. B0530WS-7-F) IC1 = LTC6992CS6-1, 6SOT-23 case, Linear Technology IC2 = MCP6002-I/SN, SOIC8 case, Microchip IC3 = MC7805BDTG, DPAK case, On Semiconductor Miscellaneous K1 = 2-pin pinheader, 0.1" pitch K2 = 6-pin pinheader, 0.1" pitch PI = 2-pin pinheader, 0.1" pitch PCB # 120542-1 (www.elektor-magazine. com/120542) 00 <= - I h* CJ1 <= D1 VO El psl s DiOll . ro ft- (c)ELEKTOR 120542-1 vl.00 CN CJ o ■O • O R5 R3 input voltage may range from about 7 to 15 V. Don't operate the servo for extended periods of time at the higher end of the input voltage range, because the 7805 can start to thermally limit because it is only provided with a small cooling surface on the circuit board. As was already indicated in the heading, this project is a nice soldering exercise for those who would like to get some experience with SMD com- ponents. As it happens, all the parts used here (with the exception of the headers) are SMD ver- sions. Good luck with the construction! ( 120542 ) Advertisement Sjlicon. based life forms of the World YWJ JFf 5l«lin is non Pi*-, 4 nvty&bh* r?w» H unite! ■vt r tw? wwfcj is * ftrt ,,Vrtw * trtmwjjn.u Orfaw Elefcior.TV frATCH IT ON F l,E KTOft, 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 @ektor elektor(4nost T" 19 3 www.elektor-magazine.com March 2013 | 47 •Projects Battery-Nearly-Empty Indicator Simple but effective V+ This circuit gives a signal using an LED when the voltage of a monitored battery drops below an adjustable minimum value. The NEI (Nearly-Empty-Indicator) consists of a voltage reference, a comparator and an LED indicator. The LM10 IC contains a reference source gener- ating 200 mV, which is buffered by an opamp. The output voltage of this buffer is compared by the second opamp in the LM10 to a fraction of the battery voltage. The output of this compara- tor, pin 6, goes high when the battery voltage drops below the value set by PI. The output is connected to the indicator section. Here you can choose between two versions with two or one LEDs respectively. With version 1 of the indicator a red LED will turn on when the battery is (nearly) empty (the green LED can serve as an on/off indicator). The ver- sion 2 indicator uses a programmable UJT and a high-efficiency LED. This produces flashes that even in full daylight will attract attention from a considerable distance (useful, for example, in remote controlled model boats). The entire circuit can be built on a small piece of prototyping board. As an example, both indi- cators are built on the circuit board shown here and you can choose one or the other by placing a jumper on the 3-pin header. But in practice you would build the board with only one indicator. The calculation of the voltage divider is done as follows. Choose the threshold voltage of the battery at which the LED should turn on. For example, for a LiPo cell this is 3.3 V per cell. At this point the battery is not quite empty, but it has the advantage that you can return a model boat to the shore before discharging the battery below the dangerous voltage of 3 V, when bat- tery damage will occur. As an example we take a battery consisting of 2 LiPo cells. The minimum voltage L/ min , is then 2 x 3.3 V = 6.6 V. (For NiCd cells a suitable mini- mum value is 1.1 V per cell. 6 cells will then also result in U mm = 6.6 V.) Calculate R2 as follows: R2 = (48.5 x a mjn - 14.7) kft Therefore at U m - m = 6.6 V: R2 = (48.5 x 6.6 - 14.7) = 305.4 kfi. Take the nearest E12 value, which in this case is 330 kft. Instead of the battery connect a lab power sup- ply and set it to the desired value (6.6 V). Now adjust the trim-pot so that the indicator is just on the threshold of on and off. The series resistors R3 and R4 for the LEDs are calculated as follows (the difference in voltage drop between the green and red LED is relatively small and so for simplicity's sake we take an average of 2 V): 48 March 2013 www.elektor-magazine.com battery indicator COMPONENT LIST Resistors R1 = 4.7kft R2 = see text R3,R4 = see text R5 = 680kft R6 = 22ft R7 = 15kft R8 = 27kft PI = lOkft trimpot Capacitors Cl = 2.2pF 16V Semiconductors D1 = LED, green D2 = LED, red D3 = LED, high-efficiency, red T1 = 2N6028 IC1 = LM10 Miscellaneous Prototyping board e.g. Elektor UPBB (Elex) Type 1 ^series = (^battery _ 2) / -^LED becomes 3 resistor of 1.5 kft. The circuit is now ready to be built into a device, Assuming high-efficiency LEDs requiring about model aeroplane or model boat. 3 mA and the aforementioned battery-pack, (120350) this results in a value of 1533 ft; rounded this Advertisement powered by Eurocircuits Elektor Benefit now: Elektor PCB Service offers a permanent 90-day launch discount on new Elektor PCBs! Check www.elektor.com/DCb.for an overview of all Elektor PCBs www.elektor-magazine.com March 2013 49 •Projects Taming the Beast (3) Counting to 100 with 250 K gates & ISE Project Navigator (P.2gxdl - C:\woA\FPOA\heiie.woridihetio.wdfidJtiie - (C:\wdrfc\FPGA\hell 0 .wOrtd\toe.tch) Iciayw 0 file fdit tfew Pioject Source frocess Add Joel* Window layout Help • € X U & U & 1 dh .iJ X | » | * ’ d 1® ^ ^ ■ >*? ►i-f’ 7 I Cnyi View: ° O fa pb m e n tabon SoJjtnr Hierarchy 5^ hello. world B □ «3050*-4vgl00 S O^HSXfiSSS] ^Of.ud () NoPrgctneiMirg Processes: lop B User Constraints Create Timing Constraints I/O Pin Planning (PlanAhead) - Pre- Synthesis I/O Pm Planning (PlanAhead) Post Synthesis Floorplan A/ea'IO,' logic (PlanAhead) Synthesize • XST Implement Design Generate Programming File Configure Target Device CB16CE CB8CE LCE> r a k iu> 0(15 3) >c TC an VLVH S I KSB ' fr {VrXN_H> op 01 Cf CfO an ■fer IJB) 6UT> C 2 E 22 D A A egrT3> - IMim ?4> ITDb - * « m \ “it Oeegn He* UbranOJ 2 SvmOotJ \‘.r' Otrta < » Deagn Summary (Programming He Generated) 0 C:Vw**rPd»ieto_iwrtdVop.*eh Q S toe.ucf Cral» □ 9 x WebTalk Is complete. - Precess "Generate Programing rile" completes successfully Started : "Launching Schematic Editor to edit top.sch*. = 4 m 1 H Console O &ror» Jl Warring* ft Fnd .1 Fi« RMUtt [1340.6641 By Clemens Valens (Elektor Labs) Last time we showed you how to set up an ISE project for programming the Elektor FPGA development board, with a simple LED blinker as a sample applica- tion. In this instalment we look at how to set up a hierarchical project structure with components you develop yourself. As a sample application for this instalment, I chose a simple up/down counter with a two-digit seven-segment LED display. In this instalment I also tell you how to define the pins on the board directly in the User Constraint File (UCF) without using the PlanAhead tool. Here we go again Open the "Hello World" project from the sec- ond instalment in ISE Project Navigator and click File -> Copy Project... Enter a name for your new project (I called it part3 ) and tick the option Exclude generated files from the copy, since you will be generating everything from scratch. All we're interested in at this point is creating a pro- ject with the right settings for the Elektor devel- opment board. Also tick the option Open copied project, since that will save you a few mouse clicks later on. Click OK and enjoy the view of crocuses coming up (it must be spring) while ISE prepares the new project and finally opens it. 50 March 2013 www.elektor-magazine.com Elektor FPGA Dev Board In order to create a hierarchical project, you have to start by clearing out most of the items in the top level. Move the circuit in top to a new file, which I named clock. To do this, right-click the FPGA symbol on the Design tab and select New Source..., then select Schematic, enter the file name, and click Next and then Finish. Now you can use the usual Windows copy and paste operations to move the contents of top to clock. Make sure that the CLK_IN net with its IBUFG buffer remain in top, as well as the LEDl_OUT and LED2_OUT nets (assuming you did your home- work; otherwise you will only have LEDl_OUT) with the associated OBUF buffers and bus taps. In the clock schematic you now have to add an I/O label in order to provide a proper termination for the clock input that you just cut off. Place an I/O marker as described in the second instal- ment and assign the name CLK to the net that joins the clock inputs (C) together. Later on you will connect the LEDs in top in the same way as in the "Hello World" example. Our aim here is to build an up/down counter that is driven by the clock signal from the clock cir- cuit. We don't need the CLR signal for this, and we can tie it directly to a fixed low level in the FPGA without using a pin for this purpose. This can be done in various ways; I chose the option of using a pull-down resistor so that the signal remains usable. You can find the pull-down resis- tor in the Symbols list after you click the Add Symbol button (or select the Symbols tab) and then select General under Categories. Drag the pull-down resistor to the schematic and place it on the CLR net. Creating a component Save all the files that haven't been saved yet (marked by an asterisk in ISE). Open the Design tab and select the clock file in the Hierarchy list. If necessary, click the plus sign next to Design Utili- ties in the Processes window in order to open the item. Then double-click the entry Create Sche- matic Symbol. A bit later, after ISE has finished processing the task, you should see a big check mark next to the Create Schematic Symbol entry. Your new component has now been added to the top of the Categories list on the Symbols tab. There you will see an new entry with the pro- ject path name, which in my case is . Once you have selected this entry, a clock component appears in the Symbols win- A clock B clock CLK XLXN_20 CLK XI XN 21(15 0) A XLXN_23 o CLK XLXN_24 o □ CLK 0(7 0) 0(5) 0(70) O CE Q(6) o 0 CE CB16CE ee>- 011*01 CFO t>C TC cm 4- v > o L — 1— W CB8CE clock CCCR>- nranii eufG aft OK 0(7 0) CE LE01 QUT > nFDp-puT> A A - TuTO dow underneath, and you can place it in top in the usual way. Do this, and then have a good look at it (Figure 1A). As you can see, the component has a lot of "extra" inputs and outputs with names that start with XLXN_. You don't need these for the pre- sent project, so you can simplify the component a bit. Remove all unnecessary labels and wire segments in the clock. sch file (see Figure 2). Select the Design tab, then select the clock mod- ule, and then place it under top with a differ- ent name (which includes "clock"). Right-click Create Schematic Symbol in the window under- neath, select Process Properties... , and tick the option Overwrite Existing Symbol. Click OK, and then right-click Create Schematic Symbol again and select ReRun. Wait until ISE is finished, and then go to top. sch. Here you will still see the previous version of the symbol, but if you click on it ISE opens the Obsolete Symbols window, where you can edit the symbol. Select clock, click Update , and then click OK to close the window. www.elektor Figure 1. The A version of the clock component has a lot of unnecessary inputs and outputs, which we remove to arrive at the B version. Figure 2. The schematic diagram of our clock component. Figure 3. The clock component in the top module. magazine.com March 2013 51 •Projects Figure 4. Now the symbol has been changed to the ver- A 4-bit BCD up/down sion in Figure IB. counter derived from a 4-bit Connect the clock symbol as shown in Figure 3, binary counter. and ^ en launch Implement Top Module by click- ing the button with the green triangle or by right- clicking the top module. A number of warnings of type Xst:753 will appear on the screen: Figure 5. The BCD to 7-segment decoder is a purely combinational design. WARNING :Xst: 753 - "C : /work/FPGA/ part3/top . vhf" line 1962: Uncon- nected output port 'Q' of component ' CB16CE_MXILINX_top ' . These warnings relate to the unconnected outputs of the components in the clock module. Although we always try to avoid warnings, it appears that ISE - or more precisely, XST - does not have any useful way to get around these warnings. In this regard, Xylinx says that these warnings can be ignored if the open outputs actually do not need to be used [2]. Even so, it's a bit annoy- ing to have a yellow warning triangle next to the Synthesize - XST entry on the Design tab. For- tunately, the rest of the implementation delivers green check marks. Next, generate a bitstream by right-clicking Generate Programming File (or in some other way), and copy the file to the SD card on the FPGA board as described in the sec- ond instalment. Reset the board, and if you did everything right you should see the LEDs blinking as before. If so, you're ready to continue with the rest of the project. Otherwise you will have to find the problem and correct it. Building a BCD counter The ISE libraries contain all sorts of counters, but they are all binary and what we need here is a decimal counter. That means we'll have to build it ourselves. Our counter needs to be able to count in both directions - up and down. To avoid unnecessary design effort, we base our work as much as possible on existing components in the ISE libraries. A bit of searching turns up the CB4CLED counter, a 4-bit binary up/down coun- ter with reload capability. This is the only type of up/down counter available, so it will have to do. This counter counts from 0 to 15 or from 15 to 0, so we have to modify it so it counts from 0 to 9 or 9 to 0. This can be done by reloading the counter with a new starting value when it reaches the end count. For instance, when it is counting up and it reaches 9, it must be loaded with 0 on the next clock pulse, and if it is counting down and it reaches, 0, it must be loaded with 9. We can use bit of clever circuit design to derive the initial values from the Up/Down signal. This only requires a single inverter, as shown in Figure 4 (note the signals UP and D0-D3). A load signal must be generated when the coun- ter reaches the end count corresponding to the counting direction. We use two AND gates to detect the end counts 0 and 9 for the counter. A wide variety of AND gates are available in the ISE libraries, and you can choose the ones with exactly the right number of inverting and non- inverting inputs. That saves a bit of work with the wiring. The two load signals are combined by an OR gate to generate the signal L. The CB4CLED 52 March 2013 www.elektor-magazine.com Elektor FPGA Dev Board counter responds to this signal on the next ris- ing edge of the clock signal C, which is exactly what we want. You should bear in mind that the output of the counter always changes after the rising edge of the clock signal. Nothing happens immediately; there are always small delays due to propagation times in the logic. On the next rising edge of the clock signal, the active level of signal L is loaded into flip-flop FDC and the CB4CLED counter loads the new start- ing value. As a result, signal L goes inactive a short time later, causing the output of the flip- flop to return to the inactive state on the next clock pulse. Consequently, a pulse appears at the output of FDC each time after the counter has reached an end count. This pulse can be used to clock a subsequent counter. Flip-flop FDC is more important than you might think at first glance, since it allows the next coun- ter to be clocked directly by signal L. However, if you do this ISE will generate an error message during implementation: WARNING : PhysDesignRules : 372 - Gated clock. Clock net XLXN116 is sourced by a combinatorial pin. This is not good design practice. Use the CE pin to control the loading of data into the flip-flop. Seven-segment decoder Figure 6. To go with your counter, you need a 7-segment A single-digit BCD counter decoder with outputs for a 7-segment LED display. with outputs for a I couldn't find one in the ISE libraries, so you will 7-segment display. have to make it yourself. This sort of component is fairly simple, but it is somewhat bulky due to the four inputs (BCD) and seven outputs. My design, made entirely from logic gates, is shown in Figure 5. Another option would be to use lookup tables (LUTs), but that's not what I chose. This component can remain purely combinatorial because it does not generate any signals that need to be synchronized with the clock signal. Draw this design in a new schematic source file and turn it into a component. In this message XLXN_116 is the name of the net, which depends on the design. As the warn- ing indicates, using combinatorial signals as clock signals in FPGA designs (and in other complex logic circuitry) is not recommended. "Combinato- rial" means that the signal is generated entirely by a number of logical operations (logic gates) without any clock stage, and the delay of this type of signal depends on the number of gates it passes through. The delay may be variable or poorly defined, so there is no guarantee that the signal will be synchronized to the main clock signal. As a result, undefined states (such as glitches) can occur, and they may cause prob- lems. Signal L is a combinatorial signal. You can synchronize it by feeding it to a flip-flop clocked by the main clock signal, which causes the warning to disappear. Once the design is finished, you can turn it into a component in the previously described manner. Seven-segment counter Now you can use the two components you have just implemented to build a new component: a counter with an integrated 7-segment driver. Start by creating a new schematic source file, then drag the BCD up/down counter and the 7-segment decoder onto this file. Connect them to each other as shown in Figure 6. The out- puts of my counter_updown_bcd4 component are not arranged in an entirely logical order, which makes the schematic look a bit messy. So far I don't know how to force them into a particular sequence. After the schematic is finished, you can turn it into a component. After you do this, you will see that the two other components are shown below the new component on the Design tab of ISE. The hierarchical structure is starting to take shape. The complete design Now all the component are ready, and you can www.elektor-magazine.com March 2013 53 •Projects counter_updown_7segment Figure 7. start putting them together on the top sheet. The top-level design of the in addition to the clock component, you need two-digit up/down counter. two seven-segment counters. Assign an OBUF to each output that must be connected to a pin of the FPGA. Except for the CLK signal, no buffers are necessary for the inputs, but you should put labels on them. Also put a label on the unused CEO output of the second 7-segment counter and a label on the Q(7:0) bus, to avoid warnings about unconnected outputs (our old friend XST:753). Anther thing worth knowing is that ISE secretly connects unconnected labels at the top level to FPGA pins. You can see this for yourself by using an oscilloscope to check the unconnected pins of the FPGA on the board. This means that you should think twice before connecting "sensitive" circuitry to FPGA pins without first explicitly driv- ing the pins concerned in the FPGA (for example, Figure 8. The structure of the hierarchical design. if you think you might want to do so later on). It is better to temporarily set such pins to defined levels of your choice. In the end, you schematic should look something like the one in Figure 7. Here I chose to clock the counters at 7.6 Hz (clock output Q3), but you may find this too fast. If so, choose another output for your counting rate. The hierarchy on the Design tab is now complete, with the device above the top level and the com- ponents below it (Figure 8). Editing the UCF file All you have to do now is to connect the circuit to the pins of the FPGA. You can use the UCF file attached to the top module for this. Open the Design tab, and if necessary expand top by click- ing the plus sign. You should now see the item top.ucf. Double-click it and wait for ISE to open the file. Now you are looking at a simple text file containing the definitions of the pins from instal- ment 2. It's a bit chaotic, but it is not especially difficult to understand. Each of the pins is con- nected to a net by a LOC variable. Naturally, the net name must appear in the design. "LOC" stands for location, and it includes FPGA pin num- ber. Each pin also has an IOSTANDARD, which is always the same for the Elektor FPGA board: LVCMOS33. There is no distinction between inputs and outputs. Some pins can also have the attrib- ute PULLUP or PULLDOWN, which refers to a pull- up or pull-down resistor in the FPGA. The CLK_IN, LEDl_OUT and LED2_OUT nets are always the same for the Elektor FPGA board, so you can group them at the head of the file and leave them alone. The other nets can be deleted or edited, since you need other ones. You can add a comment by starting the line with a hash sign (#). When assigning pins, remember that pin 37 (FPGA pin 13) can only be an input. The first part of my list looks like this: # Hardwired pins NET "CLKIN" LOC = P32; NET "CLKIN" IOSTANDARD = LVCM0S33 ; NET "LED10UT" LOC = P90; NET "LED10UT" IOSTANDARD = LVCM0S33; NET "LED20UT" LOC = P91; NET "LED20UT" IOSTANDARD = LVCM0S33; # 7-segment display 1 54 March 2013 www.elektor-magazine.com Elektor FPGA Dev Board NET "DISPLAY1A" LOC = P15; NET "DISPLAY1A" IOSTANDARD = LVCM0S33 ; NET "DISPLAY1B" LOC = P16; NET "DISPLAYl B" IOSTANDARD = LVCM0S33 ; Implementing the design Now you have everything you need to generate a bitstream for the FPGA. To do this, click the Implement Top Module button (refer back to the first instalment if necessary) and wait until ISE has finished. Unfortunately you will see a cou- ple of warnings, but (fortunately) you can ignore them. Warnings of the following type: WARNING :Xst : 653 - Signal is used but never assigned. MODI O. S2 I S3 I*) *1*1 JT jT 4T DOWN HOLD c RESET are the fault of XST itself, since it creates aux- iliary nets to build the 7-segment decoder and the 7-segment counter but doesn't actually do much with them. The Place & Route (PAR) step also generates a warning: To be continued In the next instalment we will delve into the simulation of this design. In the process there's a very good chance of coming in contact with a hardware description language (HDL), such as VHDL or Verilog. ( 120743 ) Figure 9. Two 7-segment displays connected to the FPGA board @ Elektor Labs. WARNING: Route: 455 - CLK Net:Q_3_0BUF may have excessive skew because It's hard to know what to do with this warning, since there's nothing after "because". The reason for this warning is therefore a mystery. For now, let's simply ignore it and hope that the circuit does not have a real problem with excessive skew. Next, select Generate Programming File to gen- erate the bitstream, give it the name config.bin, and copy it to the SD card on the FPGA board. Restart the board, and if you have connected it as shown in Figure 9, it should start count- ing. You can control the counter by setting the appropriate levels on pin 27 (reset; active high), pin 28 (stop; active low) and pin 29 (up/down; high = up, low = down). The two LEDs on the board will blink as in the previous project. Homework Build the 7-segment decoder using LUTs. Remem- ber that whenever you edit a component, you must not only generate it anew but also update it in the higher-level sheets. Otherwise you will get an error message during implementation. Maybe there is some way to have ISE handle all the updating automatically? Internet Links [1] www.elektor-magazine.com/120743 [2] www.xilinx.com/support/answers/14065.htm The fully assembled and tested FPGA development board is available in the Elektor Shop for under $ 70.00 plus shipping. See www.elektor-magazine.com/ 120099. www.elektor-magazine.com March 2013 55 •Labs Frontline breaking news Numitro ^sica," components' 1 * ' Usi "9 on/y ***** 5?»1 I C±-~§ .H*. I i o *»■» °o you knew * ho,e 7 to mitl A . , .. *** m «'iU b^ilb. By Clemens Valens (Elektor .Labs) Elektor dot Labs is at the heart of Elektor, it is the place where all electronics related designs start. Projects and ideas are posted on the website; circuits get developed, debugged, tried and tested in our labs, and progress and results are reported back to you. Elektor dot Labs is also the frontline where all the action takes place. Here are some heartbeats from the front. What's in a name? Titles and product names have to be short to immediately grab the attention of the potential reader or buyer, or at least that's what they always told me. The problem with snappy titles is that they cannot convey too much information about the content or the product, which is why marketing departments and advertisement agencies got invented. Although Dot Labs original poster (OP) SuperlabTV is working on an interesting project, so far he has not found time, inspiration or both, to come up with a catchy name for his project. This is a pity because it definitely needs one. For now his project is called "Electric guitar pickup seismograph with Arduino cell phone remote control ", a title that has the merit of being detailed and informative, but on the down side is hard to remember. SuperlabTV created this seismograph as a platform for both demonstrating and learning about earthquake seismographs, Arduino microcontrollers, cell phone remote controlled servo motors and upcycling. According to Wikipedia, upcycling is the process of converting waste materials or useless products into new materials or products of better quality or for better environmental value. How much exactly this project 'upcycles' depends probably on the reader, but it is true that several parts for this seismograph were recovered from waste equipment: the base of the instrument is an old automobile brake rotor and foe the sensor the OP used an electric guitar pickup from an old guitar. Wondering what the Arduino cell phone remote control is for? It allows you to create an artificial seismographic shock simply by sending a text message to the instrument so you can see that it works. Neat, ain't it? Do you have a suggestion for a good title for this project? www.elektor-labs.com/912 1102688 56 March 2013 www.elektor-magazine.com elektor labs No schematics, no followers Elektor magazine has had its share of clocks and thermometers with nixie tube displays and now they have also surfaced on .Labs! The project "Numitron Arduino Clock and Thermometer" by 'Courty' is one of them. The nice thing of this project is that the OP, not having any previous experience with Numitron tubes, explains from the start how he went about and how he managed to get it all working in the end. Unfortunately, the OP did not post any schematics or source code so the project has limited use. If you, as a reader, would like to build Courty's clock/ thermometer please post a contribution or comment. If there are enough people interested we will try to get Courty to publish his design in the magazine. OP JmBee posted a similar project, but based on a PIC16F887 instead of the ATmega328 used by Courty. He even went so far as to post his project in English (" Numitron desktop clock - Using only classical components") and in French (" Horloge du bureau a tubes Numitron et composants classiques"). JmBee used the same Numitron tubes as Courty. Also like Courty, JmBee did not post any schematics or source code so nobody can replicate his design. Therefore I ask you again: please post a message if you would like to see this design published or ask the OP to post his design files. Apparently, finished projects lacking details for other people to replicate the project are interesting, but will not attract a lot of attention. Make some noise: Courty: www.elektor-labs. com/9 120902460 JmBee (English): www.elektor-labs. com/9120702370 JmBee (French): www.elektor-labs. com/9120702371 Editor's Choice A number of .LABS projects have been selected by our editors and should be published in the near future. For some of these projects, sadly we found that the original poster (OP) does not reply to our messages. Therefore, if you posted a project, please check on a regular basis the email account you used to access .LABS. We will not get you in publication if we cannot get in contact with you. Here is a selection of projects we think is interesting and which we would like to publish in the printed magazine. Microcontroller Networking Framework MCNF is a framework to build measurement, control and automation applications. It targets systems where a PC controls real-time functions in an embedded system. Networking is based on a command- response protocol handled by a small kernel on each microprocessor. Many standard functions are built in, like connectivity tests, read and write of embedded variables and saving them to EEPROM, gateway functions, etc. The network allows mixing of UART, I 2 C, SPI, Ethernet and other communication protocols, www. elektor-labs.com/912 1202735 www.elektor-magazine.com March 2013 57 •Labs Conducted Emissions Tester Imagine the following scenario: you are working on a project which works fine in the morning but becomes unstable in the evening. After three days of head scratching you conclude that the problem is due to the energy saving lamp that helps you work when it is dark outside! Bizarre? Nope, it happened to OP HooliganO. Annoyed by this waste of time the OP decided to develop a small line impedance stabilization network so that he can visualize with a spectrum analyser or oscilloscope with FFT the noise on the power line. www. elektor-labs. com/9 1212027 10 Very Large Image or PIC \ * VI Development Board With 'T 4 \\ On-Board Programmer \ ^ J. OP Meerweten is working on a / k ■ ^ * u ^ * small development board for % k \ ■ PIC microcontrollers. The board - ^ \ will include its own PICkit2- ^ > . compatible programmer not t ''tVrf only to program the PIC i \ under development, but also . v. I T • A for use as a stand-alone programmer. Now the OP h \ posted his design files ^ \ ** ' nc l u d' n 9 a PNG version of the schematic. The .LABS ^ ^ \ jl website however could not display this picture \ 4 \ooco" 150 ' ■*- £, ,, .■ as it was a flabbergasting ^ 10222 x 6629 pixels in size! Because the server would need some 250 MB of memory to display images of such dimensions, the maximum size of illustrations has been limited to 2048 x 2048 pixels. So, when you export a schematic from Eagle, please use the default 150 DPI option. And if your drawing is still too big, cut it into several parts before posting it. Note that larger pictures are allowed, they will just not be displayed, but you can download them. www.elektor-labs.com/9121 102689 www.elektor-labs.com Real-time Pitch Shifter Some people do not believe in coincidences, but what else can you make of this? OP bkelektronik, also known as the reputed Elektor author Burkhard Kainka, posted a project on .Labs in German entitled Echtzeit Stimmhohen Teiler, a real-time pitch down-shifter for people that have trouble hearing high frequencies. A few days later I received an email from such a person looking for such a circuit. Is that a coincidence or not? Check it out for yourself, it may be exactly what you needed, www. elektor-labs. com/9 121002536 i ► f - 0,88 + 7 dB On Off 58 March 2013 www.elektor-magazine.com Professional Quality Trusted Service Secure Ordering r Elektor PCB Service at a glance: O 4 Targeted pooling services and 1 non-pooling service o Free online PCB data verification service O Online price calculator available o No minimum order value O No film charges or start-up charges Delivery from 2 working days •Labs Power supply issues By Thijs Beckers (Elektor Editorial) After several wrecked prototypes and blown up components, we started to suspect one of our power supplies might be the common denomina- tor. A quick measurement on the supply's out- put seemed to eliminate the supply as being the culprit. The voltage on the output seemed to be stable and correspond to the supply's voltage display. But when referenced to ground, something odd was going on: both the positive and negative outputs carried a negative voltage compared to ground. For example, when set to 12 volts, the positive output measured -14V and the nega- tive output measured -26 V referred to ground. In most situations this doesn't create a problem, but when this supply is used to power circuits that are referenced to ground somehow, for example when they are also connected to a PC, things start to get messy (or smoky). So we opened up the case to determine what was wrong with this PSU. At first we couldn't see any- thing wrong. No black copper traces, no burned components, nothing. We started measuring the resistance between various key components and ground and soon discovered that the collectors of the output transistors seemed to be hard wired to ground. Tapping into several points of the circuit with our multimeter, we narrowed the fault down to one of the transistors not being isolated from the heat sink, which was directly bolted onto the case and therefore grounded. With the isolating sheets clearly in view, could it be that during construction the plastic wash- ers for isolating the collector from the screws and the heat sink got omitted? We removed the screws and we found a solder blob of substantial size seized between transistor and heat sink (of course on the last one examined). The blob had torn a hole in the isolation sheet, establishing a conducting path from collector to ground. 'Luckily' the rest of the circuit was floating with respect to ground, so no (internal!) components were damaged. However, this unit having passed the factory's Quality Testing leaves much to doubt and fear about the test methods applied. With the solder blob removed we reassembled the device and tested it. No abnormalities were measured and the power supply now functions as expected. Now who's going to repair those blown up pro- totypes... Any volunteers? ( 130020 ) 7805 replacement grilled While setting up a test with his 'switching 7805 replacement' project (November 2012 edition) for the purpose of generating some better 'scope screenshots for his webinar on the subject (webcast on November 22, 2012), designer Raymond Vermeulen noticed a slight irregularity in the circuit's behaviour. Raymond created a difficult to drive ballast for his circuit: a switching load using one 47Q 5 W resistor as a static load and one 6.8 Q 10 W resistor in series with an IRF530 MOSFET to act as a switching load. The gate of the FET was connected to a function generator set to square wave o/p — duty cycle 50%, allowing a load to be realized that was constantly switching between 106 mA and 840 mA. At a frequency of about 18.6 kHz (the resonant frequency of the output filter) the output of the 7805 replacement was stable, but a little 60 March 2013 www.elektor-magazine.com Everyday Observations wiggling and ringing could be seen on the scope image (see photograph). Of course its 'normal' regulated output voltage isn't nearly as bad as you can see in the photograph, where the input voltage had been cut down to a bare minimum of 5.8 V (power supply on the right) to test the circuit to its limits, so no worries really on the circuit's performance. Also note of the scope settings: the vertical grid is only 50 mV, so the maximum amplitude of the spike shown here is about 200 mV. In conclusion we can — luckily! — state that it is a sound design; even in circumstances where many other designs fail and even possibly break down. ( 120702 ) Internet Link www.elektor-labs.com/120212 ■ayottys dbuep ui BupjaBjoj jo[\] \df] sj dea s/L]] joj oB o i Ae/v\ A/uo aq; ';eaq (dA/ssdDXd) o i Aipuiyj ayei iuop sjoyaedea sy lyuis ;eaq pue jay -paaj aBpuq at p Aq pasopua A/pa -ipead apA/ojpaia jioAjasaj jeqj aapou noA p/(j juaiuaAOjdiUj joj BuiBBaq ;snf ;noAe/ pjeoq e set/ A/ddns JdMod qq adAjojojd siq± Prototype howlers For those of you having some trouble with this 'brainteaser', here's the solution: ( 130021 ) www.elektor-magazine.com March 2013 61 Philips 'hue' Behind the scenes of an innovative bulb By Thijs Beckers (Elektor Editorial) Philips' latest lighting concept, hue [1], is sold via the Apple Store and intended for general use, hence its slick appearance and easy installation of the system. But what we electro-enthusiasts are interested in isn't on the outside. So after experi- encing the hue during an impressive demonstration of its countless possibilities in a showroom/living room specially set up for the occasion, I sat down with one of the technical engineers, Aart Vroegop, at the Eindhoven based Philips Lighting of- fices to get a glimpse of what technologies are used in this ingenious design. Cleverly named hue — the technical term for colour tone, and sounding not unlike "you" — Philips' latest product seems to be the first on the market to offer personalized lighting schemes in a very attractive way. Up to 50 intelligent RGB light points can be controlled via the 'Bridge' — the brains of the system, connected to LAN and accessible via Wifi and remotely via the Internet. A specially written app for the iPad controls the whole system. An app for Android devices boast- ing the same control possibilities — which is a lot — is also available. I have to admit, being able to control room lighting the way you can with hue has a much larger impact on your state of mind than one would imagine. Philips Lighting has a high reputation to defend, so their new product must meet the high qual- ity standard customers have come to expect. To ensure a successful design, extensive research has been done. Some 1000 prototype lamps were tested by volunteers in Shanghai, Berlin and New York — truly a global test! Aspects to evalu- ate included (ease of) installation, light quality and overall system impression. Engineers have been constantly battling regulations and safety demands in order to be able to deliver a product that strikes a balance between a good product and these regulations. Inside hue The light bulb is built in an aluminium case with a plastic overmold (Figure 1). After the electronics is in place, the whole case is filled with a pot- ting material. This electrically isolating material is selected by its heat-conducting capacities, so any heat generated by the circuit is evenly spread 62 | March 2013 | www.elektor-magazine.com I I I Philips hue I and diverted to the aluminium case where it can be transferred to the surroundings. In order to be able to generate the required colour set — carefully researched using things like the Black Body Radiator Curve, especially important to create a decent colour temperature of white light — engineers applied a set of red, blue and lime-green Rebel LEDs from Luxeon (Figure 2). Several prototypes were made with a silicone 'bulb', but the final version employs a specially coated glass to ensure even diffusion of the light emitted by the LEDs. The actual hue (colour temperature) is influenced by the temperature of the LEDs. During produc- tion each lamp is calibrated and a reference table is saved in the lamp's internal microcontroller to take this into account. This ensures different lamps to generate exactly the same colour when they are asked to do so. Power Supply Aart Vroegop and his team have been responsi- ble for the SMPSU and LED current control parts of hue. Figure 3 shows the basic schematic of the power supply and LED control circuits (we can't reveal the whole schematics due to copy- right restrictions). Sultan^cwrwct bulb L 2 _ 130 S?/ E 5 94V 0 Figure 1. This is what makes hue. In the upper row the various components that make up the bulb; below, the Bridge. t t/_ i— * Figure 2. Eleven Rebel LEDs make up the light source of hue. lift 12 SI ■ A. B ■ IUU,- — • ... 1 III ~ T ■7 , Hflt rtu* - r r niunuu f-M OFT 7J,j COMfUJWTY COMMUNITY SCEtt£$ VVAm rry * MV LIGHTS IT-* tmr CJHWUflfy Fu* few'll kuif i,|«rq KHW ftodl , UIVH ! brie rr jn.m..g« Fj *•. -n u xmu. t m 4 ibl^ IM ( YIChlLki if mi, ■Gjts-g&ri . 3. iH ■ ft' . ^HlWl H'iv.l.m Flttai Ww 5-™y*i Jic^ rn bi if inert ^yuoni iVCianiiKMi ConLuiraficir Pilf alls- XT EVey^drifl IfkyflfMiNk 'i Managing Raqubnn manta .' And W l-i ■. Jpyslk* tflnlipl win BkifltcebLk ComoCtivity ANALOG TEC Analog Signal Muniig i Sol ntl Tone Detect Gu-Sjswd Audhwy Wavicphinn Sy-Ele-m Cr yiixicr on AJbcmalr lo Joystick Confoi Ffflcjmnics D^sicjn' Pr4ic.L-hMJrs. Pu^i.-r, AlnfHncing A Look Invidu- .y L, kinluiiors L'i.rt 'ii ji ■ EMBEDDED PROGS Build .1 Ca|Mdlhr*. 7 «IEij * Ptraonnl *nt|s Ada fiicu tor LcM-Poi&er Asplicnl. H;n Muih Ntdvw?rk" .tj Wflh Elio SNAP OS An EKjminitinn of ParrfKH Cipadtns ' Exphiincd . Vi-, IAL: SAVE 50% SPECIAL SAVE 50% Celebrate Circuit Cellar's 25 th Anniversary , LINE 2012 SSUE 26-3 ‘w/77/7, fjJ Jr y v CIRCUIT CE PROGRAMMABLE \ MCUSatcd SI«p^ 5 Ljgir Ari-dlyixl^ RLV Smart Eteetronk Uoad Design Embedded Linux Syate-m PFalfrwn is IrtfarTefflctoB 1 ImmuAitv for Errspifioinic D^gnr.. Smart Switc & Control St Radio Frege Diode Un interrupts MOSFET Cfi Resistance I T*er MCU-Based Automat Blood Pressure Cuff $25 Print or Digital :: $50 Combo Celebrate Circuit Cellar’s 25th year of bringing readers insightful analysis of embedded electronics technology. Visit www.circuitcellar.com/el912 to take advantage of these great deals. S OFFER! BONUS OFFER! BONUS OFFER! B Sign up today and you’ll also receive the Special 25 th Anniversary Edition with your subscription! CIRCUIT CELLAR YEARS OF EMBEDDED INSIGHT Magazine 'Radiomann' Audion Kit (ca. 1956) When boys' toys were educational By Peter Beil (Germany) Do you remember back to your youth, when you took your first steps in the world of electronics? For me, and I guess many others, radio was a source of utter fascination back in the early 1950s. Making your own receiver was virtually impossible, because in my country at least mail order component dealers were few and far between. Filling this gap in the market came the so called 'Experimenter Set' offered by the Kosmos pub- lishing house in Stuttgart, Germany, which opened a door to the electronics of the time for interested juveniles and bud- ding engineers. And even if its visual look-and-feel (Figure 1) was a little austere, a wealth of 80 experiments was nevertheless possible with this outfit. It's worth remembering that semiconductor technology was still in its infancy at this time and the vacuum tube dominated the majority of electronic circuits. With tubes one could not only amplify but also con- trol, regulate or rec- tify. Television already existed at that time but held practically no significance for hobby- ists or indeed boys. Radiomann (Radioman in English) provided an almost fun and games method of gaining an insight into wave theory, audio and radio frequency or vacuum tube tech- nology (Figure 2). Everything was made won- derfully simple: the capacitor was just a piece of plastic with a piece of metal foil glued back and front (Figure 3), and you made a resistor your- self using a thick pencil stroke on a piece of card (Figure 4). I have since checked the value of that 74 | March 2013 | www.elektor-magazine.com 'resistor' and it was almost exactly two megohms. It was painted with black drawing ink and 'fine tuned' with a pencil marking over the top. The experiments were built on a wooden bread- board that used plug-in brass clips that you placed in pre-drilled holes. In this way you learnt in the 'coherer' example what induction was, and produced your first 'wireless' transmission (Fig- ure 5). For people unfamiliar with the coherer, this was a simple indicator of electromagnetic waves, usually consisting of two electrodes and iron filings in a glass tube, but 'tubeless' here. In those days a 'crystal detector' with negative feedback emerged as the appropriate 'receiv- ing device' (Figure 6). The germanium diode was unknown then, and accordingly we built a proper 'semiconductor' out of a galena crystal and a sharply pointed piece of wire, experiencing straightaway the inevitable problem of finding the optimum junction position ('sweet spot') (Figure 7). Close to a medium wave transmitter you could even drive a small loudspeaker with this detector! Initiation into the secrets of the vacuum tube took place on the basis of exercises that were entirely comprehensible, even for juveniles. So the operation of the anode (a.k.a. plate) was compared to a vacuum cleaner; electron flow on the grid to snowballs thrown through a grat- ing and/or with an adjustable sunblind or louver (Figure 8). My vacuum tube has unfortunately gone missing during the last 60 years. All that remains is the illustration on the box lid (Figure 9). Originally it would have been a type RE074d from Telefunken, a so-called space charge grid tube. Once this became no longer available in those post-war years it was substituted by the custom-designed type DM300 (Figure 10). As this was actually no longer a space charge grid tube, we cunningly made a normal tetrode out of it by reversing the grid connections. In these applications it worked without any problems, despite the (technically unfavourable) direct current filament voltage. The vacuum tube was a pattern with an unusual filament volt- age of 3.5-4 volts and a double grid. The plate voltage used was a harmless 12-20 volts. Inci- dentally this was feasible only because the second grid was connected to the plate voltage. The whole business was powered by (then commonplace) 4.5-volt flat 'lantern' batteries (zinc-car- bon; IEC 3R12) (Figure 11). The experiments culminated in the construction of an 'audion' Retronics XL www.elektor-magazine.com | March 2013 | 75 •Magazine Retronics is a monthly section covering vintage electronics including legendary Elektor designs. Contributions, suggestions and requests are welcome; please telegraph editor@elektor.com with reaction, which provided pretty good selec- tivity (Figure 12). By connecting up the domestic record player (if you had one), and the receiver 'reverse-connected', you could transmit to your broadcast receiver over an awesome distance of around 10 feet (Figure 13). Apparently some mischief also took place, as this experiment was not included with follow-up models. The person who conceived this and other 'experi- menter sets' to was the honorary Dr Wilhelm Frohlich, by profession a teacher at a school in the Lake Constance district. His original wish was to bring technology closer to his students with simple physics class experiments. During the 1960s the Radiomann was updated to an extent with an EF 89 (6DA6) pentode tube and a transistor. Subsequently the well-known elec- tronics writer and Elektor contributor Burkhard Kainka adapted the set for more sophisticated technologies. The model described here dates from around 1956, and at the time cost the equivalent of $6.76 ($57 today) plus $2.73 ($23 today) for the tube, which was sold separately. In those days, that was a substantial amount of money, requiring much arm-twisting on my part but pro- viding many hours of pleasure for me. Today the Franckh-Kosmos publishing company is still very much at the cutting edge of learning and experimentation materials right up to the Arduino microcontroller platform. Even today there remains plenty of informa- tion about the old Radiomann on the Web. Type "Kosmos Radiomann" into your favourite search engine, you will be amazed. ( 120650 ) Original drawings reproduced with the kind permission of Franckh-Kosmos publishing company, Stuttgart. Photos by the author. Advertisement Schaeffer Customized front panels can be designed effortlessly with the Front Panel Designer. The Front Panel Designer is available free on the Internet or on CD. FRONT PANELS & HOUSINGS Cost-effective single units and small production runs • automatic price calculation • delivery in 5-8 days • 24- Hour-Service if required Sample price: 34,93€ plus VAT/shipping Schaeffer AG • Nahmitzer Damm 32 • D-12277 Berlin • Tel +49 (0)30 8058695-0 Fax +49 (0)30 8058695-33 • Web info@schaeffer-ag.de • www.schaeffer-ag.de 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. 76 | March 2013 | www.elektor-magazine.com lube Solid Stale, Loudipe-aicGi techn. Choose from print delivery, digital or a combination of both for maximum accessibility. Subscribe to audioXpress at www.audioamateur.com' ■ today] audio music to your ears Then you should be Recently acquired by The Elektor Group. audioXpress has been providing engineers with incredible audio insight, inspiration and design ideas for over a decade. If you're an audio enthusiast who enjoys speaker building and amp design, or if you're interested in learning about tubes, driver testing, and vintage audio, then audioXpress is the magazine What will you find in audioXpress ? Audio i, intuit! Li i 1 • In-depth interviews with audio industry luminaries * Recurring columns by top experts on speaker building, driver testing, and amp construction * Accessible engineering articles presenting inventive, real-world audio electronics applications and projects * Thorough and honest reviews about products that will bring your audio experiences to new levels J ilNi'-n IVMdtJ twcumsa f V Ter r>i nawty 'r. w-d i ■■ -i urj. ic j*:-, K:.rjp[ iino-^.1/ .■ • r.'l Igud v| HVli.fr iwm; If 1 #T 5 l so * '• iiw SI- iru-oirsA-Uf vw ^txrui.£C fcwuj ir-5 gy*r ICO ore r t to send a dreciiptlan .J youi iinjudriy d circuit cJi^gr^m iMid li photOQrjfrph for evblu omen: and maytu* you win tie granted 82 | March 2013 | www.elektor-magazine.com Technology WORLD’S FIRST OSCILLOSCOPE www.usb3scope.com/TRlll PicoScope 3207A 3207B Bandwidth 250 MHz 250 MHz Sampling 1 GS/s 1 GS/s Memory 256 MS 512 MS Signal generator Function generator AWG Price £1099 £1199 Power supply From USB port Compatibility USB 2.0 & 3.0 ALL MODELS INCLUDE PROBES, FULL SOFTWARE AND 5 YEAR WARRANTY. SOFTWARE INCLUDES MEASUREMENTS, SPECTRUM ANALYZER, FULL SDK, ADVANCED TRIGGERS, COLOR PERSISTENCE, SERIAL DECODING (CAN, LIN, RS232, l 2 C, FLEXRAY, SPI), MASKS, MATH CHANNELS, ALL AS STANDARD, WITH FREE UPDATES. PROTEUS DESIGN SUITE VERSION O Featuring a brand new application framework, common parts database, live netlist and 3D visualisation, a built in debugging environment and a WYSIWYG Bill of Materials module, Proteus 8 is our most integrated and easy to use design system ever. Other features include: ■ Hardware Accelerated Performance. ■ Board Autoplacement & Gateswap Optimises ■ Unique Thru-View™ Board Transparency. ■ Direct CADCAM, ODB++, IDF & PDF Output. . Over 35k Schematic & PCB library parts. ■ Integrated 3D Viewer with 3DS and DXF export. ■ Integrated Shape Based Auto-router. ■ Mixed Mode SPICE Simulation Engine. ■ Flexible Design Rule Management. ■ Co-Simulation of PIC, AVR, 8051 and ARM MCUs. . Polygonal and Split Power Plane Support. - Direct Technical Support at no additional cost. Labcenter Electronics Ltd. 21 Hardy Grange, Grassington, North Yorks. BD23 5AJ. Registered in England 4692454 Tel: +44 (0)1756 753440, Email: info@labcenter.com Visit our website or phone 01756 753440 for more details