^ *Sl May 2012 AUS$ 14.90 - NZ$17.90 - SAR 105.95 “ NOK102 £4.90 + Inside Pico C-Super AT231 3 programming Z80 style + Platino Controlled by LabVIEW An introduction to UFA, a LabVIEW interface for Arduino 770268 451 73 0 5 9 lektor Brought to you by Eurocircuits rvice The European reference for PCB prototypes and small series Speed up your design cycle and keep costs down using our fast, easy-access online PCB pooling services. We deliver: • Top quality PCBs at low pooling prices • Fast deliveries to suit your requirements • Comprehensive technology support • No set-up or tooling charges • No minimum order charge - order from 1 PCB • Online ordering without pre-payment • Stencil service PCB proto - dedicated engineering prototype service , fast and low-cost • 1 or 2 PCBs in 2, 3, 5 or 7 working days • DRC-checked and fully finished with 2 soldermasks and 1 legend, 150pm technology • 1 x 100 x 80mm in 7WD - 2 layer 47,02 € - 4 layer 95,52 € • 2 x 100 x 80mm in 7WD - 2 layer 36,89 € each - 4 layer 74,76 € each Prices quoted include 2 1 % Belgian VAT but exclude transport costs STANDARD pool - widest choice of Eurocircuits pooling options • 1-8 layers 150pm technology PCBs • from 2 working days TECH pool - all the benefits of pooling for high-density PCBs • 2-8 layers 100pm technology PCBs • from 4 working days IMS pool - aluminium-backed PCBs for high heat-dissipation (LED) applications • Single layer Insulated Metal Substrate PCBs • 1.5mm aluminium base with 75|jm thermally conductive dielectric and 35pm Cu foil • from 3 working days On demand - multi-option non-pooling service for specialist needs • 1-16 layers down to 90pm technology • RF and high Tg materials • from 2 working days www.elektorPCBservice.com mikroC BASIC mikroC Ibasic PRO for 8051 3 ' I I You have a choice. Pick any architecture you want. Choose the programming language that suits you best. Whatever you go for, the same comfortable and intuitive IDE will follow. Powerful SSA optimizations, resourceful Help file, dozens of Tools and lots of Examples are here to get you started quickly. And if you ever change your mind, just switch between different architectures easily. We have been carefully planning backward compatibility for over 500 of our library functions, so you will be able to literally copy-paste your existing codes and build them with just a few adjustments. Mikrollektronika DEVELOPMENTTOOLS I COMPILERS I BOOKS GET IT NOW www.mikroe.com ioqec Commandments of Electronics ooh. Beware the lightning that lurketh in an undischarged capacitor, lest it cause thee to be bounced upon thy buttocks in a most ungentlemanly manner, oih. Cause thou the switch that supplies large quantities of juice to be opened and thusly tagged, so thy days may be only on this earthly vale of tears. 02h. Prove to thyself that all circuits that radiateth and upon which thou wor- keth are grounded, less they lift thee to high frequency potential and cause thee to radiate also. 03h. Take care thou useth the proper method when thou taketh the measure of High Voltage circuits so that thou doth not incinerate both thee and the meter; for verily, thou hast no account number and can easily be replaced, the meter doth have one, and as a consequence, bringeth much woe unto CEO, Accounts & the Supply Department. 04h. Tarry not amongst those who engage in intentional shocks, for they are not long for this world. 05h. Take care thou tampereth not with interlocks and safety devices, for this will incur the wrath of thy Seniors and bringeth the fury of the Safety Officer down about thy head and shoulders. o6h. Work thou not on energised equip- ment, for if you doth, thy buddies will surely be buying beers for thy widow and consoling her in other ways not generally accepted by thee. 07h. Verily, verily I say unto thee, never ser- vice High Voltage equipment alone, for electric cooking is a slothful pro- cess and thou might sizzle in thine own fat for hours on end before thy Maker sees fit to end thy misery and drag thee into His fold. o8h. Trifle thou not with radioactive tubes and substances, lest thou commence to glow in the dark like a lightning bug, and thy wife be frustrated nightly and have no further use for thee except thy wage, ogh. Commit thou to memory the works of the Prophets, which are written in the Instruction Books, which giveth the straight dope and which consoleth thee, and thou cannot make mistakes — yeah, well, sometimes, maybe, sorry ‘bout that. (author unknown) 6 Colophon Who’s who at Elektor. 8 News & New Products A monthly roundup of all the latest in electronics land. 14 Embedded World 2012 What’s happening in the embedded world is displayed at the Embedded World electronics show in Nurnberg, Germany. A report. 17 The RL78 Green Energy Challenge has begun Present your Green Energy design and help create a future that’s bright, clean and healthy. 18 Embedded Linux Made Easy (1) This article kicks off a beginners’ course on embedding this popular OS in an inexpensive circuit board. 24 Platino Controlled by LabVIEW (1) Quickly develop your application using these programming environments. 28 Preamplifier 2012 (2) Presenting a high-end Moving-Coil/ Moving-Magnet (MM/MC) board. 34 Lossless Load A ‘green’ solution to limit energy waste normally occurring in a shunt. 40 Inside Pico-C-Super In this article we delve into the software that makes the instrument tick. 43 E-Labs Inside: Mounting Nixie Tubes, Quality check & Transformer testing, Stray oscillations, All the latest: LCR Meter & Piggybacking-i k. 47 What are you doing? This month we visited Mark Brickly, inventor of the Minty Geek. 4 05-2012 elektor CONTENTS 18 Embedded Linux Made Easy (i) Today Linux can be found running on all sorts of devices, even coffee ma- chines. Many electronics enthusiasts will be keen to use Linux as the basis of a new microcontroller project, but the apparent complexity of the op- erating system and the high price of development boards has been a hurdle. Elektor solves both these problems, with a beginners’ course accompanied by a compact and inexpensive circuit board. 28 Preamplifier 2012 (2) High-end turntables are available at extragalactic prices but none of this makes any sense if you do not have a preamplifierto match your MC or MD cartridge optimally and that’s exactly what the present design does — rather successfully. Part 2 of our preamplifier 2012: the Moving-Coil / Moving-Magnet (MC / MM) board. 40 Inside Pico C-Super The Pico C-Super is an extended version of the original idea with several extra functions crammed into the same extremely simple and low cost hardware through the use of software. In this afterburner article we delve into the soft- ware that makes the instrument tick, particularly the Plus version. 58 AVR Software Defined Radio part 3 The popular ATmega 88 AVR microcontroller can be used for digital signal pro- cessing tasks. In this instalment we will look at a few experiments involving am- plitude and frequency modulation, including a small DCF time code test trans- mitter. We will also extend the hardware by adding an active ferrite antenna which will allow longwave and mediumwave signals to be received. Volume 38 May 2012 no. 425 48 QuadroWalker This small four-legged robot walks with eight servos. 52 Electronics for Starters (5) This month we examine ways to generate stable voltages. 58 AVR Software Defined Radio part 3 In this month’s instalment we look at a few experiments involving amplitude and frequency modulation. 65 Component Tips Raymond’s Pick of the Month: MOSFETs with unusual characteristics. 66 Energy Monitor With this mini project you can judge how much energy an electrical load is using. 68 SHT11 Humidity Sensor Connected to PC This sensor conveniently measures both temperature and humidity in an all digital way. 70 RAMBOard-Serial A static RAM controller with an SPI interface provides ample memory to small 8 -bit processors. 72 Retronics: Elektor Logic Analyser (1981) Series Editor: Jan Buiting. 75 Hexadoku Elektor’s monthly puzzle with an electronics touch. 76 Gerard’s Columns: Reliability The monthly contribution from our US columnist Gerard Fonte. 84 Coming Attractions Next month in Elektor magazine. elektor 05-2012 5 ELEKTOR 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 Carlo van Nistelrooy Don Akkermans The Network Tech the Future explores the solutions for a sustainable future provided by technology, creativity and science. CIRCUIT CELLAR i hi f ouk' -• ! '-'v-! -:.i : ; l : ihonics l isSit.l i ki»C m "fwation VOICED COIL Our international teams United Kingdom Wisse Hettinga +31(0)464389428 w.hettinga@elektor.com Spain Eduardo Corral +34 91101 9395 e.corral@elektor.es India Sunil D. Malekar +9 1 9833168815 ts@elektor.in USA Hugo Vanhaecke +1 860-875-2199 h.vanhaecke@elektor.com Italy Mauriziodel Corso +39 2.66504755 m.delcorso@inware.it Russia Nataliya Melnikova 8107(965)3953336 nataliya-m-larionova@yandex.ru Germany Ferdinand te Walvaart +31 46 4389417 f.tewalvaart@elektor.de Sweden Wisse Hettinga +31 46 4389428 w.hettinga@elektor.com Turkey Zeynep Koksal +90532 2774826 zkoksal@beti.com.tr U France Denis Meyer +31 46 4389435 d.meyer@elektor.fr Brazil Joao Martins +551141950363 joao.martins@editorialbolina.com South Africa Johan Dijk +27 78 2330 694 / +31 6 109 31 926 j.dijk@elektor.com Netherlands Harry Baggen +31 46 4389429 h.baggen@elektor.nl Portugal Joao Martins +351 21413-1600 joao.martins@editorialbolina.com China Cees Baay +86 21 6445 2811 CeesBaay@gmail.com Volume 38, Number 425, May 2012 ISSN 1757-0875 Publishers: Elektor International Media, Regus Brentford, 1000 Great West Road, Brentford TW8 9HH, England. Tel. (+44) 208 261 4509, fax: (+44) 208 261 4447 www.elektor.com The magazine is available from newsagents, bookshops and electronics retail outlets, or on subscription. Elektor is published 11 times a year with a double issue for July & August. Subscriptions: Elektor International Media, Regus Brentford, 1000 Great West Road, Brentford TW8 9HH, England. Tel. +44 208 261 4509, fax: +44 208 261 4447 Internet: www.elektor.com/subs Email: subscriptions@elektor.com Rates and terms are given on the Subscription Order Form. Head Office: Elektor International Media b.v. P.O.Box 11 NL-6114-ZG Susteren The Netherlands. Telephone: (+31) 46 4389444, Fax: (+31) 46 4370161 Distribution: Seymour, 2 East Poultry Street, London ECiA, England. Telephone:+44 207 429 4073 UK Advertising: Elektor International Media b.v. P.O.Box 11 NL-6114-ZG Susteren The Netherlands. 6 05-2012 elektor ELEKTOR Membership Counter We now have members in countries. Not a member yet? Sign up atwww.elektor.com/member Take out a free subscription to Elektor Weekly Do you want to stay up to date with electronics and information technology? Always looking for useful hints, tips and interesting offers? Subscribe now to Elektor Weekly, the free Elektor Newsletter. Your benefits: ■ The latest news on electronics in your own mailbox each Friday 1 Free access to the News Archive on the Elektor website ■ You’re authorized to post replies and new topics in our forum Register today on www.elektor.com/newsletter Supporting Companies AudioXpress www. cc-webshop. com Beta Layout www.pcb-pool.com Eurocircuits www. elektorpcbservice. com [uJ e£j EzPCB EzPCB www. silicon ray. com Jatfalaad Jackaltac www.jackaltac. com 57 55 . 2 55 11 Labcenter www. labcenter. com MikroElektronika www.mikroe.com . 88 . 3 pic'O Pico Technology www. picotech. com /PS 1 42 69 Circ'.’fi OneiEV Chalking: Renesas RL78 Challenge www.circuitcellar.com/RenesasRL78Challenge ... 13 Not a supporting company yet? Contact Johan Dijk (j.dijk@elektor.com, +27 78 2330 694) no later than 24 January 2012 to reserve your own space for the next edition of our members' magazine Telephone: +31 46 4389444, Fax: +31 46 4370161 Email: j.dijk@elektor.com Internet: www.elektor.com 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 transmit- ted in any form or by any means, including photocopying, scan- ning and recording, in whole or in part without prior written per- mission 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 guaran- tee 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. 2012 Printed in the Netherlands elektor 05-2012 7 NEWS & NEW PRODUCTS Smart Reset™ Chips cure frustration STMicroelectronics announces its new gen- eration of Smart Reset™ chips. Pioneered by ST who has already supplied tens of mil- lions to major consumer-electronics brands, smart-reset Integrated Circuits provide a safe, convenient and intuitive means of resetting ‘frozen’ gadgets, such as mobile phones, media players, and other portable consumer devices. Traditionally, when electronic devices freeze or lock up, users would either try to remove the battery, which is not always conveni- ent, or find an appropriate tool to press the dedicated reset button placed in a hole that is often difficult to access. Smart resets extend the functional capability of the exist- ing buttons so that users can simply re-set their frozen device with a long push of one or two buttons simultaneously, depend- ing on the device configuration. With the increasing popularity of touch-screen devices, smart resets remove the need for extra buttons, saving space and cost for the equipment manufacturers, and significantly increasing convenience for the user. Effective prevention of accidental resets is secured with the STM6524, ST’s newest dual-assert Smart Reset 1C. Its two inputs connect to a selected pair of buttons on an electronic gadget. When these buttons are held down simultaneously for a manu- facturer-specified time, the 1C sends a reset signal to the main processor. The combina- tion of two inputs and programmable delay time effectively prevents accidental resets. ST is also introducing a new single-assert Smart Reset 1C, the STM651 9, which targets single-button electronic devices like tablets and e-readers, with a similar programmable delay reset. The new generation of ST’s Smart Reset 1C offers several improvements over existing solutions: in addition to a smaller package size, the new devices implement a custom- izable extended input delay time, from 0.5 to 1 0 seconds, which increases flexibility and enables manufacturers to distinguish their products through specific user-interface set- tings. The new smart resets also integrate a dedicated test mode, which improves device testability and slashes test costs. http://www.st.com/internet/analog/ product/252433.jsp (120209-8) New 50 W, 4-channel AC-DC LED driver with standard dimming Phihong USA has developed a new series of multi-channel drivers for indoor and out- door lighting applications. Designated the PDA050W-450G, the driver is equipped with four outputs of 450mA and offers a standard 0-1 OV dimming capability. “The lighting industry is making a decided move from fluorescent and compact fluo- rescent bulbs to much more cost-effective and environmentally friendly LED diodes and drivers for longer lasting energy sav- ings,” said Keith Hopwood, Vice President of Marketing for Phihong USA. “Phihong is committed to staying ahead of the curve by introducing a line-up of cost-competi- tive external AC-DC drivers to retrofit exist- ing lighting installations as well as for OEMs and their rapidly growing demand for high quality lighting power.” The power supply is equipped with four constant current outputs of 450 mA at a nominal output voltage of 24.5 VDC. With an AC input range of 90 VAC to 304 VAC the driver can be operated at the standard North American mains voltages of 1 20 VAC or 277 VAC for residential, commercial and industrial applications. The driver bears safety approval from UL, meeting UL8750, and has outputs that are Class 2 per UL1 310 that are appropriate for linear fluorescent replacement installations. The PDA050W is water-resistant and fully potted with ingress protection ratings of 65 and may operate in a temperature range of 0°C to 50°C. The highly efficient and reli- able driver has minimum average efficiency ratings from 82% at 1 20 VAC input to over 84% at 277 VAC input and has a calculated lifetime of 50l< hours at maximum load and ambient 50°C. The LED driver comes fully equipped with input over-current protection, short-circuit protection, output over-voltage protec- tion and open-circuit protection and has a minimum power factor correction greater than 0.9. Phihong also offers a 5-year war- ranty on selected LED drivers including the PDA050W. Designed in a typical ballast shape and size for ease of retrofit implementation in office lighting fixtures, the series measures 242 x 43.5 x 30.5 mm and weighs 675 grams. www.phihong.com/LED (120209-9) New Digilent Pmod Enables Arduino® / Digilent Interface Digilent® has announced expanded capa- bilities for the chipKIT™ development plat- form for the Arduino® community. The company has released another shield, the chipKIT Pmod Shield-Uno™. This shield provides circuitry and connectors to ena- ble Digilent peripheral modules (Pmods™) to be used with the chipKIT Uno32. “The Pmod Shield-Uno bridges the connec- tion between chipKIT and Digilent Pmods. Professionals, hobbyists, and academics can now build both simple and advanced chip- KIT-based projects with over 50 different Digilent Pmods,” said Clint Cole, president of Digilent. Digilent Pmods include sensors, WiFi and Bluetooth interfaces, rotary encoders, LED displays, keypads, joy sticks, data acqui- sition & conversion, connectors, external memory, and much more. The Pmod Shield-Uno has five 2x6 Pmod connectors. It also provides access to the I/O connectors on the Uno32 as well as connecting to the I2C bus supported by the Uno32. When used together, the Pmod Shield-Uno and the Uno32 let both Arduino-style shields and Digilent Pmods 8 05-2012 elektor NEWS & NEW PRODUCTS use all the features of the Microchip PIC- 32 MX320 FI 28H microcontroller on the Uno32. Digilent’s chipKIT development platform is a 32-bit Arduino-style solution that enables hobbyists and academics to easily and inex- pensively integrate electronics into their projects, even if they do not have an engi- neering background. The platform consists of two PIC32-based development boards and open-source software that is compat- ible with the Arduino programming lan- guage and development environment. Digi- lent’s chipKIT hardware is compatible with existing 3.3 V Arduino shields and applica- tions, and can be developed using a modi- fied version of the Arduino IDE and existing Arduino resources, such as code examples, libraries, references and tutorials. The chipKIT Pmod Shield-Uno costs only $26.95. www.digilentinc.com (120332-II) High-speed digital data logger with extended recording capacity and data filtering capability Saelig Company, Inc. has introduced LOG Storm, a new high-speed digital data logger fortroubleshooting digital system buses. LOG Storm contains an 8-MSample mem- ory buffer, enabling large bursts of data up to 20bits at 1 00 MHz to be sampled. A USB connection is used to stream collected data to the PC, enabling Gigabytes of data stor- age. LOG Storm’s most useful feature is its data filtering capability, efficiently storing only relevant data. Design engineers often use a logic ana- lyzer for digital system debug. But they fre- quently report that this type of equipment 150 farads at 14 volts Australia-based CAP-XX, a developer of thin, prismatic supercapacitors, has developed a supercapacitor module which supplies the cranking current to start the engine in Stop- Start vehicles (also known as start-stop, idle-stop, or micro-hybrid vehicles), reduc- ing wear on the battery and eliminating the need for larger, more expensive ones. CAP-XX’s prototype Stop-Start supercapaci- tor module supports the battery by supply- ing the peak current (up to 300 A) needed for each engine start. Containing six of the company’s thin supercapacitors, the mod- ule is about the size of six DVD cases so it integrates easily into a vehicle’s floorpan, engine bay, or other tight spots. With 1 50 F at 1 4 V, and an ESR of just 4.5 milliohms, the module offers the best power density avail- able today, and the energy necessary to sup- port frequent start cycles in all conditions. It includes the control electronics to manage Stop-Start functions, balance the voltage across each supercapacitor cell, and limit the battery current during each restart. With the module installed, the vehicle battery only needs to support continuous power functions such as air conditioning, navigation and lights. The battery also charges the supercapacitors for their first start, but once driving, the alternator keeps them charged. Additionally, the module will start the engine in low temperatures where a battery would falter, and can store energy in vehicles with regenerative braking systems. In testing under the New European Drive Cycle (NEDC) standard, the supercapacitor module completed more than 1 1 0,000 Stop-Start cycles at room temperature, suc- cessfully maintaining the battery voltage above 1 1 .8 volts. CAP-XX identifies the bat- tery as having failed when voltage falls below 1 0 volts because, based on input from a leading European automaker, batteries at this state of charge can no longer operate vehicle electrical systems reliably. Comparative tests of a battery-only system, also at room temperature, saw the battery fail after only 44,000 cycles. CAP-XX will partner with automobile parts suppliers to manufacture the modules, designing and prototyping the modules to suit their requirements. CAP-XX estimates its module would cost approximately US$60 in mass production, and is already in nego- tiations with a Chinese automotive component company to commercialize the tech- nology in China. www.cap-xx.com (120332-I) is unhelpful when problems result from a long sequence of combined software and hard- ware events. Logic analyzers cannot record sufficient depths of relevant data history to be useful. In contrast, LOG Storm is a dedicated hardware/software combination that can collect high-speed digital bus activ- ity for periods of hours or even days, and extract specific func- tional events of interest. LOG Storm offers compact, elektor 05-2012 9 NEWS & NEW PRODUCTS easy-to-deploy data logging with huge storage capability, a high sampling rate and rich data storage qualification capabilities. Examples of use include: SPI message moni- toring of specific slave select lines; continu- ous, filtered data packet header evaluation; long-term bus monitoring; in-lab develop- ment; on-site, after-installation servicing for chip-to-chip communication emulation, IP evaluation, etc. LOG Storm will be introduced at the Design- West Conference and Exhibition in San Jose on March 27-29, 201 2. Made in Europe by Byte Paradigm, a lead- ing embedded test equipment manufac- turer, LOG Storm will be available in March 201 2 at $1599. www.saelig.com (120332-IV) Atlantic Technology: WA-5030 wireless with power Amp Atlantic Technology has introduced a 30-watt amplified wireless audio sys- tem which can drive a pair of loudspeak- ers at ranges of up to 300 feet from the transmitter. The Atlantic Technology WA-5030 Wireless Transmitter/Amplifier System combines a brand new WA-5030-r zone amplifier and wireless receiver with the company’s proven three-zone WA-50-t wireless transmitter. The WA-50-t transmitter can be sourced from any RCA analog audio line outputs or to a Mac or PC via a built-in USB connec- tion. It broadcasts lossless, uncompressed CD-quality digital audio with a 48 kHz sam- pling rate over on the 2.4 GHz radio band. The wireless technology is highly robust with no data drop issues and essentially no time delay over distances of 1 50 to 300 feet depending on intervening structures. A three-position zone switch on both the transmitter and receiver allow up-to three separate WA-5030 systems to be used in close proximity to each other. The system’s WA-5030-r receiver/ampli- fier contains a matching 2.4 GHz RF sec- tion, digital-to-analog converter, and a high-quality 30-watts per channel stereo power amplifier. The receiver is is suitable for driving most compact bookshelf or in- wall/ceiling 8-ohm speakers to high sound levels with low distortion. The WA-5030-r also comes with an infrared wireless remote control, to allow users adjust volume and to mute the system. WA-5030-r can also be programmed to drive speakers in the bi-amp mode or to drive speakers in a com- mercial or distributed audio system. “Our WA-50 wireless audio system has High accuracy programmable DC Power supply generation Magna-Power Electronics has released its next generation product line featuring major performance upgrades. The new generation, spanning every product model from 2 kW to 2000 l, co o' d < a o > < a o > JTAGSEL RSTIN_N IC6.A TRST_N TDI TMS TCK ARM_TDO SCAN_TDO BUFJTRST_N BUF.TCK BUFJTMS CLK_256FS_0 CLOCKJDUT SYSCLKJ3 Nil H14 RESET P13 TRST N K9 TDI P10 TMS M14 TCK Ell TDO LPC313XFET180 SPI_CS_OUTO SPLSCK SPLMISO SPLCSJN SPLMOSI MI2STX_DATA0 MI2STX_BCK0 MI2STX_WS0 MI2STX_CLK0 I2STX_DATA1 I2STX_BCK1 I2STXJ/VS1 UART_RXD UART_TXD MUART_CTS_N MUART_RTS_N PWM_DATA 03 < GPIOO GPI01 GPI02 GPI03 GPI04 MGPI05 MGPI06 MGPI07 MGPI08 MGPI09 MGPIOIO GPI011 GPI012 GPI013 GPI014 GPI015 GPI016 GPI017 GPI018 GPI019 GPIO20 ADC10B-GPA0 ADC10B-GPA1 ADC10B-GPA2 => °, ADC10B-GPA3 03 < 2 T 1 0u 2 T 10u ■ +1V2 _F1 0 _F1 1 _D13 _D14 _H12 _J4 G13 +3V3 R2 K10 J10 SYSCLKJ) GPIOO L14 GPI02 B11 LED1 _C11 B6 LPC_MCI_CLK \ \ A6 LPC_MCI_CMD A5 LPC_MCI_DATO BS LPC_MCI_DAT1 C5 LPC MCI DAT2 A4 LPC_MCI_DAT3 H13 GPI011 _H10 _J12 J14 \ \ \ \ \ \ "N GPI014 J13 GPI015 _J11 _K12 K14 \ A GPI018 H11 GPI019 K13 B14 \ A GPAO A14 GPA1 _B13 C14 \ GPA3 GPI015 1 +3V3 9 | R17 £ C30 | | C29 !l2MHz 1 22p 22p S3 i N RESET -P | C1 1 /■ LPC DO G2 ^LPC _D1 F2 ^LPC D2 FI ^LPC D3 El ^LPC _D4 E2 ^LPC D5 D1 ^LPC _D6 D2 ^LPC D7 Cl ^LPC _D8 B1 ^LPC _D9 A3 ^LPC. DIO A1 ^LPC Dll C2 ^LPC D12 G3 ^LPC D1 3 D3 ^LPC D14 E3 ^LPC D1 5 F3 / LPC_DQMO HI LPC_WE J2 J1_ J 3_ K1_ K2_ E6_ E7_ LPC_MC1_CD B4 D4 EBI_D_0 EBID 1 EBI_D_2 EBI_D_3 EBI_D_4 EBI_D_5 EBI_D_6 EBI_D_7 EBI_D_8 EBI_D_9 EBID 10 EBID 11 EBID 12 EBID 13 EBID 14 EBID 15 IC6.B MLCDJ3BJ) MLCD_DB_1 MLCDJ3B_2 MLCD_DB_3 MLCD_DB_4 MLCD_DB_5 MLCDJ3BJ5 MLCD_DB_7 MLCD_DB_8 MLCD_DB_9 MLCDJ3BJ0 MLCD_DB_11 MLCDJ3BJI2 MLCDJ3BJ3 MLCDJ3BJI4 MLCDJ3BJI5 LPC313XFET180 EBI_DQMJ)_NOE EBLA„0_ALE EBI_A_1_CLE EBLNWE EBLNCAS_BLOUT_0 NAND_NCSJ) EBI_NRAS_BL0UT_1 NAND_NCS_1 NAND_NCS_2 NAND_NCSJ3 MNANDJRYBNO MNANDJRYBN1 MNANDJRYBN2 MNAND_RYBN3 MLCD_RS MLCD_RWJ/VR MLCD_EJ?D MLCD_CSB N8 LPC_CLK _P9 N6 LPC_A2 P6 LPC_A3 N7 LPC_A4 P7 LPC_A5 K6 LPC_A6 P5 LPC_A7 N5 LPC A8 LS LPC_A9 K7 LPC_A1 0 N4 LPC_A1 1 K5 LPC_A12 P4 LPC_A1 3 P3 LPC_A14 N3 LPC_A1 5 B3 LPC AO A2 LPC_A1 G1 LPC_CAS H2 LPC_RAS P8 LPC_CS N9 LPC_DQM1 L8 LPC_CKE K8 \ LPC AO H7 7~ R15 T +3V3 1 ■X CM o CL O SV1 o o- +3V3 R16 © Ll ^ X4 X +3V3 © @ 3.3V GND U1 DM3D-SF DAT2 DAT3 CMD V+ CLK GND DATO DAT1 SVVA SW_B © © © 1 GPA1 / 2 GPI011 y 3 GPI014 / 4 GP 1015 y SD-CardSocket X m o> CM I CM QC I QC LPC MCI DAT2 / LPC MCI DAT3 / LPC_MCI_CMD / LPC MCI_CLK / LPC MCI DATO / LPC_MCI_DAT1 A LPC_MCI_CD +3V3 © V LPC A1 H8 V LPC_A2 J8 V LPC_A3 J7 V LPC_A4 J3 V LPC_A5 J2 V LPC_A6 H3 V LPC_A7 H2 V LPC_A8 HI V LPC_A9 G3 \ LPC A10 H9 \ LPC All G2 \ LPC A15 G1 V LPC A14 G7 \ LPC A13 G8 V LPC_DQMO E8 V LPC_DQM1 FI V LPC_CLK F2 \ LPC CKE F3 h- cn co h- co cn < < CD O Q —3 AO A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 All A12 BAO BA1 LDQM UDQM CLK CKE cj O LLI d a > CJ CJ CJ goo LLI LLI LLI Odd d d d > > > IC5 DRAM A43E26161 o o o o o o o o o o DQO DQ1 DQ2 DQ3 DQ4 DQ5 DQ6 DQ7 DQ8 DQ9 DQ10 DQ11 DQ12 DQ13 DQ14 DQ15 CAS RAS1 WE CS C/3 C/3 C/3 C/3 C/3 C/3 C/3 C/3 C/3 C/3 C/3 C/3 C/3 C/3 >>>>>>> co < < CD O O A8 LPC DO / B9 LPC_A1 / B8 LPC D2 / C9 LPC D3 / C8 LPC D4 / D9 LPC_D5 / D8 LPC D6 / E9 LPC D7 / El LPC D8 / D2 LPC D9 / D1 LPC DIO/ C2 LPC_D11 / Cl LPC D12 / B2 LPC D13 / B1 LPC D14 / A2 LPC D15 / F7 LPC, CAS/ F8 LPC, RAS / F9 LPC WE/ G9 LPC CS / +5V 1 nrn L— ' 1 ii 1 K1 vcc O D- O D+ O GND O' USB RIO Tr1~ J-X LPC VBUS / LPC DM / X Jci 8 Jci ^Ou ^^On^ O H3 L7 L12 C12 C6 +1V2 ©■ +1V8 t |C3: C38 MOOn A9 C9 Dll E10 ^C33 Jc ■ ^Ou ^^On^ O +1V8 1 B2 E5 F5 G5 H5 L4 ^Jc26 Jc5 ^Ou ^^On^ O +3V3 1 MS M7 M9 C13 ^C22 Jci ^Ou ^^On^ O D5 D7 E8 G12 L10 +3V3 SH K11 R19 10R A13 VDDI VSSI VDDI VSSI VDDI VSSI VDDI VSSI VDDI VSSI VSSI VPP A VPP_B IC6.C VDDA12 VSSA12 VDDA12 LPC313XFET180 VDDE_IOA VSSEJOA VDDE.IOA VSSEJOA VDDE_IOA VSSEJOA VDDE_IOA VSSEJOA VDDE_IOA VSSEJOA VSSEJOA VDDEJOB VDDEJOB VSSEJOB VDDEJOB VSSEJOB VDDEJOB VSSEJOB VSSEJOB VDDE_IOC VDDEJOC VSSEJOC VDDEJOC VSSEJOC VDDEJOC VSSEJOC VDDEJOC VSSEJOC VDDEJOC VSSEJOC VSSEJOC VDDE_ESD VSSEJOC ADC10B VDDA33 ADC10B GNDA All C7 D12 G4 L6 L11 E9 C3 C4 E4 F4 H4 K3 M3 M4 M6 M8 B12 D6 D8 D9 G11 L9 LI 3 A12 LPC_DP y *-* \USB ID CIO lOOn 120026 - 11 MC78M05ABDT +5Vext H© Figure 3. The circuit diagram is surprisingly straightforward for such a powerful board. 20 05-2012 elektor MICROCONTROLLERS • a C compiler, linker and assembler (a ‘toolchain’) • a text editor to write source code • an operating system kernel • various utility programs • a root file system for the operating system By 1990 all the important parts had been assembled, with the exception of the oper- ating system kernel. Richard Stallman knew that it only made sense to start working on the kernel when a stable text editor and compiler were in place. The beginnings of Linux At around the same time a Finnish student by the name of Linus Torvalds bought his first x86 computer and wrote a simple ter- minal program as an exercise to understand the computer better [9]. He installed Minix, a paid-for Unix variant that had been devel- oped by a professor from Amsterdam and his team (and which is still in use today). As he worked on his terminal program, Linus Torvalds saw that it was becoming more and more like an operating system in itself. So as to allow compatibility with the wid- est possible range of existing software it was clear that the system would have to be POSIX compliant. ‘POSIX’ defines a standard for how a Unix operating system should appear externally. Fortunately for us, his local bookshop had the relevant POSIX documentation: this was probably in the form of a manual for one of the many other Unix variants. The main thing was that Linus Torvalds had the information about how the system calls were named and with what arguments they were used. In 1992 the young developer made his creation available on the Internet for free download [10]. He needed a suitable licence under which to release it, and it so happened that he had recently heard Richard Stallman speaking at his univer- sity. The GNU GPL (the open source licence used by the GNU project) was ideal. And then something happened which had not been planned: the open source community quickly realised that Linus Torvalds’ kernel was the missing element in Richard Stall- man’s GNU project! It is worth noting that Stallman had already started on a free GNU kernel called ‘Hurd’, although this does Figure 4. Roadmap of our multi-part introduction to embedded Linux. PC Elektor Linux Board Text editor Compiler Assembler > ‘Toolchain’ Linker RS232 serial console Kernel (as source text) File system (as source text) C library (libc) USB Text editor Bootloader Kernel (as image) Shell (Console) C library (libc) User application File system (as image) 120026 - 14 Figure 5. For software development a PC (running Linux) is used in conjunction with the target board. elektor 05-2012 21 MICROCONTROLLERS 540netwQr;himi]i end ^ Start! nrj portmap Ha«»naii . . . SMbch&tiUc.ah start rtcL.ipv* .tnn l.dtf aull . rp I ILtcr «■ 1 net . ipi/1. eonf .all . rp filter l System time was Thu Jar I BEkSH ttl;. Li TL ll/». setting the Systen Clock using the Hardware Clock » reference... hwclack: can't open 7^/mist/rtc': Ho such Tile or direct nr y SysLem Clock ict. System local time is. noy Tliu lari 1 6B:00‘0ft UTC 1570. Hon Sep 7 to 33:13 :9fl 1JSC 7911 Saying the System Clock, time te the Hardware Clock... hwclack: can't a pen Vdev/mi k/tU' : ha Jiuch file or directory Hardware Clock updated to Hon 5-ufj 26 I2-D:M LTTC 2611. ni sablinq protocol version. I. could rot load hns-T key S55hiaat*J sc . *h end IWIT: truer Aug runlevel: 5 S tiiT Ling sys Luijd^klagd: C64 m 26 done ELEKTOR edlk r Built by Poky 5.0) 5,Q elehtur-gnubUn ttyse h Up ■ / / www . gn uh l in _ oi g el ektor - q r uh 1 in 1 oq i o : I Figure 6. Screenshot of the console in action. nothing to detract from the importance of Torvalds’ contribution. Now, with the GNU project complemented by the Linux kernel, a complete free and open operating system was available for the first time. Strictly speaking it is best to refer to the operating system as GNU/Linux, the ‘Linux’ part referring to the kernel and ‘GNU’ to the rest of the operating system supplied by the GNU project. The big picture After that brief historical digression it is time to take a look at the overall picture of what components make up our GNU/Linux system (see Figure 5). In essence little has changed since the early days: the same basic elements that were needed then are needed for the Elektor Linux board today. For this project we will use several of these original Linux programs. Others we will need to give a wider berth, and we will men- tion the reasons for this later on. Text editor Today’s developers are accustomed to using their own particular choice of text editor, with syntax highlighting, code completion and built-in API documentation. In order to make small changes quickly to files on the Elektor Linux board we need a text edi- tor that can be used over the Linux console (see below). There are traditional editors such as ‘vi’ (or ‘vim’ in its more user-friendly form) and ‘nano’ that fit the bill perfectly. Both of these are present in the root file system (see below) of the Elektor Linux board. Linux developers often use the same text editor on their desktop PC, so as to avoid confu- sion when switching between editors. Another option is the widespread ‘Emacs’ editor, whose reputation some readers may be familiar with. Emacs was developed by Richard Stallman as part of the GNU pro- ject. It is popular with experienced develop- ers because of the wide range of functions it provides; however, beginners might be better off with a more lightweight editor. Compiler + linker + assembler = toolchain In order to run programs on a processor it is necessary to convert it to the machine code of the relevant target architecture. The GNU toolchain includes all the software compo- nents needed to convert C into machine code. It has been designed so that it is rela- tively straightforward to add a new instruc- tion set, and so, for example, versions are available for x86, AMD64, AVR, ARM, MIPS, MSP430 and many other processors. The Elektor Linux board uses an ARM-compati- ble microcontroller and so we use the corre- sponding ARM toolchain. More on this later, when we come to install it. The kernel The kernel lies at the heart of the operat- ing system. It originates in the source code written by Linus Torvalds, but since then some ten thousand kernel developers have worked on the code. However, Torvalds has always had the final say on whether changes and extensions are accepted into the kernel or rejected. Any developer not agreeing with his decision is of course free to fork his own version of the kernel, as the whole thing is open source. To date, how- ever, there has been no significant forking of the Linux kernel code. The development of the software is organised using mailing lists, and anyone is allowed to join these lists and make suggestions. These suggestions will be examined by others and discussed. With the exception of just a few lines of code, the kernel is written entirely in C, and can be simply converted from C to machine code using the GNU toolchain. We will see how this is done at a later point in this series. File system Under the Windows operating system it is clear enough that a user’s files go in the directory ‘Documents and Settings’, pro- grams are installed in ‘C:\Program Files’, and lower-level operating system files are kept in the System32 directory under ‘C:\ Windows’. Like any other operating system, Windows has its own structure for organ- ising its many program and data files. So naturally we ask how things are arranged in embedded GNU/Linux systems. Here the origins do not lie with Linus Torvalds or Richard Stallman; the common basis for all Unix and Linux file systems was mostly developed incrementally as part of POSIX standardisation. The so-called ‘root file system structure’ has been further devel- oped by the well-known distributions such as Debian, SUSE and the like. These distribu- tions each offer the user a complete GNU / Linux system with applications already installed, a graphical user interface, and an up-to-date kernel. To use Linux on our board we will also need to set up a root file system. For our situa- tion a fully-featured desktop version of Linux would be too unwieldy, and a cut- down version of the full system will usu- 22 05-2012 elektor MICROCONTROLLERS Internet Links [1] sauter@embedded-projects.net [ 2 ] www.gnublin.org (site in German only) [3] www.elektor.com/ 1 20026 [4] http://en.wikipedia.org/wiki/Unix [5] http://en.wikipedia.org/wiki/Free_software [ 6 ] http://en.wikipedia.org/wiki/Open_source [7] http://en.wikipedia.org/wiki/ Massachusetts_lnstitute_of_Technology [ 8 ] www.gnu.org [9] 'Rebel Code: Linux and the Open Source Revolution 1 , Glyn Moody: ISBN 0738206709 [ 10 ] www.kernel.org ally suffice, with a relatively small choice of programs and libraries. There are specially- written programs that can be used to create custom root file systems; alternatively, all the mainstream distributions offer ready-made versions for ARM processors. More on this topic later. The standard C library Applications provide the vis- ible face of any computer or similar product. The operating system sits in the background, driving the hardware, allocat- ing memory, handling com- munications over the network or other interfaces and much else besides. Now, application writers do not want to spend their time forever rewriting functions to read and write files, manipulate strings and so on. To the developer’s res- cue comes the standard C library, in its most popular form known as ‘libc’. Slimmed-down ver- sions of this library are available that are suitable for embedded systems where com- puting power and storage are relatively lim- ited compared to desktop PCs. The standard C library provides the inter- face between the application and the kernel. It also includes a number of com- monly-wanted utility functions. The library is loaded at run-time as required by appli- cation programs (it is ‘dynamically linked’). This saves memory as a single copy of the library can serve all running applications. The serial console and shell The console, which can be compared with the command prompt in Windows, can be used for entering commands, trigger- ing actions (possibly on a remote machine) and displaying results. In this way it pro- vides a user interface to the system. Usually it is used in conjunction with a ‘shell’, which provides many handy extra features that make a Linux system easier to operate. We will look at the shell in greater depth later. When Linux is booted on a desktop PC the keyboard and screen provide the traditional root console. (It is usually pos- sible to switch to this console from the graphical user interface by pressing control-shift-FI .) When administering machines remotely it is common to use a protocol such as SSH or, where security is not a consideration, TELNET, to access the root con- sole over a network connection. A third option is to access the console over an RS-232 interface. A PC with a serial port can be used at the other end of this con- nection, running a terminal emu- lator program such as HyperTer- minal orTeraTerm (under Win- dows) or picocom (under Linux). What the future holds In the next instalment in this series we will look at how the hardware (Figure 1) is arranged. We will look closely at the power supply, the micro- controller, the SDRAM device and the vari- ous interfaces. On the software side, we will examine the boot process: thanks to the pre-installed demonstration software (Fig- ure 6) the board is ready for experimenta- tion straight away. (120026) Elektor Products and Services • Elektor Linux board, ready built and tested: # 120026-91 All products and downloads are available via the article support • Free software download page: www.elektor.com/ 1 20026 elektor 05-2012 23 MICROCONTROLLERS Platino Control led by La bVI E W (i ) Although at first blush they appear completely different, Arduino and LabVIEW both are programming en- vironments aimed at people who do not, or do not want to know how to program. Both platforms were designed for quickly developing an application without being slowed down by complex syntax issues or in- tricate procedures. Reusability of earlier work plays an important role in both environments. By Clemens Valens (Elektor UK/INT Editorial) With the possible exception of their success, that’s where any simi- larities end. Where LabVIEW (LV) is a graphical programming lan- guage (GPL), Arduino is text based; where LV is a closed commercial package, Arduino is free and open; where the commercial success of LV is actively being pursued by a company, Arduino was simply thrown at the online electronics community. But there is one other thing that LV and Arduino have in common: both platforms see a lot of use in education, at schools and universities. It is therefore not surprising that they finally met when National Instruments (Nl) in 201 1 introduced their LV Interface for Arduino (LVIFA or LIFA). This interface allows easy control of hardware from LV without having deep pockets. Although it’s always been possible to control cheap custom hardware from LV, doing so requires some LV experience that many users lack. LIFA solves this problem by providing a simple serial protocol for communicating with the external hardware. Even though LIFA is targeted at Arduino there is no reason whatsoever to stop there. Anyone capable of implementing the protocol on what- ever hardware platform may use this library. LIFA comes as a free and open source library containing quite a few Arduino style functions. Analogue and digital I/O are available, as are SPI and l 2 C communications. Although LIFA featuring servo and stepper motor control seems slightly robotics oriented, it also allows continuous sampling at up to about 5 kHz. At the time of writing LIFA version 2.0 had just been released. Nl has done a nice job of making Arduino easy for LV users, but unfortunately they appear to have forgotten to make LV easy for Arduino users. Most LIFA functions have examples that illustrate their use, yet the most basic example of all, how to flash an LED, is sadly missing. Although this should be an easy exercise for the aver- age LV user, the average Arduino user attracted by the power of LV will probably stand clueless. In this article I intend to show you how to get started with LIFA and LV, assuming that you are comfortable with Arduino. First of all I will walk you through the creation of a Hello World blinking LED exam- ple, then we will delve into the modification of existing functions, followed by the creation of your own functions and finally we will add extra hardware to our Arduino platform that we control from LV. To cap it all we will add some shared variables that can be moni- tored wirelessly over the Internet on an iPad or Android tablet from anywhere on the globe. Our hardware platform will be Platino as it is compatible with Arduino but has on-board peripherals so you don’t have to wire anything up. The examples presented here will also work with standard Arduino hardware and the right peripherals (buzzer, LCD, rotary encoder). LIFA Let’s be clear about it from the beginning: LIFA is not LabVIEW on Arduino, it is LabVIEW with Arduino. It is important to understand this difference to avoid unjustified expectations. LIFA is a way of controlling external hardware from LV. It consists of three parts: a kind of server running on the Arduino board, a serial communica- tions protocol and a library of LV functions to control the board. With LIFA you can use Arduino to interact with the real world under control of LV. Without LV it will not work. Okay, this last statement is not completely true, because you can of course implement the LIFA protocol in another program written in like Visual Basic or Qt and use that to control the Arduino. What’s important here is that the Arduino is a LIFA slave device and will not do anything until it is ordered to do something. To use LIFA you have to install first LabVIEW (I used version 201 1 ), then NI-VISA (Virtual Instrument Software Architecture, if not installed already) that will allow LV to talk to the serial port (and more) and then LIFA (version 2.1 .0.69 at the time of writing, you need version 2 or higher if you want to use Arduino 1 .0). You are supposed to do this last step with the VI Package Manager. These are massive files and installing it all takes some time. When the installation is finished (I suppose that you managed to get Arduino 1.0 up and running all by yourself) you have to load the LIFA serial server sketch into the Arduino board. You can find it in the ‘vi.lib\LabVIEW Interface for Arduino\Firmware\LVIFA_Base\’ sub- folder. Load the file LVIFA_Base.pde in the Arduino IDE and upload it to the board. You may run into trouble here if your board does not have 32 KB or more of flash memory. The Arduino Uno or Mega are fine, but older boards with ATmegal 68 chips are not. The reason for this is the 5 KB stepper motor library included in the sketch. You can deactivate it by commenting out a line in the file LabVIEWInterface.fi. Among the issues you may run into if you use a non-standard Arduino board, e.g. Platino with an ATmegal 64(P), are compile 24 05-2012 elektor MICROCONTROLLERS An introduction to UFA, a La bVIEW interface for Ardui no errors spawned by the stepper motor driver library because it does not support the MCU. To prevent this from happening you have to rename or delete the CPP files so they will not be compiled at all. Without stepper motor support and without compiling the CPP files the UFA sketch will fit into 1 6 KB devices too. Once you have the UFA sketch running on the Arduino you probably would like to see if it works. For this you launch LabVIEW, click Find Examples in the main window, select the Search tab, search for Arduino and discover that there is no example that will run without additional hardware... That’s right; they forgot to include the Blink- the-Arduino-LED example. Duh! To fix this omission I will show you here how to make it yourself. Hello World with a virtual LED Programming in LV differs a lot from programming in Arduino. Because LV is a graphical ‘language’ a program is drawn instead of being written. Probably 99% of the very little typing you do in LV is related to constants, comments and documentation. Where in Arduino a program is called a ‘sketch’, in LV it is called a ‘virtual instrument’ (VI, LV has its origins in test and measurement applica- tions where lots of instruments are used). Functions are represented as blocks and data streams are repre- sented by the wires that connect the blocks. The wire colours indi- cate the type of data being transported. LV is very strict in this regard and you simply cannot accidentally mix up wires of differ- ent colours. Also, if you forget to connect an important function input, LV will not let you run the VI. Being an LV novice I preferred to start simple, being a microcon- troller enthusiast I wanted to blink an LED. This can be done easily in LV as it has LEDs. We’re off. From the LV main window select Blank vi. Two windows will open, one named ‘Block Diagram’, the other is called ‘Front Panel’. The drawing is done in the block diagram; the LED will show up on the front panel. Right-click somewhere in the block diagram to bring up the functions menu. Click the down arrow to expand it (Figure 1). To make a continuously blinking LED I chose to use an endless while loop with a delay. You can find it in the Programming -> Struc- tures palette. Of course there is more than one way to skin a cat, also in LV, and another possibility would be to use the timed loop from the Programming -> Structures -> Timed Struc- tures palette, but it looks more intimidating. To make the loop ^ P LlWtH*» Pi«v -silling hV-.vi r imfft ijt) [•-rfbrijfrtMV Ijo Urctm iL: h I hhduui MatittfTdbC* n flit Rv,'. i'ivjtj ri’.wrfifi Qjmw-Lrvly rviT'h Putgn fi ■im.taitfffl ic-M L I ■ St] Irfjaf I- gjpgj Bl r p* ftiWrrH hflVDfltej I kn Lia-fliim. lidWC-lYI.. "v’durrj 1 ftniy.wTf-iri E 1 y 3 51 ; ( ltructur« Array UBtW, UfrH... : Ti 1 0 * © ^ fslJTtrrr flnft.wi 1 1 &r_ O' 1 Cuiium-iPi Trarj ti . t 41 mi b WwefQmt Ap$4:e£k:o C-. ■ 0 ®; Af- * raw Rvnrt’f n«W rn '.Vrtfiiinft'Vi... fcrfMwOnw... 4 £1 m tjs VtaJjfe IP-ahriJE et , . . Figure 1 . The Functions context menu. Click the Search button to quickly locate a function that may be hidden deep down a function sub palette. The riqht mouse button click One of the difficulties the LV novice encounters is finding the functions he needs. Functions are grouped by type in so-called palettes, but since there are so many palettes it is not easy to find the one you want and of which you did not even imagine its existence. For this problem LV has a powerful solution: the right mouse button click. Whenever you are lost, click right and LV will show you a context menu with the most probable options for the situation you are in. Need a function? Click right and look at the palette options. Need a data type? Right-click and ask LV to create it for you. Idem for controls, indicators, advanced edit- ing options, you name it, it will probably be in the context menu right in front of your eyes. elektor 05-2012 25 MICROCONTROLLERS Do not abort I n MM 'I tcwj ccm COWb RrlrivJi When developing an application in LV you will be tempted often to abort the execution of the VI you are working on by pressing the button with the red dot. In many cases this is not a problem, but sometimes it is, especially when you use serial ports. It is important to properly close the serial connection in LV to prevent the communications between the VI and your board getting messed up. If you’re lucky you may see an Error 5002 message, if not your setup simply won’t work. This happens most often when the VI does not go through the Arduino Close sub-VI because you pressed the abort button. It is extra annoying when you are working on Arduino and LV code at the same time to fine tune your application, because you will not be able to upload any code to your Arduino board as the serial port is already in use. You can see in LV that a port is open (or was not closed) when there is a little icon in front of the COM port when you open the drop down list (see screenshot). To get out of this situation you have to either quit LabVIEW to get the COM port back or find another way to close the port. If your VI has a path to the Close sub-VI you can restart the VI and guide it through the Close sub-VI to recover the serial port. Therefore al- ways make sure that you can get out of endless loops to close your VI properly. Add a Stop button if necessary. Avoid using the Abort button. endless we will have to set its Loop Condition (the square with the red dot in the lower right-hand corner of the loop) to False. Do this by placing the mouse on the square in such a way that its left side starts blinking (the mouse cursor changes into a little reel of wire), then press the right mouse button (see inset) and select Cre- ate Constant from the menu that pops up. A green square with an F(alse) in it is created, meaning that the loop will never end. Note the dashed green line between the two squares; it indicates a Boolean data stream. From the Programming -> Timing palette I picked the Wait Until Next ms Multiple block to slowdown the endless loop. You have to place it inside the loop. Now hover the mouse over the left of the timer block to find the millisecond multiple input. When it appears use the right mouse button to bring up the context menu and then select Create -> Constant (Figure 2; this is slightly different from setting the Loop Condition). You will now have a little rectangle with a blue rim and a zero in it. Change the zero to, say, 250. This means that the loop will be executed every 250 ms. Now comes the hard part: the LED toggle mechanism. Again, sev- eral techniques can be used, but I chose to use the Loop Iter- ation box, the little blue square in the lower left-hand corner of the loop. The value of this box is incremented every time the loop is executed, so if we continuously test this value for even or odd we end up with a toggling result. An odd/even test is easy in the binary domain by testing the least significant bit of the value. To do this we perform a logical AND (get it from the Programming -> Boolean palette) of the value with a constant value of 1 . First wire one input of the AND gate to the loop counter to change the data type of the gate from Boolean to Integer, then create the constant of 1 by right-clicking the remaining input of the AND gate. The order is important here. Supposing you had created the constant first, you would have obtained a Boolean that cannot be AND-ed with an integer, causing LV to refuse to connect the other AND input to the loop counter. The result of the logic AND is now also an integer and it has to be converted to a Boolean first before it can be connected to an LED. We can do this by adding a Greater? function from the Program- ming -> Comparison palette. If you place it close enough to the AND-gate, LV will make the connection automatically. Connect a constant of zero to the other input of the comparison function. The output of the Greater? function is a Boolean that we can con- nect to an LED. To do this, right-click the output, select Create -> indicator and an LED will appear in both the block diagram and the front panel (use Ctrl-E to move quickly between these two windows). That’s it; our LV Hello World blinking LED VI is now ready (Figure 3). Click the Run button on either the block diagram of the front panel to see the LED flash at a rate of 2 Hz. To stop it you will have to press the Abort button (see inset). To finalise it, if you like, you can move all the bits around to create a pretty looking VI, or you can let LV clean it up for you by using the Clean Up Selection function (by clicking the button with the broom, selecting it from the Edit menu, or by pressing Ctrl-U). When done, save it. With a real LED Now that you have an idea of how to go about programming in LV we will continue by extending the Hello World example to the hard- ware, that is, instead of making the LV LED blink, we will now make the Arduino LED blink. The LED is the one connected to digital pin 1 3 (Arduinospeak) also known as port B pin 5 (PB5). The steps to do this in LV are very similar to those in an Arduino sketch. You have to select the board and the serial port, make digital pin 13 an output (setup) and then toggle it (loop). In LV there is one extra step at the end because you have to close the serial port when you’re done. In the VI we take these steps as follows: Arduino prepare From the Arduino palette get the init block (Figure 4) and place it to the left of the loop in the block diagram. Hover over its inputs and notice that they all have default values (the values between round brackets) except for the visa resource and the error in. The latter can be left unconnected, not the first, so do a right-click on this one and create a constant. This constant is a drop- down list from which you select the serial port that is used by the Arduino board. The other inputs can be left at their default values, even if you have an Arduino Mega. Arduino setup From the Arduino -> Low Level palette get the Set Digi- tal Pin Mode block and place it between the init block and the loop. Connect the pink Arduino Resource pins of the two 26 05-2012 elektor MICROCONTROLLERS blocks, and also connect the error out of the init block to the error in of the Set Digital Pin Mode block. Create a con- stant on the Digital I/O Pin input and set it to 13. Create another constant on the Pin Mode input and set it to output. WtaHr TIhtk r H*j Desaptaxi and Tp.„. FUf>’JymfV ¥ Trim P*ilfl ¥ NUfTW Cflvrfn 1 I Crvrehwtf r l.'lWlVj P^fLwc ¥ ImfiLdLur PujfjerLws. _J r Figure 2. A typical context menu that pops up when you do a right mouse button click on a function input or output. Arduino loop From the Arduino -> Low Level palette get the Digi- tal Write Pin block and place it inside the loop. Connect its left Arduino Resource and error pins to their counterparts on the right side of the Set Digital Pin Mode block. Connect the Digital I/O Pin input to the pin number constant 13 that you created during the previous step. Connect the Value input to the output of the AND gate. LabVIEW extra step From the Arduino palette get the Close block and place it to the right of the loop. Connect its left Arduino Resource and error pins to their counterparts on the right side of the Set Dig- ital Write Pin block. Do a right-click on its error out pin and from the Dialog & User Interface Palette entry in the context menu get the Simple Error Handler. If you hover this function block to the right of the Close block, LV may connect it automatically for you. If not you will have to do it yourself. Finally, click right on the green square with the F that is connected to the loop’s stop condition and select Change to Control from the context menu. This will create a pushbutton on the front panel that allows you to stop the VI in a controlled way (see inset “Do not abort”). Your VI should now look something like Figure 5. If you made a mess of your block diagram, now is a good time to press Ctrl-U to clean it up, then save your work. Run the VI. If all is well the LED on the Arduino board should start to flash at the same rate as the one on your computer screen. The real one may not blink as regularly as the virtual one, I suppose due to real-time and USB issues within Windows, but it should not go slower or faster. If the real LED does not start flashing but the virtual one does, you probably have entered the wrong serial port for the board. Click the Stop button and you will probably see an error 5005 “Unable to find Arduino”. You do not see this error before stopping because the error dialog is at the end of the VI. If you connect it directly to the Init block, you will see it earlier, but you will also get more because the other Arduino related functions will produce errors too. In the second part of this article we will dig in deeper and really get our hands dirty. Although you may not become a LabVIEW expert, you’re sure to get to know LIFA very well. (120208) Figure 3. My First Virtual Instrument, or how to flash a virtual LED at 2 Hz using LabVIEW. The smaller window with the gray back- ground is the front panel that holds the flashing LED. Ariluiiiu i ft 1 f A >■«■'+■ ( ^,riJ4«Hw | m JUT 1M u* rj\ \wl\ IJ#y Figure 4. The Arduino function palette as seen from the block diagram. The embossed squares with a black triangle in the upper right corner lead to sub palettes and examples too. LET' p4n nxtl*f [LB] * LED |iri iiijJ? {"QiAni. D ~ ■ TiJ .« =H P«jd n! fVi f+i Ir .vi m # ■Tjrnp Firrt r,-iiv-: Figure 5. The Hello World VI from Figure 3 extended so that it will also flash a real LED on the Arduino board. Note the Stop button that allows a clean exit. elektor 05-2012 27 AUDIO & VIDEO Preamplifier 2012 (2) Part 2: Moving-Coil / Moving-Ma (MC / MM) board By Douglas Self (UK) Just in case you didn’t know, vinyl records are making a comeback and there are even under-25 musicians releasing new material on CD cheerfully along with vinyl, preferably of the 180-gram variety. Also, high- end turntables are available at extragalactic prices but none of this makes any sense if you do not have a preamplifier to match your MC or MD cartridge optimally and that’s exactly what the present design does — rather successfully. Referring back to the block diagram of the Preamplifier 201 2 shown in part 1 of the article [1 ], this month we discuss the blocks identified as ‘MC preamp’, ‘Load synth’, MM preamp’, Bandwidth definition filter’ and ‘Switched gain’. Note that the switch drawn with Switched gain’ block is actually an on- PCB jumper block. All units are comprised on a single circuit board, the second of a total of seven that make up our very high end audio control amplifier. Let’s see how it all works by taking a tour of the circuit dia- gram in Figure 1. Moving-Coil (MC) stage This stage built around transistors T1-T4 and opamps IC1 A and IC2A gives very low noise with the low impedances of moving- coil cartridges. It provides a fixed gain to its output of +30 dB. Gain switching to cope with the very wide range of MC cartridge sensitivities is done later in the switched- gain stage. There are no compromises on noise or headroom with this architec- ture, and no necessity to switch the gain of the MC stage, which simplifies things considerably. The total gain of the stage is actually +45 dB, to allow a sensibly high value of feedback resistance defined by R8 and R9. Only part of this gain is used, tapped off via C7. The extra 1 5 dB of gain causes no head- room problems as the following MM stage will always clip long before the MC stage. The DC conditions for the 2SA1 085 input transistors are set by R3 and R4. The DC conditions for the opamp IC1 A are set inde- pendently by the DC integrator servo IC2A, which enforces exactly 0 V at the output. This MC stage design gives a 1 dB improve- ment in noise performance (for 3.3 Q and 10 Q source resistances) compared with earlier versions of this circuit. This results from using four paralleled 2SA1085 pnp transistors, which should be easier to obtain than the obsolete 2SB737; the latter can however be used if you have them. Component positions R1 and Cl are pro- vided so the cartridge loading can be mod- ified. This has only a marginal effect on MC cartridge response in most cases because the cartridge impedance is so low. However, if you want to experiment then the appro- priate range for R1 is 1 0 ^1- 1 kQ, and for Cl O-IOnF. Moving-Magnet (MM) stage This is a relatively conventional stage, except that it uses multiple polystyrene capacitors to obtain the required value 28 05-2012 elektor AUDIO & VIDEO Performance araoh MC/MM board # 1 1 0650-2 only. Test equipment: Audio Precision Two Cascade Plus 2722 Dual Do- main (@Elektor Labs). Here we have the AP-2 supplying an amplitude corrected signal ac- cording to RIAA pre-equalisation curve. This allows the deviation from the ideal RIAA curve (amplitude error) to be visualised con- veniently. The curve with the higher roll-off point was plotted with the IEC Amendment relay energised. The error at 20 kHz is less than 0.06 dB, measured on the left-channel MC input. Measurements on the right-channel MD input gave practically identical results, the curves matching extremely closely. In conclusion it is safe to say that the investment in a large number of relatively costly polystyrene capacitors in this section of the Pream- plifier 2012 is justified. (polyester capacitors have worse tolerance and introduce non-linear distortion) and to improve RIAA accuracy (because random errors in the capacitor values tend to can- cel). Multiple RIAA resistors R22-R23 and R24-R25 are used to improve accuracy in the same way. The value of Cl 2 is large as the IEC amendment is not implemented in this stage. The HF RIAA characteristic is corrected for the relatively low gain of the stage by R26, R27, and C22. Once again two resistors are used to improve accuracy, and C22 is polystyrene. Note that an NE5534A is used here for IC3 as it is quieter than half an NE5532, and considerably quieter than an LM4562 with its higher current noise. The high induct- ance of an MM cartridge makes low cur- rent noise important. Cartridge loading, and capacitance in particular, has a much greater effect on MM cartridges. Compo- nent positions R13 and C8 are provided so it can be modified. The appropriate range for C8 is 0-330 pF. Adding extra loading resistance is rarely advocated; if used here it will partly undo the noise reduction given by the load synthesiser. The lowest recom- mended value for R1 3 is 220 kCL The load synthesiser A load-synthesis circuit around IC4 is used to make an electronic version of the required 47 kCl loading resistor from the 1 M Q resistor R16. The Johnson noise of the resistor is however not emulated and so noise due to the rising impedance of the MM cartridge inductance is eliminated. R1 6 is made to appear as 47 l by driving its bottom end in anti-phase to the signal at the top. IC4B shows a high impedance to the MM input while IC4A is an inverting MM/MC Board Performance Test conditions: supply voltage ±1 7.6 V, B = 80 kHz; measured at Volume/Balance/Tone control board output (# 1 1 0650-1 ); volume set to 1 Vout. Test equipment: Audio Precision Two Cascade Plus 2722 Dual Do- main (@Elektor Labs) MD: 5 mV in, 1 kHz, JP1/2 = 15dB (source 750 £2) THD+N S/N S/N S/N (input shorted) 0.008% 82 dB 86 dBA 88 dBA MC: 0.2 mV in, 1 THD+N 0.016% kHz, JP1 /2 =1 5 dB S/N 76 dB (source 1 £2) S/N 79.5 dBA MC stage gain 29.8 dB Low roll-off (-3 dB) 19.8 Hz (L) 20 Hz (R) 23.3 Hz (L, IEC Amendment on) 24.8 Hz (R, IEC Amendment on) Deviation from straight line: -0.06 dB (100 Hz to 20 kHz) Gain definitions on JP1 /JP2 (dB) L R 0 0 0 5 5.22 5.23 10 10.95 10.97 15 14.71 14.72 20 19.52 19.51 elektor 05-2012 29 AUDIO & VIDEO 4x2SA1085 0 MC L MM L 0 MC R MM R Optional ■17VO 4x2SA1085 RE1C TR63 1 C36 ■ Pi ; |co| lOOp 1 > 1 L R65 IC1 = NE5532 IC2 = TL072 IC4 = NE5532 IC6 = NE5532 Figure 1 . The circuit diagram of the moving coil / moving magnet preamplifier section of our Preamplifier 201 2. Everything is designed with low noise in mind, as well as perfect adaptability to a wide variety of MC or MD cartridges out there. stage. Multiple resistors R19-R20 and R17- R1 8 are used to improve gain accuracy and therefore the accuracy of the synthesised impedance. Subsonic filter This is a two-stage 3rd-order Butterworth highpass filter that is -3 dB at 20 Hz. Mul- tiple resistors R28-R29 and R30-R31 are again used to improve accuracy. My pre- vious preamp designs have used a single- stage version of this, but I have found the two-stage configuration is preferred when seeking the best possible distortion perfor- mance [2]. An LM4562 is used here (IC7A) as 30 05-2012 elektor AUDIO & VIDEO V23105-A5003-A201 +Vre MM/MC IEC Amendment C27 220u 35V OdB R48 Htr LLL P L PHONO+_L PHONO-_L K6 17V X . 1 => 1 =>■ |o:| n^l IC7 = LM4562 lol ■ cm ■ |cm| ■ cm IC8 = LM4562 r^zg) LLL P R R96_ K7 47R | K) I PHONO+_R PHONO- R r R94 ■17VO 110651 - 11 Check the figures in the Performance inset to see if we’ve been anywhere near successful. it significantly reduces distortion. Switchable IEC amendment The IEC amendment is an extra LF roll- off that was added to the RIAA spec at a later date. Most people regard it as unwel- come, so it is often omitted. Here it can be switched in by placing an extra resistance R34 across the subsonic filter resistances R32-R33. This is something of an approxi- mation, but saves an opamp stage and is accurate to ±0.1 dB down to 29 Hz. Below this the subsonic filter roll-off begins and the accuracy is irrelevant. elektor 05-2012 3i AUDIO & VIDEO Figure 3. Fully assembled and tested MM/MD board “escaped from the Elektor Labs”. The switched-gain stage This stage around IC7B allows every indi- vidual MC and MM cartridge on the market to receive the amount of gain required for optimal noise and headroom. The gain is varied in 5 dB steps by a jumper on jumper block JP1 selecting the desired tap on the negative-feedback divider R36-R45. Each divider step is made with two paralleled resistors to get the exact value required, and improve accuracy. R35 provides con- tinuity of DC feedback when the switch is altered. The drive signal to the Log-Law Level LED stage (LLLL) is tapped off via R47 and appears on connector l<4. The LLLL circuit and circuit board will be discussed next month. Construction The circuit is constructed on double-sided through-plated printed circuit board # 110650-2 (note number) of which the silkscreen (component overlay) is shown in Figure 2. As with the board we dis- cussed in the previous instalment, assem- bly is largely a routine matter since only through-hole parts and conventional sol- dering are involved. For assembly we again recommend the use of a grill or the even better a flip-over type of PCB assembly jig. Assuming you have positively identi- fied each and every part using the compo- nents list, the flip-over jig enables the parts leads to be inserted first. Next, the parts are held securely in place at the top side of the board by a thick layer of packaging foam and a clamp-on panel. The board then gets flipped over allowing the wires to be sol- dered one by one without the parts (now at the underside) dropping or dislocating. Experienced users do the low-profile parts first for obvious reasons. The end result should be a board that’s as thoughtfully built as the circuit was designed — check your personal effort against our prototype pictured in Figure 3. (110651) References [1 ] Preamplifier 201 2 part 1 , Elektor March 201 2; www.elektor.com/ 1 1 0650. [2] Peter Billam ‘Flarmonic Distortion in a Class of Linear Active Filter Networks’, Journal of the Audio Engineering Society June 1 978 Volume 26, No. 6, p426. 32 05-2012 elektor AUDIO & VIDEO COMPONENT LIST Resistors (1 % tolerance, metal film, 0.25W) R1 ,R13,R49,R61 = optional, see text R2,R8,R50,R56 = 1 00£2 R3,R24,R35,R51 ,R72,R83 = 1 0k ^ R4,R52 = 56kn R5,R53 = 2.2I<£1 R6,R54 = 330£1 R7,R55 = 3.3£1 R9,R38,R57,R86 = 470£1 R10,R11,R58,R59 = 2.2M£1 R12,R32,R60,R80 = 220I<^ R14,R62 = 51 Ok£l R15,R63 = 430kn R16,R64 = 1 R17,R65 = 27kn R1 8,R66 = 39k£l R1 9,R20,R26,R67,R68,R74 = 2.00kQ R21 ,R45,R69,R93,R97,R98 = 220£1 R22,R70 = 110l<£2 R23,R71 =150kn R25,R73 = 11 kn R27.R75 = 2.4kft R28,R29,R76,R77 = 36kn R30,R78=180kn R31,R79 = 120k£l R33,R81 = 43 kQ R34,R46,R82,R94 = 68kn R36,R84 = 820^ R37,R85 = 1.3kn R39,R87 = 750Q R40,R88 = 300^ R41 ,R42,R43,R89,R90,R91 = 160£1 R44,R92 = 200^ R47,R48,R95,R96 = 47£1 R99,R100 = 100I<£1 Capacitors Cl ,C8,C28,C35 = optional, see text C2,C4,C7,C1 2,C27,C29,C31 ,C34,C39,C54 = 220pF 35V, 20%, diam. 8mm, lead spacing 3.5mm C3,C9,C30,C36 = 1 0OpF 630V, 1 %, polysty- rene, axial C5,C32 = 1 5pF ±1 pF 1 60V, polystyrene, axial C6,C33 = 470nF 1 00V, 1 0% Cl 0,C37 = 22pF 35V, 20%, diam. 6.3mm, lead spacing 2.5mm Cl 1 ,C38 = 4.7pF ±0.25pF 1 00V, lead spacing 5mm Cl 3-C1 7,C40-C44 = 1 0nF 63V, 1 %, polysty- rene, axial Cl 8, Cl 9,C20,C45,C46,C47 = 4.7nF 1 60V, 1 %, polystyrene, axial C21 ,C48 = 220pF 630V, 1 %, polystyrene, axial C22,C49 = 2.2nF 1 60 V, 1 %, polystyrene, axial C23,C24,C25,C50,C51 ,C52 = 220nF 250V, 5%, polypropylene, lead spacing 10mm C26.C53 = 1 0OOpF 35V, 20%, diam. 13mm, lead spacing 5mm C55-C62 = lOOnF 100V, 10%, lead spacing 7.5mm C63.C64 = 220nF 1 00 V, 1 0 %, lead spacing 7.5 mm C65,C66 = 1 0OpF 25V, 20%, diam. 6.3mm, lead spacing 2.5mm Semiconductors T1 -T8 = 2SA1 085, Hitachi, e.g. Reichelt.de # SA 1 085; RS Components # 1 97-9834 IC1 ,IC4,IC6 = NE5532, e.g. ON Semiconductor type NE5532ANG IC2 = TL072 IC3JC5 = NE5534, e.g. ON Semiconductor type NE5534ANG IC7JC8 = LM4562, e.g. National Semiconduc- tor type LM4562NA/NOPB Miscellaneous K1 ,l<2 = 4-pin straight pinheader, pitch 0.1 ” (2.54mm) Socket headers for K1 ,l<2 l<3 = 3-pin straight pinheader, pitch 0.1 ” (2.54mm) Socket header for l<3 K4-K7JP3 = 2-pin straight pinheader, pitch 0.1” (2.54mm) Socket header for K4-K7 Jumper for JP1,JP2,JP3 JP1 ,JP2 = 1 0-pin (2x5) pinheader, pitch 0.1 ” (2.54mm) l<8 = 3-pin screw terminal block, lead pitch 5mm RE1 ,RE2 = relay, DPDT, 1 2V/960n, 230V/3A, PCB mount, TE Connectivity/Axicom type V231 05-A5003-A201 PCB # 1 1 0650-2 (www.elektorpcbservice. com) Note: parts available from Farnell (but not ex- clusively), except T1 -T8 and PCB 1 1 0650-2. Figure 2. Component overlay of the MM/MC board. The high quality ready-made board is available from ElektorPCBservice.com. elektor 05-2012 33 POWER SUPPLIES & BATTERIES Lossless Load Keeps energy waste low By Carlo Cianferotti (Italy) While the title might sound controversial (a load always dissipates some power), the concept presented in this article is spot on: it mimics a load to in-vehicle circuitry that checks for lamp faults. The circuit is great whenever a glass lamp gets replaced by an energy-saving LED substitute. Remarkably, it does not torch extra energy like a shunt would do. Instead, the Lossless Load briefly stores the energy needed to trick the fault circuitry and feeds it back into the car’s electrical system when appropriate. Whenever you replace one of your car’s lamps (head/ta il/ bra ke/indicator/ boot/ parking etc.) with an LED aftermarket equiv- alent, one problem often arises: the lamp failure monitor built into your car’s electri- cal circuitry faithfully responds by making a lamp fault indicator come on when there’s nothing wrong with the LED unit. The (sup- posed) error can be traced back to the much smaller current drawn by the LED unit com- pared to that of its incandescent counter- part. In fact, if you buy an LED replacement lamp, it often comes with a bulky power resistor for wiring in parallel with the energy efficient LED just to cheat the lamp failure monitor. Energy-wise, this workaround is widely off the mark. One of the benefits of LED light- ing is the reduced power requirement. And saving power on one side while wasting it on the other is just plain wrong. This shunt resistor can also get pretty hot and prob- lems might arise in the car’s plastics nearby. A simple step-up switching converter capa- ble of feeding up to 4 amps back to the failure monitor can be used to overcome this problem. “Another Fine Mess?” No, a challenge. Some theory Take a look at the schematics of the stand- ard circuit to see how the problem gets solved. Figure 1 shows the original configu- ration drawing, say, 1 .75 A from the vehicle battery. The coloured block represents the in-car lamp failure monitor. From Figure 2 1.75A ► £ 12V 12V 21W 5 I Figure 1 . Standard current flow in a car’s lamp circuit. There’s about 1 .75 A flowing through the failure monitor circuitry. 1.25A ◄ Figure 2. To trick the lamp failure monitoring circuit, we need 1 .25 amps to flow besides the current through the LED replacement unit. Figure 3. To trick the monitoring circuit, a 1 .25 A current source could be connected as shown. 34 05-2012 elektor POWER SUPPLIES & BATTERIES Vref 8(14) RjCj 4(7) Voltage Feedback 2(3) Output Comp. 1 ( 1 ) GND 5(9) Figure 4. Inside the PWM generating 1C. Figure 5. The full schematic shows our step-up converter based on the popular UC3845 PWM current mode controller. it follows that about 1 5 watts (1 2 Vx 1 .25 A) needs to be dissipated in a shunt (‘bleeder’) resistor after replacing the original lamp with a LED equivalent, in order to have the same current flowing through the lamp fail- ure monitor. In practice a little less power could be wasted, since the trip level is very likely lower than the nominal current. Now suppose we connect a current source as shown in Figure 3. The current flowing through the lamp failure monitor is still 1 .75 A, but the battery effectively only sup- plies the 0.5 A or so effectively used by the LED lamp unit. This way we greatly reduce the power otherwise wasted. Unfortunately, an ideal current source does not exist as a single component, so we have to design a circuit that mimics one. A simple and affordable circuit would be desirable. We should also be aware of the fact that an ideal current source is nonexistent and that some dissipation losses can not be avoided. However, with the circuit presented here, losses are reduced by a factor of ten com- pared to those caused by a bleeder resistor. In a practical setting Since we are starting off with a voltage that’s slightly lower than the battery volt- age itself and we want current to be forced back into the battery, we need a step-up converter. To keep costs and parts count low, a popular current-mode PWM con- troller in an 8-pin DIP housing will be at the heart of our circuit. For the same rea- son we do not measure the current con- sumption with a feedback loop, but instead implement a simple MOS peak current con- trol loop. Circuit analysis, simulations and prototype testing have shown this to be a more than adequate solution for achieving the intended current within a few hundred milliamps, even with large variations in bat- tery voltage and the inherent voltage drop across failure monitor circuits. One controller Let’s have a look at the operation of the PWM controller by examining its block dia- gram, drawn in Figure 4. The oscillator fre- quency can be set as required by selecting the appropriate combination of R4/C6 (see Figure 5). The main function of the PWM block is to control the peak current meas- ured at the current sense input, taking into account the error amplifier output. This happens in cyclic fashion. In our applica- tion the error amplifier is actually always saturated (High output), but this will be discussed below. The current set point is adjusted by clamping the Output compen- sation pin to the required level. The clamping level is a constant voltage derived from a 5-V reference by voltage divider R3/P1 and temperature-compen- sated by diodes D1 and D2. This way we implement a closed-loop control for the peak current with a setting point adjusta- ble by PI. You may have noticed voltage divider R1 / R2 in Figure 5. It might look as if a voltage control loop is being closed, but the resistor values tell a different story. This is no more than an open-circuit protection. In normal operation the voltage at +B is limited to about 14V — even with engine running — so we get about 1 .8 V at the feedback pin (pin 2), which compared to the 2.5 V refer- ence at the non-inverting input will saturate the error amplifier as required. But if the controller kept regulating to a constant cur- rent and an open circuit fault would occur elektor 05-2012 35 POWER SUPPLIES & BATTERIES COMPONENT LIST Resistors R1,R4 = 6 . 8 kQ R2,R3,R7 = 1 1<£2 R5,R12 = 10Q R 6 = 22kQ R8-R11 = 0.47Q 0.5W* R13 = 0.1^2W* * see text Capacitors Cl ,C2 = 1 OOjllF 35V, low ESR C3,C4 = lOOnF C5 = 10nF C 6 = 1 nF C7 = 470pF C 8 = 2.2nF Inductors LI ,L2 = 1 0juH, 5A, Wurth type 74471 1 005 or Conrad Electronics #420284 L3 = 1 OOpH, 5A, Wurth type7447070 or Con- rad Electronics #438020 Semiconductors D1 ,D2 = 1 N4148 D3 = MBR1045 D4 = P6KE1 5A, TVS diode 1 5V 600W IC1 = UC3845N T1 = IRFZ48N Miscellaneous PI = 470^2 trim pot 6.35 mm (0.25 in.) spade terminals for PCB mounting TO220 thermal insulator kit for D4 and T1 Heatsink, 10K/W* PCB # 1 1 0755, www.elektorpcbservice.com *see text Figure 6. The PCB is designed to accept through-hole components, making soldering a breeze. One exception though: shunt resistors R8-R1 1 may be substituted by a single SMD resistor (R1 3). at +B, there would be no way out for the energy stored in inductor L3, causing surges and possibly damage to components. Now the voltage feedback loop comes into play. Once the voltage at +B reaches about 1 9 V, the post error amplifier pulls down the cur- rent set point to a safe level. When work- ing in constant-voltage mode C4 stabilises the feedback loop by slowing down its response. On a side note, under transient loads this is not a good voltage source, but it suffices in our application. Schematics The schematic in Figure 5 shows the com- plete circuit. Power arrives via terminal post +L1 . Choke L2 smoothes the current drawn by the circuit, keeping EMI in check, while transient voltage suppressor diode D4 eliminates voltage surges and spikes. Capacitor Cl provides the main power for the switcher stage. Its value is not very criti- cal, but a good quality low ESR/ESL type is imperative. Moreover, as in any fast switch- ing application, conventional capacitors usually fail rather quickly due to drying up of the electrolyte. Next in line is the step-up stage consist- ing of L3, T1 and D3. Both the MOSFET and diode are conservatively specified, but cost little more while boosting reliability of the circuit. Safe operation requires a heatsink to be fitted when more than 1 A is sourced. D3 heats up quickest: the average current flowing through it is much larger than the current flowing through the MOSFET and the voltage drop across it is also larger even when using the specified Schottky diode. RC snubber network R1 2/C8 suppresses ring- ing due to stray capacitances on the MOS- FET drain. The current emanating from the cathode of D3 is buffered by C2 (apply the same con- siderations as for Cl ) and fed back into the battery through choke LI . Both Cl and C2 are a relatively low value with respect to similar switching applications, but in this circuit we are trying to kill those fast on/off transients, whilst the quality of the gener- ated current is less important. The PWM signal from controller IC1 is fed to the gate of the MOSFET via resistor R5. This resistor limits the peak current through the gate and attenuates ringing due to 36 05-2012 elektor POWER SUPPLIES & BATTERIES stray inductance and gate capacitance. R6 is added to avoid a floating gate in case of an open circuit. The source current is passed through shunt resistors R8-R1 1 /R1 3, gen- erating a feedback voltage for the control- ler. Four parallel connected 0.5 watt resis- tors ora single 2512-shape SMT resistor are used instead of one common 2 watt resistor. The latter is mostly available as a wirewound type that cannot be used in this circuit in any case due its high stray induct- ance. The feedback voltage passes low- pass filter R7/C7 into the controller to avoid glitches that would impair its current regu- lation operation. With R4/C6 the PWM switching frequency is set at around 1 00 kHz, which seems to be a good trade-off between smaller inductors and capacitors versus increasing switching losses and parts and PCB layout require- ments. C5 filters the reference output. C4 does the same for the clamping voltage while also limiting the rising of the current set point, effectively providing a soft start function. C3, finally, buffers the 1C supply voltage. Construction and bench testing Populating the PCB (Figure 6, layout avail- able as a free download from [1 ]) is easy. As usual, start off mounting the low pro- file components and mind the orientation of the polarised ones, including electro- lytic capacitors, diodes and the other semi- conductors. Keep in mind the car is not a particularly friendly environment for any electronic device, so with the heavier com- ponents — especially the electrolytic capaci- tors and the inductors — it is safer to use a drop of silicone sealant on them. For mount- ing purposes two holes are conveniently provided to secure L3 to the board with a cable tie (when using the inductor from Conrad Electronics; see components list). After testing you may also want to protect the board with an electric grade lacquer (don’t forget to mask the terminal posts and heat conducting surfaces of the diode and MOSFET with tape first). None of the components are particularly critical. Nonetheless, think before you exchange or replace a component. Chokes LI and L2 are not critical at all, any induc- tor capable of handling the rated current without saturating (too much) can be used safely. L3 can be bought ready made per the component list, but some experimentation with parts salvaged from similarly rated switching circuits may do the job too. Its inductance is not critical; just make sure it does not saturate at the current you wish to supply to the car’s electric circuits. A single heatsink may be used for all power semiconductors. This can be bought ready made, consisting of an L-shaped alumin- ium profile, approximately 30x30 mm (1.2x1. 2 in), 2 mm (0.08 in) thick, or, in case you are using an aluminium housing, you may also use one of its walls as a heat- sink. The power semiconductors are located along the PCB edge for ease of mounting a shared heatsink. Isolate the diode and the MOSFET from the heatsink using washers, since their metal tabs must not be con- nected to ground or shorted to each other. After careful inspection the board can be wired for bench testing. Connect a digital multimeter between +B and +L1 and set it to 10 A DC mode. Then connect a 13.8 V DC power supply to +B and GND. When using a battery or a power supply with no or a high current limit, also include a quick- blow 2 A fuse in series with the power sup- ply for safety purposes. Switch on the power supply. Using PI you should now be able to smoothly adjust the current through the multimeter between almost zero and about 4 A. Do not forget to monitor the diode and MOSFET temperature. Both components should not get so hot they can’t be touched with a finger for quite some time. Other- wise, a bigger heatsink (or one with a lower K/W rating) should be used. In case you want to measure the power losses — i.e. efficiency gained — , set PI to the desired current, for example 2 A, then short circuit +B and +L1 with a wire, leav- ing everything else the same, and replace the fuse with the multimeter. If you are now seeing, say, 240 mA while supplying 2 A through the wire bridge, you’re actu- ally wasting a mere 13.8V x 0.24 A =3.3 W instead of 13.8 V x 2 A = 27.6 W that would be wasted in a simple bleeder resistor. Installation and safety It’s a misconception to think that working on ‘car electricals’ is safer than working on AC powered devices. Sure, the voltages involved generally do not exceed 1 4 VDC, Figure 7 and 8. Connecting the Lossless Load into the car’s circuitry can be done in the two ways as shown here. elektor 05-2012 37 POWER SUPPLIES & BATTERIES Figure 9. The PCB accepts different sizes of inductors. Shown on the right side is the relatively small 100 pH coil from Wurth Elektronik [2]. so indeed you may feel safe touching parts and wires. But then, a car battery is capa- ble of supplying a few hundreds of amps in case of short circuit. Such currents are dan- gerous in that they can easily melt a bind- ing post, a spanner or a screwdriver and project hot metal chunks and bits into your eyes or set fire to the whole wiring or even your beloved motor. Edd in Wheeler Dealers also issued similar warnings on TV. So the greatest possible care should be taken while installing and testing this circuit on-board! One of the diagrams shown in Figures 7 and 8 may be used. The diagram in Figure 7 is probably the easiest. Both the +B and +L1 connections are protected by the existing fuse installed in the fuse compartment in or under the dashboard. The connection to the lamp can easily be made on the lamp holder proper, but it might prove rather dif- ficult to physically reach point X without dis- mantling the whole car. In Figure 8 the +L1 connection is still pro- tected by the existing lamp fuse. A direct (unswitched) battery connection to +B could be tapped off somewhere, but it may be easier to connect it directly on battery post. In this case — and whenever you are not sure protection is provided — an exter- nal fuse MUST be fitted. This could be one of those flying-lead car style fuseholders or a panel-style fuseholder mounted in the housing for the circuit. This fuse should be rated the same as the one in the dashboard. When everything is installed, we can now do our final adjustments and testing. First turn PI to its minimum resistance, then power up the lamp circuit and slowly turn PI, increasing the supplied current until the lamp failure indicator goes out. Then turn PI just a little more to avoid a setting too close to the threshold of the detection circuit. You may want to monitor the sup- plied current during this adjustment. To do so, wire a multimeter in series with the +L1 connection and set it to 1 0 A DC. Finally, you should check whether the fail- ure monitor actually keeps working by removing the lamp. The current supplied by our circuit alone should not be enough to 'cheat' the monitoring circuit. If this were the case, the monitoring circuit would be of no use anymore. Make sure you double check everything is working as expected, even with the engine running. One last thing Using a trimpot in this kind of application might be slightly less than ideal. Vibrations and other harsh environmental conditions could change the setting. A solution would be to use pinheaders to temporarily con- nect PI during testing and adjusting. Then, after tuning your circuit, take out PI , meas- ure its resistance and put in a fixed resistor with the same value instead. Now you can look forward to saving about 7 ml of fuel per hour for each 20 watts of electric power that’s not wasted as heat. Don’t do the sums while driving, though. (110755) Internet links: [1 ] www.elektor.com/ 1 1 0755 [2] http://www.we-online.de Note: Replacing car lights with non-approved aftermarket LED units may be in violation of local, national or state laws. Check local regulations before engaging in alterations on your car’s electronics. 38 05-2012 elektor CIRCUIT CELLAR Microprocessor Design Using Verilog HDL With the right tools, such as this new book, designing a microprocessor can be easy. Okay, maybe not easy, but certainly less complicated. Monte Dalrymple has taken his years of experience designing embedded architecture and microprocessors and compiled his knowledge into one comprehensive guide to processor design in the real world. Monte demonstrates how Verilog hardware description language (HDL) enables you to depict, simulate, and synthesize an electronic design so you can reduce your workload and increase productivity. Microprocessor Design Using Verilog HDL will provide you with information about: • Verilog HDL Review • Verilog Coding Style • Design Work • Microarchitecture • Writing in Verilog • Debugging, Verification, and Testing • Post Simulation and more! www, cc-webshop.com Yours for just $ 45.00 MICROCONTROLLERS Inside Pico C-Super AT2313 programming Z80 style Our recent Pico C-Plus & Pico C-Super publications went down very well with the Elektor crowd. At the request of many of you, in this afterburner article we delve into the software that makes the instrument tick, particularly the Plus version. Graphologists will tell you a person’s character from their handwrit- ing. A programmer will tell you a person’s history from their pro- gram code. When I first thought about extending the original Pico C code, I came to it with a background in small machines and many years of programming Z80 and similar. When I first started writing software you only got 51 2 bytes of program space if you were lucky, so I have been used to trying to squeeze a quart from a pint pot (or should it be one decilitre from a whole litre now). So when I read that it was a challenge to get the code for Pico C into an AT231 3 microcontroller [1 ] and there were questionable limitations to the range, it felt like a challenge I should respond to. The result is Pico C-Super [2] — an extended version of the original idea with several extra functions crammed into the same extremely simple and low cost hardware through the use of software. In this article, I will try to explain how I did this and in the hope that others may find some of my code useful in their own projects in the same way that I have benefited from the wealth of code already available from Elektor and on the Internet. Registers Firstly, I want to talk about the use of registers briefly and this reflects my Z80 history. I find the Atmel notation of r0-r31 to be unhelpful and difficult to remember what is stored where. So it is easier to rename the registers with more useful names. In my case I rename them in Z80 style with an ‘A’ register for general purpose use, a ‘B’ register for loop counting (anyone remember DJNZ — a.k.a. Decrement, Jump Not Zero?), and register pairs HL, DE, BC as 16 bit pairs for calculations. In the case of Pico C-Super there is a need for 24-bit arithmetic so I cre- ated a register triplet GHLas shown in Listing 1. I keep all myZ80 registers in the range rl 6-31 as it’s great to be able to use the immediate mode instructions like LDI, with the working registers. The lower registers (rO-1 5) I keep for variable storage as they are quicker to use than RAM. With Pico C-Super there is a need for 24 x 24 bit multiplication followed by 48 by 24 bit division. It makes the code more compact to have the result from the multi- plication in a set of six registers (AO-5) which then directly become the dividend for the division subroutine. Macros It is useful to have some 1 6-bit Load instructions in the form of Mac- ros as these are not included in the AVR instruction set. For example, the Macro LDIZ (see Listing 2) loads the Z register pair with a 1 6-bit value as a single program line. This Macro is replicated forthe other 1 6 bit pairs BC, DE as well as X, and Y. There is also a Macro DJNZ to make me feel at home. Assembler programming can become a little monotonous when you have to write the same set of code lines repeatedly but with different values included. The monotony can be relieved by writing 40 05-2012 elektor MICROCONTROLLERS appropriate Macros or subroutines. As an exam- ple, Pico C-Super uses a Macro wrnumi 6 shown in Listing 3, to convert a binary number to deci- mal and do a formatted display on the LCD. This is just a single program line, but becomes sev- eral lines of assembler code when the program is compiled, which in turn call various subroutines. In these ways, the flexibility of the AVR reg- isters and the Atmel Macro Assembler can be exploited to create a tailor-made environ- ment to closely fit the application and so make the program both easier to write and more compact. Interrupt service routine The interrupt service routine or ISR shown in Listing 4, is the key to the period measurement function. Time is measured by using TO and T1 concatenated to give a 24+ bit counter driven by the CPU clock running at 20 MHz. The inter- rupt mode is set for a rising edge so that the time interval between interrupts is equal to the period of the input at INTO. The ISR must start the timing process and stop it again after a pre- determined number of periods. It does this by counting the number of interrupts that have occurred using a variable icnt. This variable is set to zero in the main program before inter- rupts are enabled. This signals to the ISR that the next interrupt will start the count. The ISR then compares icnt with the number of peri- ods to be measured using the register ‘C* and stops the count when the target is reached, but still increments icnt. Meantime the main pro- gram is sitting in a tight loop which it cannot leave until icnt reaches the target+1 in regis- ter ‘D’. Because the main program is not using any of the registers used by the ISR apart from the status register and icnt, the ISR only has to save and restore the status register. This ISR (int sub) is used for both interrupts on INTO and INTI , which are used to measure external period and capacitance respectively. The arithmetic routines used are written for 24 bits, so it is important to check that the count value does not exceed 24 bits or the arithme- tic will go wrong. Overflow detection is not straight forward because the counter pair TO/ T1 is 25 bits long as it includes OCOB. Overflow is checked by combining a conventional overflow ISR (ovf sub) which tests bit 26, with a rotate and test carry for bit 25 in the routine MeasB. The main arithmetic routines are the 24 x 24 bit multiply and a 48 by 24 bit divide. These have Listing i. Part of register definition include file, creating Z8o look-alike registers. .DEF A=rl6 .DEF B=r2 0 .DEF C=r2 1 .DEF D=r22 .DEF E=r23 .DEF H=r24 .DEF L = r2 5 .DEF G=r28 /this one is special for Pico Super Listing 2. Examples of extensions to AVR instruction set. .MACRO LDIZ LDI LDI . ENDM /value to load ZH, high ( @ 0 ) ZL, low ( @ 0 ) .MACRO DJNZ DEC B BRNE @0 .ENDM ;Z80 decrement and jump not zero /jumps to label @0 Listing 3. Bin to dec conversion and number formatting for LCD. .MACRO WRNUMI 6 ; position. predp, postdp . 16 bit variable HL RCALL CNV5B /convert to BCD LDI A, @0 /LCD position LDI B, @1 /digits before decimal point LDI C, @2 /digits after decimal point .ENDM RCALL wrnumb /display it Listing 4. Interrupt service routine for period measurement. /Note 'C' is Int sub: iOstrt : timing equal IntOx: INC used to control number of Periods to be timed N A, SREG ; save SREG PUSH A TST icnt /if icnt=0 use int to start count BREQ iOstrt CP icnt,C /else check for end of count BRCS IntOx STOP COUNT /is end of count RJMP IntOx NOP /keeps start and stop NOP START COUNT / If icnt=0 icnt /bump count and exit POP A /restore SREG OUT SREG, A RETI elektor 05-2012 4 i E, el(tor/e/eni entl 4 Webinar S/gn Apr// U P at 7 9. 2072 . www.e/e/ct 7 5:oo C/VIT or. COrr >/webinars been derived from 1 6-bit versions from Atmel’s note AVR200 and are binary versions of the long division and multiplication I learnt long ago at junior school. The Atmel divide routine needed some extra code to make it work correctly when the top bit of the divisor is set. Tables The software makes extensive use of tables particularly to set parameters in response to the multiplier selection but also to set up T1 in the signal generator mode and display the correspond- ing frequency. These tables are of the fixed record length variety so that a simple calculation can be used to find the start of a par- ticular record (see gtrcd). Since ATtiny controllers don’t include a MULtiply instruction, the calculation uses repetitive addition to do the multiplication. The structure of the records can be whatever is needed and it is only important to use them in the same way that they have been created. As an example the table in the EEPROM for setting the output frequency consists of 6 byte records. The first byte contains the prescaler bits for T1 , the next two bytes contain the setting for 0CR1 , the next two are a binary value for the fre- quency to be shown on the LCD as decimal, and the last byte is the ASCII code for the units character displayed in front of the fixed text ‘Hz’. The macro get record makes the tables easier to access. Mode selection again uses a table which contains the address of the LCD message and the address of the program module that will be executed when the mode is selected. This provides a good oppor- tunity to use the indirect jump instruction ijmp which is otherwise rarely used by me. Subroutines There is a style of writing subroutines that saves all the registers used on entry and restores them again on exit. I prefer not to bother with this within my subroutines, which keeps them more compact. As a consequence, I sometimes have to save and restore registers in the main program, but more often important variables are stored in SRAM or different registers can be chosen and the problems of register corruption avoided. Classic/Super options The program is designed to work with both the early (‘classic’) hard- ware configuration (board # 1 00823) and the modified one (board # 1 1 0687). The program uses conditional assembly to do this and the Boolean variable PB (first Published Board) is used to modify the program as required to work on the two different boards, and PB should be set correctly before compiling and programming chips. A second assembly option allows the larger ATtiny43 13 micro to be used, which can provide additional frequency options for the signal generator mode. Bonus In the process of tidying up this program ready for publication of this article, I got rid of some code that was no longer needed and ended up with enough space to include one more function. This is a simple table driven pulse generator where the length of each pulse segment (High, Low) can be set in the range 1 to 64 ps with 0.25 ps resolution and an arbitrary sequence length. The sequence then repeats. An example is shown in the screenshot in Figure 1 . The table structure is explained in the source code (ptab). This function uses 8-bit numbers to set the segment length and whilst a 1 6-bit version would offer longer segment lengths, I suspect it would have lower resolution. To be investigated. The source code now released on the Elektor website includes this extra function. Figure 1 . A 1 -2-3-4-ps pulse train shown on the Piccolo DSO at 4 Msa. Compilation and AVR Studio 4 The program must have access to the Macro and Register definition files at compilation time, and these are included in the archive file # 1 1 0687-1 1 .zip found on the Elektor website at [2] and [3]. The pro- gram has been written using Atmel’s Studio 4 available free from their website [3]. Courier typeface has been used in this article text to indicate names and labels in the program code and these can eas- ily be located in the program using the Edit>Find function in Studio 4. (120237) References [1] Pico C, Elektor April 2011. www.elektor.com/ 1 00823 [2] Pico C-Plus and Pico C-Super, Elektor February 201 2. www.elektor.com/ 1 10687 [3] www.elektor.com/1 20237 [4] www.atmel.com/tools/ AVRSTUDI04.aspx 42 05-2012 elektor By Thijs Beckers (Elektor Editorial & Labs) Conning up next month in Elektor Magazine — normally; hope- fully— is a thermo/hygrometer project with Nixie Tubes. These vintage display tubes are making a comeback and projects using these famous tubes are popular as never before. Even Steve Wozniak carries them with him, or better: on him [1 ]. As customary with our projects, this Nixie Tube project was also replicated by the Elektor Labs. While assembling it, my fellow lab worker Luc Lemmens initially struggled a little when trying to get the tube leads through the PCB mounting holes. Have a look at the photographs to get an idea of the problem. After giving it some thought, he came up with an interesting solution we don’t want to keep from you. As the photographs tell, the cathode is marked by an arrow on the bottom of the glass envelope. So to begin with it would probably be helpful to mark the tube stand-off as well, so you still know the correct orientation when mounting the tube. A red dot works a treat and is not too conspicuous. Now for the ‘more advanced’ part. Start with cutting one lead to about the correct length (not too short!) for the tube to be mounted on the PCB. If the tube leads are not inserted in the stand-off, don’t forget to take into account the extra length required. Now cut the lead next to it (left or right, it doesn’t matter as long you keep shifting in the same direction) but leave it a millimetre or so longer than the first one. Cut the next lead leaving another millimetre and so on. The end result should be that all leads have a different and clockwise increasing length (or decreasing, depending on how you look at it). The photographs show what the result should look like. This way it is much easier to guide the leads through the PCB pinholes and if needed also through the stand-off in one pass. (120229) Internet Link: [1] http://youtu.be/m4R3hODnTGo elektor 05-2012 43 E-LABs INSIDE E-LABs INSIDE Quality check By Thijs Beckers (Elektor Editorial & Labs) This year’s July & August double edition of Elektor magazine will be somewhat different from the ones we produced over the past years. This year we pay extra attention to quality. We upped our standards and went through all the ideas, propos- als and practical solutions in our IN box a second time to pick the ones we really liked. Only the top-notch of the cleverest of ideas that get past our first round of editorial filtering make it to this year’s extra-thick magazine — the Project Generator Edition, PGE. There is no reason to be apprehensive; the concept of this edi- tion will not be not touched. You will still be able to pick up wagonloads of ideas and practical solutions from this most suc- cessful blockbuster edition. As a matter of fact, we will adjust our focus and elaborate on each and every circuit a lot more than we did in previous editions, aiming to leave no ends open and making sure every detail is crystal clear to all of you who digest this copy. We know this will be a very ambitious goal for all of us here at Elektor as well as for our highly esteemed freelance contribu- tors and experts, but it is all for the greater good — to serve and supply our community with fresh and exciting new pro- ject ideas, as well as keep the current flowing and the electrons kicking around. (120305) Transformer testing By Raymond Vermeulen (Elektor Labs) Elektor Labs are forever working on new projects and ideas. At the moment I am working on a USB isolating circuit. Besides iso- lating its data lines, it is also important to isolate its supply lines. Because the USB is DC powered, a traditional isolation trans- former can not be used. I reverted to an isolated flyback con- verter instead. This solution also required a transformer, albeit a small one. The one I picked for the job goes by the arcane name ‘part# 75031 0471 ’from manufacturer Wurth Elektronik [1 ]. The photograph tells you a bit about its size. This little transformer is production-tested for one second at 1 850 volts. From this the manufacturer extrapolates that the device withstands 1 500 volts for one minute continuously. The primary and secondary side are both shorted during this test so no current will flow through its windings. This confirms the isolation between the primary and secondary side. That’s nice & all, but what I’d really like to know is what hap- pens when something goes wrong in a real situation. What if, for example, on one side the ground plane is shorted to the live wire resulting in the local AC powerline voltage continuously being superimposed on one side for hours and perhaps even days? This hasn’t been tested by the manufacturer (at least I didn’t find it in the documentation), but I did need this infor- mation to be able to proceed with my project. So off to the test bench and hook it up! Fused and connected using a variable autotransformer (Variac), 44 05-2012 elektor I replicated the manufacturer’s test (with the two sides individu- ally shorted) and left it for a couple of hours with 230 volts on its legs. It passed the test. Just to be sure, I then set up a sec- ond test in which the Variac was connected in such a way, that double the voltage was at my disposal. After a few hours at this higher than normal voltage and also passing this test success- fully, I was convinced this transformer would suite my applica- tion without any concerns and moved on to implementing it in my project. (120302) Internet Links [1 ] www.we-online.de Stray oscillations By Thijs Beckers (Elektor Editorial & Labs) Many companies offer internships. There are several motives behind this established practice like providing a service to col- leges and universities and improving educational standards, getting youngsters to do chores that are quite boring to senior designers but quite enlightening to interns, or educating poten- tial employees who — by the time they finish their internships — are already familiar with the in house work flow, et cetera. Elektor at the moment also accommodates two interns in the Lab department, Koen Beckers and Jesper Raemaekers. Apart from their college projects, to which our designers provide assistance in times of need, they also work on circuits currently being prepared for publication in our July & August double edi- tion. Koen & Jesper are even actively contributing ideas and cir- cuits. This is one of them — and its design quirks. The Line Out/Headphones Out signal from most laptop com- puters is rarely powerful. Driving a pair or rather power hungry headphones could end up clipping or overloading the output circuitry and sorely disappoint the listener. To overcome this inconvenience, a small external amp, preferably USB powered, might be considered. Now where to find something like that... That’s when Koen’s and Jesper’s electronic nerve got triggered and they launched a small project of their own: a USB-stick- sized, LM386-based headphone amp. The first prototype, built up on breadboard, appeared to work. That is, until an oscil- loscope was hooked up to take a closer look at the amplified signal, revealing a nasty issue with the little amplifier: wild oscillation. Lucky for them, senior designer Ton Giesberts provided the answer. In his experience breadboards are not great solutions for prototype testing. They suffer from large amounts of stray capacitance between each row of connections, which in this elektor 05-2012 45 E-LABs INSIDE application invoked oscillation of the AF amplifier. His sugges- tion, to build up (exactly) the same circuit on a regular circuit board, paid off instantly. No more nasty oscillations and another circuit idea finished for our upcoming double edition! The crux: stay clearheaded with every decision you take regard- ing your electronic endeavours, even if AF, and be weary of Pico & The Strays, they often perform unsolicited on the scope screen. And keep them circuits coming, guys! (120334) All the latest: LCR Meter By Thijs Beckers (Elektor Editorial & Labs) Just in! At the desk of fellow lab worker Antoine Authier colleagues gather round to get a glimpse of a cute LCR meter a French author submitted to Elektor “with a view to publication”. This neatly finished device is connected to a PC via USB. Specially developed software on the PC displays its measurement results. The meter employs the well established four-point measuring principle to get highly accurate measurements down to the lowest feasible & discernible level. The test hooks are specially selected; each pin forms a connection, so all you have to do is clamp them onto the component you want to check out and the instrument is able to perform a rather accurate analysis of the DUT. Our initial tests looked very promising. This circuit is sure to be “evaluated for publication value” (as we call it) in Elektor magazine soon. Already the author is working on an extension to include an LCD so the instrument can be used in stand-alone mode. ...Can’t wait to see this in publication! (120331) Piggybacking-1 k By Thijs Beckers (Elektor Editorial & Labs) In this year’s January edition of Elektor we discussed a couple of adjustments on Microchip’s In Circuit Debugger 3 (ICD 3) ( Debugging the debugger) in order to prevent a few issues when using the device. This called for desoldering two 1-l<^ SMD resistors and replacing them with 1 00-£2 types. A kind & attentive Elektor reader from The Netherlands, Wim Sanders, tipped us off about an even easier way to complete this job: leave the 1 -k£l resistors in place and just solder the 1 00-£2 resistor on top of them. A “light backpack”, is what they call this at Sanders’ daytime job. This piggypacking of 1 00 £1 onto 1 k£l causes a mere 1 0% deviation of the required resistance, which in this case is not critical. Thanks for the tip, Wim! Indeed, it confirms that adding is sometimes easier than replacing! (120326) 46 05-2012 elektor INTERVIEW What are you Doing? Minty Geek’s Mark Briclcley By Wisse Hettinga (Elektor UK/INT Editorial) A keen observer of teeth during the day in his profession as a dentist, Mark Brickley stares at cells in the evening and gazes at stars at night. And yes, he is also looking into the future with his new projects dubbed Minty Geek. Time to put the question to him: “What are you Doing?” “we are building a peppermint” Wisse: “On and on” means that Mark holds two Ph.D.s (one on Neural Networks and one on the electrical/mitochondrial signals in green algae) — he established his own research laboratory in the middle of Somerset and combines it all with an orthodontic practice. Mark: I can do with little sleep, he explains when asked where he is finding time to do it all. Wisse: What background? for an ‘Arduino-in-a-Box’ capable of communicating with the 1 01 Mark: I’ve always had a lot of interest in technology. From the Lab Box for example. In this way it will be possible to interconnect earliest days I used to read Elektor and I made my first Z80 computer based on your publications, and then it went on and on. Minty’s. Also, we are looking at new ways to integrate electronics and clothes. Wisse: The reason for this interview is the ‘Minty Geek’ product line you and your team are producing and selling through Elektor [1 ]. Whence the drive? Mark: I believe there is an enormous value in making things. Young people have to experience that and the Minty Geek line of products is aiming at that group. Wisse: Now, that Hadron Collider is perhaps pushing it too much, but having said that I wouldn’t be surprised to hear about a huge experimental ring somewhere in Somerset in 10 years’ time — possibly looking like the largest ‘Life Saver’ sweet ever made [2], with you in the middle. Thanks Mark — good luck! Wisse: Is there something left on you wish list? Mark (jokingly): Sure, one day I would like to build a Hadron Collider! (more serious) I think we are entering a new phase in history where producing products is not longer the exclusive realm of the big companies, because with 3-D printers consumers will be able to print their own products”. Wisse: We’ve seen different types of Minty Geek products; you have the 1 01 Lab allowing you to do some interesting experiments without soldering and there appear to be new products in the pipeline. Mark: Our next product aims at people wanting to have a go at microcontrollers. We are building a ‘Peppermint’ which allows (120333) Internet Links [1 ] www.elektor.com; search: Minty Geek [2] http://en.wikipedia.org/wiki/Life_Savers “I can do with little sleep” elektor 05-2012 47 HOBBY & MODELLING QuadroWalker Small four-legged robot with eight servos Small robots are eminently suitable for experimenting with various possibilities for generating movement. Particularly when a number of legs are used, the designer has many options for the method of locomotion that the robot could use. Our QuadroWalker has a very simple construction using four legs, which anyone can easily build for themselves. The robot receives commands from a standard IR-remote control. By Cert Baars (The Netherlands) The concept of a robot is usually under- stood to be a programmable machine that’s designed to carry out specific tasks. Exam- ples of these are welding robots in carfacto- ries, which weld car parts together along a conveyor belt and are always moving at the same speed and are invariably making the exact same movements to yield a consist- ent quality. There are also robots which got developed to look as much as possible like a human, both in appearance and in function- ality. A famous example of this is the ASIMO robot developed by Honda. The closest resemblance of the robot described here is that to an animal, because it walks on four legs. A number of methods of locomotion were examined before arriv- ing at this concept. A spider, for example, has six legs and can always have at least three legs on the ground for balance. To ensure that the construction does not become overcomplicated, the preference here is for using four legs only. The robot does not have an organ of balance, in the form of a gyroscope or accelerometer, as they are often implemented. With four legs there is the option of a method of locomo- tion that contains a moment of imbalance, but by making the step size not too high and the step time not too long, this dura- tion of imbalance is short enough to make walking possible. There are animals which actually do the same thing, but these often have a low centre of gravity, such as lizards. In this robot the centre of gravity has been kept as low as possible too, and most of the weight (the batteryholder with batteries) is located on the underside. Before even starting a design like that, it is necessary to check first whether it is even possible. From studying several methods of locomotion, it appears that a leg is suit- able provided that it can move around at least two axes, and where these axes of movement are at the top of the leg. This eliminates the necessity for a knee or ankle joint. In this way a kind of ball joint is cre- ated, which allows two simultaneous move- ments, such a lifting and repositioning of a leg. Single axis movements can be realised nicely using servos. With a servo the angle of rotation can be set, and therefore also the amount of movement. In this case, each leg requires two servos, so as a con- sequence there are a total of eight servos. Design The design of the robot can be divided into three parts: mechanical, electronics and software. The mechanical part takes care 48 05-2012 elektor HOBBY & MODELLING of attaching the base plate to the legs via the servos. The servos also have to be joined together. This requires the manufacture of a few mounting brackets, two right-angle brackets for four servos to attach them to the base plate. Also, for each pair of servos a bracket to allow them to move at right angles with respect to each other (this kind of bracket is available for sale for certain types of servos) and a bracket to attach the leg to the second servo. The materials used here are aluminium angle extrusion and flat bar material, which have to be cut to the correct size and require the drilling of a few holes. Figure 1 gives an indication of how all this can be achieved. There are obviously other ways of doing this. The legs of the prototype are made from 4 mm alu- minium round rod. These can be fastened to the servo bracket by drilling a 4 mm hole in a bolt so that it forms a clamp, but 4 mm U-bolts are often also available from hard- ware supply stores and these would also be suitable. The amount of horizontal length from the 90 degree bend in the legs must not be more than what is necessary to allow unrestricted movement going forwards and backwards, and vertically keep the centre of gravity as low as possibly so that there is just a small margin between the bottom of the robot and the floor while walking. The particular choice of the servos that have been used, depends on the force that they have to deliver. These are specified as a torque in kilograms times meters. Because two legs can be off the ground while walk- ing, each of the servos that’s connected to the base plate has to be able to support half of the total weight. The weight of the pro- totype, including the batteries, amounts to about 750 grams (26.5 oz.). The hori- zontal length of the legs is 6 cm (4 inches). The torque then amounts to 2.1 kgf.cm (1 .82 Ibf.in). Servos of the type RS-2, a com- monly used, readily available and afforda- ble servo can supply over 4 kg. cm (3.47 Ibf. in) at 5 volts and is therefore very suitable for this robot. The horizontal length of the legs determines the torque, so it is not pos- sible to just change this. Also, the current consumption is proportional to the torque supplied; placing the legs closer to the body therefore also means that the batteries will last longer. Figure 2 shows how the robot Figure 1 . The servos are attached with the aid of a few pieces of angle bracket. Figure 2. Design of the robot and positioning of the servos. is put together. The base plate of the pro- totype consists of a piece of circuit board with the eight servos mounted on the four corners, in the middle, on top is the circuit board with the controller, and the RC5 IR- sensor is pointing upwards for a maximum range of the remote control of several meters. The battery holder is attached to the underside, note that this should be posi- tioned reasonably well in the centre, keep- ing in mind the centre of gravity. Electronics In the hardware, the servo control and the other functions are taken care of by a microcontroller. Not all that many I/O lines are required, but the author already had a small board containing an ATmega32, so that got used here (see Figure 3). Because the controller has a large program memory, the robot can easily be expanded with many other features. Eight outputs from the con- troller supply the pulsewidth-modulated signals for the servos, so that each servo can be controlled individually. An inter- rupt input reads the data that is received by the RC5 sensor, in this way a standard RC5 compatible remote control can be used to control the robot from a distance. The motor currents of the four servos control- elektor 05-2012 49 HOBBY & MODELLING Figure 3. The electronics comprises mainly of an an ATmega32. Two voltage regulators, made from discretes, take care of the power supply for the servos. ling the horizontal movement of the legs are available as voltages, using resistors in the ground wires. This is not a constant voltage because the motor in a servo is con- trolled digitally. That is why lowpass filters are added, which smooth the voltage wave- form. These can then be measured via the ADC inputs, with the objective of detecting when the robot is impeded in its movement. In this way it is possible to detect obstacles so that the robot may avoid them. This is also the only intelligence that the robot pos- sesses, but it is sufficient to allow it to be called ‘autonomous’. The current at which an obstacle is detected can be set with a potentiometer on an additional ADC input (ADCO), which is used by the software as a reference. This threshold depends also on the friction between the legs and the sur- face underneath. In the prototype, small hard plastic balls were attached to the end of the legs to pre- vent scratches, but at the same time also minimises the friction with the walking surface. This works well on a wooden floor, and also on vinyl and carpet, because the motor currents remain relatively small in the absence of an obstacle. When rubber feet are used there is so much friction that it becomes difficult to find a good position for the potentiometer to reliably detect an obstacle. The servos require a power supply volt- age of 4.8 to 6 V. Using four AA -batteries, resulting in 6 V, would be perfect without requiring any further regulation, but the voltage does drop considerably when the batteries discharge. That is why six AA bat- teries are used, which means that voltage regulators are now required to ensure that the voltage does not exceed 6 V. Many ICs are available for this purpose, but the pref- erence goes to regulators with a low voltage drop, to obtain maximum life from the bat- teries. A cheap solution turns out to be two simple discrete regulators with less than 1 V voltage drop, consisting of a few transistors and a Zener diode. Two regulators are used here, not only so that the voltage drop is minimised, but also because this avoids the need fora heatsink. Software The software is written in assembler and consists mainly of a few interrupt routines. For example, it is important that the servos receive a pulse with a duration of 1 to 2 ms every 20 ms. Deviating from this results in vibration in the legs. The TSOP2236 IR receiver also has to be read using a hard- ware interrupt, because here the timing has to be exact as well. In the software, the con- trol of the eight servos is spread across the period of 20 ms. If all the servos were to be controlled simultaneously this would result in an undesirably large peak in the battery current. The control of the servo positions is derived from a sine lookup table which contains 256 values between 0 and 100, corresponding to the 1 ms control range divided into steps of 1 0 ps. By controlling the two servos of each leg with a phase difference between the sine waves it is possible to move the leg joint in a circular or elliptical motion. This is desirable because it allows steps to be taken in which a leg can be lifted and moved for- wards simultaneously, or lowered and moved backwards. This corresponds suffi- ciently to a walking motion. All eight servos are now controlled with phase differences in such a way that two main ways of walking are possible: forwards and backwards, which for the latter case is just a matter of reversing the phase, but also turning to allow a change of direction. The values of the phases for these two basic movements are also stored in a table, eight values for each movement, where each value is the phase difference for a servo. It should also be possible to turn both to the left and to the right, which again is also a case of phase reversal. The function of this robot is, in principle, only moving around and being controlled on command from the infrared remote con- trol. But additionally, with a certain com- mand the obstacle detection can be turned on and off. When this is the case, the motor current as measured by the ADC inputs is compared with the value from the potenti- ometer; when this is exceeded four actions are taken. Firstly, the loudspeaker emits a signal and the robot stops. Subsequently, it will walk several steps backwards. After that, the robot turns a number of degrees, 50 05-2012 elektor HOBBY & MODELLING where the direction depends on which leg detected the obstacle and in such away that it turns away from the obstacle. Now the robot stops again and then continues on its way. In this way the robot can continue to walk without any help from the outside. If it walks into a wall, for example, it will con- tinually move away from this and continue on forever, well for as long as the batteries a I low anyway. To study whether a robot of this type is also suitable to play soccer, for example, an additional function is built in which allows one leg to make a kicking movement. With this, the diagonally opposite leg is also lifted briefly as a counter movement for improved balance. The result is that the robot can kick a ping-pong ball about a metre away, which can offer interesting possibilities, pro- vided the playing field is not too large. It is, of course, also pos- sible to expand the robot with, for example, a kind of electro- magnet which is sometimes used in special soccer playing robots. Battery life is strongly depend- ent on the activities of the robot; rechargeable batteries are probably the best choice here. It can be noticed when the batteries are nearly flat, because the brown-out function of the microcontroller will operate, which results in a convulsive motion. When the batteries discharge even further the robot will just sag on its legs. Remote control Controlling the robot is done using an RC5-compatible TV-remote control. In the software the first byte of the RC5-code is ignored, which means that other types may be usable as well. This can be changed, of course, so that multiple robots can be con- trolled independently of each other. The commands are straight ahead, reverse, turn left and right. By using the mute-but- ton (loudspeaker symbol) on the remote control additional functions are available, for example to turn obstacle detection on and off, and also another function for bal- ancing the robot. This last function allows a vertical offset to be added to servo6 of the front-right leg, so that in the initial state all four legs touch the ground at the same time. Because of mechanical variations it is possible that one leg is too high or too low, which makes walking more difficult. After making the adjustment, the value of this offset is stored in the internal EEPROM of the controller, so that it is used again on next power on. Table 1 shows an overview of the available commands. The buttons 1 through 9 are for the normal control. The mute-button is used as a function-key and has to be followed by a number. With these, function-1 : obstacle detection on/off, with function-2 a kind of tilt movement can be made, but after that the Table 1. Commands available via RC5 remote control 1 kick left front leg 2 move forward 3 kick right front leg 4 turn left 5 halt 6 turn right 7 kick left rear leg 8 move backward 9 kick right rear leg mute X ‘Function’ volume + speed up, servo6 up volume - speed down, servo6 down brightness + stepsize up brightness - stepsize down colour saturation + stepheight up colour saturation - stepheight down treble + spider height up treble - spider height down I step height and size are set to zero, this function has very little use other- wise and is really only for testing. With function-9 the offset of the height of servo number 6 can be adjusted and is stored in EEPROM. This should be a once-only adjust- ment to set the balance. To make this adjustment, turn the robot on and push [function] [9]. Support the robot with one hand underneath and push the button [volume+] a few times. Servo num- ber 6 will now go up. Lift the robot so that all legs, except servo number 6, just touch the ground. Now push [volume-] until the leg of servo number 6 also just touches the ground. Push [function][9] again and the settings are stored. While walking, the walking behaviour can be adjusted with the volume-, brightness-, colour- and tre- ble-buttons as shown in the table. If, for example, the robot needs to step across a threshold then the step height and size can be increased. Also to obtain maximum speed, the volume con- trol can be used to set the step speed and the brightness control is used to set the step size. On a slippery surface is it sometimes better to use slow, large steps, while on carpet the walking goes better with faster, large steps. During tests a maximum speed of about 1 km/hour (0.63 mile/hr) was measured. The assembly and hex code for this project are available on the accompanying web page [1 ]. In the video of [2] you can see the robot in action. (120051) Internet Links [1 ] www.elektor.com/ 120051 [2] www.youtube.com/ watch?v=8ToHa4hQi_0 elektor 05-2012 51 BASICS Electronics for Starters (5) Voltage stabilisation In the previous instalment of this course series we looked at circuits for constant-current sources. Now it’s time to examine ways to generate stable voltages. Of course, you can always use an integrated voltage regulator, but there are many other interesting approaches, most of which need only a few (usually discrete) components. By Burkhard Kainka (Germany) If you carefully inspect the many schematic diagrams published in Elektor magazine, you will repeatedly encounter voltage stabi- lisation circuits. Some devices are powered by batteries, and the output voltages of bat- teries can vary over a relatively wide range. For this reason, a voltage regulator is often used in such devices to provide a somewhat lower but stable voltage, such as 5 V for dig- ital circuitry ora microcontroller. Diode stabilisation Voltage stabilisation is not a difficult issue in practice, since wonderful voltage regulator ICs such as the 7805 are readily available. Operating from an input voltage anywhere between 7 V and 30 V, it supplies an output voltage of exactly 5 V. However, this 1C con- tains a large number of components. You can manage with a single semiconductor device instead, namely a Zener diode. The 7805 actually contains a Zener diode, along with lots of transistors. A Zener diode is a type of diode in which breakdown occurs at a well-defined reverse voltage. For instance, you can buy a Zener diode with a rated volt- age of 6.8 V if you want to stabilise a sup- ply voltage at this value. Figure 1 shows the corresponding basic circuit. The operating principle of this circuit can be seen from the characteristic curve of a typical Zener diode (Figure 2). First break- down occurs when the reverse voltage rises above a certain value (L/ z ), leading to a sharp increase in the reverse current. The voltage across the diode remains stable at the breakdown voltage, as long as you don’t overdo it with the reverse current. Second breakdown is a frequently observed fault with Zener diodes. If the Zener diode becomes too hot, the junction shorts out, and after this the diode ‘stabilises’ the volt- age at something close to zero volts. Strictly speaking, the designation ‘Zener diode’ is not always correct, because two different phenomena are responsible for the breakdown effect with voltages over the range of 3 V to 200 V. The true Zener effect predominates at voltages below 5.6 V. It has a negative temperature coeffi- cient, causing the Zener voltage to drop by up to 0.1 % per degree. The avalanche effect, which predominates above 5.6 V, has a posi- tive temperature coefficient. Zener diodes with a rated voltage of 5.1 V have the lowest temperature coefficient, while Zener diodes rated at 7.5 V or so have the steepest char- acteristic curves and therefore the lowest differential internal resistance. This means that they provide the best voltage stabilisa- tion with variable Zener current. Quick solution Sometimes all you need is a more or less stable voltage in the range of 2 to 3 V, with relatively little current. For example, you may want to power the RF front end stages of a simple radio circuit from a low voltage, while the output amplifier operates directly from a 9 V battery. In such cases you can use a forward-biased LED as a simple voltage stabiliser (Figure 3). The base-emitter junction of a perfectly ordinary NPN transistor has the same char- acteristics as a Zener diode. The Zener voltage is usually somewhere in the range of 7 to 12 V. The value with a BC547B is approximately 9 V, which lies in the favour- able range with very low internal resistance. This type of transistor can therefore be used quite nicely as a Zener diode, although the exact Zener voltage cannot be known in advance. The manufacturers’ data sheets don’t say anything about this, although they do state that the reverse breakdown voltage of the base-emitter junction is at least 5 V. Here first breakdown of the base-emitter junction is a sort of useful side-effect. If you don’t have a Zener diode handy, you may be able to make do with a transistor (Figure 4). Try it for yourself: apply reverse voltage to the base-emitter junctions of a few transistors and measure their Zener voltages. By the way, there’s another little-known side effect: the ‘Zener diode’ of an NPN transistor emits yellow light. If you try this experiment with a transistor in a metal L 3 _ > 10 U [V] 5 0 -j -5 -3 -1 -5 1 -10 -15 Figure 1 . Voltage stabilisation with a Zener diode. Figure 2. Characteristic curve of a Zener diode. 52 05-2012 elektor BASICS Current mirror A current mirror, as illustrated by this circuit, is a dis- tant cousin of a constant-current source. The (con- stant) current through the 1 k£l resistor is mirrored by the two transistors, and the collector current of the right-hand transistor is nearly the same as the that of the left-hand transistor. The base and collector of the left-hand transistor are connected together, which causes the base-emitter voltage to automatically as- sume a value that results in the specified collector current. In theory, if the second transistor has the same characteristics it should have the same collector current at the same base-emitter voltage. In practice, the current is usually slightly different because it’s difficult to obtain identical transistor charac- teristics. This circuit is primarily used in ICs, where a large number of transistors on the same chip have the same characteristics. It’s also important that both transistors have the same temperature, since the transfer characteristics are temperature dependent. A current mirror of this sort can therefore be used as a temperature sensor. Try touching one of the transistors with your finger. The resulting heating changes the output current, which can be seen from the change in the brightness of the LED. Depending on which of the two transis- tors you touch, you can make the LED a bit brighter or a bit darker. The temperature dependence of the current mirror is actually a drawback of this circuit. This sort of thing is often seen in electronics, where something that is an undesirable ‘degrading’ effect in one situation is a desirable ‘useful’ effect in an- other situation. package (such as the BC1 40 in a T05 pack- age) with the package opened up, you can see this light if you work in absolute dark- ness. Let’s hear it for silicon LEDs! Efficiency Although voltage stabilisation with a Zener diode is easy, it has some drawbacks. One of the major drawbacks is power dissipation. This results from the fact that the series resistor must be dimensioned for the low- est input voltage and the highest output current. For example, if the circuit shown in Figure 4 has to supply a maximum cur- rent of 2 mA, the maximum output power is just 1 8 mW. The voltage over the series resistor is 3 V at the lowest input voltage of 1 2 V. This means that 1 mA flows through the Zener diode and 2 mA flows through the load. A current of less than 1 mA through the Zener diode is undesirable because it places the operating point on the knee of the characteristic curve, resulting in higher Figure 3. Voltage stabilisation with an LED. internal resistance and poorer voltage stabi- lisation. However, even at this current level one-third of the input current is ‘wasted’ in the Zener diode. With even higher load requirements, the recommenced minimum Zener current is 5 mA. Things are even worse when the input volt- age rises to 24 V. In this case the voltage drop over the series resistor is 1 5 V and the current is 1 5 mA. The resulting total input power is 360 mW. Compared with the use- ful power of 1 8 mW, this yields an efficiency of just 5%, which is terrible and is hardly tol- erable in times of energy crisis. Fortunately, there is a solution to this problem. Series regulators Efficiency can be improved significantly if the Zener diode is followed by a transistor operating in common-collector mode, with the collector of the transistor connected directly to the positive terminal of the sup- ply voltage (Figure 5). This type of circuit is also called an emitter follower because the voltage on the emitter always follows the voltage on the base, with an offset of 0.6 V. In the present case the emitter voltage is 5.6 V (6.2 V -0.6 V). Here the Zener circuit only has to supply the base current for the transistor. As a result, the input current is only slightly higher than the output current of the circuit over a wide range of operating conditions. Most of the power dissipation occurs in the series-pass transistor, and it depends only on the out- put current and the difference between the input voltage and the output voltage. Only a small change is necessary to convert this circuit into an adjustable voltage reg- ulator. As shown in Figure 6, a potentiom- eter acts as a voltage divider for the stabi- lised auxiliary voltage. The output voltage is always approximately 0.6 V lower than the voltage on the wiper of the potentiometer. Figure 4. Using an NPN transistor as a Zener diode. Figure 5. Using a transistor as a series regulator. elektor 05-2012 53 BASICS Voltaqe monitor Many circuits require an operating voltage of 5 V and have a maximum tolerance range of +1 0%. In such cases it’s a good idea to monitor the actual voltage. Here we want to use a microcontroller to monitor the voltage and generate suitable indications. A green LED should light up when the voltage is within the tolerance range (4.75 to 5.25 V). A red LED should light up if the voltage is too low, and a yellow LED should light up if it is too high. The microcontroller operates from the voltage that it moni- tors. It compares this voltage with an internal reference voltage of 1 .1 V. The source code file for this project, Tinyl 3_V-V_monitor.bos, can be downloaded free of charge from www.elektor.com/ 1 20005. 'Voltage Monitor $regfile = "attinyl3.dat" $crystal = 1200000 $hwstack = 8 $swstack = 4 $framesize = 4 Dim U As Word Config Adc = Single , Prescaler = Auto , Reference = Internal Start Adc Ddrb = &H07 'BO/1/2 outputs U = Getadc ( 3 ) '0. .6.1V If U < 797 Then '4.75 V Portb = &H04 ' red Else If U > 880 Then '5.25 V Portb = &H01 ' yellow Else Portb = &H02 'green End I f End I f Waitms 1000 Loop End Figure 6. An adjustable voltage regulator. Figure 7. An improved adjustable voltage Figure 8. Adding current limiting. regulator. 54 05-2012 elektor BASICS To ensure adequate stability with variable output current, the current through the potentiometer must be greater than the maximum base current. Even better stabilisation can be achieved by using an active output voltage follower, as shown in Figure 7. Here an adjustable por- tion of the output voltage is compared with the voltage on the Zener diode. The differ- ence forms the error input to the control circuit, which drives the base voltage of series-pass transistor T1 via transistor T2. With this circuit it is possible to obtain an output voltage that is significantly higher than the Zener voltage, and which is close to the input voltage. This circuit can be used to build an adjustable power supply for cur- rents up to 1 A. The actual load capacity depends on the cooling of the BD1 37 power transistor. All that’s missing here for a full-fledged adjustable power supply is current limiting. For this purpose, we insert a small resist- ance in the negative lead (Figure 8). The voltage drop over this resistor is propor- tional to the output current. The extra tran- sistor starts conducting when this voltage drop rises above 0.6 V or so. This reduces the base voltage of the series-pass transis- tor. With a 1 Q current sense resistor, the maximum possible current in the event of a short circuit is 0.6 A. However, the power dissipation of the series-pass transistor is very high in this situation. It won’t be able to handle this without a large heat sink. Integrated voltage regulators It’s good that low-cost integrated voltage regulators are available for all common output voltages. A 7805 can deliver up to 1 A at 5 V, although a heat sink is necessary at such high current levels. In many situa- tions the current is much lower, and in such cases the 78L05, with a maximum current rating of 1 00 mA, is sufficient. However, you should note that the 78L05 has a different pinout than its larger cousin. These voltage regulators require two capacitors — one at the input and the other at the output — to prevent oscillation at frequencies of several hundred kilohertz (Figure 9). These voltage regulator ICs contain every- thing already described in this instalment of our basics course using discrete semicon- Advertisement o L iiliconRoy Online Electronics Store Boards * Kits * Modules • Components * Tools * Instruments FOR * Companies * Professionals * Students * DIYers * Amateurs USB STC 8051 MCU Programmer • , WM Free For 8051 Developers SEN1060 GPS Module With Antenna Small, Low Cost, Easy To Develope Add to cart (HMC5883L) 3 Axis Compass Module Integrate Compass Easily $ 12.5 It E SA-22 HiFi Tube Amplifier HiFi Sound At Affordable Price $282 CTtii h Simplify your electronics projects by visiting http://www.siliconray.com THE ORIGINAL SINCE 1994 PCB-PniL' Free Stencil Get a free SMD laser stencil with every Prototype order EAGLE order button pcb-pool.com/download-button on your first PCB order Free Phone UK: 0800 389 856 sales(?>pcb-pool.com PHIITPI 1 *- >i\i m>.iiJHfri % m RS-274-X Cidtnt* LD,V|.', pnQjde U PCB-POOL® is a registered trademark of www.pcb-pool.com LAYOUT elektor 05-2012 55 The following voltage stabilisa- tion circuit is intended to provide approximately 6.2 V, and it uses a BF245B JFET instead of a series re- sistor. The JFET is used as a simple constant current source in order to improve stabilisation with vari- able input voltage. The circuit is intended to be used with an input voltage range of 9 to 1 8 V. 1) What is the maximum current that can be drawn from the output? A) Just under 10 mA B) Up to 100 mA C) Less than 1 mA 2) How does the efficiency with high input voltages compare to the efficiency of a Zener diode circuit with a series resistor? D) The efficiency is better with the JFET. E) The efficiency is worse with the JFET. F) The efficiency is the same. 3. What is the purpose of the electrolytic capacitor in the circuit? G) It improves the efficiency. H) It reduces the internal impedance at high frequencies. I) It is intended to continue supplying power for a few minutes in the event of a power failure. If you send us the correct answers, you have a chance of winning a Minty Geek Electronics 101 Kit. Send you answer code (composed of a series of three letters corre- sponding to your selected answers) by e-mail to basics@elektor . com. Please enter only the answer code in the Subject line of your email. The deadline for sending answers is May 31 , 201 2. All decisions are final. Employees of the publishing companies forming part of the Elelctor Inter- national Media group of companies and their family member are not eligible to participate. The correct answer code for the March 2012 quiz is ‘BDI\ Here are the explanations: 1 . The voltage over the collector resistor is 2.2 V (5 V- 2.8 V). The collec- tor current is therefore I mA (ignoring l B ). The base-emitter voltage is around 0.6 V, so the voltage over the base resistor is 2.2 V (2.8 V- 0.6 V). This means that the base current is 4.68 pA (2.2 V / 470 l -55 °C ; Tj- < -1 75 °C , V GS > 1 0 V 500 ^CS(th) Tj- = 25°C, / D = 1 mA 3 V d Figure 1 . Schematic symbol. CR4.1NI Figure 2. Equivalent circuit. Ur 11 sense FET current. Figure 3. Application example for current measurement. elektor 05-2012 65 MINI PROJECT Energy Monitor Luminous AC current indicator Ton Giesberts (Elektor Labs) The energy consumption at home is difficult to check because of the ever increasing number of electrical devices. So it is about time to do something about this! With this energy monitor you can judge how much energy an electrical load is using, even from a distance. used for this, so that there is no need to search for difficult shunts. The dissipation at 1 0A is not all that high at 5 W. This shunt can also be made from other resistor values, of course, and the exact resistance value is not important (because there is the oppor- tunity to calibrate the circuit). A full-wave rectifier is built around IC1A. During the positive half cycle of the current through shunt R1 /R2, D1 blocks and the input cur- rent passes via R3 and R4 to filter R5/C1 . During the negative half cycle, IC1 A ampli- fies the input signal such that the cathode of D1 has the same amplitude as the input. The voltage across Cl is a measure of the average value of the measured current. As thresholds for the indicator we chose 25 W, 75 W and 1 50 W. The correspond- ing voltages across Cl are about 4.9 mV, 1 5 mV and 29 mV. This means that quite a bit of gain is required before the 3 rows of LEDs can be driven with the aid of transis- tors. The base-emitter junction of the tran- Fortunately more and more people are beginning to realise that we have to use energy sparingly. This is not only true for large companies, but at home it is also sensi- ble to ‘watch the small things’. So do not leave mains power adapters plugged in when not in use and actually turn electronic appliances off, instead of using the standby button. It is also good to get an idea as to how much energy each appliance uses. The intention is that this leads to more sensible use of these appliances at home. For this purpose we designed an indicator which changes colour depending on the current consumption. Operation and dimensioning The operating principle of the circuit is very simple. By connecting a shunt in series with the load we can measure the current con- sumption. The parallel connection of R1 and R2 is suitable for measuring currents up to 14 A. Two standard 0.1 £lj 5 W resistors are sistor for the first indicator (T3) determines how much the voltage across Cl has to be amplified so that it will start to conduct. If we assume a value of about 0.65 V, then the first switching threshold of 5 mV has to be amplified 1 30 times. This is what IC1 B does. With PI in the centre position the voltage across Cl is amplified a little more than 1 30 times. R1 2 limits the base current to T3. The transistors for the other 2 rows of LEDs, T2 and T1, have to be driven via voltage dividers. It is not difficult to calculate these: at 75 W the output of IC1 B is at 1 .9 V and at 1 50 W it is 3.8 V. In order to obtain a defined switching threshold it is necessary that the current through the divider is a little more than what is required for the base current. We selected a value of 0.5 mA. R1 1 and R9 then become 1 1<2. R1 0 and R8 then become 2I<7 and 5l<6 respectively. To ensure that only one row at a time is lights up, T3 is switched off by T1 and T2, 66 05-2012 elektor MINI PROJECT TR1 2x6V 0VA35 IC2 CM B80C1500 IC1 = TLC272 T1...T3 = BC547B D1...D4 = BAT85 V+ IC1 220u (T) „ 40V 1 I C3 lOOn D5 D8 |R8 R9 M”' X® srKj ® TOO '^O R11 080415 - 11 Figure 1 . Three sets of white LEDs with colour filters show how much energy the appliance is using. and T2 by T1 . This is done with the aid of Schottky diodes type BAT85 (D2/D3/D4). The simplicity of this drive mechanism gives the circuit a nice touch. Just before D5 through D7 are fully illuminated, D8 through D13 will just start to turn on (at exactly the correct load, of course). This is because at the transition from T2 to T1 nei- ther transistor is conduction sufficiently to ensure that T3 is fully turned off via D3 and D4. However, once the current increases a little more only D5 through D7 remain lit. Three rows of white LEDs with colour fil- ters are used for the colour indication. The reason that only white LEDs are used is to ensure that each of the branches are all identical in brightness, assuming that the filters do not influence the brightness too much. The advantage of this is that you can choose your own colours. Instead of the standard colours green/yellow/red, you could, for instance, use blue/lilac/pur- ple. For the filters you could, for example, use discarded filters for PAR56 spot lights or something similar and cut these to the required size (such filters are also available separately from Conrad, among others). To drive three white LEDs in series a volt- age of nearly 1 0 V is required to make sure that LEDs draw sufficient current. By power- ing the circuit from a 0.35 VA transformer only a limited amount of current is avail- able, about 30 mA. This corresponds with the maximum value for the white LEDs that we used here (HLMP-CW24-TW000, 24 g ). So make sure you do not substitute a bigger transformer otherwise the current through the LEDs will be too high. More power is permitted only when the LEDs can handle that. But it is of course the intention that the circuit itself uses as little power as possible. In this way there is no need for a current limiting resistor. The 3 series con- nected LEDs actually function as a kind of zener diode, so the output voltage cannot drop below about 9.5 V (this depends on the exact forward voltage of the diodes, of course). In this way the power supply volt- age for the opamp is always sufficient. The 78L08 regulator is mainly to limit the power supply voltage to the TLC272 and the regu- lator will stop regulating when a row of LEDs is fully illuminated. When none of the LEDs are turned on, the voltage across the filter capacitor C4 can increase to nearly 30 V when a 1 5-V transformer is used (2 x 6 V can also be used, and incidentally, this type is also easier to obtain). Construction and safety The most obvious enclosure for this circuit is to build it into a case with integrated plug and socket. Unfortunately we were unable to find a transparent version. You can of course cut a hole in the enclosure and fit it with a window made from acrylic sheet of sufficient thickness. Another idea is to buy a remote control switch that comes with a plug-and-socket enclosure and remove the electronics inside it. This is often cheaper than buying a sepa- rate case... For safety considerations the LEDs may not protrude through the enclosure. The entire circuit is connected to the mains the the LEDs are not specified for class-ll isolation! The remainder of the construction we leave to your own imagination. (080415-I) elektor 05-2012 67 TEST & MEASUREMENT SHT11 Humidity Sensor Connected to PC Trace and prove long-term % RH issues By Pavel Setnicar (Slovenia) Although the datasheet of the SHT1 1 is essential reading [1 ] we can have a head start by mentioning that the device’s output is pure digital; accuracy is ±3% RH and the measure- ment range is a solid 0-1 00% RH. For tem- perature, we have a range of -40 to +1 25 degrees Celsius (-40 to +257 degrees F). The SHT1 1 ’s digital output closely resem- The SHTn humidity sensor made by Swiss company Sensirion measures both temperature and humidity in an all digital way. Here we investigate how it can be used to record and log air humidity over longer periods of time — with the help of a PC of course. bles l 2 C but in fact on closer inspection is different to the extent that certain protocol should be used to retrieve data. The sensor commu- nicates with other devices trough two pins called SCK and DATA. SCK (clock) is used for synchronizing with other device and the tri- state DATA pin transfers data to and from the sensor. Certain start and command sequences are required to retrieve data from sensor and in good Swiss tradition these are well documented in the datasheet. My goal was to connect this sensor to my PC, suitably programmed to take measure- ment at predetermined intervals, display sensor data on the screen and, if desired, save data as a text file on disk for analy- sis or documenting. The PC’s legacy serial port (COM/RS232) was chosen for interfac- ing with the sensor because of its simplicity. Nowadays serial ports are rare on PCs, but there are USB to serial converters which do the job just fine. The circuit diagram (Figure 1 ) of the little interface shows that the following signals are used on the serial port: Figure 1 . In terms of hardware this is all you need to connect the SHT1 1 sensor to a PC and do some serious temperature/humidity logging. Figure 2. The program in action; data whooshing past but rest assured everything is logged securely for saving later. 68 05-2012 elektor DTR (pin 4, Data Terminal Ready) to output data from the PC to the sensor via a BC557 tranny; RTS (pin 7, Request To Send) to clock the SHT1 1 as required for any transmission to and from the device; CTS (pin 8, Clear To Send), an input receiving data from the SHT11. CD E CD CD > "O < Power for the SHT1 1 is stolen (some say: borrowed) from the serial port signal pins. No problem since the current consumption of sen- sor amounts to a mere 0.5 mA when active. Moreover, the sensor is in idle state most of the time so average power is extremely low. The COM port signal pins are connected to two rectifying diodes D1 and D2 and capacitor Cl is charged through them. Depending on the computer used the voltage on the capacitor is roughly 1 0 V so it needs reducing to 5 V by zener diode D4. Since the RS232 signals on the serial ports are typically ±1 0 V, the clock signal also needs stepping down to 5 V by D3. Using Bit Shifting-In and -Out (which is extensively documented in sensor datasheet) we get two chunks of raw information, one for temperature and one for humidity. During my experiments I noticed a slight offset in temperature readings so I decided to extend the program with an option to cal- ibrate the chip’s temperature sensor. If for example readings for temperature are consistently 1 .2 degrees Celsius too high you enter ‘-1.2’. in the Temp.offset window. Humidity data supplied by the sensor requires some math in terms of linearisation and this is done in program. For sticklers there an indicator window to see non-linearised values, and another for lin- earised values. The differences are very small because the non lin- earity of the sensor is minimal by all standards. In the lowest part of the screen a sample interval window is displayed, which allows you to set any desired period. As shown in Figure 2, data is concatenated and scrolls past in the text window. If you want, you can save data on disk anytime and work on it in other program (like Excel) at your convenience later. The control program was written in C# using Microsoft Visual Stu- dio 2008. To install it on computer, Microsoft .NET framework 3.5 must be installed first. The free archive file at [2] includes the source code and program install package. The source code can be modified if desired provided you are familiar with C#and dot NET program- ming. The PC program was tested on several machines running Windows XP. It should also work with a USB to serial converter (like my STLab-4). The circuit was tested with a 5 m long cable (approx. 1 5 ft.) between it and the PC. An experiment is the only way to find out the maximum length. (090384) Internet Links Technology PicoScope® PC OSCILLOSCOPES THERE’S A PICOSCOPE FOR EVERY APPLICATION 1/) QJ <0 OO o o CM 04 B v 1 i» a 1 ^ 1* ti li [a ] rjann | |j |W*n L L.lfuliCr FTDI specialise in USB silicon, hardware and software solutions. • USB WHQL complaint drivers. • USB host and slave solutions. • Free firmware development tools. ^ • USB IC’s, modules, cables and turnkey custom solutions. ^ • World renowned FOC application support. USB MADE EASY HEXWAX LTD www.hexwax.com World leaders in Driver-Free USB ICs: • USB-UART/SPI/I2C bridges • TEAleaf-USB authentication dongles • expandlO-USB I/O USB expander • USB-FileSys flash drive with SPI interface • USB-DAQ data logging flash drive SCOPES and more Instruments A Rohde & Schwarz Company www.hameg.com Great Value in TEST & MEASUREMENT satisfy your inner geek minty geek a fresh approach Cool portable electronic projects and kits www.mintygeek.com WWW. elektor. com 78 05-2012 elektor products and services directory THE NEXT GENERATION OF MAXSONAR The HRLV - MaxSonar Sensors •Amazing One-Millimeter Resolution •Simultaneous Multiple Sensor Operation •Superior Noise Rejection •Target Size Compensation for Accuracy •Temperature Compensation ($4.95) •Outputs now include TTL Serial $3495 (msrp) f www.MaxBotix.com ROBOT ELECTRONICS http://www.robot-electronics.co.uk Advanced Sensors and Electronics for Robotics • Ultrasonic Range Finders • Compass modules • Infra-Red Thermal sensors • Motor Controllers • Vision Systems • Wireless Telemetry Links • Embedded Controllers ROBOTIQ http ://www. robotiq .co . u k Build your own Robot! Fun for the whole family! Now, available in time for X-mas • Arduino Starter Kits *NEW!!* • Lego NXT Mindstorms • Affordable Embedded Linux Boards • Vex Robotics (kits and components) • POB Robots (kits and components) email: sales@robotiq.co.uk Tel: 020 8669 0769 TYDER http://www.tyder.com • ONEoverT Digital Filter Design Software (Full version for only £30) • Design FIRs, HRs, NCOs, FFTs for DSPs and FPGAs • VHDL Code Generators • Makes DSP design simple • Download demos from website ELEKTOR Preferred Suppliers • Coast Electronics • CS Technology • Easysync • Elnec • FTDI Chip • Robot Electronics Surf to www.elektor.com 365 days per year preferred suppliers online with up to date and relevant information. CtCtCTOR l£. a r rWl'lrttK, TetltTHi F uiui t> t-ur-wi Mnti.mi r *• mil I* rtw yi-;4jr ? Fascinated by technology’s impact on the future? Check out Tech the Future! r www.techthefuture.com Computing power and global interconnectivity are pushing tech innovation into overdrive. Pioneering technologies and creative workarounds affect even the couch potato 24/7. Tech the Future reports on technology strides that shape the future — yours included. Follow Tech the Future f 8 + ^ elektor 05-2012 79 SHOP BOOKS, CD-ROMs, DVDs, KITS & MODULES Limited Period ut» )r Elektor Subscnbersl 1 5% DISCOUNT elektor.comjmay Design your Fevzi lektor A comprehensive and practical how-to guide A world of electronics from a single shop! Design your own PC Visual Processing and Recognition System in C# This book is aimed at Engineers, Scientists and enthusiasts with developed programming skills or with a strong interest in image processing technology on a PC. Written using Microsoft C# and utilizing object-oriented practices, this book is a comprehensive and practical how-to guide. The key focus is on modern image processing techniques with useful and practical application examples to produce high-quality image processing software. Analysis starts with a detailed review of the fundamentals of image processing. It progresses to explain and explore the prac- tical uses of two highly sophisticated and freely downloadable, open source image processing libraries; AForge.NET and Emgu.CV, utilizing dotnet technology within the Microsoft Visual Studio environment. All code examples used are available - free of charge - from the Elektor website; you can easily create and develop your own results to demonstrate the concepts and techniques explained. 307 pages • ISBN 978-1-907920-09-7 • £35.50 • US$57.30 Dcrsign your own Enhanced second edition: 180 new pages Design your own Embedded Linux Control Centre on a PC The main system described in this book reuses an old PC, a wireless mains outlet with three switches and one controller, and a USB webcam. All this is linked together by Linux. This book will serve up the basics of setting up a Linux environment - in- cluding a software development environ- ment - so it can be used as a control centre. The book will also guide you through the necessary setup and configuration of a Webserver, which will be the interface to your very own home control centre! 41 6 pages • ISBN 978-1-907920-02-8 £34.50 • US $55.70 Creative solutions for all areas of electronics 311 Circuits 31 1 Circuits is the twelfth volume in Elek- tor’s renowned 30x series. This book con- tains circuits, design ideas, tips and tricks from all areas of electronics: audio & video, computers & microcontrollers, radio, hob- by & modelling, home & garden, power supplies & batteries, test & measurement, software, not forgetting a section'miscel- laneous’ for everything that doesn’t fit in one of the other categories. 31 1 Circuits of- fers many complete solutions as well as use- ful starting points for your own projects. 420 pages • ISBN 978-1-907920-08-0 £29.50 • US $47.60 8 o Prices and item descriptions subject to change. E. & O.E 05-2012 elektor Mastering the l 2 C Bus VinbanC h-mpa Qlohtor LabWorX 1 LabWorX: Straight from the Lab to your Brain Mastering the l 2 C Bus Mastering the l 2 C Bus is the first book in the LabWorX collection. It takes you on an exploratory journey of the PC Bus and its applications. Besides the Bus protocol plenty of attention is given to the practical applications and designing a solid system. The most common PC compatible chip classes are covered in detail. Two expe- rimentation boards are available that allow for rapid prototype development. These are completed by a USB to PC probe and a software framework to control PC devices from your computer. 248 pages • ISBN 978-0-905705-98-9 £29.50 • US $47.60 Controller Area Network Projects Free mikroC compiler CD-ROM included Controller Area Network Projects The aim of the book is to teach you the ba- sic principles of CAN networks and in addi- tion the development of microcontroller based projects using the CAN bus. You will learn howto design microcontroller based CAN bus nodes, build a CAN bus, develop high-level programs, and then exchange data in real-time over the bus. You will also learn how to build microcontroller hard- ware and interface it to LEDs, LCDs, and A/D converters. 260 pages • ISBN 978-1-907920-04-2 £29.50 • US $47.60 Processor design in the real world Microprocessor Design using Verilog HDL If you have the right tools, designing a microprocessor shouldn’t be complicated. The Verilog hardware description lan- guage (HDL) is one such tool. It can enable you to depict, simulate, and syn- thesize an electronic design, and thus increase your productivity by reducing the overall workload associated with a given project. This book is a practical guide to processor design in the real world. It presents the Verilog HDL in an easily digestible fashion and serves as a thorough introduction about reducing a computer architecture and instruction set to practice. You’re led through the microprocessor design process from the start to finish, and essential topics ranging from writing in Verilog to de- bugging and testing are laid bare. 337 pages • 978-0-9630133-5-4 £27.90 • US$45.00 More information on the Elektor Website: www.elektor.com Elektor Regus Brentford 1 000 Great West Road Brentford TW8 9HH United Kingdom Tel.: +44 20 8261 4509 Fax: +44 20 8261 4447 Email: order@elektor.com More than 70,000 components cd Elektor’s Components Database 6 This CD-ROM gives you easy access to de- sign data for over 7,800 ICs, more than 35,600 transistors, FETs, thyristors and triacs, just under 25,000 diodes and 1 ,800 optocouplers. The program package consists of eight databanks covering ICs, transistors, diodes and optocouplers. A further eleven applications coverthe calcu- lation of, for example, zener diode series re- sistors, voltage regulators, voltage dividers and AMV’s.Acolour band decoder is includ- ed for determining resistor and inductor values. All databank applications are fully interactive, allowing the user to add, edit and complete component data. ISBN 978-90-5381 -258-7 £24.90 • US$40.20 Circuits, ideas, tips and tricks from Elektor cd 1001 Circuits This CD-ROM contains more than 1000 circuits, ideas, tips and tricks from the Summer Circuits issues 2001 -201 0 of Elek- tor, supplemented with various other small projects, including all circuit diagrams, descriptions, component lists and full- sized layouts. The articles are grouped alphabetically in nine different sections: audio & video, computer & microcontroller, hobby & modelling, home & garden, high frequency, power supply, robotics, test & measurement and of course a section miscellaneous for everything that didn’t fit in one of the other sections. ISBN 978-1 -907920-06-6 £34.50 • US$55.70 elektor 05-2012 81 SHOP BOOKS, CD-ROMs, DVDs, KITS & A whole year of Elektor magazine onto a single disk i DVD Elektor 2011 I The year volume DVD/CD-ROMs are among the most popular items in Elektor’s product range. This DVD-ROM contains all editorial articles published in Volume 201 1 of the English, American, Spanish, Dutch, French and German editions of Elektor. Using the supplied Adobe Reader program, articles are presented in the same layout as originally found in the magazine. An extensive search machine is available to locate keywords in any article. With this DVD you can also produce hard copy of PCB layouts at printer resolution, adapt PCB layouts using your favourite graphics program, zoom in / out on selected PCB areas and export circuit dia- grams and illustrations to other programs. ISBN 978-90-5381 -276-1 £23.50 • US $37.90 1 1 0 issues, more than 2,1 00 articles dvd Elektor 1990 through 1999 This DVD-ROM contains the full range of 1990-1999 volumes (all 110 issues) of Elektor Electronics magazine (PDF). The more than 2,100 separate articles have been classified chronologically by their dates of publication (month/year), but are also listed alphabetically by topic. A compre- hensive index enables you to search the entire DVD. What’s more, this DVD also contains the entire The Elektor Datasheet Collection 1 ...5’ CD-ROM series. ISBN 978-0-905705-76-7 £69.00 • US$111.30 RS-485 Switch Board (April 201 2) Our ElektorBus series has shown how much interest there is in home automa- tion applications. This small circuit board can switch two AC (230 VAC) loads. Also, two of the inputs to the on-board micro- controller are brought out to terminals so that the state of two switches can be read back. The board works with the Elektor- Bus and so is an ideal building-blockfora home automation system controlled from a PC, tablet or smartphone. RS485-Relay board, assembled and tested Art.# 11 0727-91 • £40.00 • US$56.00 AVR Software Defined Radio (March 201 2) This package consists of the three boards associated with the AVR Software Defined Radio articles series in Elektor, which is built around practical experiments. The first board, which includes an ATtiny231 3, a 20 MHz oscillator and an R-2R DAC, will be used to make a signal generator. The second board will fish signals out of the ether. It contains all the hardware needed to make a digital software-defined radio (SDR), with an RS-232 interface, an LCD panel, and a 20 MHz VCXO (voltage-con- trolled crystal oscillator), which can be locked to a reference signal. The third board provides an active ferrite antenna. Signal Generator + Universal Receiver + Active Antenna: PCBs and all components + USB-FT232R breakout- board Art.# 1001 82-72 • £99.90 • US$133.00 AndroPod (February 201 2) With their high-resolution touchscreens, ample computing power, WLAN support and telephone functions, Android smartphones and tablets are ideal for use as control centres in your own projects. However, up to now it has been rather difficult to connect them to exter- nal circuitry. Our AndroPod interface board, which adds a serial TTL port and an RS485 port to the picture, changes this situation. Andropod module with RS485 Extension Art.# 11 0405-91 • £53.35 • US$74.70 Improved Radiation Meter (November 201 1) This device can be used with different sensors to measure gamma and alpha radiation. It is particularly suitable for long- term measurements and for examining weakly radio-active samples. The photo- diode has a smaller sensitive area than a Geiger-Mtillertube and so has a lower back- ground count rate, which in turn means that the radia-tion from a small sample is easier to detect against the background. A further advantage of a semiconductor sensor is that is offers the possibility of measuring the energy of each particle. Kit of parts incl. display and programmed controller Art.# 11 0538-71 • £35.50 • US$57.30 82 Prices and item descriptions subject to change. E. & O.E 05-2012 elektor May 201 2 (No. 425) US$ + + + Product Shortlist May: See www.elektor.com + + + April 201 2 (No. 424) Preamplifier 201 2(1) 110650-1 Line-ln/Tone/Volume board www. LED Touch Panel 070558-1 Controller board www. 070558-2 LED board www. AVR Software Defined Radio (2) 100181-1 Receiver board www. 100181-71 .... Universal Receiver: PCB and all components.... 100182-72 .... Signal-Generator + Universal Receiver + Active Antenna: PCBs and all components + USB-FT232R breakout-board Thermometer using Giant Gottlieb® Displays 1 1 0673-1 Printed circuit board www. 1 1 0673-41 .... ATTINY231 3-20PU, programmed RS-485 Switch Board 1 1 0727-1 Printed circuit board www. 1 1 0727-91 .... RS485-Relay board, assembled and tested 110727-92 .... Set of 3 RS485-Relay boards elektorpcbservice.com elektorpcbservice.com elektorpcbservice.com elektorpcbservice.com 49.90 65.90 99.90 133.00 elektorpcbservice.com 8.85 12.40 elektorpcbservice.com 40.00 56.00 106.75 149.50 March 201 2 (No. 423) AVR Software Defined Radio (1 ) 080083-71 .... USB-AVR Programmer: SMD stuffed board and all components 23.50 47.00 1 00180-71 .... Signal Generator kit; PCB and all components 25.1 5 33.20 100181-71 .... Universal Receiver: PCB and all components 62.95 83.1 0 1 00182-71 .... Active Antenna: PCB and all components 25.1 5 33.20 100182-72 ....Signal Generator + Universal Receiver + Active Antenna: PCBs and all components + USB-FT232R breakout-board 99.90 133.00 1 1 0553-91 .... Populated and tested BOB 1 2.90 1 9.99 AndroPod (2) 1 1 0258-91 .... USB/RS485 Converter: ready assembled module 22.20 35.70 110405-91 . 110553-91 . 120103-92. 120103-94. ..Andropod module with RS485 Extension 53.35 74.70 .. Populated and tested BOB 1 2.90 20.90 .. 1 . 8 m USB 2.0 A male to USB micro-B 5 pin black cable . 3.50 4.90 ..5V/ 1A(5W) PSU with micro-USB connector 8.00 11.20 V February 201 2 (No. 422) AndroPod (1) 1 1 0258-91 .... USB/RS485 converter, ready-made module 22.20 35.70 1 1 0405-91 .... Andropod module with RS485 Extension 53.35 74.70 1 1 0553-91 .... USB-FT232R breakout board, assembed and tested .. 1 2.90 20.90 1 20103-92 .... 5-way cable USB 2.0 A male to USB micro-B, black 3.50 5.70 1 20103-94 .... 5V / 1 A (5W) PSU with micro-USB connector 8.00 1 2.90 Pico C-Plus and Pico C-Super 1 1 0687-41 .... Pico C-Plus controller, programmed (ATTINY2313-20PU) 4.40 7.10 1 1 0687-42 .... Pico C-Super controller, programmed (ATTINY2313-20PU) 4.40 7.10 Electronics for Starters (2) ELEX-1 Prototyping board 4.90 7.90 ELEX-2 Prototyping board (double size) 8.85 14.30 January 201 2 (No. 421) Wideband Lambda Probe Interface 110363-41 .... Programmed controller ATMEGA8-16AU 8.85 14.30 Audio DSP Course (7) 1 1 0002-71 .... Printed circuit board partly populated with SMD’s .... 44.50 71 .80 Grid Frequency Monitor 1 1 0461 -41 .... Programmed controller AT89C2051 -24PU, for 50 HZ areas (Europe) 8.85 14.30 1 1 0461-42 .... Programmed controller AT89C2051 -24PU, for 60 Hz areas (USA) 8.85 14.30 Bestsellers .a Microprocessor Design using Verilog HDL ISBN 978-0-96301 33-5 £27.90 US $45.00 o o CO O Q£ I O Q Q U od {/) 2 Mastering the l 2 C Bus ISBN 978-0-905705-98-9.... £29.50 .. ...US$47.60 3 Controller Area Network Projects ISBN 978-1 -907920-04-2 .... £29.50 US $47.60 4 311 Circuits ISBN 978-1 -907920-08-0 .... £29.50 .. ...US$47.60 5 1 2 3 Design your own PC Voice Control System ISBN 978-1 -907920-07-3 .... £29.50 US $47.60 DVD Elektor 201 1 ISBN 978-90-5381 -276-1 .... £23.50 US $37.90 DVD Elektor 1 990 through 1 999 ISBN 978-0-905705-76-7 .... £69.00 ...US $1 1 1 .30 CD 1001 Circuits ISBN 978-1 -907920-06-6.... £34.50 US $55.70 4 CD Elektor’s Components Database 6 ISBN 978-90-5381 -258-7 .... £24.90 US $40.20 Masterclass c DVD High-End Valve Amplifiers ISBN 978-0-905705-86-6.... £24.90 US $40.20 Improved Radiation Meter Art. # 1 1 0538-71 £35.50 US $57.30 1 2 E3 3 4 5 AVR Software Defined Radio Art. # 1 001 82-72 £99.90 ...US $1 33.00 FT232R USB/Serial Bridge/BOB Art. # 1 1 0553-91 £1 2.90 US $20.90 Here comes the Bus! Art. # 1 1 0258-91 £22.20 US $35.90 USB Long-Term Weather Logger Art. # 1 00888-73 £31.10 US $50.20 Order quickly and securely through www.elektor.com/shop or use the Order Form near the end of the magazine! Elektor Reg us Brentford 1 000 Great West Road Brentford TW8 9HH • United Kingdom Tel. +44 20 8261 4509 Fax +44 20 8261 4447 Email: order@elektor.com elektor 05-2012 83 COMING ATTRACTIONS NEXT MONTH IN ELEKTOR Nixie’d Thermometer / Hygrometer Circuits with Nixie tubes rank tops everywhere, presumably because of the special attrac- tion exerted by the magical glow of the lighted tube. In the June 2012 edition we present another design with four such tubes. This time we present a circuit that allows both tem- perature and humidity to be measured. In terms of hardware the project consists of a PIC microcontroller, a SHT21 air humidity sensor, a step-up converter built around a MC34063 and control of the Nixies with the good old 74141. Swimmer’s Distance Counter It’s a familiar sight in parks: the pedometer, a small device that counts the number of steps joggers have run. to our knowledge there’s no such device for swimmers yet. Our design allows you to build an ‘aquameter’ (if that is the correct name), which counts the swim- mer’s number of head movements. The circuit is simple and mainly consists of a micro- controller and a readily available accelerometer module. Heliostat A heliostat is a device fortracking moving objects in the sky. This way you are able to main- tain a maximum amount of sunlightto absorb on a surface, take a series of photographs of a moving planet or detect a satellite for optimal reception using a dish. This project in the June 2012 edition describes the outlines of a heliostat made from two servo motors. With the aid of a model continuously calculating the sun’s position as a function of the time and place on earth, the servos are driven and always pointed in the direction of the sun. Article titles and magazine contents subject to change; please check the Magazine tab on www.elektor.com Elektor UK/European June 2012 edition: on sale May 77, 2072. Elektor USA March 2012 edition: published May 75, 2072. w.elektor.com www.elektor.com www.elektor.com www.elektor.com www.elektor.com wv Elektor on the web All magazine articles back to volume 2000 are available individually in pdf format against e-credits. Article summaries and compo- nent lists (if applicable) can be instantly viewed to help you positively identify an article. Article related items and resources are also shown, including software downloads, hyperlinks, circuit boards, programmed ICs and corrections and updates if applicable. In the Elektor Shop you’ll find all other products sold by the publishers, like CD-ROMs, DVDs, kits, modules, equipment, tools and books. A powerful search function allows you to search for items and references across the entire website. 0lektor hiia, rental Also on the Elektor website: • Electronics news and Elektor announcements • Readers Forum • PCB, software and e-magazine downloads • Time limited offers • FAQ, Author Guidelines and Contact If W rn™h-Kiuk if C-tHtki t ftmrli J tfa ij !<:-■! . LO 1 |lLI II ■- At -« « Oib EWnitfa ic:i Jl-h.o hK.vr o* mm Ur pnr ih nm-w. Tr t Ipn Eijii.in.ra;, rt -inu ■sor^ sc MANl It >V- t? Pr^ifciirfihky PE MiCnxoiUiioBcrj 0 0 * Fay. H MHMBM FSEE WE BBWAK AVn Era'tWAr. D’l-riiHrt RrttlWi F-Pir ra-rfrirt hSih 7 pa in & dayi 84 05-20120 lektor Description Price each 1 Design your own PC Visual Processing and r^a^l £ 35.50 Recognition System in C# DVD Elektor 201 1 £23.50 Microprocessor Design using Verilog HDL £27.90 31 1 Circuits £29.50 Controller Area Network Projects £29.50 LabWorX - Mastering the l 2 C Bus £29.50 CD 1 001 Circuits £34.50 Prices and item descriptions subject to change. The publishers reserve the right to change prices without prior notification. Prices and item descriptions shown here supersede those in previous issues. E. & O.E. Sub-total P&P Total paid METHOD OF PAYMENT (see reverse before ticking as appropriate) □ Bank transfer | Cheque (UK-resident customers ONLY) n visa □ EUROCARD MasterCard Expiry date: Verification code: Please send this order form to* (see reverse for conditions) Elektor Reg us Brentford 1 000 Great West Road Name Address + Post code Brentford TW8 9HH United Kingdom Tel.: +44 20 8261 4509 Fax: +44 20 8261 4447 www.elektor.com order@elektor.com Tel. Email Date Signature EL05 Yes, I am taking out an annual subscription to Elektor and receive the E-book Microcontroller Basics totally free!* (Please fill in your emailaddress below) I would like: Microcohirolur Basics Standard Subscription (11 issues) I I Subscription-Plus (1 1 issues plus the Elektor Volume 201 2 DVD-ROM + exclusive access to www.elektor-plus.com ) * Offer available to Subscribers who have not held a subscription to Elektor during the last 12 months. Offer subject to availability. See reverse for rates and conditions. Name Address + Post code Tel. Email Date Signature EL05 *USA and Canada residents should use $ prices, and send the order form to: Elektor US 4 Park Street Vernon CT 06066 USA Phone: 860-875-2199 Fax: 860-871-0411 E-mail: order@elektor.com METHOD OF PAYMENT (see reverse before ticking as appropriate) □ Bank transfer | Cheque (UK-resident customers ONLY) n visa □ EUROCARD MasterCard Expiry date: Verification code: Please send this order form to Elektor Regus Brentford 1 000 Great West Road Brentford TW8 9HH United Kingdom Tel.: +44 20 8261 4509 Fax: +44 20 8261 4447 www. e I e kto r. co m service@elektor.com ORDERING INSTRUCTIONS, P&P CHARGES All orders, except for subscriptions (for which see below), must be sent BY POST or FAX to our Brentford address using the Order Form overleaf. Online ordering: www.elektor.com/shop Readers in the USA and Canada should send orders, except for subscriptions (for which see below), to the USA address given on the order form. Please apply to Elektor US for applicable P&P charges. Please allow 4-6 weeks for delivery. Orders placed on our Brentford office must include P&P charges (Priority or Standard) as follows: Europe: £6.00 (Standard) or £7.00 (Priority) Outside Europe: £9.00 (Standard) or £1 1 .00 (Priority) HOW TO PAY All orders must be accompanied by the full payment, including postage and packing charges as stated above or advised by Customer Services staff. Bank transfer into account no. 4027021 1 held by Elektor International Media BV with The Royal Bank of Scotland, London. IBAN: GB96 ABNA 4050 3040 2702 1 1 . BIC: ABNAGB2L. Currency: sterling (UKP). Please ensure your full name and address gets communicated to us. Cheque sent by post, made payable to Elektor Electronics. We can only accept sterling cheques and bank drafts from UK-resident customers or subscribers. We regret that no cheques can be accepted from customers or subscribers in any other country. GCredit card VISA and MasterCard can be processed by mail, email, web, fax and telephone. Online ordering through our website is SSL-protected for your security. COMPONENTS Components for projects appearing in Elektor are usually available from certain advertisers in this magazine. If difficulties in the supply of components are envisaged, a source will normally be advised in the article. Note, however, that the source(s) given is (are) not exclusive. TERMS OF BUSINESS Delivery Although every effort will be made to dispatch your order within 2-3 weeks from receipt of your instructions, we can not guaran- tee this time scale for all orders. Returns Faulty goods or goods sent in error may be returned for replacement or refund, but not before obtaining our consent. All goods returned should be packed securely in a padded bag or box, enclosing a covering letter stating the dispatch note number. If the goods are returned because of a mistake on our part, we will refund the return postage. Damaged goods Claims for damaged goods must be received at our Brentford office within 10-days (UK); 14-days (Europe) or 21 -days (all other countries). Cancelled orders All cancelled orders will be subject to a 1 0% handling charge with a minimum charge of £5.00. Patents Patent protection may exist in respect of circuits, devices, components, and so on, described in our books and magazines. Elektor does not accept responsi- bility or liability for failing to identify such patent or other protection. Copyright All drawings, photographs, articles, printed circuit boards, programmed integrated circuits, diskettes and software carriers published in our books and magazines (other than in third-party adver- tisements) are copyright and may not be reproduced or transmitted in any form or by any means, including photocopying and recording, in whole or in part, without the prior permission of Elektor in writing. Such written permission must also be obtained before any part of these publications is stored in a retrieval system of any nature. Notwithstanding the above, printed-circuit boards may be produced for private and personal use without prior permission. Limitation of liability Elektor shall not be liable in contract, tort, or otherwise, for any loss or damage suffered by the purchaser whatsoever or howsoever arising out of, or in connexion with, the supply of goods or services by Elektor other than to supply goods as described or, at the option of Elektor, to refund the purchaser any money paid in respect of the goods. Law Any question relating to the supply of goods and services by Elektor shall be determined in all respects by the laws of England. January 2012 SUBSCRIPTION RATES FOR ANNUAL SUBSCRIPTION United Kingdom & Ireland Standard £54.00 Plus £66.50 Surface Mail Rest of the World £68.50 £81.00 Airmail Rest of the World £86.00 £98.50 USA & Canada | Seewww.elektor.com/usaforspecialoffers | HOW TO PAY Bank transfer into account no. 4027021 1 held by Elektor International Media BV with The Royal Bank of Scotland, London. IBAN: GB96 ABNA 4050 3040 2702 1 1 . BIC: ABNAGB2L. Currency: sterling (UKP). Please ensure your full name and address gets communicated to us. Cheque sent by post, made payable to Elektor Electronics. We can only accept sterling cheques and bank drafts from UK-resident cus- tomers or subscribers. We regret that no cheques can be accepted from customers or subscribers in any other country. Credit card VISA and MasterCard can be processed by mail, email, web, fax and telephone. Online ordering through our website is SSL-protected for your security. SUBSCRIPTION CONDITIONS The standard subscription order period is twelve months. If a permanent change of address during the subscription period means that copies have to be despatched by a more expensive service, no extra charge will be made. Conversely, no refund will be made, nor expiry date extended, if a change of address allows the use of a cheaper service. Student applications, which qualify for a 20% (twenty per cent) reduction in current rates, must be supported by evidence of studentship signed by the head of the college, school or university faculty. A standard Student Subscription costs £43.20, a Student Subscription-Plus costs £55.70 (UK only). Please note that new subscriptions take about four weeks from receipt of order to become effective. Cancelled subscriptions will be subject to a charge of 25% (twenty-five per cent) of the full subscription price or £7.50, whichever is the higher, plus the cost of any issues already dispatched. Subsciptions cannot be cancelled after they have run for six months or more. January 2012 i f »v9- ou urtwci ci>«AHivy nr in tapK niMti^u 1 Iwuhi iKa ’ iH . jLh ^ tUj LOCATION U'MdSMrt pj»u a t'Jt-jC ii DECEMBER: 20ii ISSUE 257 Build a cl MCU-Based Sleep-Stage Checkout Ana | ysis Hardware with a usi DIY Smart Electronic Electronic Load Design Thermal a Embedded Linux System Platforms AnMCU-E Network c interference Immunity for Electronic Designs M hCMt 1 DK9 AOV pWifi hhnrsrt M«.ji Joystick Control with I Bluetooth Connectivity ^ ■ ivuerc Design Inside I ho Mind qS a Microprocessor Devs lopcf .7 Analog Gipolar T*ch la Oigjtad Design !i Tftfe Uwf,*Mi * 01 Vtnbg HDL U DrtJgr. Lli-iva RrOflrArr.m«li Loflk K And Ww* Sfimwaw S unpliTtiKt AvtanWiyi Khkafirt K?ji«Miv* r««Aa Subscribe now to the leading computer applications magazine specializing in embedded systems and design! 1 2 issues per year for just Digital: $50 : : Print: $75 : : Combo (Print + Digital): $110 Select your personal subscription at WITH PROTEUS PCS DESIGN Our completely new manual router makes placing tracks quick and intuitive. During track placement the route will follow the mouse wherever possible and will intelligently move around obstacles while obeying the design rules. All versions of Proteus also include an integrated world class shape based auto-router as standard. PROTEUS DESIGN SUITE Features: ■ Hardware Accelerated Performance. ■ Board Autoplacement & Gateswap Optimiser. ■ 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 ARM7. ■ Polygonal and Split Power Plane Support. ■ Direct Technical Support at no additional cost. Prices start from just £150 exc. VAT & delivery www.labcenter.com Labcenter Electronics Ltd. 53-55 Main Street, Grassington, North Yorks. BD23 5AA. Registered in England 4692454 Tel: +44 (0)1756 753440, Email: info@labcenter.com Visit our website or phone 01756 753440 for more details