curve tracer on USB \ \ w Free CAD design tools online LED Lighting FPGA for model coaches programming inC VISIT 2000 SERIES 3000 SERIES PicoScope 5000 Series 25G MHz bandwidth 1 GS/i real-time sample rate 12G mega sample record length yj The No Compromise _ PC Oscilloscopes g With chw leading h.indwidch, dimpling J.itif, nuTnc-rv dtp - 1- ! 1 nnd 3.n flirray qf .ldv.inced high-end Ee^tyrpi, the PJtflStGp* Ln bC OD Ft give you the tearures and per forma nee ytu need without any compromise. k fh-f-Fic escape KKKS i r r*ii a F^w 1 1 kraDpcv fir c-m Plggltahnofogy irxl'jdn s. purpose hi^h sciyl-gii \nc*&h\ W« 1 h M biL NT-HSl^KWi *nd m *taJTK£ ?l\*r Hj.UHj it #feJt iq 0 #f«i chjrgrs-ds sniiPi^3 ! d.0i4%ll-f4pf3rnl *- making \< the ktal 4*dhMtel HCffofCCpt r&i ■ i ii-''nK] nnm , The ft£® 5 -bni w-lh. [Mk urtnskW. rimiV-HC. sMfltf IfVfl triggering 2 JO MHz Spectrum Analyser Highspeed uS6 2.0 Connection Automatic Measurements Arbitrary Waveform Generator £wA'ii> your pun *.<•.• Iurrm cr il#I^-: I Irnm A pifdf^rvd Uu - I J tW. I IE* Mjjbj jrhilrjr r wjvf rmn g#r_f rjfcv Waveform PidybackTo^l P<-oScope i^ho^feii non jJIa-rs c* flo thuk. irv^-w. ind j-^-iIy+c- up -a 1000 ■: jpru'-.-s mih*n •h N^ri-lampl^tMLk^L Technology to check out our tu II line of PC- baaed instruments or tall 01 480 396 395 for information and a product catalogue Capacitive Touch Sensing In a Flexible, Single-chip Solution Capacitive touch interfaces provide an excellent way to add low-cost, reliable and stylish buttons into your design. Microchip Technology's mTouch™ Sensing Solution includes comprehensive development kits and a free diagnostic tool to make implementation easy and fast. Our free source code can be seamlessly integrated with your existing firmware on a single PIC® microcontroller - eliminating the need for additional controllers. THE mTouch SENSING SOLUTION FEATURES: • FREE license libraries and source code • A FREE diagnostic tool • Integration with 8- and 16-bit PIC microcontrollers • Easy expansion, with support from 6 to 100 pins • Low-power operation GET STARTED IN 3 EASY STEPS 1 . Visit the mTouch Sensing Solutions design center at www.microchip.com/mTouch 2. Download free libraries and source code 3. For a limited time, save 20% off a variety of touch sensing development tools when you purchase from www.microchipDIRECT.com and use voucher code EUMTOUCH. ooo <1 Intelligent Electronics start with Microchip mtcrochi www.microchip.com/mtouch & Microchip The Microchip name and logo, the Microchip logo, MPLAB and PIC are registered trademarks of Microchip Technology Incorporated in the USA and other countries. mTouch and PICDEM are trademarks of Microchip Technology Incorporated in the USA and other countries. All other trademarks are property oftheir respective companies.© 2008, Microchip Technology Incorporated. All Rights Reserved. ME211Eng/08.08 Microcontrollers Digital Signal Analog Serial Controllers EEPROMs Cooking and grilling with Elektor Our technical staff in the Elektor lab always do their best to make a seri- ous impression, working all the time with complicated electronic designs and test equipment. However, sometimes their sense of fun gets the upper hand, and then there's no telling what might happen. This time the action revolved around a can of frankfurters left standing in a corner for half a year already, waiting for some sort of special preparation. And when we say special, we mean special. Needless to say, cooking and grill- ing with Elektor always goes hand in hand with a certain electric tension (literally) and suitable sensation. The plan was to apply an ac voltage directly to the frankfurter so it could be cooked almost instantaneously. Our lab staff are keen on special effects, so they decided it would be nice to stick a few LEDs in the frank- furter, with the idea that they would light up when the frankfurter was cooked through. This led to a fairly animated discussion of whether they would actually light up. Apparently it's not that easy to apply Ohm's law and Kirchoff's rules to a frankfurter. Finally, the time came for action. The can of frankfurters was opened, a heavy-duty adjustable, double isolated transformer was brought out of storage, forks were borrowed from the canteen so the current could penetrate deep into the frankfurter, and a good crowd of people gathered around to watch the events first-hand. Interestingly enough, our lab manager, Antoine Authier, took up a position behind a low cabinet that provided strategic cover. The French naturally know how to deal with food, and he probably thought the frankfurter might suddenly catch fire. ...Tension rising ... of 40 V, the frankfurter still resolutely maintains its resistance. . . the first wonder occurs at 70 V: the LEDs light up! ...the voltage rises even higher... at 80 V, the first plume of smoke comes from the frankfurter , and it's done! The LEDs made a positive contribu- tion to the cooking session. After some experimenting, we found that the best results can be expected at 80 V. The only other thing we should mention is that Jan Visser ate the frankfurters and is still in good health (as far as we know). And of course: never try this at home! Wisse Hettinga International Editor leKio r electronics worldwide This practical instrument can be used to measure and record the cha- racteristic curves of NPN and PNP bipolar transistors, N- and P-chan- nel JFETs, and N- and P-channel MOSFETs. The circuit is based on an R8C/1 3 microcontroller, which transfers the measurement data to a Windows application program via USB. 3 _ =I.[X| fr\ lypr SpiCalci 3 Cj’-< Eit? VottiD* Dlil*rtrt< C-zp-Kriznc* 13HJT] [01 tJ [30 3 Anib .*n T* “.p* mLi *i * C | Ttmptrjcur* Riik(‘£i MfinunJ Cnp QpirjEion Fr*q.yiiKV in 1 In men " 4 P -U J -LJ p JJJ " 1 |M VW 1 pjiril 51 cm mm Quit c Hpt*4lCBllSWIJ Ul I hi-- Dublin lipt-iiiliiiiihori! varying 1 H-mp.; A'A PjiI tan-tor Pitfi fr* stpttiw (yifj Stfl flB'SKIll'i:* Freq (BIAS Amps| ESUZI ^lUtwni) f £SL[nMV ["" VA. [RMS Amps;! 18 Free CAD HSft ll 0[4I I I'M yu. fW| Several electronic component manufacturers now offer design tools online or for free download. We registered on a dozen or so websites to see just what's being offered and what it's like. ■V5 n ■>, I 'Xlu-u-ra-h M riata.UJVi*i ■ 11 H [lH X rnrfi »ar I ■ -r-a ..m u+r .urn li Ir Indrt fans- - it ai H. Ha*- ._rt i - jbi KlfU r - * t T, -K + CONTENTS Volume 35 February 2009 no. 386 The lighting controller described in this article is a combination of an SMD LED strip and a PIC1 2F683 for compatibility with the Marklin system. The LEDs allow easy adaptation to different colours while three different lengths of the board enable the project to fit all common coach types. 69 Mini VHF FM Receiver These days tiny FM radios are often integrated in many portable devices such as mobile phones and MP3 players. But why not make a simple receiver ourselves? There are currently several nice ICs available that contain a (nearly) complete receiver. projects 24 Transistor Curve Tracer Microcontrollers for Dummies... 4 ' Tri-State Timer 53 BASCOM-AVR Course (6) (final) 56 Model Coach Lighting 65 Mini VHF FM Receiver Opacity Measurement by PC 74 Design Tips: No varicap? Try a Schottky diode Three-from-four fan control technology 1 8 Free CAD 38 From 1 7x4 to Channel Routing 46 An Eye for Distance 60 Prog ramming FPGAs in C 64 C Sharp (1 ) info & market 6 Colophon 8 Mailbox News & New Products 52 Decibit 2.4 GHz RF Transceiver Development Kit (review) 68 Electromagnetic Compatibility (EMC) page 80 ElektorSHOP Sneak Preview infotainment 76 Hexadoku 77 Retronics: Elektor Digisplay (1976-77) ELECTRONICS WORLDWIDE elektor international media Elektor International Media provides a multimedia and interactive platform for everyone interested in electronics. From professionals passionate about their work to enthusiasts with professional ambitions. From beginner to diehard, from student to lecturer. Information, education, inspiration and entertainment. Analogue and digital; practical and theoretical; software and hardware. Volume 35, Number 386, February 2009 ISSN 1 757-0875 Elektor aims at inspiring people to master electronics at any personal level by presenting construction projects and spotting developments in electronics and information technology. 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 1 1 times a year with a double issue for July & August. Elektor is also published in French, Spanish, German and Dutch. Together with franchised editions the magazine is on circulation in more than 50 countries. International Editor: Wisse Hettinga (w.hettinga@elektor.nl) Editor: Jan Buiting (editor@elektor.com) International editorial staff: Harry Baggen, Thijs Beckers, Eduardo Corral, Ernst Krempelsauer, Jens Nickel, Clemens Valens. Design stc Antoine Authier (Head), Ton Giesberts, Luc Lemmens, Daniel Rodrigues, Jan Visser, Christian Vossen Editorial secretariat: Hedwig Hennekens (secretariaat@elektor.nl) Graphic design / DT Giel Dols, Mart Schroijen Managing Director / Publisher: Paul Snakkers Marketing Carlo van Nistelrooy 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 6 elektor - 2/2009 CapSense Express Evaluation Kits f \ CapSense Buttons Evaluation Kit This kit contains the CY321 8-CAPEXP1 evaluation board, a retractable USB mini cable (A to mini B), a PSoC CY3240-I2 bridge board and an AA battery. Also included is the kit CD which contains your perfect guides to better switches and slider devices PsOC programmer, .NET Framework 2.0, PSoC Express 3, CapSense Express Extension Pack and the CapSense Express documentation. £27.50 • US $39.95 If ever there was a chance to get into PSoC and cap sense at a sensible price, it's right now. By special arrangement with Cypress, Elektor offers two entry-level CapSense Express development kits to enable readers to get acquainted with capacitive sensing technology in a time efficient way. Both kits represent excellent educational value for all of you wishing to eradicate, once and for all, the weaknesses and failures of mechanical switches and slider pots. CapSense Sliders Evaluation Kit Contents as CapSense Buttons Evaluation Kit, except CY321 8-CAPEXP2 evaluation board included in this kit. Art.# 080875-92 • £27.50 • US $39.95 v J Further information and ordering lektor SHOP Email: subscriptions@elektor.com Rates and terms are given on the Subscription Order Form. Head Office: Elektor International Media b.v. P.0. Box 1 1 NL-61 1 4-ZG Susteren The Netherlands Telephone: (+31 ) 46 4389444, Fax: (+31 ) 46 43701 61 Distribution: Seymour, 2 East Poultry Street, London EC1A, England Telephone:+44 207 429 4073 UK Advertising Huson International Media, Cambridge House, Gogmore Lone, Chertsey, Surrey KT1 6 9AP, England. Telephone: +44 1932 564999, Fax: +44 1932 564998 Email: p.brody@husonmedia.com Internet: www.husonmedia.com Advertising rates and terms available on request. Copyright Notice The circuits described in this magazine are for domestic use only. All drawings, photo- graphs, printed circuit board layouts, programmed integrated circuits, disks, CD-ROMs, software carriers and article texts published in our books and magazines (other than third-party advertisements) are copyright Elektor International Media b.v. and may not be reproduced or transmitted in any form or by any means, including photocopy- ing, scanning an recording, in whole or in part without prior written permission from the Publisher. Such written permission must also be obtained before any part of this publication is stored in a retrieval system of any nature. Patent protection may ex- ist in respect of circuits, devices, components etc. described in this magazine. The Publisher does not accept responsibility for failing to identify such patent(s) or other protection. The submission of designs or articles implies permission to the Publisher to alter the text and design, and to use the contents in other Elektor International Media publications and activities. The Publisher cannot guarantee to return any mate- rial submitted to them. Disclaimer Prices and descriptions of publication-related items subject to change. Errors and omissions excluded. © Elektor International Media b.v. 2009 Printed in the Netherlands 2/2009 - elektor 7 INFO & MARKET MAILBOX PLDM LED Driver — DIY and commercial Dear Editor — I noticed the December 2008 issue's LED bike lamps and clever related step-down current regulator trick: to reduce feedback votage loss — it's been filed! However with the 60 lux Busch and Muller Cyo available (and legal) with efficient optics, one might as well leave DIY LED bike lamps as extra auxiliary lamps. I discovered a "£9.74 Nite Ize L.E.D. Upgrade for C & D Cells [LRB-07-PR]" pre-focus bulb with 3-watt LED and electronics: a rectifier and cap would allow easy conversion of lamps: presumably you would need to ensure heatsin- king via a metal bulb holder connection to, for example, foil. It seems to work for 2 to 6 cells so must have a buck-boost converter. Also, LED domestic bulbs are made by a Phillips division called Lemnis, see www.lemnislighting.com/pha- rox_led_bulb.html Alan Bradley (UK) That's brilliant (pun intended ), thanks Alan for letting us know this commercial alternative. Hi from the USA The following testimonial about the early days of Elektor was received from our correspondent Ed Dell of Audio Amateur Inc., forwarding an email from Dick Campbell. "If you are of a certain age or traveled in Europe you will remember the wonderful mag- azine, "Elektor". I subscribed back when it was translated into English (from the original Dutch) in the UK and shipped to the USA. Then my finances changed and I had to drop the subscription. Later when I tried to find them again the UK publisher had disappeared. I still have the issues I bought back then and still make reference to them from time to time. Besides the great construction articles they also have very clear explana- tions of how the circuitry in the articles work. In particular their explanation of how a pseudo random noise generator works is the very best and clear- est I have ever found. I have passed that explanation onto one of the best DSP engineers around and he found it useful. "It is now available in the USA — see www.elektor.com/ USA/ for subscription info." I saw them at the AES in San Francisco and somehow did not stop and subscribe. Thanks for the reminder, I have just sent in my subscription. "This is a remarkable maga- zine for DIY or just plain inspirational projects in many areas of electronics." They also make quality bare circuit boards available at reasonable prices for their projects which makes them very easy to build. Ray A. Rayburn (USA) Wiring up (3) Dear Editor, regarding Phil Pumphrey's letter in Mailbox, October 2008, what he needs is something called a DRO (digital readout). There are many websites on the subject and many homebrew contrap- tions, including a few ones based on hacked mic even the optical ones. Just ask Google about 'homemade / home- brew dro'. Please tell Phil that I'll be happy to be of assistance; you may give him my e-mail address. Jorge L. (Spain) Thank you Jorge for your kind offer, we'll do the necessary to get you in touch with Phil. Electrobike — kit supplier Hi Jan — last November's issue had an interesting article on an electrobike retrofit con- version kit, reportedly sourced via EBay. Unfortunately I was unable to find the kit described. Can you help me, please? Herbert Polzer (Germany) The prototype was bought from Wilkotec's e-boy shop at http://stores/ebay.de.E-bikeTec which was olive and kicking at the time of publishing. Wilkotec also have their own online shop ot www.wilkotec.de. Other sup- pliers of e-bike wheels and kits may be found on ebay.com. Electrobike — need to know Dear Elektor — after reading this great article, some ques- tions remain, if I may. 1 . did you fit new spokes, reposition the front wheel or convert a children's bike? 2. Any findings on the esti- mated range? 2. How much should I expect to pay for a battery pack? Joachim Herbert (Germany) For the test we had a mountain bike ovoiloble with 26-inch wheels. However, owing to on error somewhere in the supply chain, the electrobike wheel we received was a 24-inch type (for sure, 26-inch and 28-inch versi- ons are available). Three series connected 12 V 7.2 Ah batteries represent 30 to 40 minutes worth of bike riding without any pedal assistance. However if the motor is used as a support only, a range of 40-50 kms is not exceptional, depending of course on the ter- rain and the load. A set of 12- Ah batteries almost doubles the range. For the experiment we used CSB batteries from the 'EVX' range, which ore specially designed for electric wheel powering and 8 elektor - 2/2009 cyclic charging. A 12 V 7.2 Ah battery costs about 45 €, or 60 € for a 12 Ah type. Jan Visser (Elektor labs) New Elektor videos on YouTube Recently added videos on Elek- tor's YouTube channel include the Messaging Spin Top from the December 2008 issue , and a filmed report of Elektor's Live! event held in the Netherlands on 22 November 2008. An over- view of current Elektor videos is found at www.youtube.com/elektorim where 'im stands for Internatio- nal Media. Once on the chan- nel you'll be able to watch short films on the Profiler milling machine , Microdrones , the Elek- tor SMT oven , Ball & Beam , For- mant , study trips to China and o few items from the Retronics series. New films will be added to the 'channel' os they become ovoiloble. Selecting 'videos' on YouTube and then searching for 'elektor' will return all videos somehow linked to the word 'elektor'. It should be noted that many of these videos ore unrelated to our magazine , or to electronics in general. Vinculum not secure? Dear Editor — I'd like to thank you for the article 'ATmega meets Vinculum' ( Elektor November 2008, Ed.), which should keep me busy solder- ing and programming for a few winter evenings. I was surprised however to read the notice on having to remove the USB stick when the Vinculum is switched on or off. As I see it, the Vinculum is not ready for its expected application. After all, it should be perfectly possible to switch an electronic device on or off without suf- fering data loss. I may have missed something and would be grateful for your advice. Very likely another error was present at the time the doto loss occurred. Whatever the cause , one thing to ovoid at all times is supply removal during a write process. Windows even has a special function for this: remove hardware securely. Burkhard Kainka Elektor magazine's Messaging Spin Top A Messaging i r » j A - •JW; LED Sp' M I Elektor Decerinber'ZOOS www.elektor.com Electronic Transformers Dear Elektor — as a staunch reader since issue # 1 I'd like to provide some information that's supplemental to your article 'Electronic Transformers Revealed and Explained' in the December 2008 issue. These 'transformers' are actually switch-mode power supplies or, more accurately, 'power auto oscillators' and most of them are based on application note AN528 from STmicroelectronics. Even if bipolar transistors have been replaced by MOSFETs in recent models, the principle remains the same. The applica- tion note provides a detailed operation of these supplies, and has good educational value. Interesting as that may be, if we look at the schematics in detail, it's apparent that these the load, which will benefit the life expectancy of the bulbs (effectively preventing the high inrush current when the filament is cold). It is also much more agreeable in the bathroom, particularly in the morning when harsh lights normally greet you there. Electronics enthusiasts may reap another benefit from these cheap supplies by simply rectifying and smoothing the output voltage, and so make a cheap, powerful, 0 to 15 volts adjustable supply. Be sure to observe electrical safety, as the potentiometer terminals are connected to the rectified AC mains voltage. A potentiometer with a plastic spindle must be used, prefer- ably in combination with an ABS enclosure. Alain Caillard (France) supplies may be modified to act as dimmers. The oscilla- tor is triggered by a diac using an RC network. If a potentiom- eter with value 10 R is inserted in series with R, a dimmer is created with a range close to 0 - 100 %. Sure, you have to know a bit about electronics but I would expect Elektor readers to be able to locate the resistor (if necessary, consult the appli- cation note), and lift up one of its legs. The resistor value is usually between 100 k£l and 220 k£l, depending on the model and the associated capacitor. Do not remove the resistor completely, as it will act as a protection if the pot is set to zero. In the absence of the fixed resistor, a resistance below the original value could well cause the supply to go up in smoke. An even more exciting modi- fication is to link the potenti- ometer to a switch. This setup allows a smooth switch-on of Electronic Transformer for a 12V Halogen Lamp, Fichera, P. and Scollo, R., AN528/0999, STMicroelec- tronics, 1 999. www.st.com/stonline/prod- ucts/literature/an/3707.pdf Mai I Box Terms • Publication of reader's orrespondence is at the discretion of the Editor. • Viewpoints expressed by correspondents are not necessarily those of the Editor or Publisher. • Correspondence may be translated or edited for length, clarity and style. • When replying to Mailbox correspondence, please quote Issue number. • Please send your MailBox correspondence to: editor@elektor.com or Elektor, The Editor, 1 000 Great West Road, Brentford TW8 9HH, England. 2/2009 - elektor 9 ADVERTISEMENT 3 NlikroElektronika DEVELOPMENT TOOLS I COMPILERS I BOOKS Now you need a... By Dusan Mihajlovic Do you want your new device to have a simple and intuitive interface? If the answer is YES, then a graphic LCD display with touch panel is the best choice because together they create a Touchscreen (Glcd + Touch Panel = Touchscreen). In that way, with a small number of electronic components you will be able to create an attractive and easy to use device. Mikroelektronika Hardware Department In this case, the voltage is read on the left contact of the X surface. Connecting to microcontroller What is a touch panel? A touch panel is a thin, self-adhesive transparent panel placed over the screen of a graphic LCD. It is very sensitive to pressure so that even a soft touch causes some changes on output signal. There are a few types of touch panel. The simplest one is the resistive touch panel which will be discussed here. Principle of operation A resistive touch panel consists of two transpar- ent rigid foils, forming a "sandwich" structure, that have resistive layers on their inner sides. The resistance of these layers usually does not ex- ceed 1 Kohm. The opposite sides of the foils have contacts available for use through a flat cable. The process of determining coordinates of the point in which the touch panel is pressed can be broken up into two steps. The first one is the de- termination of the X coordinate and the second one is the determination of the Y coordinate of the point. In order to determine the X coordinate, it is necessary to connect the left contact on the X surface to ground and the right contact to the power supply. This enables a voltage divider to be obtained by pressing the touch panel. The val- ue of the divider is read on the bottom contact of theY surface. Voltage can be in the range ofOVto the power supply and depends on the X coordi- nate. If the point is closer to the left contact of the X surface, the voltage will be closer to OV. In order to determine the Y coordinate, it is necessary to connect the bottom contact on the Y surface to ground, and the upper contact to power supply. Flat cable detail In order to connect a touch panel to the micro- controller it is necessary to create a circuit for touch panel control. By means of this circuit, the microcontroller connects appropriate contacts of the touch panel to ground and the power supply (as described above) in order to determine the X vcc X surface Determination of Y coordinate Figure 1. Touch panel internal structure Advertisement article of MikroElektronika www.mikroe.com mikroC® and mikroC PRO® are registered trademarks of MikroElektronika. All rights reserved. NOTE: ... 4~n*jJlc SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD WWW.mikroe.COm +5VO- -OVCC ova TOUCHSCREEN 10E 22pF, GLCD Schematic 1. Connecting Touchscreen and Y coordinates (Refer to Schematic 1 ). The bottom contact of the Y sur- face and left contact of the X surface are connected to the microcontroller's A/D converter. The X and Y coordinates are determined by measuring voltage on these contacts, respectively. The software consists of writing a menu on graphic LCD, turning the circuit for touch panel control on/off (driving touch panel) and reading the values of A/D converter which actually represent the X and Y coordinates of the point. Once the coordinates are determined, it is possible to decide what we want the microcontroller to do. For the purpose of illustration, let us examine Example 1. It explains how to turn on/off two digital microcontroller pins, connected to LED diodes A and B, using a display and a touch panel. Flat cable on-board connector before... ...and after connecting touch panel. Considering that the touch panel surface is slightly larger than the surface of the graphic LCD, in case you want greater accuracy when determining the coordinates, it is necessary to perform the software calibration of the touch panel. Functions used in the program ADC_Read() Read analog value Delay_ms() Delay Gicd_box() Draw filled box* Glcd_circle() Draw circle Glcd_Dot() Draw dot Glcd_Fill() Delete/fill display* Glcd_H_Line() Draw horizontal line Glcd_lmage() Import image Glcd_lnit() LCD display initialization* Glcd_Line() Draw line Glcd_Read_Data() Read data from LCD Glcd_Rectangle() Draw rectangle* Glcd_Set_Font() Select font* Glcd_Set_Page() Glcd_Set_Side() Glcd_Set_X() Glcd_V_line() Glcd_Write_Char() Glcd_Write_Data() Select page Select side of display Determine X coordinate Draw vertical line Write character Write data | Glcd_Write_Text() Write text* * Glcd library functions used in the program mikroC PRO for AVR® library editor with ready to use libraries such as: Ethernet, CAN, SD/MMC etc. Code for this example written for AVR® microcontrollers in C, Basic and Pascal as well as the programs written for PIC® and dsPIC® microcontrollers can be found on our web site www.mikroe.com/en/article/ Examine 1j_ Program to demonstrate touchscreen operation // Glcd module connections char GLCD_DataPort at PORTC; sbit GLCD_CS1 at P0RTD.B2; sbit GLCD_CS2 at P0RTD.B3; sbit GLCD_RS at P0RTD.B4; sbit GLCD_RW at P0RTD.B5; sbit GLCD_EN at P0RTD.B6; sbit GLCD_RST at P0RTD.B7; sbit DRIVE_A at P0RTA.B2; sbit DRIVE_B at P0RTA.B3; char GLCD_DataPort_Direction at DDRC; sbit GLCD_CS1_Direction at DDRD.B2; sbit GLCD_CS2_Direction at DDRD.B3; sbitGLCD_RS_Direction at DDRD.B4; sbit GLCD_RW_Direction atDDRD.B5; sbitGLCD_EN_Direction atDDRD.B6; sbit GLCD_RST_Direction at DDRD.B7; // End Glcd module connections sbit DRIVE_A_Direction at DDRA.B2; //Touch Panel module connections sbit DRIVE_B_Direction at DDRA.B3; // End Touch Panel module connections long x_coord, y_coord, x_coord1 28, y_coord64; // scaled x-y position unsigned int GetX() { DRIVE_A = 1; DRIVE_B = 0; Delay_ms(5); return ADC_Read(0); } unsigned int GetY() { DRIVE_A = 0; DRIVE_B = 1; Delay_ms(5); return ADC_Read(1); } //reading X // DRIVEA = 1 (LEFT drive on, RIGHT drive on, TOP drive off) // DRIVEB = 0 (BOTTOM drive off) // READ-X (BOTTOM) //reading Y // DRIVEA = 0 (LEFT drive off, RIGHT drive off, TOP drive on) // DRIVEB = 1 (BOTTOM drive on) // READ-X (LEFT) void main() { DRIVE_A_Direction = 1; DRIVE_B_Direction = 1; PORTB.BO = 0; DDRB.BO = 1; P0RTB.B1 =0; DDRB.B1 = 1; GlcdJnitO; Glcd_Fill(0); Glcd_Set_Font(font5x7, 5, 7, 32); Glcd_Fill(0); // Set DRIVE_A pin as output // Set DRIVE_B pin as output // Set PBO pin as output (Default value 0) // Set PB1 pin as output (Default value 0) // Initialize GLCD //Clear GLCD // Choose font, Glcd_Write_Text("TOUCHPANEL EXAMPLE", 10,0, 1); Glcd_Write_Text("MIKROELEKTRONIKA", 17,7,1); Glcd_Rectangle(8, 16,60,48,1); Glcd_Rectangle(68,1 6,1 20,48,1 ); Glcd_Box(1 0,1 8,58,46,1 ); Glcd_Box(70,1 8,1 18,46,1 ); Glcd_Write_Text("BUTTON 1 ",1 4,3,0); Glcd_Write_Text("PB0 OFF", 14, 4,0); Glcd_Write_Text("BUTTON2"74,3,0); Glcd_Write_Text("PB1 OFF", 74, 4,0); while (1) { x_coord = GetX(); y_coord = GetY(); x_coord 1 28 = (x_coord * 1 28) / 1 024; y_coord64 = 64 -((y_coord *64) / 1 024); //Display Buttons on GLCD: // read X-Y and convert it to 1 28x64 space //if BUTTON 1 is selected if ((x_coord1 28 >= 10) && (x_coord128 <=58) && (y_coord64 >= 18) && (y_coord64 <= 46)) { if(PORTB.B0 == 0) { PORTB.BO = 1; Glcd_Write_Text("PB0 ON ",1 4,4,0); } else { PORTB.BO = 0; Glcd_Write_Text("PB0 OFF", 1 4,4,0); } } //if BUTTON2 is selected if ((x_coord1 28 >= 70) && (x_coord1 28 <= 1 1 8) && (y_coord64 >= 1 8) && (y_coord64 <= 46)) { if(PORTB.B1 == 0) { PORTB.B1 =1; Glcd_Write_Text("PB1 ON "74,4,0); } else{ PORTB.B1 =0; Glcd_Write_Text("PB1 OFF", 74, 4,0); } } } Delay_ms(100); Atmel®, logo and combinations thereof, AVR® and others are registered trademarks or trademarks of AtmelCorporation or its subsidiaries. Other terms and product names may be trademarks of others. Saturday, February 21, 2009, from 10:00 am to 3.30 pm. Masterclass Hiqh-End Valve Amplifiers Birmingham City University, Technology Innovation Centre. Presenter: Menno van der Veen , MSc. Introducing Jeremy, the ultimate 3D 1C customer The future success of the semicon- ductor industry will depend on how successful it is in implementing 3D 1C technology to meet the demands Donabedian sees Jeremy (and the next generation of electronics con- sumers) as ready to buy a host of integrated applications that will In this Masterclass Menno van der Veen will examine the predictability and perceptibility of the specifications of valve amplifiers. Covered are models that allow the characteristics of valve amplifiers to be explored up to the limits of the audible domain from 20 Hz to 20 kHz. This then leads to the minimum stability requirements that the amplifier has to satisfy. The coupling between output valves and output transformer are also modelled. This gives new insight into a unique type of distortion: Dynamic Damping Factor Distortion (DDFD). Negative feedback is often used in amplifiers. What is the optimum and what are the audible consequences? The correct amplification of micro details is explained, based on new research, and new models about this are presented. The course fee is £ 160, including handout, certificate and lunch. Elektor subscribers are entitled to a 5% discount. Register now, seating capacity is strictly limited. Further information and registration at www.elektor.com/events April 3-1 2, 2009. Study trip: Visit China with Elektor Tour host: Margriet Debeij ( with assistance from local guides and interpreters). Elektor's third study trip to China is planned for 3-12 April 2009. And you can join us! During this 1 0-day trip we will visit the China Electronics Fair in Shenzhen, a professional industrial electronics fair with an area of no less than 60,000 m 2 . We will also pay at least one visit to the well-known 'electronics high street' in Shanghai. As the name suggests, this street is entirely dedicated to electronics shops, each vying to be the largest. In addition, a variety of interesting company visits are on the itinerary (with a tour of the production department). We are also organising a business conference where you can obtain a wealth of information about doing business (and how not to do business) in China. We put all the do's and don'ts in a tidy list for you. Naturally, there's also time for culture. We will visit the Bund, French Confession and the Shanghai TV tower. There's also a Shanghai sightseeing tour planned. As with the first and second 'Elektor goes to China' tours, this edition will again be blogged using the Elektor website. Further information at www.elektor. com/china-trip of a 17-year-old consumer named Jeremy, according to Ziptronix CEO Dan Donabedian. In a pres- entation at the fifth annual The future success of the semiconductor industry will depend on how suc- cessful it is in implementing 3D 1C technology to meet the demands of a 1 7-year-old consumer named Jer- emy, according to Ziptronix CEO Dan Donabedian. In a presenta- tion at the fifth annual 3D Architec- tures for Semiconductor Integration and Packaging conference today in Burlingame, CA, Donabedian described the role his company's revolutionary bonding technology will play in the emerging 3D 1C supply chain. According to Donabedian's presen- tation, one of the crucial elements for successful implementation of 3D 1C technology is a reliable, econom- ical, low temperature oxide bond- ing process that will enable true 3D integration of semiconductors. "A high throughput bonding proc- ess that achieves true metal-to-metal interconnect without requiring high temperature or compression has long been seen as the 'missing link' in the 3D 1C supply chain that is now taking shape in the semicon- ductor industry," he explained. "Ziptronix technology will be one of the key factors in making 3D 1C integration a mainstream semicon- ductor technology." be enabled by 3D 1C technology, including: • Mobile phones with high res- olution digital cameras and increased functionality • Ultramobile, low power, light- weight PCs • Interactive handheld gam- ing devices with projection capabilities • Embedded pico-projectors in a variety of portable multimedia devices • Advanced automotive sen- sors (lane change/collision warning) • Sophisticated medical imaging systems The Ziptronix processes can be implemented throughout the present semiconductor supply chain - by the OEMs/IDMs; by fabless and 'fab-lite' companies; by the major foundries; by semiconductor tool manufacturers and EDA vendors; and by the OSAT houses. www.ziptronix.com (080965-VIII) elektor - 2/2009 i~\ r~\ r~\ r\ r~\ A N T E X LJLJLJ LJL J Mil I30v-£( am t( 60+ years of experience If may &urpri£.£+ you but buying an A-ilfr-: soldering iron costs Iks th* n you Ihinfe in the long fun P British msde to -evading standards ihify tost significantly tender than many imported brands. With a wide range of thermally balanced modets, and temperature controlled irons too, you can always be sure to find an iron that meets your newts.. A large range of replacement tips are available for most irons, and technical help is on hand from our oh ices in UeMO n UK. Buy Online Our now website has all of our runs, and soldering spares and accessories available 2-3 hrs a day. Ntost items are shipped next day, and we offer free carriage throughout Europe. Why not give antes.co.uk a try! Antex offer a w=de choice of input voltages and bit profiles for our soldering non range i . www.antex.co.uk FREE shipping on all order? Antex Electronics Ltd 2 West bridge Industrial Estate Tavistock, Devon PLH9 8DE r UK Tel: ^ 44(0)1822 613565 fax: +44(0}1S22 61759S Email: salesdSantex.co.uk Web: www.antex.co.uk n Elektor SMT Oven ^ Multi-purpose and indispensable to professional and enthusiast Selected, tested & certified by Elektor Including Elektor-produced user manual Fully menu controlled Ideal for R&D laboratories, schools, small companies and. electronics enthusiasts Product support from Elektor Customer Services r3lektor L~ SHOP r Art. # 080663-91 • Price: £962.00 • € 1195.00 • US $1665.00 (Excl. VAT) Main technical specifications Line voltage: 230 V AC / 1 650 W Line frequency: 50-60 Hz Size: 418x372x250 mm (16. 5 x 14. 6 x 10 inch) Weight: 1 6.7 kg (net) Effective PCB area: 280 x 280 mm (11 x 1 1 inch) Further information and ordering at www.elektor.com/smtoven k 2/2009 - elektor 13 INFO & MARKET NEWS & NEW PRODUCTS Elektor USA on newsstand distribution Following a three-month introduc- tion period and the rapid growth of its subscriber base, Elektor USA is now progressing to newsstand sales, allowing 'folks' to browse a copy before buying. Starting with this February 2009 issue, the magazine is stocked by Bor- ders bookshops in selected cities in the USA. This may be followed by other store chains. Elektor USA joins the successful English, Dutch, Spanish, French, German, Italian, Portuguese and Brazilian editions centrally produ- ced by Elektor International Media, with websites to match. American and Canadian readers originally subscribed to the Euro- pean Elektor can now subscribe on-line using the specially created USA landing page, which con- tains an offer they will find hard to refuse. The expanded Elektor USA website is expected to come online around 1 February 2009. electronics worldwide wwM.eiek1ar.6Dni OCTOBER 2008 US tr.Ofr'CjradA Elektor International is coming to North America www.elektor-usa.com MontaVista: big endian support for ARM1 1 family MontaVista® Software, Inc. announced that MontaVista Linux now provides support for the ARM1 176JZ-S™ and ARM- 1 176JZF-S™ processors, including the first ever 'big endian' support option for the ARM1 1™ family in a Linux environment. By suppor- ting these ARM1 1 family proces- sors, MontaVista gives consumer device manufacturers a commer- cial-quality Linux implementation along with tools to reduce time-to- market and development costs for custom SoC designs. MontaVista provides a commercial quality Linux platform for mobile device manufacturers. Its broad hardware support, dedication to quality, and full support has made it the undisputed leader in the mobile Linux market. Its advanced power management, fast startup, and advanced connectivity provide the features mobile device manuf- actures require. In addition to pow- ering a majority of today's Linux handsets, MontaVista Linux is the only Linux to demonstrate support of and integration with all major Linux mobile software stacks, is the only mobile Linux certified as being ready for IPv6, provides sup- port for new mobile device proces- sors from Freescale® Semiconduc- tor, Intel®, Texas Instruments and others and was awarded "Best Software Innovation of the Year" for 2007 by EDN. www.mvista.com (081040-IX) BIGAVR-2 Board MikroElektronika recently introduced a new develop- ment tool for AVR® microcon- trollers. The new BIGAVR®2 supports 8, 64-pin and 100- pin AVR (TQFP package) AVR® and gives designers an easy to use platform to try a multi- tude of designs. The BIGAVR®2 comes complete with everything you need to learn, experiment, design and program with AVR®. The BIGAVR®2 includes a Touch- Panel controller, so you can eas- ily add additional input to proto- type devices. Like its predecessor, BIGAVR®2 has an ultra fast on-board USB 2.0 programmer. The new board delivers an extensive list of features, including: • TouchPanel controller • Buttons for changing states of all pins • LEDs for displaying states of all pins • Support for Character LCD • Support for Graphic LCD • JTAG connector • RS232 communication • Support for PS/2 • 4.096 Vref for ADC • Selectable USB or external power supply • MMC/SD Card Slot • I DC 1 0 connectors for further expansion • Pull up/pull down selection of each pin Every feature of the board is sup- ported by examples written in mik- roC PRO, mikroPascal and mikro- Basic compilers for AVR®. The BIGAVR®2 Board is available for purchase on the mikroelek- tronika website and through authorized distributors. www.mikroe.com (081040-V) CapSense (tm) proximity sensing achieves 25 cm detection range Cypress Semiconductor Corp. announced that its proximity detec- tion solution enables a best-in-class proximity detection range of 25 cm. Proximity sensing enables new usage models where direct touch is not required, instead detecting a finger or another object as it approaches the device. The solu- tion allows for enhanced industrial designs that only expose inter- faces or buttons when necessary and provides incremental power savings by activating an interface only when needed. To simplify use of this proximity sensing functionality, Cypress also announced a free online tutorial that shows how to develop prox- imity sensing detectors without [continued on page 16 ] 14 elektor - 2/2009 QUASAR electro nics Quasar Electronics Limited PO Box 6935, Bishops Stortford United Kingdom CM23 4WP, Tel: 0870 246 1826 Fax: 0870 460 1045 E-mail: sales@quasarelectronics.conj Web: www.QuasarElectronics.com 08717 Postage & Packing Options (Up to 0.5 3-7 Day Europe Delivery - £3.95; UK Mainland (EU) - £6.95; Rtjst of World - £ SOrder online for reduced price UK Pc We accept all major credit/debit cards to Quasar Electronics. Prices include Please visit our online shop now for projects, modules and publications. | Swiid “| DlfJtfQi * fi 8| S % n -1 ■ e a j lALtaut ■■■. 7 onm ¥ m m I .'j’nmru -j-i ui :'ji ■ ■Ai-i Mill 1 1 Multisim only handles Analog Devices components, and it's not possible to modify them or create new ones. _ ffx AVX www.avx.com AVX offers several tools for selecting its capacitors. We tried SpiCALCI 3.0, a tool for dimensioning capacitors for switch-mode power supplies. Unfortunately the pro- gram does not offer a help function so a good awareness is required of the various capacitors in the AVX product range. After selecting a capacitor type, working volt- age, dielectric, etc. the program displays the capacitor's resonance frequency and dissipation at a user selected temperature. A graph can be produced showing imped- ance response and ESR. 18 elektor - 2/2009 Epcos www.epcos.com This passive components manufacturer offers several tools, including AlCap for dimensioning aluminium elec- trolytic capacitors, and the Ferrite Magnetic Design Tool, used for evaluating Epcos magnetic materials and for performing certain calculations pertaining to induct- ances and coils. Fairchild www.fairchildsemi.com FETBench is Fairchild's online design tool, and com- prises three parts: - Device Analysis lets you evaluate a component with customized graphs; - Application Analysis is a switch-mode power sup- ply simulator; - Thermal Analysis lets you specify a board and posi- tion active components from Fairchild on it. Then the tool shows a coloured diagram with the temperature distribu- tion across the surface of the board. But there's even better from Fairchild: SPM Tool, a very fine piece of software that is not only able to simulate motor drivers, but also contains all the theory of motors in the form of interactive animations. Not to be missed! Before you can download the software, you are asked for a username and password. These are the same ones you used when you signed on. The same goes for PFC Toolkit, a tool for exploring phase correction techniques. Linear Technology www.linear.com LTSpice IV is the current name of the SPICE simulator from Linear Technology, originally launched a few years ago as SwitcherCAD, principally for simulating switch- mode power supplies. Users soon found that the tool is in fact a souped-up SPICE that lends itself perfectly to other simulations. LTSpice is fairly easy and intuitive to use. You can quickly draw a circuit diagram and simulate it equally swiftly. OK, so maybe the graphics aren't the best in the world - but this is a very powerful tool and is regularly updated. Apart from LTSpice, the site also offers FilterCAD and BodeCAD and a number of tools for evaluating certain Linear Technology components. 2/2009 - elektor 19 TECHNOLOGY CAD Maxim www.maxim-ic.com Maxim does not offer any very sophisticated online design tools, but there are twenty or so useful calcula- tors available. Some of them are dedicated to a spe- cific Maxim component, but not all of them, and there are several you may find useful. The interesting thing is that Maxim gives references and detailed explanations that let you delve into the theory applied practically in the calculator. The Power-Supply Cookbook lets you download, for each regulator in the Maxim catalogue, a PDF file containing a circuit diagram and component list for several configurations of the chip. It is also possible to download all the files in one go, in the form of a 9 MB PDF, which does save time. It's a bit like the old data- books, with loads of ideas for circuits. PRODUCTS StfU-TICWS DESIGN SU V | COr.vA-'Jv WENiSERE Tula’s. -ft.iJ Hutu:* I6t= MoJflli CiDDL Tilfii C ► !'=■ ■ ■e Jl tal^ yoft'.virc Pi/wSr-Uujip *• CtnAbRnk Wrplkfti; ifF z ’Piaamerfie; Ffoforan;e (Gc'bqr Flllji) LV KH Aircwiia CAlCUlaiark OihC'" ■= o f r v, jr'i a*-,!; tcjCi-T KMtKk-n > toci-: Mr-lr anri ■= ci ft- Yi- .-i rf > CgltiiilfftW’5 Data Conversion Calculator * M trit lt h Lritirr li I VAIA CriturSNR 6 HO Ull I'ii v Cuiiuift l | SIVAO J733 rlH JU , Coir^TV j LNOU M UiLv JO | Cqitvbi 1~| HflaiafaAlqii {Nj |Ut£ rnt.r Rncnliillcin 1-i lilts C^inven HVR HH • i in Enter tfSH plus L riHr II ILi HI] iin | 1 sum ap 00 dn -» rJM avow i. j i£t Uidl iMStrib^s tfhjr adv< L-jnw’jie" W this tulcutuloi rtiuoiv. rlerJOiel (dR) A imic of rrJfitu/n gmelrturirt dnlirsarf an .1 Ing.vfthnnin Fnlrv Fur vnlt?gft volur-i iffl i r , given Ry frr poeer. It |s I fVaijc FA/riO. Wiw rtfi if ra torn a ran tu -J t Ji'piLT tiQridl, 'l a lui inLrd ifor: ilcLivfr.iti, Je ryfiii wnCui) IS l*nW iv lOrn-^e dHn 1 ’ Fur dltn, the fold fosbuflca must be Ufowh fo» mo ApecificitDis tu dutumina the woitjgu v tiurgirt difjiVd -.ipjv flhJl if, I 1 r. 1 v in(u Ha'jJ elfuttiwL’ number gr bits lag nmuL-urL-d yui foi mu'ik U ■ i ■ b'ti-: uf ju .jn.j'rjg- lu-'Ji:jitj l'ihivvi Cv ( ADC} with lUipuct tu [Iai pi put freQuUntv ffi»). A-. kn 'TiirujFuF. uv-Hrail nnita (pam&.ilarly ihF ■Iftrr.a on cni*prn*K«) akr incr.ASPS, rhurFny fPOuRirci ih* -Non and -.INACi. i'jp Aft" Aiqfial ’ i r 'i^ pnril riitrm .-,r. mhn i/. lAACi fNCin ft , r ijA if IHb nuthbflr 6 \ dtiiiiRie lavelb LI Kit Jin« irteif ip rtspruFari 1 . Mm iipnal. Tl ryjit dficwnlaly rwiHitdlc Ll'-a jridlL'H t qndl, Lhe >.FbluLifin mini be inui«d>y.i lebalvLian i!i uiudMv dah’iuil 1,1 bit. Utiinq Coiwiei> with hKlhur 'Sibutuini •vil rtaduu-B tLib Uudi'l idtiEfi orritr. HMS Jew ruul n>edii ind-s'e (PM3), root mean square ( K'tB} "ht irfffttl'Vfi .■ iluu :r e-ffc-cti j c DC > live- tbit on nC ;igiijl p'QprC'tnnti Far 0 jnc wOwu tho W^-i v-3fua it 'i W? tha pnlV v-^ur, c U.3S-1 tinnei the paal-ls-pcal'' vjJufi SF HR Fw- Fpunrv K- dvnarvr. rargp 1 ; z .FrR 1 kiij lull -tn-riflftH mid flLktnrtimi rutin (SI \Ar>) T h-i ?■' I : , vaVip at Hi. 'ft .Avn r. lT (inpul lirm wpdvu fui jn AL>'.. nr-itmilPULUld Uutpul liind wjvl- fo' j AbL/L-AC) tu thu HmE yuui- eniie FiLiiH aT thu lui n't" lift fi^ir uC !u thO Nyqur.L (pui(uiiTicy iridLpjiifti rioiriiaruC content I t i typcjlly a-arrssad ft due bcli tloo ito re. at mfrin eqjaro (PJqS) *kJ tote hinvinrye ■diitOrtian. F.INaD • 3&e^i- ■ jve fit, ‘ riLUt ii"U Yj.L- fLn in ADf., rproneiAirtod eutpul sir-» wsvp tap a PaC} i.n thp P.M^ eaIjp aP rbs nana rt thF canuRRpr (ram DC to Nyqgisr hpq.ipnpy. f.-cI idnn nmep At nr iinri hsnfanc diFtRFner • :i 1" ' nnl . It - 1 y | ■ illy — j 1 1 ! — - 1 ! IE' d-i tivft .' 'Wi 1 r g [■ I inpftirl \qiiHift iRM'tJ, nihit - Mhifl 1 1 :■! Sign, li n, RHS] item i rttti. P.H5;, rte dto Ihecratica. r-inr-i-jm coauO r 4ib ,i roijn 1 5 c>J5aei by quontiutOn ncise error on-y qrd rciuiti direetly frfim Mio data eeayertbrs rfEglutan - (b.U^V +l.Fb>dli kpurlnus Iran elyr rwnln range {SrnRJ Tha 'Aria aP tbs PMS ujUun nr Itie -tins waup t, K {•"■put tine .vove for on At t , ree.Ons5ajr Led outpj! Hire for o LiAC } la tho P!M£? vyuo ah the- {lOak Spur abiervao in thf frc-qunnty ilamjin, Jt it typical y exprefEcd da-itali. 5FDF if nigartant ft. ccrtoft epmtngraqqtien «ip!ieqtiane (hat inquire maen^iing (ha eynomic rqags gf (he ppnvarte r I FT Pi ut frequiivy rn no RMS ualns ni tha .ap jt ■, \r putpurtj k.iv wavs Daly hanruviire wnhn Ehp Mygii'U Irrik A r a BiEibRAd in II-.U niMaklj-^rnlrKl . IP is. Lypnrnl y hx| ,-HkkH.:l n rlnnl — “Is: tHd - 7Gtng k/'jCi- + ) i + . + V 1 ;, -i V L Microchip www.microchip.com Mindi is the analogue simulator from Microchip based around (X)SPICE and developed by SIMetrix. Mindi is supplied with lots of component models - we counted around 4,500 - which makes entering the circuit very convenient. After selecting a component, you can mod- ify its parameters, which in most cases comes down to choosing one of the models provided. Another free design tool from Microchip is FilterLab2, which lets you simulate Chebychev, Butterworth, and Bes- sel type filters. In a quite user-friendly environment, you can choose your filter, and the software plots the char- acteristic curves. It also offers an implementation of the filter, based on Sallen & Key or MFB (multiple feedback) sections. Several ways of designing the filter are offered. Once you are satisfied with the theoretical performance of the filter, you have immediately available a circuit dia- gram and a SPICE model. Murata www.murata.com Five design tools are available for download from Murata, for capacitors, EMC filters, and thermistors. We tried out the Murata EMI Filter Selection Simula- tor (version 3.6.0). This tool lets you dimension EMC filters for transmission lines. Several configurations are supported and users can set the circuit parameters in detail. Once these parameters have been entered, a click on the Start Simulation button is all it takes to have access to the results in the form of diagrams. In short, a fine, easy-to-use tool. National Semiconductor www.national.com National Semiconductor has been offering its WEBENGH simulator for some years now, originally for simulating power supplies, but now the tool also helps with design- ing filters, phase-locked loops, LED drivers and even audio amplifiers. In less than ten minutes, for example, we were able to design and simulate an ADC with anti- aliasing filter. Remember to enable pop-ops, otherwise you won't see all the results of the simulations. 20 elektor - 2/2009 NXP www.nxp.com SimPort brings together the online simulators from NXP, developed, like Mindi from Microchip, by SIMetrix/SIM- PLIS. In fact, there are just two: Active Datasheet and Buck Designer. Before it is possible to use them, you need to register, just like everywhere else. Nothing so special about that, you may say - but you do need to have good eyesight! If you're not yet registered, you need to follow the link at the top right of the page which lets you choose between the two simulators. In Active Datash- eet, you can select a MOSFET from NXP and generate for yourself the curves that are usually found on a data sheet. The difference from a data sheet is that here its up to you to specify the values for which the curves are generated. Buck Designer is a tool for simulating a step-down con- verter The tool offers you a block diagram and a detailed circuit diagram, and generates diagrams where you can enlarge certain zones and measure certain parameters. 2/2009 - elektor 21 TECHNOLOGY CAD STMicroelectronics www.st.com Tools from ST, online and to download. For the online tools, an audio amplifier simulator and a switch-mode PSU simulator, you need to install the Java runtime envi- ronment (JRE) first. Then the tools will work... more or less, at least, on my test computer. On the other hand, ST Lighting Designer is a Flash tool for dimensioning fluorescent lighting that is worth going out of your way for. A designer must have spent a lot of time on the graphics interface - you'll either like it or you won't - and the tool works wonderfully well. Once you have realized that it's not possible to have a solution with all the options enabled, the tool outputs the circuit, the components list, and some graphs. You can then fine-tune loads of parameters. Cftanta si -m WSFCTa b-kvcAi x c±*. x*r nivTarwi irl Mins MOTH Ki IAJU ULrSPEI pWWTm STUMC-riOM Lrl Ca-T-Vd M n w *.ir » yn. tflr i * c J i«i < Tx wn-Ib Active Datasheet 1 1=1 Buck Designer ■ 'fad ■ tju-'iT&AJ I fCu TiaJJ r-(W“0^ni r eh «w «A#?->n«Pv4i M H>Fi cm*' rda’n r*un :r*>fc.-iHic» :'- r^- Tr' hcm wodti^iwi prun ** UTV'I r-J -nil . W F»Vr™... ri f r hiMei ■■ dw« ^ wvf ■WK p « r*» , ** 4 r'a sar m orurirt -nr-r* KiC+r iz pm imim-i p«w tost ir iik.f l?^ r.< +,mr m': u i*Mi •■toil |n^r 4 «iVir Bin mil irhii'ii m'/J f I MiUi'n *t’.i ItVtfut iruJ| WQflTEI wSw* qu drapi en« w d:HW ¥sur ntei'ci i P* srir-p DT»tHfcn tr-ri i/mr u acfrfyirtw ia r-W miK Kj Nrf- wr^ Td hfhi v’ is sent to the PC. The message ‘M2’ is sent if the maximum collector or drain current is reached with a very low value of I B or U GS , which can occur with a shorted transistor. This message is also sent if too many curves are set with the “K” command. After the base current or gate-source voltage corresponding to the maximum collector or drain current has been calculated, the delta (incre- ment value) is calculated from the base current and the number of curves to be measured (delta = J B( ma x) divided by number of curves). The previously mentioned error message is also sent if the increment is zero. The actual measuring process begins if no error has been detected. For each value of I B or U GS , the collector-emit- ter or drain-source voltage is swept from 0 to 10 V while the associated col- lector or drain current is measured. The results are sent to the PC in the follow- ing format: P < curve_no. >,< IB >,< Range > N, curve_no.: the number of the curve presently being measured; IB: xbase current or gate-source volt- age (0-10 V); Range: base current range; 0 = 10 fjA , 1 = 100 /JA, 2 = 1 mA; 28 elektor - 2/2009 Table 3: Commands. Command letter Parameter Meaning Response from curve tracer module A - Query l D of curve tracer module Note 1) B 0 - 255 Pulse width for l B or U GS ; range 0-1 0 V — C 0 - 255 Pulse width for U CE or U DS ; range 0-1 0 V — D 0 = 1 0 pA 1 = 1 00 pA 2 = 1 mA Base current range — E 0 = Positive 1 = Negative Polarity of l B or U GS — F 0 = Positive 1 = Negative Polarity of U CE or U DS — G — Query current value of U CE or U DS GO - 1024 Voltage [V] = parameter value divided by 100 H — Query current value of l c or l D HO - 1024 Current [mA] = parameter value divided by 2 1 0-1024 Maximum collector or drain current Current [mA] = parameter value divided by 2 — J 1 = NPN 2 = PNP 3 = N-MOSFET 4 = P-MOSFET 5 = N-JFET 6 = P-JFET Transistor type setting — K 0 -10 Number of curves (see text) — L — Start curve measurement See text 1 ) The curve tracer module responds by sending its ID code: A + Curve Tracer VX.X + ' (X.X = current version number). After this, the curve tracer module sends the current settings of the following configuration parameters: - Maximum collector current (default = 100 mA) - Transistor type (default = NPN) - Number of curves (default = 5) Wo dhxci UCE: collector-emitter voltage; range 0-1024 (0-10.24 V); IC: collector or drain current; range 0- 1024 (0-512 mA). The base current is calculated as follows: Range = 10 juA: base current = IB x 0.025 I/UA]; Range = 100 jliA: base cur- rent = (IB - 14) -5- 2.3 [JUA] if IB > 14; otherwise base cur- rent = 0; Range = 1 mA: base current = (IB - 16) - 2.6 x 10 [ji/A] if IB > 16; otherwise base cur- rent = 0. After all the values have been transferred, the curve tracer module sends ‘0 ’ to the PC, which can then process the data and display the curves. Downloading the firmware The Renesas High-perform- ance Embedded Workshop generates a Motorola (!) hex file (Curve_Tracer.mot), which can be downloaded via the USB interface with the aid of the Flash Development Toolkit [3]. To enable downloading, fit jumper JP1 on the microcontroller board and press the Reset button. After the firmware has been downloaded, remove the jumper and press the Reset button again. Application program Trtmitlor curve tracer VI.? ft* (yrt nrk> T] (Twin'eruHk' fScS4?f w tn a? 03 04 as 07 CB IN 10 UC5(V] M« cnlretm ruienr |nA] Ciort recoidng S«re et tetaence Tiarmtw M* fS NPN r PNP r nmosht r pmosfet r NJFET r pjfet Status: connected to Curve Tracer VI .1 Figure 4. Example characteristic curve chart. The application program provides the user interface for the curve tracer mod- ule and is written in Visual Basic 6.0. All program components were pack- aged using the VB6 Packaging Wizard. They can be installed in any desired folder by running the Setup.exe pro- gram. The application pro- gram can run under Win- dows 2000, XR and Vista. All DLL files and ActiveX compo- nents are registered during installation, except for the Prolific driver for the USB to serial converter. This driver must be installed by running PL -2303 Driver Installer.exe. The Curve_Tracer.exe pro- gram can be started after the curve tracer module is connected to a USB port of the PC. Functions The window shown in Fig- ure 4 appears after the pro- gram starts up and estab- lishes a connection to the 2/2009 - elektor 29 Figure 5. Layout of the microcontroller PCB. Figure 6. Layout of the main PCB. COMPONENT LIST Controller board # 080068-2 Resistors R1 = 1 kQ5, SMD 0603 R2,R3 = 270 ., SMD 0603 R4,R1 0,R1 1 ,R1 4-R28 = 470^ SMD 0603 R5 / R6 / R7 = 220kf2, SMD 0603 R8,R9,R1 2 / R29 / R30 / R31 = 4kf27, SMD 0603 R13 = IkQ, SMD 0603 Capacitors Cl ,C2,C4,C8,C9,C1 1 ,C 1 3 = lOOnF, SMD 0603 C3,C1 2 = 22 pF, SMD 0603 C5,C6 = lOpF, SMD 0603 C7,C 1 0 = 1 OyL/F 25V, SMD case A Semiconductors D1 = LL4148 D2 = LED, 3mm, low-current IC1 = PL2303X curve tracer module. The follow- ing functions are available in this window: • Recording the characteristic curves of NPN and PNP transistors, N-chan- nel and P-channel MOSFETs, and N- channel and P-channel JFETs. • Exporting curve data to Excel and importing curve data from Excel. • Checking transistor matching. • Printing curve charts or embedding them in other applications. The program has an extensive Help function, so the operation of the pro- gram is not described in detail here. Construction As can be seen from the schematic diagrams, the hardware is divided between two PCBs. The small micro- controller board (Figure 5) holds the R8C/13 and the PL2303, along with the associated components (Figure 2a). The main board (Figure 6) contains the rest of the hardware (Figure 2b), including the transformer. All of the components on the microcon- troller board are SMDs, so a reasonable amount of soldering experience is nec- essary for assembly. The main board is more roomy, and all of the components have leads or pins. The two 12-V volt- age regulators, as well as power tran- sistors T3 and T4, are fitted with heat sinks. Here you must take care that the heat sinks of the two transistors do not 30 elektor - 2/2009 IC2 = R5F21134FP (R8C/13) Miscellaneous K2 = USB-B socket K1 = 20-way (2x10) DIL pinheader SI = pushbutton, 6mm, SMD XI = 20 MHz quartz crystal, SMD X2 = 1 2 MHz quartz crystal, SMD JP1 = 2-way SIL pinheader with jumper FI = 100 mA Polyfuse COMPONENT LIST Main board # 080068-1 Resistors R1 -R1 8,R24-R33,R37,R38,R41 - R45,R48,R51,R52,R53 = lOkD R19,R20,R22 = 4kQ7 R21 = 931 kQ R23 = 88kf27 R34,R35 = 1Q5 R36 = 100D R39,R40,R46,R47 = 20kD R49 = IQ 1W R50 = 90kf29 Capacitors Cl ,C2 = 2200jL/F 35V radial C3-C6,C1 1 ,C1 2,C1 4-C1 7, Cl 9-C35 = lOOnF, lead pitch 2.5mm C7-C10 = 10jL/F 25V radial Cl 3, Cl 8 = 47nF, lead pitch 2.5mm C36,C37 = 22nF, lead pitch 2.5mm Semiconductors D1-D4,D6,D7 = 1N4148 D5,D8 = 5.6 V 500 mW zener diode D9-D12 = LED, low-current, 3 mm B1 = VM1 8, bridge rectifier 1 A / 1 00 V, DIP4 T1,T2 = BC547A T3 = BD139 T4 = BD140 IC1 = 7812 IC2 = 7815 IC3 = 7915 IC4 = 7912 IC5,IC6,IC8,IC1 1 ,IC1 2 = TL082P IC7,IC9 = DG441DJ IC10, IC13 = TL081P Miscellaneous K1 = 20-way DIL socket K2 = 3-way PCB terminal block, lead pitch 2.5mm FI =100 mAT (slow) glass fuse, with holder TR1 = mains transformer, secondary 2x 1 5V / 1 4VA 4 heatsinks type FK218/SA32 (21 K/W) Microcontroller and PC Software: free download 080068-11.zip at [3]. PCBs 080068-1 and 080068-2, avail- able from the Elektor Shop. Controller board also with components fit- ted, Elektor Shop # 080068-91 . touch. It’s a good idea to use a piece of insulating material here. The microcontroller board plugs into a 20-pin DIL socket on the main board. The assembled board set can be fitted in a suitable enclosure, such as the Bopla type E450 FVL. Various types of transistor sockets can be fitted to the enclosure to provide connections for the transistors, although a set of three short leads terminated in alliga- tor clips is also a workable solution. ( 080068 - 1 ) Internet Links [1] www.elektor. com/0501 79-2 [2] www.elektor.com/0501 79-3 [3] www.elektor.com/080068 [4] www.elektor.com/forum, go to R8C topic. Advertisement Design a irci www.12PCB.com Email: sales@eipcb.com We add value to PCBs when others just sell it. Prototype Production! eicjasuf£ttes(gnmg Vttftffll - C uua uJi :fjjj Compancn? 2/2009 - elektor 31 MICROCONTROLLERS Microcontrollers fo ... Arduino (or the enlightened Clemens Valens (Elektor France Editorial) Apparently Arduino is an Italian name - but when you search on the Internet, you mainly find dozens of references relating to electronics and programming. What's more, these references are often in relation to art. Electronics and art - now there's an interesting subject that's worth delving into! So just what exactly is Arduino? At first sight, Arduino [1] is a small microcontroller board with a USB port (Figure 1) that comes in several models. There are even 'daisy'-shaped boards (Lilypads) intended for wearable applications, i.e. to be incorporated into gar- ments. The Arduino board is programmed in a language very similar to C using Open Source tools available for Windows, Mac, and Linux. The hardware is also Open and anyone can make their own Arduino - the circuit diagrams and PCB photo masks are available free over the Internet. Arduinos are used a great deal by artists who need elec- tronics in their creations. Figure 1. A Diecimila Arduino board. The new Duemilanove board is almost identical. These boards are cheap and easy to find. When you look at it a bit more closely, an Arduino is not exactly a microcontroller board. In fact, an Arduino is quite simply an 8-bit microcontroller from Atmel - an ATmega8 for the earliest Arduinos and now more likely to be an ATmegal68. This microcontroller is loaded with a 'boot- loader' program that lets you load an application into the controller via a serial port, without overwriting the boot- loader. Since modern computers no longer have serial ports, a USB port is often used. All this becomes an Arduino when you decide to dedicate certain pins of the controller to certain functions, since this allows the Arduino develop- ment environment to be used for writing and compiling application before loading them onto the controller. The applications, called 'sketches', are written in a lan- guage that closely resembles C. Hardly surprising - it is C, but with some additional functions. All of the functions presented as the language for Arduino form a Hardware Abstraction Layer that lets you program the controller with- out needing to delve into the innards of the processor. The language has everything you need for most applications. Broadly speaking, there are functions for digital and ana- logue inputs/outputs, a few basic mathematical functions, time management functions (delays) and a few function for serial port communication - asynchronous (UART) and syn- chronous (SPI). The digital I/O functions let you manipulate the logic levels of the pins, to read and write them. There is also a special function that makes it possible to measure the duration of a pulse. Using the analogue I/O functions, it is possible to read voltages and generate PWM signals. Lots of appli- cations don't require anything more than this, and this is exactly where Arduino's strength lies. There's no need to go ferreting around in the registers and the controller data sheet to make a PWM output or a counter work — the 'dirty work' has already been done. If these functions aren't enough, it's perfectly possible to pro- gram on a lower level and, just as in standard C, you can also add libraries with their own functions. But do watch out - if you go off into the darker depths of the Arduino programming language, you risk losing compatibility with the rest of Arduino community. The Arduino community? Already, Arduino is a microcon- troller, as well as a development environment and a pro- gramming language - now it's a community too? Yes! In fact, Arduino is more of a philosophy, the aim of which is to popularize technology to make it accessible to artists. Arduino is a logical sequel to Processing [2] and Wiring [3] projects. Processing is a multimedia programming language and Wiring is a development environment for artistic elec- tronics But now we're starting to get away from our original 32 elektor - 2/2009 point; refer to the box about the origins of Arduino if you want to find out more. the name Freeduino for home-made Arduino boards. But after all, it's only a name, so let's call ours Elektorino. Elektorino Simple, free programming is something we're interested in. What's more, the electronics involved seem to be simple - so what could be more logical than to produce our own Arduino-compatible system? Well, that's just what we're going to do! Our starting point is the basic Arduino Serial board. The office computer I use all the time still has a serial port, but for the unlucky owners of a computer that doesn't, we're going to use the USB-TTL cable [4]. In any event, we're going to be needing a TTL interface of some kind, as our own Arduino will only have a TTL serial port. Our processor is going to be an ATmegal 68, which we'll be running at 16 MHz, to avoid getting caught out. For even though the controller is perfectly capable of operat- ing at up to 20 MHz, the standard bootloader assumes a speed of 1 6 MHz. This can of course be modified if you are prepared to go delving into the bootloader - but for the moment we just want an Arduino board that works. To finish off our Arduino, all we need do is add an LED, a reset push-button, a few resistors and capacitors, and two connectors: one for the serial port and the other for pro- gramming the bootloader. We need the latter to be able to program our Arduino for the first time, when the controller is still blank. Later, when the application is finished and the bootloader is no longer needed, this connector can be used for programming the controller directly from the application, which saves memory. The LED has several functions. Given that the LED is present on several types of Arduino, lots of sketches use it. So does the bootloader, which flashes it at start-up. Here's the circuit diagram of our finished Arduino (Fig- ure 2). Thanks to the simplicity of the circuit, we can build it on prototyping board. Unfortunately, we are not allowed to call our fine project Arduino - only boards approved by the Arduino community have the right to that name. This is why a second move- ment Freeduino [5] was created, which allows free use of Implementation Before you can load a sketch into the Elektorino, you need to load the bootloader. This is where things get more com- plicated, as there are two official Arduino bootloaders, the only apparent difference between them being the way the sketch is run after loading. This is achieved by way of a controller reset, which the Arduino environment can handle if the board has been equipped for it, and if it has the right J2 +5V +5V Figure 2. The circuit of the Elektorino. Not at all complicated. The connectors for the pins are not necessary, they are mainly used as a reference. 2/2009 - elektor 33 MICROCONTROLLERS |T~| Arduino - 001 2 Alpha BO x 1 r4e rdt sketch Tocte 1 lelp i ©© uasiiaiog | uiul'jr. 0 A will art vp 1 1 i ft JuL'ifi lJae -.i'j LjjuLh . p’_ nli’ r!r | Eifit.n y I , INN ", TI'J i diuLtoJ.Sfi.iLc [ l J. j ; P’.tiKc dc I uoLa-Ei , Qtfmrri i ■Jujif. aJ.yrl.te [adtdcZj LUUfc; // Tail ninLI ar rJtr arrant jmrr.. Serial. begin (9£00| ; Si fElElt; SMfcE Chine. i b. 1 . print in | " Areulno »otot Cadrc-p ; t'l VciL I'Ji Lite ULiui'j Lu lie seni. rlr I r.Y ( ] nh |. ; Lhjid 1 iJ'JF 1 1 r { Si lie cuot initialise these variable unieis they iav J;? i/ LC-iciiLLBliBcil eatery Liifl iuij.O is L-alled. ant. prrfir; jjjL val; < > Figure 3. The Arduino development environment. bootloader. We haven't made any provision for this, and so we need the basic bootloader for the so-called NG (New Generation) boards. But there is also another option: a third bootloader called ADABOOT [6]. This bootloader, an improved version of the official bootoaders, handles the reset and run delays differ- ently. Initially, I worked for a bit with the NG bootloader, before replacing it with ADABOOT. Both worked perfectly well, but in the end I adopted ADABOOT, because it flashes the LED while the sketch is loading and because it is more convenient. See the box to find out how to load the bootloader into the controller. Hello world! Once you have succeeded in loading the bootloader, it's time to see if Elektorino manages to communicate with the Arduino environment and if it is possible to load a sketch. So let's install Arduino. I've only done it under Windows XP, and that was extremely easy. All I had to do was down- load a large zipped file and unzip it somewhere onto the hard drive. After running the Arduino environment (arduino.exe), you find yourself with a window like the one shown in Fig- ure 3. Go into the Tools menu, then Board, and select the Arduino board being used. Of course, our one isn't listed, but an NG board using an ATmega 1 68 will do. You also have to select the serial port to be used for pro- gramming the microcontroller. Go into the Tools menu, then Serial port and select the correct port. If you want to use a USB serial port, check first that the drivers are present. The Arduino environment comes with a small sketch, Blink, for checking that the board is working, and we can use this, since we have fitted the LED. The procedure is simple: - Load the sketch; it's in File > Sketchbook > Examples > Digital > Blink. - Compile the sketch by clicking the Verify/Compile button; this only takes a few seconds and (usually) ends with a suc- cess message. - Load the sketch into Elektorino; first press the Reset button briefly, then click Upload to set the program loading. If all is well and if you are using ADABOOT, after a short delay you'll see the LED start to flash randomly — this is normal, it shows the transfer is taking place. After around five sec- onds (depending on the size of the sketch), the program is loaded and the controller is rebooted (the exact way in which the program is run depends on the bootloader). If the LED now flashes at a frequency of 1 Hz, everything has gone alright. Elektorino is working! If nothing happens, try resetting Elektorino. Loading the bootloader... ...is not as hard as all that, as long as you have all the information you need. To save you hours on the Net, we've summed it up for you here in a few lines. First of all, you need a programmer. There are several possibilities, for example, the one published in the 2008 double issue [7], or another 'SK200 compatible' programmer, easy to build using the circuit available on the PonyProg website [8]. On the Arduino website [1 ] yet another parallel port programmer is mentioned which is very simple and can be used directly from the Arduino en- vironment. I tried it out, and managed to scramble one controller with it... so I went back to an SK200 one I already had. Next, choose your bootloader. I recommend ADABOOT [6], but the NG version available on the Arduino website works perfectly well too. Loading the bootloader into the controller can be done, for example, using AVRDUDE [9], supplied with the Arduino environ- ment. AVRDUDE is a typical UNIX tool - it's basically a FreeBSD tool - with lots of incomprehensible options. Because it's very easy to make a mistake, here are the commands that work well (copy the bootloader into the directory that contains the AVRDUDE executable): avrdude -p ml68 -c pony-stk200 -V -e -U lock:w: 0x3F:m -U hfuse : w: OxDF :m -U lfuse : w: OxFF :m -U efuse : w: 0x0 :m avrdude -p ml68 -c pony-stk200 -V -D -U f lash : w : ATmegaBOOT_168_ng . hex avrdude -p ml68 -c pony-stk200 -V -U lock: w: 0x0F:m If you use another programmer, replace pony-stk200 with the appropriate value. Also check the name of your bootloader. There are three commands that, broadly speaking, unlock the memory, load the program, set the fuses, and finally lock the me- mory. Refer to the AVRDUDE instructions if you want to know exactly what is going on (sensitive souls are advised to refrain!). Loc- king the memory is used to avoid overwriting the bootloader accidentally when loading a sketch. A good website about the AVR is called Lady Ada [10]. 34 elektor - 2/2009 A real application It's all very well to have an Arduino development environ- ment that works wonderfully well, but without a real appli- cation, it's not very interesting. I already had ten motorized slider pots, and it was high time to put them to good use. Why not with Elektorino? Elektorino has analogue inputs and PWM outputs — everything we need to drive a motor. So I'm going to suggest a driver for motorized faders. Note that this circuit can be used with any ATmegal 68-based Arduino board. The fader in question (Figure 4) consists of a slider pot, a small motor, and an assembly of a few rollers, springs, and a piece of cord that enables the motor to move the slider in both directions. This assembly allows the motor to freewheel when the slider is unable to move - at each end of its travel, for example. Apart from the 10K B marked on the fader, I didn't have any technical data on it, but a few experiments showed that the motor turned at a suitable speed when powered from 1 2 V. In this case, its consump- tion was around 200 mA. The B marked on the fader might lead us to think it's a log model (as is often the case), but after checking, my faders turned out to be linear ones. As a motor driver, I chose a cleverly-modified double H bridge with just two control lines and three states: anti- clockwise, clockwise, and braking - just what we need (Figure 5). Usually, two controls allow four states, but in this circuit, states 00 and 1 1 are the same. A 5 V regulator has been slipped into the circuit so as to be able to power the whole controller assembly and motor from 1 2 V. The transistor are all NPN types, and those forming the bridge must be capable of carrying 200 mA happily. In my proto- type, I used BD1 39s. The potentiometer is wired as a simple potential divider. By measuring the voltage on the wiper, we know where it is (just so long as it's a linear pot). The motor driver controls must be connected to digital out- puts capable of supplying a PWM signal. An Arduino based around an ATmegal 68 has six, an ATmega8 only three. The pot wiper itself can be connected to any of the analogue inputs - in our case, inO. The sketch Now that we have connected a motor driver to Elektorino (Figure 6), it's time to deal with the software. You'll see, the final sketch will be amazingly simple, thanks to the power of the Arduino. A basic sketch consists of two functions: setup/) and loop/), which are called by the layer of a lower level. In setup, called once at runtime, we put everything that relates to ini- tializing the system - for example, the inputs/outputs and the serial port speed. 99.9% of embedded programs probably spend their whole lives in a loop. This is why in Arduino this loop is already implemented in the form of the loop function. This loop function is called periodically and may be regarded as Arduino's main. It's important to realize that, even though it looks like a special function, loop is just like any other function in C. So its local variables are reset each time it is called and variables that are required to keep their values between different occasions loop is called must be declared globally (or as static, for those familiar with C.) The setup in our sketch doesn't contain anything very much. The Arduino pins are inputs by default, so only the two outputs need to be initialized. We're going to be using the Figure 4. A motorized fader of unknown make. IC2 +12V ©- 7805 0 t C4 in 25V +5V -© C5 lOOn INO | R 2 m 3 I CM CM I I C I I CM CM I PIN9 R1 +12V 1 R6 R5 © af,^, X @ D1 BD139 -© 1N4001 T2 Ml 1>— |^k6_J- hS BC547T BD139 D3 D6 ■ 2x ■ k 1N4001 A BD139 D4 1N4001 T5 BD139 <3T <2Ht BC547 PIN10 \ 5k6 K l 080931 -12 Figure 5. The modified double H bridge and its three states. The labels refer to the pin designations, not the terminals on the controller. Figure 6. The Elektorino prototype: the ATmegal 68 is on the left and the double H bridge to drive the motor on the right. serial port to drive our circuit, and for this it needs to be initialized. Thanks to the simplification offered by Arduino, all we have to do is enter the communication speed - in our case, 9,600 baud. 2/2009 - elektor 35 MICROCONTROLLERS Processing, Wiring, and Arduino Processing [2] is a language and an Open Source programming environment for programming images, animations, and inter- actions. The project, an initiative from Ben Fry and Casey Reas, is based on ideas developed by the Aesthetics and Computation Group of the MIT Media Lab. Processing was created in order to teach the fundamentals of programming in a visual context and to serve as a sketchbook or professional software production tool. Processing runs under GNU/Linux, Mac OS X, and Windows. Several books have already been written on Processing. Just like Arduino, Wiring [3] is a programming environment with microcontroller board for exploring electronic arts, teaching pro- gramming, and quick prototyping. Wiring, programmed in Processing, is an initiative by Hernando Barragan and was designed at the Interaction Design Institute Ivrea (IDII) in Italy. Arduino [1] is a fast, Open Source electronic prototyping platform. Arduino is aimed at artists, stylists, enthusiasts, and anyo- ne interested in creating objects or interactive environments. Created by Massimo Banzi, Gianluca Martino, David Cuartielles, and David Mellis, Arduino uses a programming language based on 'Processing'. Arduino may be regarded as a simplification of 'Wiring'. Moving the pot wiper is done in loop. The principle is very simple: if the voltage measured on the input pin is different from the voltage required, the slider must be moved in the direction which will reduce this difference. In real life, it's a bit more complicated than that. To start with, there's the The STK200 compatible programmer used by the author. There are also simpler programmers - it's a matter of personal preference. D8 problem of direction, but more significant still is the problem of inertia. Once the slider is moving, it takes a little time for it to come to a complete halt. So it's easy to overshoot the required position if braking occurs too late. In the event of an overshoot, the slider has to be brought back, with the same risk of overshooting again, and so on. The system may even begin to oscillate. To avoid these problems, we have used a Proportional Dif- ferential (P-D) regulator. In this type of regulator, the system reaches its final value without overshoot by continuously adjusting the correction signal according to the difference remaining to be corrected. So at the start of an adjustment, when the error is greatest, a strong correction signal is applied. Then, once the difference starts to reduce, the cor- rection signal reduces too and the system slows down. The correction signal consists of two parts: a signal propor- tional to the error (P) and a signal proportional to the error reduction (D). With a properly adjusted system of this sort, the slider can be moved quickly without overshooting the target value. In the sketch (Listing 1) we can see the P-D regulator in the loop function. First, we measure the voltage at the wiper. The target value is subtracted from the measured value to obtain the error to be corrected. From this value, we calcu- late the two components P and D of the correction signal. The P component is the error multiplied by the constant K p ; the D component is obtained by multiplying the difference between the current value and the previous error by the con- stant /C d . The values for these constants were determined by experimentation, and you can modify them to see how the affect the adjustment. It's highly instructive. The two components P and D are combined and the result is adapted to the range of usable values. The pot slider doesn't move for values below 50, and the maximum value for the PWM signal is 255. Then we look to see if the error is small enough for us to be able to stop the motor. This comparison has to be performed for both slider directions. We leave a small margin for error, since perfection is perhaps a little over-ambitious. When the error is small enough, we prevent further correc- tions so as to free up the slider; we make the assumption that the system is never going to overshoot the target value. AVR ISP via USB If you use the FT232R chip as a USB interface and if you have access to all its pins, it is possible to use this chip to load the boot- loader into the microcontroller without even needing a special ISP programmer! The FT232R chip has a bus called a CBUS with a bit function that lets you manipulate the associated pins individually. A certain Mr Suz from Japan has written a small piece of software that exploits this possibility and which can be downloaded free. Its avrdude-serjtag tool only works under Windows and its website is unfortunately in Japanese (suz-avr.sblo.jp/article/4438871 .html). However, on his site one of his compatriots kindly explains in detail in English howto program an Arduino using this tool. See reference [1 1] for details. 36 elektor - 2/2009 In this way, it's possible to move the slider manually, with- out the system's trying to move it back into place. (Who's the strongest?) Once the slider has been released, the system starts to out- put the slider position periodically (10 Hz) via the serial port. The serial port input is also scanned and as soon as four characters have been received, they are transferred as a target value for the slider and the PD regulator is re-acti- vated to move it to its new position. No format checking is performed for the value received, the system requires an ASCII four-digit value between 0000 and 1023. To mini- mize errors, the target value obtained is limited between 3 and 1020, which minimizes problems of continuous activa- tion at the ends of the travel. The serial port is not used while the motor is operating, as this might produce interference, resulting in inaccurate posi- tions or even oscillation. I've not taken the trouble to find out why: I'll leave that for you to do! ( 080931 - 1 ) References and Resources [1 ] http://arduino.cc [2] www.processing.org [3] http://wiring.org.co [4] www.elektor.fr/usb-ttl [5] www.freeduino.org [6] http://nearspacevermont.org/TheShoppe/freeduino/ADA- BOOT.shtml [7] SimpleProg - ISP for AVR, Elektor, July/August 2008 [8] www.lancos.com/prog.html [9] www.bsdhome.com/avrdude [10] www.ladyada.net/learn/avr/index.html [11] www. geocities. jp/arduino_diecimila/bootloader/index_en.html Getting Started with Arduino, Banzi, Massimo, O'Reilly, 2008 Making Things Talk, Igoe, Tom, O'Reilly, 2007 The Duemilanove Arduino board is available from several sour- ces including FunGizmos (US), LittleBird (Australia), SKPang (UK), Tinker (Italy), Make Magazine (Makershed.com). Listing 1 “ Easy-peasy! void loopO { int error; int val ; int spd ; float spd_p, spd_d; // read wiper voltage, val = analogRead ( slider) ; // Calculate error, error = val - target; // Calculate proportional component P. // Two directions - so use absolute value. spd_p = abs (error ) *Kp ; // Calculate differential component D. spd_d = ( last_error-error ) *Kd; last_error = error; // Now mix P and D. spd = int ( spd_p+spd_d) ; //Do not exceed limits, spd = constrain ( spd, 0 , 255 ) ; // Compensate friction, if (spd<50) spd += 50; if (error<-l && stop==0) { // To maximum value ("left") . digitalWrite (motor2 , LOW) ; analogWrite (motorl, spd) ; } else if (error>l && stop==0) { // To minimum value ("right") . digitalWrite (motorl , LOW) ; analogWrite (motor2 , spd) ; } else { / / Shut down motor digitalWrite (motorl , LOW) ; digitalWrite (motor2 , LOW) ; stop = 1; // Transmit cursor position. Serial . println (val ) ; de 1 ay ( 1 0 0 ) ; // 4 characters form a new target value, if (Serial . available () >=4 ) { target = Serial . read ( ) - 'O'; // Thousand. target = Serial . read ( ) - 'O' + target *10; // Hundred. target = Serial . read ( ) - v 0' + target*10; // Ten. target = Serial . read ( ) - 'O' + target *10; // One. constrain (target , 1 , 1022 ) ; / / Start motor stop = 0; } } } 2/2009 - elektor 37 TECHNOLOGY SATELLITE TV Marc Neujahr (Germany) Direct reception of satellite broadcasts is still not a reality — we need to fit a dish and receiver before viewing can begin. However, with the help of a little hardware it is now possible to supply programmes to over 100 subscribers using just one dish. Another novel system allows eight receivers to view different programmes over a single coax cable! It was back in the mid 1 990's that domestic reception of satellite TV programmes first became economically viable. The satellite signal path is line-of-sight and highly directional so it does not suffer so much from the obstacles to propagation that sometimes afflict terrestrial TV broadcasts. The picture and sound quality were a revelation at the time but some of the limitations of this type of reception also became apparent: How could you record one programme while watching another? How could a second TV be added to the system? How could programmes be distributed to many users in apartments without producing an unsightly forest of dishes? The technology is a little more mature now and many sys- tems have since been developed which directly address these problems. A typical domestic installation consists of a dish pointed at the satellite of interest with an LNB (see Glossary at the end of the article) fitted at the dish focus sending a frequency down-converted band of signals to a receiver (tuner). Adjacent channels are transmitted with alternate polarisation to help reduce interference. This set up effec- tively produces a horizontal and vertical receive band of frequencies, the basic LNB cannot receive both bands simultaneously so switching between vertically or horizon- tally polarised signals is achieved by changing the supply voltage from the receiver to the LNB from 14 to 1 8-V. When the satellite bandwidth (10.7 to 1 1 .7-GHz) was increased with the introduction of the high band (1 1 .7 to 1 2. 7-GHz) the number of satellite receive bands went up to four: (horizontal Low-Band, vertical Low-Band, horizon- tal High-Band, vertical High-Band). The high band is used almost exclusively for digital transmissions and is often referred to as the digital band but this is not strictly correct. The receiver superimposes a 22-kHz signal on the LNB coax to make it switch from low to high band reception. Using the basic LNB only one of the bands can be down- converted (to prevent unacceptable losses in the coax) and sent to the tuner at any one time so a single coax cable is required between each LNB and receiver. Band selection takes place inside the LNB or in more complex systems in a Multiswitch unit. Switched LNBs and Multiswitch units One solution to the problem of using two TVs in the sys- tem is to fit a second complete system so that both receiv- 38 elektor - 2/2009 Illustration: courtesy GTN GmbH ers work independently. More recent advances in design have produced LNBs with multiple outputs, these are sup- plied with single, twin (known as a 'twin output'), quad or octal outputs supplying signals for one, two four or eight set-top tuners. Each tuner can independently select its own band from the LNB by putting the appropriate control voltage on its coax. This system requires a single coax for each tuner so up to eight cables are run from the LNB to wall mounted satellite signal outlets. The term 'uni' when applied to an LNB indicates that it can receive all four bands transmitted by the satellite. This type of installation gives several users independent control over programmes transmitted by one satellite but when more than eight subscribers want to select programmes from more than one satellite and also incor- porate terrestrial/cable TV feeds it is necessary to install a Multiswitch unit. This is used with a special Quattro LNB which does not need to be switched between bands and simply outputs the four satellite bands simultaneously to the Multiswitch via four lengths of coax. The Quattro LNB is not to be confused with the quad LNB mentioned above. Conventional 'uni' LNBs can also be used here and in this case the Multiswitch fixes the receive band Figure 1. The ECS 1708 from GTN GmbH Is a cascadeable Multiswitch capable of distributing 16 satellite bands (plus a terrestrial TV input) to eight subscribers. for each LNB by generating the necessary tone and/or voltage level. The Multiswitch unit now has access to the complete satellite signal spectrum so it can switch any selected channel through to any of the 1 6 user outputs. Sometimes when a Multiswitch installation cannot receive all programmes the problem can be traced back to a fault in the control signals to the LNBs. Looking for something bigger? Conventional Multiswitch installations are suitable for up to 1 6 subscribers and some of the larger units provide inputs for up to 16 bands which allow four Quattro LNBs to be fitted to the same dish, each focussed on different satellites. This type of installation provides a large num- ber of transponders from a single dish and should help to reduce the urban 'dish clutter' often seen in inner cities. Figure 2. Visual inspection of an SMD populated Multiswitch PCB. (photo: GTN GmbH). 2/2009 - elektor 39 TECHNOLOGY SATELLITE TV Figure 3. Cascaded Multiswitches distribute the signals from four satellites (16 satellite bands plus 1 terrestrial) to more than 1 00 subscribers on the left and right of the diagram while input bands are bussed through to the next cascaded Multiswitch unit. Figure 4. The Unicable system employs channel routing: The Unicable LNB takes the programme of interest from the satellite signal and converts it to a specific satellite IF which will only be detected by the requesting receiver. Programmes for up to eight receivers can be routed onto the same coax, (illustration: STMicroelectronics) More recent Multiswitch units provide an additional input for a terrestrial UHF TV signal so that this signal can also be switched to the subscriber and sent over the same coax feed. The system can be expanded beyond 1 6 subscribers by using cascadeable Multiswitch units Fig- ure- 1). Th is installation allows up to 100 subscribers to be serviced by just one dish and would be suitable for a small block of apartments or subscribers in a neighbour- hood. One advantage of this type of installation is that it is quite simple to expand a relatively simple one-satel- lite system up to a four-satellite system just by swapping the Multiswitch/LNB units, the existing subscriber coax cabling need not be disturbed or expanded. As can be seen in Figure-3 all the received signal bands Web links ST7LNB LNB microcontroller: http://mcu.st.com/ mcu/ inchtml.php?fdir=pages&fnam=st7lnb Channel Router Chip: www.st.com/stonline/ products/literature/bd/1 0465.htm DiSEqC: www.eutelsat.com/ satellites/ pdf/Diseqc/ Reference%20docs/bus_spec.pdf are bussed to the inputs of all the cascaded Multiswitch units, signal buffering and amplification may be neces- sary to compensate for signal attenuation and correct ter- minating resistors should be used at the end of the bus. DiSEqC switching Using switched quad LNBs together with a DiSEqC switch it is possible to produce a relatively small system suitable for four tuners which can receive programmes from four satellites. DiSEqC commands are generated when a receiver requests a programme to route the receiver input through to the correct LNB via the DiSEqC switch, selection of the correct band is performed with 14/1 8-V voltage level shifting and the 22-kHz tone switching which is routed through the switch to the correct LNB. These switches are available with two, four and more recently eight inputs. Satellite equipment suppliers offer so called '1 7 by 4' (17x4) -Multiswitch units which actually comprise of four individual 4-to-l DiSEqC switches fitted in the unit together with a feed from a terrestrial TV signal. Power for the switch is taken directly from the receiver and routed through to the selected LNB via the coax cable so there is no requirement for an external power supply. This method of power distribution can sometimes be a source of interference to other subscribers when the supply load- ing is switched during channel selection. The single cable solution With the advent of digital satellite signal there have been a number of 'single cable' solutions to the problem of distributing the broadcasts especially for satellite receiver owners interested in one language only. Germany, for example, has one of the highest uptakes of satellite TV equipment in Europe (approx. 40% of households) and there are many satellite programmes available in this language. One such system uses a special LNB which selects spe- cific parts of the received bands carrying programmes of interest to German speakers and packs them all together on a single coax. A potential disadvantage of this approach is if for any reason one of the TV stations changes their transponder it may no longer be possible to receive that programme without fitting a new LNB! Channel Routers The 1C manufacturer STMicroelectronics has produced its own solution to the single-cable system and not 40 elektor - 2/2009 surprisingly it involves microcontrollers and integrated circuit wizardry. The system is known as 'linkable' and employs an 8-bit microcontroller type ST7LNB integrated into an LNB. The single coax output supplies programme feeds for up to eight receivers, each with a fully indepen- dent program signal. In this set up each satellite receiver or recorder has a fixed receive frequency in the SAT IF band and informa- tion about each receivers programme channel selection is sent to the controller in the LNB where the requested channel is selected and down-converted to the unique IF band for that particular receiver (Figure-4) programme signals for up to eight receivers are then sent along the coax. The LNB is in fact a highly integrated Quattro LNB together with a mini channel-router and microcontroller. The system uses the existing DiSEqC control protocol together with some application specific additional com- mands and can easily be expanded to cater for signals from more satellites. This system can currently supply eight independent sig- nals over a single daisy-chained coax which should be sufficient for an average home installation. Single receiv- ers can be replaced by twin receivers without the need for any additional cabling. The price of a Unicable LNB is currently around £1 00-150 (145-2 1 0 euros) which is a little more expensive than a small Multiswitch together with a suitable LNB but the cabling costs are much lower. ( 060228 - 1 ) Glossary LNB: Low No ise Block (down converter). Satellite sig- nals are focussed into this unit by the dish. It converts the received 10.7 to 12.7-GHz signal into a 950 to 2150-MHz signal and sends it to the receiver over one or more coax cables. Sat IF: Satellite receiver intermediate frequency. The fre- quency range from 950 to 2150 MHz sent from the LNB to the satellite tuner. Twin Receiver: Receiver containing two independent tun- ers allowing the simultaneous reception of two programmes (one for the TV and the other for a video recorder). DiSEqC: Digital Satellite Equipment Control. A standard produced by Philips and Eutelsat in 1994 defining a control method between the LNB or Multiswitch and the receiver, (see web links and the DiSEqC moniter article in this maga- zine). Transponder: Receive channel from a satellite. Analogue satellite TV used one channel per transponder but several compressed digital TV signals can now be packed into one transponder using a single wideband carrier. Advertisement GENERA I , CIRCUITS CO., LTD ■ jr QUALITY PCB& SERVICE PROTOTYPE TO instant online quote shopping cart ordering system China competitive prices free electrically test weir i 1 1 ITp ■lvltt.t- DfrrrT 01 v r; EWM IF SdhKfcgpC bGflrlGLYrt Taj *a&&rt-a7m3at9 Fax *8&-5?lS7D357Q5 Add to. 76 (kiCiti Ctum 2/2009 - elektor 41 CLOCKS Markus Bindhammer (Germany) Inspired by a binary clock he saw at a mathematics museum the author of this design went one step further and came up with a more mathematically challenging timepiece... This unusual large format digital clock in the photo shows the time in binary and is exhibited at the German Museum of Mathematics ‘Mathematikum’ in the town of Giessen, Germany [1], The museum is the brainchild of Prof. Beutelsbacher and has been described as the first ‘hands-on’ mathematical museum in the world. The clock inspired Marco Freitag to design the PIC16C54 based binary clock fea- tured earlier in this magazine [1]. After a visit to the museum the author was moti- vated to experiment with this alternative format for time representation which re- quires a little more concentration to read compared to the average clock. The Trit We are familiar with the role of the ‘bit’ in binary systems so it is probably not surprising to discover that in trinary systems we use the trit which is a con- traction of the words ‘trinary digit’. The basis of the trinary system (a.k.a. ter- nary or base three) is 3. The positional power of any number expressed in tri- nary (starting from the least significant position) is given by: 3° = 1; 3 1 = 3; 3 2 = 9; 3 3 = 27; etc. The only numbers allowed to represent a value are 0, 1 and 2. To indicate that a value is written in trinary it is append- ed with a subscripted 3, for example 1210 3 = 48 d (1x27 + 2x9 + 1x3 + 0x1). In order to display any value in trinary it is necessary to use a device which can have three visible states. Bi-colour LEDs have been chosen here to repre- sent ‘0’ (both LEDs off), ‘1’ (green LED on) and ‘2’ (red LED on). The table (Figure 1) shows the decimal values of a clock reading together with its representation in trinary and the cor- responding LED colours used for the dis- play. It can be seen that for the hours (0 to 23) we need three bi-colour LEDs and the minutes (0 to 59) require four. It is also necessary to use a corresponding number of counters to count the seconds and minutes. The counters go from 0 to 2 while the third output resets the coun- ter to zero and acts as a carry-out to in- crement the next in the chain. The AND gate IC11.B detects when the hour count reaches 24 and resets the hours while IC11.D does the same to the minute counters when they reach 60 and also increment the hour counter. Counting the time Reading the time on this clock can be a little challenging but in contrast the circuit diagram is quite simple to fol- low. In principle it shouldn’t be too dif- ficult to read the time providing you can count up to three. . . All of the timing and counting for the clock is not hidden away somewhere inside a microcontroller memory but instead is done the old fashioned way by wiring the hardware counters and 42 elektor - 2/2009 logic shown on the circuit diagram in Figure 2. A division ratio 2 15 (32768) is necessary to provide a 1 Hz signal from the 32.768 kHz watch crystal XI. The 14 stage binary counter IC10 can manage 2 14 which gives a 2 Hz clock output from pin 3. Resistor R39 has a relatively high value and this helps reduce loading on the crystal. A small watch crystal like this can dissipate a maximum power of around 1 jl/W (nominally 0.1 jl/W). The D-type flip-flop IC12A is config- ured as a divide-by-two to produce a 1 Hz output while IC8 and IC9 provide a divide -by- 10 and divide -by- six func- tion to generate minute pulses. IC12. B drives the second pulses to LED D4 which alternates between red and green. The use of 5-stage Johnson counters (which can count up to 10) for IC1 to IC7 may seem a bit like overkill since they never need to count above three but these devices are less prob- lematic to interface than some of the trinary decimal trinary decimal trinary decimal 0000 0 0 2 1 0 21 1 1 2 0 42 000 i 1 0 2 1 1 1 22 1 1 2 1 1 43 o o o 2 2 0 2 1 2 23 1 1 2 2 44 00 1 0 3 0 2 2 0 24 1 2 00 45 00 1 1 1 4 0 2 2 1 1 25 1 2 0 1 46 00 1 2 5 0 2 2 2 26 1 2 0 2 47 00 2 0 6 1 000 27 1 2 1 0 48 00 2 1 1 7 1 00 1 28 1 2 1 1 1 49 00 2 2 8 1 o o 2 29 1 2 1 2 50 0 1 00 9 1 0 1 0 30 1 2 2 0 51 0 1 0 1 10 1 0 1 1 1 31 1 2 2 1 1 52 0 1 o: 2 11 1 0 1 2 32 1 2 2 2 53 0 1 i 0 12 1 0 2 0 33 2 000 54 0 1 1 1 1 13 1 0 2 1 1 34 2 00 1 55 0 1 i 2 14 1 0 2 2 35 2 o o 2 56 0 1 2 0 15 1 1 00 36 2 0 1 0 57 0 1 2 1 1 16 1 1 0 1 37 2 0 1 1 1 58 0 1 2 2 17 1 1 0 2 38 2 0 1 2 59 0 2 00 18 1 1 1 0 39 2 0 2 0 60 0 2 0 1 19 1 1 1 1 1 40 0 2 o: 2 20 1 1 1 2 41 Figure 1. Time represented in trinary together with the decimal equivalent. The colours indicate the bi-colour LED display. IC10 +5V 0 IC11 =4081 IC12 = 4013 D9 ... D22 = 1N4148 T1 ...T16 = BC547B IC11.A IC11.C Cl 27p l ' — | 4M7 | — f — 1 1 Ir39 _9_ ;1 32768Hz c; C2 1JL loop CTR14 !G RCX 4 RX + 5 CX 6 CT < 7 8 4060 9 11 CT=0 12 13 IC11.B 3 2 4 7 10 1 5 6 9 11 '1A 0 CTRDIV10/ 1 DEC 2 IC1 3 & 4 + 5 6 7 4017 8 9 CT=0 CT>5 3 2 4 7 10 1 5 6 9 '1A 0 1 CTRDIV10/ DEC 2 IC2 3 & 4 + 5 6 7 4017 8 9 CT=0 CT>5 3 2 4 7 21 i 5 6 9 21 '1A 0 CTRDIV10/ 1 DEC 2 IC3 3 & 4 + 5 6 7 4017 8 9 CT=0 CT>5 y 13 T S D IC12.A c< R 1 JE CTRDIV10/ 0 DEC 1 O 00 NJ & 3 4 + 5 6 4017 7 8 CT= 0 9 CT>5 CTRDIV10/ 0 DEC -| IC9 2 & 3 4 + 5 6 4017 7 8 CT= 0 9 CT>5 IC11.D T 12Z S D IC12.B C< R +5V 1 3 2 4 7 10 1 5 6 9 11 '1A 0 CTRDIV10/ 1 DEC 2 IC4 3 & 4 + 5 6 7 4017 8 9 CT=0 CT>5 3 2 4 7 21 i 5 6 9 2i '1A 0 1 CTRDIV10/ DEC 2 IC5 3 & 4 + 5 6 7 4017 8 9 CT=0 CT>5 3 2 4 7 21 1 5 6 9 21 '1A 0 CTRDIV10/ 1 DEC 2 IC6 3 & 4 + 5 6 7 4017 8 9 CT=0 CT>5 a 13 ^+5V +5V @-0- _3 2 4 7 10 1 _5 6 9 11 '1A 0 CTRDIV10/ 1 DEC 2 IC7 3 & 4 + 5 6 7 4017 8 9 CT=0 CT>5 v\ 13 C3 © ^ ici : 100n (7) 25 V y C4 ■ IC2 ■ lOOn (Cl T C5 ■ IC3 5 lOOn (C T C6 (™) ■ IC4 ■ lOOn (C T C7 (™) ■ IC5 " lOOn (C T C8 ■ IC6 Z lOOn (C T C9 ■ IC7 ■ lOOn (Cl T CIO 4) ■ IC8 Z lOOn (C T cii (™) ■ IC9 Z lOOn (C 1 C12 (^) ■ IC10 ■ lOOn (C T C13 (^) ■ ICI 1 Z lOOn (C Cl 4 (^) ■ ICI 2 Z lOOn (C Cl 5 lOOn Figure 2. The circuit diagram shows a classic hardwired hardware approach. 2/2009 - elektor 43 CLOCKS Figure 3. The finished PCB layout. w U \ 1 0 r — ' I rl ; <33] i 1 trSSB'-r ~\ u u, (j •. *!> 'ID 5 I - , 3 turn „ - - .ass; i )“SSD 1 n 451 '! IOI 3 corn Ir O-J.&. 9^o ■ - * r o'" XDI r = cr>m ■ 1 s tj-n rgSt ■ I O-J^o I I Om^J Q IDI I 3 cn.nr ■ 3 (jJ'Tl i O --J -t»- n £2*1 IDX i d cnm i 3 w -n Ip o^-b. 9^0- I ^ oS 3 j i. tu TJ 0 ,- XCX 3 On ■ = ton ! n o 1 /“’i Is. « □ I I cnm 1 — uj I r o -^j Af. i . OJiQ I n £ ^ tri ■ 1 0nl DP - ! CaJ Tt 1 ^ UJ“n I O I N O-J Ji 9£o Otu T) I 0 m^ Iw -O 0 A/.1K10 Af *1 K 100 JV* IK 100 p W*1K 100 Af*1 K 100 A/ *1 K 100 A/*1 K 1J}Q A/*1K100 N *1 K100 NS099SHH l NBB 090 m s Q0£06d 0 uisjl™w etitisysses aaisondOH £ GKX^H 3^l7Z£9a daZT0W*3H £ GHXJUUH 3mi£9Q d9Zt0frd3H Figure 4. The prototype clock. Can you work out at what time the picture was taken? 44 elektor - 2/2009 other CMOS digital chips and produce a simpler circuit. With reference to the table LEDs D1 to D3 display the hours, D5 to D8 the minutes and D4 pulses at second intervals. Setting the time The PCB layout shown in Figure 3 is rather reminiscent of a digital clock de- sign from around 30 years ago when TTL technology was king. Thanks to CMOS circuitry and the LED outputs used in this design it consumes far less energy. The operating current de- pends on the number of LEDs illumi- nated which in turn is governed by the time of day. The prototype board shown in Figure 4 draws between 22 and 88 mA. This current level would give a relatively short battery life but should be no problem for a low power 5 V, 100 mA mains adapter. The five volt supply does not need to be too precise; the circuit will function happi- ly at any voltage between 4.5 and 6 V. To set the clock it is necessary to pull out the jumpers JP1 and JP2 from their RUN positions to the SET H (set hour) position and then SET MIN (set minute). The hours and the minutes will increment at second intervals un- til the correct value is achieved where- upon the jumpers are returned to their original position. The jumpers can be replaced by slide or toggle switches to make time setting easier. With the component values given the accuracy of the crystal in the prototype was measured at +43 ppm which is within the quoted crystal tolerance. The crystal ran below its nominal value but those of you who have the means to measure the frequency accurately (or who have enough patience) can im- prove the accuracy by adjusting (trim- ming) the values of Cl and C2 slightly to change the capacitive loading on the crystal. Increasing the capacitance will slow the frequency. (060030e) Literature and Links: [1] The German Museum of Mathematics: www.mathematikum.de [2] Marco Freitag: 'Binary Clock', Elektor Electronics July/August 2006 COMPONENTS LIST Resistors R1-R8 = 220 Q R9-R26 = 1 kD8 R27-R37 = lOOkD R38 = 4MD7 R39 = 270kQ Capacitors Cl = 27pF C2 = lOOpF C3 = 100/+ 25V radial C4-C15 = lOOnF Semiconductors D1-D8 = bicolour LED, red/green, common cathode (e.g. Conrad Elec- tronics # 1 85000) D9- D22 = 1N4148 T1-T18 = BC547B IC1-IC9 = 4017 IC10 = 4060 IC11 = 4081 IC1 2 = 4013 Miscellaneous JP1,JP2 = 3-way SIL pinheader with jumper, or miniature changeover switch XI = 32.768kHz quartz crystal 7 wire links PCB, ref. 060030-1 from www.thepcbshop.com See your design in print! Elektor Electronics (Publishing) are looking for Freelance Technical Authors/Designers If you have # an innovative or otherwise original design you would like to see in print in Europe's largest magazine on practical electronics # above average skills in designing electronic circuits # experience in writing electronics-related software # basic skills in complementing your design with an explanatory text # a PC, email and Internet access for efficient communication with our in-house design staff; then do not hesitate to contact us for exciting opportunities in getting your designs published on a regular basis. Elektor Electronics Jan Suiting, Editor P.O. Box II, NL-6II4-ZG Susteren, The Netherlands, Fax: (+31) 46 4370161 Email: editor@elektor.com 2/2009 - elektor 45 MICROCONTROLLERS Udo Jursz and Wolfgang Rudolph (Germany) People don't come with built-in rulers, but if we need to know how far away an object is, we can estimate the distance (and we do it all the time). However, how can a robot determine the distance to an object and do so with sufficient accuracy? In this article, we examine the various methods that can be used and describe a distance measuring system that uses an infrared sensor and the ATM18. Our ability to estimate distances accu- rately depends on many factors, such as how well we can see the remote object and whether we know the size of the object and other objects in its vicinity In any case, our estimates are approx- imations and rarely exact. However, a moderately accurate estimate is usually sufficient for finding our way around in our surroundings. Things are different with a robot, for example when it has to adjust its speed and acceleration while approaching an object located 80 to 150 centimetres away. We started by taking a closer look at various methods for determining the distance to an object. The following three methods are apparently the most important: 1. Propagation time and relative phase measurements using radio signals 2. Optical measurements (including laser measurements) 3. Measurements using ultrasonic signals With regard to the last of these meth- ods, we would like to make a small digression here to the animal world. As you know, bats use various sonar techniques with fixed frequencies and varying frequencies that yield a con- stant reflected frequency from station- ary objects. The results are calculated so fast that these small aerobatic art- ists can navigate through narrow caves in full darkness with incredible virtu- osity, and they can locate and capture insects in full flight. Although artificial ultrasonic measuring devices employ methods that are similar to those found in the animal world, our technology falls far short of the capabilities of nat- ural sonar systems. Every method has its advantages and disadvantages. Ultrasound is very sen- sitive to reflections and the physical properties of the atmosphere. Measure- ments based on the propagation time of radio signals require lightning-fast signal processing circuitry. Optical triangulation [1] is a commonly used method for measuring distances with light. Angle measurement Optical triangulation is based on meas- uring the angle between emitted and reflected light beams instead of the propagation time of a light signal. Pro- fessional equipment uses laser diodes for this purpose in order to obtain high accuracy, but a normal LED can be used for relatively short distances if high accuracy is not necessary. The operating principle of optical trian- gulation is shown in Figure 1. The LED at the left end of the sensor acts as the emitter. A precision lens forms the light emitted by the LED into a narrow beam that is reflected from the target object. A portion of the reflected light enters the lens of the receiver section of the sensor (at the right in the figure). The angle of the reflected light beam depends on the distance between the sensor and the target object. A ‘posi- tion-sensitive detector’ (PSD), or in other words a linear-array CCD IC, is located behind the receiver lens. The receiver lens focuses the reflected light beam into a spot that illuminates as few of the light-sensitive cells of the CCD array as possible, so that its position can be determined. If the dis- tance to the target object changes, the angle a of the received light beam also changes, and a different part of the light sensor is illuminated (Figure 2). This clearly illustrates the operating principle: when the distance changes, the spot of light on the PSD (which 46 elektor - 2/2009 results from the reflected light beam) moves to a different position. The inte- grated signal processing circuit of the sensor can thus generate a signal volt- age that depends on the angle a and thus on the distance. Unfortunately, the relationship between the signal value and the distance is not linear, since it is based on a trigonometric function. The essential requirements for using this method are that the distance between the emitter diode and the receiver array of the sensor is known, as well as the angle a. The signal process- ing circuit obtains the latter value indi- rectly from the position of the light spot on the PSD. Using this information, the sensor’s integrated signal processing circuit generates a signal that is avail- able at the sensor output. Another con- sideration is that this method is only suitable for short distances (up to a few metres) because the sensitivity depends on the distance between the emitter and receiver sections, which are both contained in a small package. If you want to determine the distance from the voltage generated by the sen- sor, you have to do some calculations. The following trigonometric formulas can be used to determine the distance x - x 0 from the measured distance tan d = x' — x ! 0 / -> tan a = Xg D x = D • tan {a + d) = D • tan£r + tanJ 1 — tan^r* tanJ x = D • ~y v _ V* ^ A 0 I A A 0 D ^ f -y ^ ^ •A-q .A .A q ~d'~T Figure 1. Distance measurement using optical triangulation. Figure 2. The distance x - x 0 can be determined from the measured distance x' - x 0 ' by using trigonometry. 2/2009 - elektor 47 MICROCONTROLLERS Figure 3. Sharp infrared distance sensor. 0 20 40 60 80 100 120 140 Distance to reflective object L (cm) > 080847 - 14 Figure 4. The relationship between output voltage and distance is non-linear. Figure 5. The sensor needs an additional SMD electrolytic capacitor for decoupling. From the final formula for calculating the value of x, it should in any case be clear that our little 8-bit microcontrol- ler has far too little processing power for continual measurement of the dis- tance to any given object. There are other methods that can be used to determine the distance from the sen- sor output voltage without using a lot of processing power, but we don’t want to get bogged down in theoreti- cal aspects here. What matters now is putting the theory into practice! IRDMS in practice The focus of this project is using infra- red distance sensors made by the Jap- anese manufacturer Sharp [2]. They go by the moniker ‘IRDMS’, which stands for ‘infrared distance measurement sensor’. There are two different sorts of IRDMS sensors. One sort has dig- ital outputs with an internal compara- tor set for a specific distance [3], while the other sort has analogue outputs. Here we use only sensors with ana- logue outputs. Several sensors suitable for different distance ranges are listed in Table 1. For our experiments, we selected the GP2Y0A02YK0F, which is intended to be used with distances of 20 to 150 cm. However, any other type listed in Table 1 can also be used, so you can select the type that best suits your particular application. As you can see from Figure 4, the sen- sor output signal is highly non-linear. The distance cannot be derived directly from the signal without linearisation. However, this is not necessary for our initial experiments. In theory, all you have to do to obtain a sensor signal with a range of up to approximately 2.7 V is to connect a 5-V supply voltage to the sensor. The IR diode operates in pulse mode and emits short, powerful flashes, which create a high peak load on the power supply. It is thus recommended to con- nect an electrolytic decoupling capac- itor close to the sensor. Incidentally, the emitted light is in the near infra- red range and is just barely visible to the naked eye in a dark environment, but it is readily visible on the monitor of a digital camera. The internal linear array CCD has approximately 100 active pixels. As a result, the level of the output sig- nal changes in steps of approximately 20 mV. A small ripple voltage with around the same amplitude is super- imposed on the output signal, so a low- pass filter is a good idea. The 10-bit A/ 48 elektor - 2/2009 D converter of the Mega88 has a reso- lution of around 5 mV with the exter- nal 5-V reference voltage, which in theory is adequate for this application. However, the C code developed for this project selects the microcontrol- ler’s internal 1.1 -V reference voltage, which yields a resolution of approxi- mately 1 mV. Caution: make sure that REF jumper JP2 is not fitted. A voltage divider consisting of a 5.6-kQ resistor and a 4.7-kQ resistor must be connected ahead of the input to match the signal to the measuring range. With this arrangement, the measuring range of the microcontroller extends to 2.4 V. A 1 -jL/F capacitor connected across one leg of the voltage divider lets it act as a low-pass filter as well. The additional hardware is quite mini- mal. Aside from the two resistors for the voltage divider, you only need two capacitors. First you have to sol- der a capacitor with a value of 10 to 100 /jF as close as possible to the sen- sor. It’s beyond us why Sharp didn’t Table 1 Sharp IR distance sensors with analogue out- puts, suitable for various distance ranges. Type designation Range [cm] GP2D1 20XJ00F 4-30 GP2D1 2J0000F 10-80 GP2D1 5J0000F 10-80 GP2Y0A02YK0F 20-150 GP2Y0A71 OKOF 1 00-500 simply include this on the PCB in the sensor package. Figure 5 shows this ‘user enhancement’ implemented with an SMD capacitor fitted directly to the PCB.. If you don’t want to mon- key with the sensor PCB, you can fit a small electrolytic capacitor externally, which means soldering it to the pins - but keep the leads as short as pos- sible. Then you have to put together the combined voltage divider and low- pass filter, which as previously men- tioned consists of a 6.8-kQ resistor and a 4.7-kQ resistor (preferably with a tolerance of 1% or better). Then sol- der a 1-/JF capacitor across the 4.7-kQ resistor (see Figure 6). Connect the junction of the voltage divider to the AD 6 input. The full circuit on the pro- totyping board is shown in Figure 7. Connect buttons SI, S2 and S3 to PB3, PB4 and PB5, and connect the PCO and PCI outputs to any desired inputs (one each) of the ULN 2003 so they can be used to drive the associated LEDs (these connections are not shown in Figure 6. Two resistors and an electrolytic capacitor form a combined voltage divider and low-pass filter for the sensor signal. si GP2012 / GP2Y0A02 GND +5V 10|J...100|J (close to sensor) 080847 - 15 Figure 7. All connections at a glance. Figure 8. Displayed sensor values. 2/2009 - elektor 49 MICROCONTROLLERS Listing 1 Distance calculation in Bascom Sub Calculate_s D = Getadc ( 6 ) ' U = D/1023 * (4 . 7 + 5 .6) /4 . 7 'U = D * 5 U = D * 1 . 1 U = U * 10.3 U = U / 4 . 7 U = U / 1023 'Print U ' 0.008271 + 939.6 x Us ' s = ' 1 - 3.398 x Us + 17.339 x Us x Us If U > 0.4 Then SI = 930.6 * U 51 = SI + 0.008271 S3 = U * U S3 = 17.339 * S3 52 = 3.398 * U S2 = 1 - S2 S2 = S2 + S3 S = SI / S2 Else S = 0 End If Print S End Sub End the photos). Software The C software for this project (ATM18_IRDMS_GP2xxx, download- able from www.elektor.com) is quite straightforward in use. Two limit val- ues are defined, and the program moni- tors these values and uses the LEDs to indicate the switching points. If the LC display is connected, three values are displayed: the output of the A/D con- verter (ADC: xxx), the upper limit (UL: xxxx), and the lower limit (LL: xxxx) (see Figure 8). You can press SI (left button) to set lower limit to the current sensor value, or press S3 (right button) to set the upper limit to the current sensor value. If you press the middle button (S2), the upper limit and lower limit are set to the default values. After the limit values have been set, you can move almost any desired object around in the acquisition range, and the voltage generated by the sen- sor will be shown on the display. If the either of the limit values is reached, the corresponding LED on the prototyp- ing board lights up. A possible appli- cation for this arrangement would be controlling a robot so that it never gets trapped in a corner and avoids obsta- cles. Of course, the distance parameter values could also be adjusted dynami- cally by the software according to the speed of motion. For developing your own applications, we can provide a small tip here. You can determine the distance with rea- sonably good accuracy by using the following simple formula: 0.00827 1 -1- 939.6 X U s 1)1 — — 1 - 3.398 XU S + 17.339 xU s xUs Here Us is the sensor signal voltage, which ranges from 2.5 V at a distance of 20 cm to 0.45 V at a distance of 150 cm. Naturally, this can be calculated much faster than the previously stated for- mulas. It can also be used in a Bascom- based solution. If you need to make distance meas- urements in an application and con- vert them to physical units, you natu- rally want to use the fastest possible method, which means using a look-up table. This involves creating a table of sensor output voltages for the entire distance range and having the soft- ware read values from this table. However, the implementation described here provides an adequate starting point for enabling a mobile object to decide which action to take, similar to the way a bat navigates with its ultrasonic localisation system. If an obstacle is looming, the motors can be stopped, and if the object keeps on coming, they can be put into reverse. That’s something even a bat can’t do! Lamp control in Bascom The Bascom program (downloadable from www.elektor.com) uses the sen- sor for a simple lamp control instead of displaying the measured distance to an object. The lamp in question is a desk lamp, which is controlled via all bits of Port B. One option is to use the ULN2003 driver IC on the board to drive a relay. In use, the distance sensor is aimed at the work station. If someone approaches the desk, the lamp goes on automatically. If they leave the work station, the lamp is switched off after a delay of 100 seconds. The movements of the person working at the desk are also monitored. With nor- mal desk work, people constantly move around by more than 3 cm. If motion is no longer observed, the person being monitored has probably fallen asleep. In this case, the desk lamp is switched off in the interest of a good office nap. However, it switches back on immedi- ately if the boss comes by and wakes his employee. The function Calculate_s (Listing 1) makes a measurement and converts the result into the distance s in cen- timetres. The calculation must be performed in individual steps in Bas- com; writing the full expression in a single line with lots of parentheses won’t work here. The voltage meas- urement code takes into account the voltage divider (6.8 kQ / 4.7 kQ) and the internal reference voltage (1.1 V). The calculated distance is also sent to the PC via a 9600-baud link. Expe- rience shows that the accuracy of the distance measurement is relatively good, with an error of around 10%. If no object is present in the visible range, a value of zero is output. The lines for an alternative sensor connection without a voltage divider, which requires using the 5-V supply voltage as the reference voltage, have been commented out. ( 080847 - 1 ) References and links [1] Contactless Distance Measurement, Elektor Electronics, April 2002 [2] www.sharpsma.com [3] Distance Measurement using Infrared, Elektor Electronics, July/August 2002 The ATM18 project at Computer:club 2 ATM18 is a joint project of Elektor and Computer:club 2 (www.cczwei.de) in collaboration with Udo Jursz, Chief Designer of www.microdrones.de. The latest developments and applications of the Elektor ATM1 8 are presented by Computenclub 2 member Wolfgang Rudolph in the CC 2 -tv programme broadcast on the German NRW-TV channel. The IR distance sensor and ATM1 8-AVR board combination described here was featured in instalment 25 of CC 2 -tv. CC 2 -tv is broadcast live by NRW-TV via the cable television network in North Rhine-Westphalia and as a LiveStream programme via the Internet (www.nrw.tv/home/cc2). CC 2 -tv is also avail- able as a podcast from www.cczwei.de and - a few days later - from sevenload.de. 50 elektor - 2/2009 SERVICING YD U R COMPLETE PROTOTYPE NEEDS 1 EUROCARD (160 x 100 mm) + Tooling v + Photoplots^f + VAT Ml/ €49 Price example Any size and contour possible! Optional: • Soldermask • Fast-turnaround • Silkscreen • 4-Layer Multilayer • 6-Layer Multilayer mt t^ur- fd""j 4. ; i . *-i+p Simply send your files and order ONLINE: PC8-POOL.COM *1 tel. 01298 70012 ^^EMft298 70046 ^ I e c . c o . u k Mll fiBjSlalpklec.co.uk VAT Reduction AND Special Offers! Atlas DCA ynW, Atlas ESR includes new premium probes! [Special [Offer AN D, Reduced iVATj ! Atlas DCA Model DCA55 Semiconductor Analyser Identifies type and pinout! Atlas LCR<^> Atlas ESR Model ESR60 ESR and Capacitance Meter Resolution of 0.01 ohms! Atlas SCR includes new premium probes! J Better- than >2 WoWATi Reduction ! Atlas LCR MttW «§40 [Special .Offer- AN D, Reduced iVATi ! Atlas SCR Model SCR1 00 Inductor, CapacitcMiesistor AnalvSHB Triac and Thyristor Analyser Automatic pa|iidentification. Auto gate tesjlB^H^BP to 100j^[ UK: Please ajli£2 p&p to your order. Price^pi^^^Kji|^9 Please see website for overseas prpi^B Starter Kit Professional for ARM a low cost entry into ARM development This bundle is perfect for low cost entry into ARM develop- ment and is great for engineers who need to develop prototypes of electronic systems quickly using the super fast ARM 7 core from Atmel. The pack is fully compatible with the range of E-block accessories. Datasheets on each individual item are available separately. Elektor Regus Brentford 1 000 Great West Road Brentford TW8 9HH United Kingdom Tel. +44 20 8261 4509 r^lektor L_3shop Flowcode 3 for ARM (CD-ROM) E-blocks ARM board E-blocks LED board E-blocks LCD board E-blocks Switch board USB cable Power supply Total value Special offer £274.50 £ 162.00 7 Free P&P* Further information and ordering atwww.elektor.com/arm-kit w 2/2009 - elektor 51 INFO & MARKET REVIEW Decibit 2.4 GHz RF Transceiver Development Kit Jan Buiting (Elektor UK/USA Editorial) Decibit DDK contents • CD-ROM: programmer, AVRasm2, WinAVR, example code files, USB driver • USB programmer • USB cable • 2 DCBT-24AX modules • 1 DCBT-24R6 Tiny RC • 2 Handheld Testers • 6 AA batteries 1 printed datasheet I never considered a battery holder for three AA batteries or a CD-ROM bulky components until I opened the DDK v. 2.1 RF development kit from Decibit. For sure, it’s because of the tiny (25 X 10 mm) RF transceiver modules with even tinier ICs on them (like 5x5 mm and 4x4 mm). Decibit rely on proven technology: Atmel’s ATMegal68 microcontroller in combination with an nRF24L01 trans- ceiver chip from Nordic Semiconductor together from the IC complement of a series of intelligent 2.4 GHz (ISM band) transmitter/receiver (TX/RX) modules with ISP connectivity and, remarkably, the ability to run AVR firmware created by you, the user. Plug & Play but AVRasm too The DDK kit, advertised at US$ 69 at the time of writing (December 2008) has great educational value as there is so much to discover and develop for different levels of users. Schools, for example, may follow the plug and play approach: install CD on PC; plug mod- ule on USB programmer and run the batch file. Next, insert the programmed modules in HHTs (hand held test- ers), press a button on one HHT and observe the LEDs on the other located at the far end of the classroom. More advanced users should explore the examples demonstrating differ- ent RF data transfer methods and per- haps expand or modify the example code chunks supplied. These cover one-way and two-way RF links using Shockburst protocols, with or without ACK(knowledge). There is even a ping- pong demo allowing you to check the TX/RX range by walking around (I was able to cover distances up to about 50 m in and around my home). You can see (well, kind of) the data send/resend actions on the HHT LEDs. Development tools The USB compatible programmer unit contained in the kit is a gem as it allows you to develop your own code for blow- ing into the ATmega on the modules. The ingredients: Decibit’ s own pro- gramming software; AVRasm2 from Atmel, the WinAVR C/C + + Compiler and a USB driver. If you can make an ATmega write “hello world”, you’re equally okay to talk to the Nordic TX/RX on the Decibit module as if it was just another peripheral device like an LCD. For example, CALL_label is sufficient to do a data transfer. The abilities of this system go far beyond those of com- monly found ‘passive’ transceiver mod- ules listening to AT-style commands — the Decibit DCBT-24 modules can be controlled right down (or should we say ‘up’?) to AVR assembly code level which makes them highly interesting to developers designing RF remote control applications ‘the embedded way’. Modules: you choose • DCBT-24N (low-power ultra small size TX/RX); • DCBT-24B (low-power TX/RX w. external antenna connection); • DCBT-24C (80 mW power amplified TX/RX with SMA antenna connector); • DCBT-24R6 (6-button key for remote control). For the TX/RX modules, several hard- ware/software versions are available, which customers can specify using the extensive ordering information system. According to Decibit, ETSI and FCC approvals are pending for the DCBT-24 products. Also, RF modules with more pins will be released in the future, or versions based on the latest AVR technology like XMEGA. For now, the ATmegal68 does a fine job already. ( 080868 - 1 ) www.decibit.com 52 elektor - 2/2009 MICROCONTROLLERS BASCOM AVR Course ( 4 ) A DDS generator using the ATmega32 Burkhard Kainka (Germany) The first five instalments of this course have already covered many programming techniques with an emphasis on practical applications. This final instalment builds on this theme giving a detailed insight into all the software routines needed to make a simple DDS generator. We also have an offer for you, see the final page of this article! To get a good overview of some of the possibilities of the BASCOM language and the ATmega controllers it is worth looking through the BASCOM AVR help pages, particularly all the Config options (Figure 1). Some of the topics we have already covered in this course and in other ATM-1 8 projects include: • COM-interface, hardware and software • Ports, input, input pull-ups, output • A/D converter • Timer and counter • Timer interrupts • PWM outputs • RC5 input • l 2 C master • Servo impulse • One-wire bus (elsewhere in this edition) There is of course much more internal and external hard- ware that can be used. The ATmega family share the same basic core but more specialised applications call for a care- ful study of the datasheets to find the version best suited to the task. This month we build an AF generator using the principles of DDS to produce the signal. The microcontroller interfaces to an LCD which is driven from the port pins. The DDS generator produces a sine wave signal from a digital PWM output. Two pushbuttons increment or decre- ment the output frequency in steps of 10 Hz. The output frequency is shown on an LCD and also sent to the COM interface port. For this test a Me ga32 type controller has been used, it has many I/O pins and is a popular choice. It would be simple to make changes to allow the program to run on other controllers from the ATmega family. The principle The block diagram in Figure 2 gives an overview of the external components connected to the microcontroller. The PWM signal is output from pin OC1 B, and passes through $ BASCOM AVR H«lp E H.V El Ark Horn* & l*rnl Ccftfertt ijjdex Search ! avw/lej 2) CONFIG SI CONFIG lWIPf SI CONFIG ACI SI CONFIG ADC SI CONFIG ATEMU SI CONFIG BCCARD SI CONFIG CLOCK SI CONFIG CLOCKDIV SI CONFIG COM1 SI CONFIG COM2 SI CONFIG COMk 21 CONFIG OATF 21 CONFIG OCF77 2) CONFIG OFAOUfJC.F 21 CONFIG Hi TAG 21 CONFIG I2COFI AY 2] CONFIG I2CSI AVF 21 CONFIG INPUT 2] CONFIG INTk 2] CONFIG GRAPHl CD ff- Uplims CONFIG IfiC Etfi mui M£22 DIRECTIVE ( UNI IG ! WIKI :0NFIG ACI CONTIG ATCMU CONFIG BCCAKD CO NF IG CLO CK DIV CONI 1G COM I CONFIG COM2 also COM3. COM4 CONFIG DATE CONFIG DCr 77 CONFIG UfcBOUNCfc CONFIG GRAPHLCD CONFIG HITAG CONI 1G I2CDILAY :ONFIG I2CSLAVE com |C, IN lk NO YFS RE- USABLE NO YES NO NO NO YU YES NO NO NO NO NO NO NO NO Yl Figure 1. Bascom help for the config options. a low-pass filter to produce a sine wave. The filter design is very simple but for test purposes is sufficient. A better solu- Figure 2. Block diagram of the DDS generator. 2/2009 - elektor 53 MICROCONTROLLERS Figure 3. The LCD setup page. Listing 1 Initialising and writing to the LCD Config Lcdpin = Pin , Db4 = Portb . 4 , Db5 = Portb . 5 , Db6 = Portb . 6 , Db7 = Portb . 7 , E = Portb . 3 , Rs = Portb . 2 Config Led = 16 * 2 Initlcd Cls Led "DDS" Listing 2 Sine wave lookup table and frequency selection For N = 1 To 256 A = N - 1 A = A * 3 . 1415 A = A / 128 B = Sin(a) B = B * 120 B = B + 128 Table (n) = Int (b) Next N Freq = 10 Do Locate 2 , 1 Led Freq Led " Hz If Pind.6 = 0 Then Freq = Freq + 10 Print Freq End If If Pind.7 = 0 Then Freq = Freq - 10 Print Freq End If Waitms 10 A = Freq '43200/65535 B = A / 0 . 65918 F = Int (b) Loop tion would use a (many-poled) filter with a much steeper response and a cut-off frequency of around 15 kHz. A sim- ple piezo buzzer can be directly connected to the output without the need for any filter at all. LC display Whenever a design calls for an LCD to display lines of char- acters it can be achieved using six port pins for the drive signals. The LCD usually works in 4-bit mode with each data byte split into two before being sent to the display. Two control signals, E and RS, are also needed. In addition to these six signals we need three for the power supply and contrast setting. The port pin assignments can be defined in the Menu Options/Compiler/LCD (Figure 3). A better method is to make the assignments in the source file (Config Lcdpin). Th is ensures that it runs successfully on different systems. It is also necessary to define the type of LCD used (Config Led = 16*2). When the system is first switched on one line of the LCD will be dark and the other light. After the display is initialised (Initlcd) the dark line becomes light. Characters (Led "Text") or a variable (LCD Freq) can now be sent to the display. After each character is written to the display the position is automatically incremented ready for the next character, but the second line does not automatically follow from the first. Writing to the second line it is necessary to define the position (Locate 2 , 5). The entire screen can be cleared at any time using the Cls command. The example given in Listing 1 writes the text / DDS / to the first line. The frequency value is sent to the second line of the display (Listing 2) followed by the units 'Hz'. The displayed frequency value will not always have the same number of characters so it is necessary to include enough spaces to ensure that all characters previously displayed will be overwritten by the new value. Sine table and frequency selection A sine function lookup table must be written into memory for use by the DDS generator. The table size is 256 bytes. These represent the analogue values of the wave which are sent to the PWM output to produce the sine wave. At start up the generator has an output frequency Freq = 10 Hz (Listing 2). The two pushbuttons PD6 and PD7 increment and decrement the output frequency in 1 0 Hz steps. The output frequency value is written to the two line display and each time the frequency is changed the new value is sent to the PC. Operation without an LCD is there- fore possible. The generator can be used for example to tune an instrument; the standard ' K note (440 Hz pro- duced on a tuning fork can be selected without problem. The frequency in Hz is scaled to give the variable F. Every change of F immediately affects the output frequency. This is made possible by the use of an interrupt routine. Timer and DDS The sine wave generator uses the DDS (Direct Digital Syn- thesis) principle with values of a sine waveform stored (as bytes) in a lookup table. A phase accumulator (the variable Accu) is increased by the value of the variable F to point to the next value in the lookup table. Only the high byte of the 1 6-bit Accu is used as a pointer to the table. When F has the value 1 it will therefore take 256 timer interrupts before the next value in the table is used and produces an output sine wave with a frequency of 0.6591 8 Hz. This is the resolution of the frequency generator. As the value of F 54 elektor - 2/2009 increases the pointer steps through the table more quickly. When its value reaches 256 the pointer will start to jump over individual values but the output will still be sinusoidal. At the highest frequency of 1 0 kHz only around four val- ues are used to produce a complete sine wave cycle. The lowpass filter ensures that a good approximation to a sine wave will still appear at the output. The program uses two timers. Timer 1 generates the 8- bit PWM signal. In this setup the PWM frequency is 1 1 059200 Hz / 256 = 43200 Hz. The 8-bit Timer 0 with- out any prescaler overflows at a rate of 43.2 kHz. This is therefore the rate at which the interrupt service routine is called, a new value is fetched from the lookup table and written to the PWM register before the next interrupt occurs (Listing 3). Without any prescaler an 8-bit timer will interrupt every 256 clock cycles. Between interrupts the controller must not only execute all the instructions in the interrupt service routine, but also push all the working registers onto a stack and lastly pop them off again. In some cases the timing could be a little tight. It is important to be sure that there will be enough time to carry out all the activities. The simplest way to indicate how long the controller spends servicing the interrupt is to get it to set a port pin (Port.O = 1) as it enters the ISR and reset it (Portb.O = 0) when it exits. With an oscilloscope probe on the pin we can now observe the mark/space ratio directly to see how much time is avail- able. In the example here the pin is high for less than 50% of the time. The main routine can only execute its tasks when this waveform is low. Using a simple software delay like Delayms will produce noticeably longer delay times than expected. Two lines are 'commented out' in the interrupt routine. When these comment characters are removed the signal generator now has a sweep function. The frequency is incremented each time an interrupt occurs, the generator now sweeps from 0 to 1 0 kHz approximately three times per second. The oscilloscope display (Figure 4) shows the resulting output waveform after the low-pass filter. A piezo buzzer connected to the output will produce a characteris- tic twittering sound. ( 080866 - 1 ) Downloads and more info Go to the project page at www.elektor.com/080866 for more in- formation and the program downloads. We welcome your feed- back in the Elektor forum. BASCOM-AVR Reader Offer Exclusive to Elektor readers, the download version of MCS BASCOM-AVR is now available at £ 55.00 (€ 69.00), a discount of more than 20% compared to the normal price of £ 71 .00 (€ 89.00). As a bonus, pdf copies of all six BASCOM-AVR course instalments that appeared in Elektor are included with the download. The offer is valid from 19 January 2009 through 9 February 2009. Further details at www.elektor.com/bascom- avr. US readers please check US$ prices on website. Listing 3 The DDS Config Timerl = Pwm , Prescale = 1 , Pwm = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down Config TimerO = Timer , Prescale = 1 On OvfO TimO_isr Enable TimerO Enable Interrupts Pwmla = 127 Pwmlb = 0 TimO_isr : 'Timer 43.2 kHz at 11.0592 MHz Portb .0=1 Accu = Accu + F N = High (accu) Pwmlb = Table (n) 'F = F + 1 'If F > 15000 Then F = 1 Portb .0=0 Return Figure 4. Oscilloscope display of the swept output signal. Advertisement Prototype & small series PCB specialists Simple online pricing Fast online ordering Clear online order tracking CIRCUITS new online stencil Call us: 020 8816 7005 Email: euro@eurocircuits.com www.eurocircuits.com Order pooling All services On demand low pooling prices wide pooling choices 1-8 layers - no tooling charges - no minimum order - from 3 working days - 100% DRC verification full options service 1-16 layers UL marking 2/2009 - elektor 55 _ 1 _ ii 1^,/M f P i jjj- ^ ~t. ’ ■>; y m 4| mj’,' One area that many model train enthusiasts have never been totally happy with is the lighting of coaches. Until now. The lighting controller described in this article is a combination of an SMD LED strip and a PIC12F683 for compatibility with the Marklin system. The LEDs allow easy adaptation to different colours while three different lengths of the board enable the project to fit all common coach types. The controller can be assigned an address without removing it from the coach. • Being able to turn the lighting on and off in a model railway coach used to be a challenge, as a separate decoder in the coach was at times not easy to conceal, and when installed, the address for the decoder was not easy to set or change. This challenge led the author to develop a solution that would address the following list of criteria: • Cost effective with regard to buying commercial units. • Easily adaptable to various colours. • Switching individual coach lighting on and off. • Controlling the intensity of lighting in individual coaches. • Turning coach marker (‘tail’) lights on and off. • Changing addresses of the decod- ers without having to open the coaches. • Having a single feed for power link- ing coaches. • Eliminating flicker due to the unbal- anced Marklin track signal. • Different length units to fit all com- mon coach types. The result has been the building of a coach lighting strip with an on-board controller. The board uses a PIC12F683 8-pin microcontroller to decode the incoming Marklin signals and con- trol the intensity of the LED lighting. This microcontroller contains a PWM (pulsewidth modulator) and it can be obtained for a very reasonable price, keeping the cost of the unit low. LEDs, colours & board sizes In principle, any colour SMD LEDs may be used. When purchasing LEDs ensure that they are rated at least 100 mcd (milli-candelas) with a view- ing angle of at least 110 degrees. White LEDs in a 0805 package with 140 mcd output and a viewing angle of 140 degrees work very well. For yel- lowish) lighting, LEDs in a 1206 pack- age are also a good choice. Experiment with a number of different LEDs until you find the ones that you think pro- vide the colour that you like best. The board is available in three lengths to accommodate different model coach lengths. The short board has a length of 110 mm and has four illuminating LEDs. The medium board has a length of 190 mm and accommodates eight LEDs. Finally, the long board is 230 mm in length and has 10 LEDs. All boards are single-sided and surface mount components are used throughout. The circuit As shown in Figure 1 , the Marklin system supply voltage arrives via the rails on the bridge diodes D1-D4 via PCI (Marklin RED) and PC5 (Marklin Brown). The output of the bridge is clamped by a 27-volt zener diode, D2, to protect the regulator from exces- sive voltage spikes that may occur on the track layout. The 22 /jF capacitor C3 acts as a reservoir device to pre- vent the microcontroller from resetting owing to short periods of power loss. This power configuration also elimi- nates the flickering of the LEDs due to the unbalanced Marklin track sig- nal. The 16-19 V raw DC output from the bridge is fed to the 5 volt regulator IC1 that in turn feeds the PIC micro- controller and the TLE4913 Hall effect switch, IC3. The Hall switch pulls its output Low if a magnet is detected in its vicinity. Using software, this condition is used to enter the board address setup pro- cedure discussed further on. Output GP2 from the PIC microcon- troller then drives an MMBF170 sur- face mount FET (T2) to turn the coach illumination LEDs on and off via PWM. A second output (GP4) and a second FET (Tl) control two external LEDs that form the left and right tail lights on the coach. The tail lights should be connected between terminals A’ (anode) and ‘C’ (cathode) and pro- vided with their own current limiting resistor (2.2 kQ is suggested). If you do not need tail lights, Tl and R9 may be omitted from the board. It should be noted that the circuit dia- gram shown in Figure 1 is generic for the project. Three options exist for the construction — you decide. 56 elektor - 2/2009 Quick project specs • Marklin compatible The short board uses LEDs D6, D8, DIO and D15 only. The medium board uses LEDs D6, D8, DIO, D15, D7, D9, Dll and D13 only. The long board uses all LEDs shown, i.e. D6, D8, DIO, D15, D7, D9, Dll, D13, D12 and D14. The PIC micro We’re sorry if this sounds patronising to microcontroller boffins but the PIC 12F683 device used in this project is (1) an SMD device and (2) has to be programmed before it has any func- tionality: so, either you buy it ready- programmed from the Elektor Shop (order code 080689-41) or you obtain a blank device from your favourite sup- plier and do the programming yourself using your own programming system and the software that’s supplied free of charge through the Elektor website (archive file 080689-11. zip). Assembly language and hex files are provided. The project software was developed using Microchip MPLAB IDE v3.14. Construction The boards all employ SMD compo- nents and those of not you not used to handling these tiny parts (or recover- ing them from mom’s vacuum cleaner all the time) may want to seek help from fellow modellers in a club or on the Elektor forums, also when it comes to ordering parts and boards, using the motto: Strength in Numbers! Elektor does its part by supplying bundle discounts for the PCBs and the microcontroller, see the Shop section of our website. IC1 UA78L05ACL -j 2 ^. £3* Cl 27V 500mW 22u 35V PIC12F683 *see text tail lights (optional) Figure 1. Circuit diagram of the coach lighting controller: basically, it's no more than a PIC micro and a series of LEDs under PWM control. 2/2009 - elektor 57 MODEL RAILWAY 0 i II 1 1 'o J in tx _ co H'co ^Hco iri'co H co, ml Els ■“: Els Eli °gi a C C C C c in a a o a a Figure 2. The control board comes in three sizes: long (a), medium (b) and short (c) to suit most model coach sizes. Full- size PCB artwork for all three board versions is available free of charge from the Elektor website. The component mounting plans for the board are given in Figure 2a (long board), 2b (medium board) and 2c (short board). All three board sizes are available individually and ready-made from the Elektor Shop (order codes 080689-1, -2, -3). In the Elektor labs, it was proved that populating these boards is feasible with a steady hand, a fine tipped solder iron and nothing in the way of special SMD soldering tools. This is probably due to the fact that the parts are small but generously spaced on the board. You should start, however, by mount- ing the programmed microcontroller. A few more remarks. The length and spacing of the copper pads for the LEDs allow a wide range of devices to be used including ‘0805’ and ‘1206’. Be sure to know, verify again, and dis- cuss with your friends, the polarity of the electrolytic capacitor C3 before fit- ting it on the board with absolute cer- tainty. The electrolytics on our proto- type boards had their positive ( + ) terminal marked with a red bar. C3 may be increased if you require the coach lights to stay on longer in the absence of power on the rails. You may even consider replacing C3 with a ‘Goldcap’. Regarding the SMD diodes, when in doubt, do a polarity measurement or seek advice from your supplier. It is recommended to test the board before mounting it in a coach. This is easily done by providing a tempo- rary wired connection to the rails. Our thanks are due to Mr. Henk Prince for testing the three prototype boards in his privately owned Marklin layout. Mounting it in the coach The light strip should be attached to the inside roof of the carriage using Prestic adhesive or double sided tape. Ground (Marklin Brown) should be con- nected to ground pickup springs on a set of the coach’s wheels and routed to PC 5 of the lighting board. The cen- tre shoe pickup Red wire should be connected to PCI on the lighting strip or from the conductive coupler on the end of the coach. PC2 should carry current from the oppo- site end of the coach to the opposite end con- ductive coupler to feed positive supply voltage to the following coach. Setting up the board address Having digested that in a Marklin sys- tem each device — whether locomo- tive, semaphore or turnouts — has its unique, individual device address, it’s no surprise that the coach lighting con- trol is just another device to be incor- COMPONENT LIST Resistors (all SMD 0805 except R8) R1 ,R2 = 1 kQ R3 = 2kD2 R4 =270kD R5 = 47kD R6,R7,R9 = lOkD R8 = on (wire link) (SMD 1 206) Capacitors Cl ,C2,C4 = 1 OOnF (SMD 0805) C3 = 22/L/F 35V tantalum (in D or X case) Semiconductors 01,03,04,05 = BAS16 D2 = 27V 500mW zener diode in SOD- 80C case, e.g. BZV55C27 D6-D1 4 = white or yellow SMD LED, min. 1 OOmcd, min. 1 1 0 degrees (see text) T1 ,T2 = PMBF1 70 (or equivalent for BS1 70 in SOT-23 case) IC1 = 78L05 (SOT-89-3 case, e.g. L78L05ABUTR) IC2 = PIC1 2F683-E/SN or-l/SN, pro- grammed, Elektor Shop # 080689-41 IC3 = TLE4913 (Hall sensor) Miscellaneous PCB, long version (I = 230mm), Elektor Shop # 080689-1* PCB, medium version (I = 190mm), Elektor Shop # 080689-2* PCB, short version (I = 1 10mm), Elektor Shop # 080689-3* * select length to fit coach size. 58 elektor - 2/2009 porated in the system. The board is Figure 3. The three boards, ready for installing into model configured as follows, assuming it’s railway coaches, working correctly, connected up and installed in a coach. 1. Place coach on rails. 2. Reset the Marklin control unit: Press and hold the stop and go buttons until con- trol unit resets. 3. Enter address of engine, e.g. 06. 4. Hold a magnet over the end of the coach until the coach lights blink. 5. Remove magnet, then wait till light stops flashing. 6. Turn on engine lights using F0. 7. Adjust speed dial to adjust desired illumination level of lights. 7. Turn on FI to save illumination level. 8. The coach light will blink a few times to indicate acceptance of the level. The decoder is now programmed to address 06. Lights can now be turned on and off with the F0 buttons. If you have connected marker lights, then they can be operated using the F3 but- tons. FI has no function after setting the illumination level during program- ming setup. Model railway fans, please send us your photographs of coaches fitted with the controller described here! ( 080689 - 1 ) Programmer settings Device: PIC12F683 SOIC-8 Oscillator internal RC, no clock Watchdog: enabled Power Up Timer: enabled CPD: disabled Brown out: enabled SBOREN: disabled MCLR pin: enabled Internal External Switch Over: disabled Fail-Safe Clock Monitor: enabled About the author Graham Guthrie worked as an IBM cus- tomer Engineer for 31 years on mainframes and entered early retirement at the end of 1999. After retiring he took up model trains as a hobby to keep himself occupied. Graham now makes various decoders and control- lers for the local model train fraternity in his spare time. He is also involved in helping others in the hobby with computer automation of their layouts. Email: grahamg7@telkomsa.net 2/2009 - elektor 59 TECHNOLOGY PROGRAMMING Programming FPGA C-to-Hardware synthesis using Alt Volker Brandstetter (Altium Germany) FPGAs are normally programmed in special-purpose programming languages such as VHDL, which unfortunately can be hard to learn. Now, however, it is possible to program hardware in good old-fashioned C! Compared with conventional sequential execution of a program in a microcontroller, the results are considerably faster. We look at how C code can be compiled into hardware, using the Altium Designer development suite as an example. FPGAs are hardware devices whose internal structure is determined by software. Compared with sequential pro- gram execution in a microcontroller, an FPGA can offer a considerable increase in speed; compared with ASICs FPGAs are more flexible and overall design costs for small to medium quantities are much lower. Traditionally FPGAs (and ASICs) have been designed by specifying the structure and function of the circuits inside the device at the register transfer level (RTL) via a hardware description language such as Verilog or VHDL. Once the design has been simulated and verified the RTL description is converted into GDSII data for mask making (in the case of ASICs) or into binary configuration files (in the case of FPGAs). The RTL development approach allows the hardware designer to work with the final silicon implementation in mind, and hence to optimise the circuit for speed or for power. Sometimes, however, these factors can be less important than low development costs or short develop- ment time. In these respects the RTL approach has a number of disadvantages: • Development is carried out at a low level of abstrac- tion. A program that might run to 100 lines in a high- level language might easily balloon into a 1 000-line RTL description. • There are limited opportunities for code re-use as the RTL description specifies the structure of a system explicitly. • When using an RTL description optimisation is usually carried out at the sub-system level; optimisation at a higher level can often have a greater impact on cost and performance. C with benefits Now we shall look at how so-called C-to-Hardware synthe- sis can address these disadvantages. Parts of a C program, that normally would be run on a microcontroller, can be transformed into FPGA hardware using the development suite, with an immediate performance gain. One powerful development suite offering such a feature is Altium Designer from Australian software maker Altium (http://www.altium.com/ products/altiumdesigner). The company also sells development boards which offer such a wide range of peripherals and expansion possibilities that they can be used directly for hardware prototyping. An example is the NanoBoard (see text box), which was used to test the sample applications described in this article. The C-to-Hardware synthesis feature of the design suite allows designers to develop FPGA-based prototypes with- out having to learn Verilog or VHDL. C is used as the hard- ware description language, supported by a comprehensive IP library of ready-made FPGA modules including soft proc- essor cores (microcontrollers implemented within the FPGA), memory controllers and various peripherals. The C-to-Hardware synthesis process in Altium Designer con- verts an ISO C/C++ program into synthesisable RTL code. The compiler generates the circuit on the basis of a list of functional units (such as adders, ALUs, MACs, dividers and so on) and their characteristics. In doing so it endeavours to obtain the highest possible performance, for example by constructing functional units in such a way that they can be run in parallel. The advantages of C-to-Hardware synthesis come to the fore when a processor core is integrated into the FPGA. C code can then either be executed on the processor or be converted into RTL code. The embedded compiler and C-to-Hardware synthesis are closely integrated in Altium Designer. Which functions are executed by the processor and which in hardware can be selected with just a couple of clicks of the mouse. 60 elektor - 2/2009 The twofold way In principle there are two ways of using the C-to-Hardware compiler. 1 . The first use is in developing functional circuit blocks in C. In this case the compiler is used to convert individual C functions into hardware. A so-called 'C Code Symbol' makes it easy to integrate the function into the design. The result of the compilation process is an FPGA block that can be used as a module alongside other circuit blocks written in VHDL or Verilog, or ready-synthesised IP modules, con- nected via its defined inputs and outputs (Figure 1). The C-to-Hardware compiler can convert the C function into a purely combinatorial circuit or into a multi-cycle circuit. This choice is made by setting the relevant property on the C Code Symbol (Figure 2). In the case of combinatorial blocks only the parameters to the C function appear as inputs and outputs on the C Code Symbol. For multi-cycle circuits Altium Designer adds in the extra signals (such as clock and reset) that need to be connected. 2. The second use is in increasing the speed of a proc- essor-based system. Here the C source code for selected software functions is converted into hardware in such a way that they can still be 'called' from the main embed- ded program, which is now running in a processor imple- mented in the FPGA. The C-to-Hardware compiler is used in conjunction with the embedded software compiler which is also part of the design suite. Implementing speed-critical functions in hardware can result in enormous increases in speed (Figure 3). Faster in parallel Operations that are described as occurring sequentially in C but which could be run in parallel in hardware are converted into suitable RTL code by the compiler. For many algorithms, such as those used in image and signal process- ing, the parallel use of the available FPGA resources not only relieves the processor of computational burden but also provides a performance improvement. The so-called Application Specific Processor block (or ASP block functions here as an interface between the opera- tions being carried out in hardware and the remainder of the C program still running on the processor. When a hard- ware function is called from the embedded program, the processor passes the values of the function parameters to the ASP, which then initiates the function. When the hard- FFCiA Dvwvi AikHvutf Dnyi "-WC W "-UtflC C Code Syrcibol Acldrtm*! Dn^i lUtHuiri Dwy-> ■Tbri ! dnvf ■ Lr!w i wt 1 : I . Ejiajnpte_S™rcu.c htii¥tam»rC * 1 m rr.il HThi? t n ciaj OC--,KV5F._0 S* m- START RESET [Xtt-T JZ. IS P£SET Figure 1. A C function, represented using a C Code Symbol, is converted into an FPGA block and connected into the overall system. Figure 2. Selecting a circuit type (combinatorial or multi- cycle) for a C Code Symbol. Figure 3. Speed-critical C functions are implemented in hardware; less critical functions run on the CPU. ware operation is complete it passes the results back to the main program. The ASP therefore has access to a memory shared with the processor, through which the values of variables common to the hardware and software functions are communicated. The software can pass a pointer into this memory to the 2/2009 - elektor 61 TECHNOLOGY PROGRAMMING Figure 4. Intuitive configuration of an ASP block for C-to- Hardware synthesis. All !uii Liuiiicrtrr Summei IHJ ■ t:\Pr uumiHuriHliuin Unquiet Sviiiini 03U jHnipl»Vfl 4V5K1 iMiripInWpenflui. CHL Jl> t ulnitCHC.JUL ubujSyilem.OiKiiBiRi • IHt _3IH. ube.Pi it ;'i: Lk( lived lo Lfcmse Store HQ. Hot liitped in. . r? X Kltyp yo (ith K»W fcWStf l>Kti ftfrUppi IkkAi IfrV J Ji -i j | * A i.-t | . • ij + •: x-' 1 1 . j IHUI. 1 . , DfrttM J (hCjiKuwjSy««in bF«ync ‘ ~ ■! \ xttwi 14 ^ — n.,.i n "?■= r — . *=i » TWMpWfl 0 =w<*. LMC.DL'ubfl Ffl-w | Pr.ycJ ffi ffeVrw O jili-i Am- I 1 iHif J cite iv .- ljI Skk? Dooiirtn* - _J qc snrn> $ch>k JR1 i_J ^c>tn£: - J LSI I. HUJufer ft* mb - I I IrlnpVi Si mrmi ■ i.fltartraish ijMpspIv Tjfltot h ’qflwsSh ..0 'ore h /Lfl Hsi*e_ 5 ta h ; j itafalh _J DiwuiwnlE ^AtoSPC 3 a] bn*> e : ;0 fart t ^ 0 «riE.t ^ddc J e ( uni iijijii' J,ti> ijWILAM* 3' hip., I ci*tl TI W rm'Hi M r.* !. Si *ij rfv-^VTVJRl At AKPEIttaa — — • r iii-. In Hiiihwrr PllCFCUI MDJ ¥ Gktotveim / AlK«4 ■: Hmhnr * (K-. IKJlfc Ute It* fafawrg to SAStfa a -iijtofc rt>t_DtSi_VSlfc(l V ■vijrlnirtan Vau imi iki Mix ti rfhri h- FPTiA m the Hixfri icr c«k- fevel [|-t _[+:!_►> a ■j The Umeia/to fSf raton tOTtoli Htatttei uy 1 altfi fc^= E rjwrr.*m\ Hi ns-t.i diiit* U>s A5J' Vfi »■ g*oeid<- rhr.jieljct M 1 yi * fta UstA£H'*(m Soitaut Mxflwi iW-Cad. nvray ai Lin tilinzir JiJtrMP ir j4pi. ie- t cht_Dlol_^xl v ' r>ef Ui!«te Hw id dirsHt u* tf wFJa iHiM-arag ASP l^|ic m thrt FPf>A cht_i4ol_3: a E-HtjbLO 1 a itejtojri &i diwvw*! aw hnakdriin hnn M UiD A^P lisp ‘istvurc n □ ri-j n 2^1 FuvJvirk 1: ftwE ntiMA f:T ^1 lr, !m*v,«a ■■■ l "i h»Ak- 1 riv- te* ti lr«« .vi-k#:- buc hwth ll bt^arge- etwutfi to the- pkMMTwAMc ti Hfyi lirvhvi in rtw i ha : lc j m ■ 1 [Jb.t tbv*,,b JEtort E] y yj y a*w_:hs( Adit: : Uik Wdh : 3 t nari nsii«_ii)ii jc-uii__urca 9a*kM._rr#f SRAM |Y«MUb IIjBJUII DiOLDA GpPI0O_MDP *Z.u*m(irA^d* RAMj iJ,p-i,lil_9 *rM' uai Ul iUOt, bad f.-tip rp-:«V: vadf. PIEIM| drtflW 2JIT Dimiou.MO VMlttWjXK# e-00W_W43e £« mQj&m AtSflAS_»Sfl Nhm ■A5*-n M r 3. ran 44 (MOOOOW 0*290X1 VtibbH Ml 1 1»»J MajSfKid •mb cm ■ ra (kiusiwi OT kUdflpRtfi it. hrii«'L ?9U*. MQU FI AJ.-.t-'A.-jV ***• (ir.f Jrq fPS*. ' 1 W I I Cred I ASP to indicate where the values of the function param- eters are stored. The ASP block is easily configured via a dialogue box (Fig- ure 4). A list (upper right) allows the designer to specify which global variables are implemented in ASP block RAM. Access to this memory, internal to the ASP, is many times faster than access to memory which is also directly visible to the processor. A further list (lower right) lets the designer select which C functions are implemented in hardware and which in software. Rotating 3D cube Now we shall see how these ideas fit together using a dem- onstration example where we show a three-dimensional rotating cube on the NanoBoard's TFT display. To enter the example system design into Altium we use the 'OpenBus' editor. The components needed to construct the system are selected from a list and then placed and con- nected together; all this can be done without needing to worry about the nitty-gritty of implementation. The C source code is then entered using the integrated edi- tor. Altium Designer includes a compiler, linker and debug- ger for the TSK3000 (a 32 bit RISC processor) as well as a range of other 8 bit and 32 bit processors. When the individual components have been created and connected together the system can be configured using the corresponding forms. This includes the ASP configuration form described earlier as well as (for example) facilities for setting the address ranges occupied by various periph- erals and the quantities of internal and external memory available to the processor (Figure 5). The memory map is displayed graphically, and any change made is auto- matically propagated to the embedded software project. This is one of the advantages of an integrated development environment. 62 elektor - 2/2009 The C program can be tested and verified in real time using the Nano- Board. The resources avail- able on the NanoBoard and the interfaces to the FPGA daughter board are selected using special sym- bols from a supplied library, and connected to the FPGA circuit in the overall circuit diagram (Figure 6). For our 3D cube examp e we need to represent the TFT panel, the clock and reset signals, a LED display and two SRAMs. The document describing the FPGA cir- cuit is wired into the sche- matic in a hierarchical fash- ion using an automatically generated symbol to rep- resent it. It is connected to the resources of the Nano- Board in the overall circuit diagram. Chocks away! When the system specification is complete the build process can be initiated (Figure 7 shows the so-called 'cockpit'). The build process takes place in four steps. First, the C-to-Hard- ware synthesis step takes the selected functions and compiles the corresponding C source code. The subsequent steps (RTL synthesis, placement and routing) then create a binary con- figuration file suitable for programming the FPGA. The C program can be debugged by the design software using the so-called 'soft JTAG chain' while the program is running in the processor core implemented in the FPGA. In our example the buttons arranged below the TFT panel allow the user to choose whether or not the C functions syn- thesised into hardware are used to compute the individual frames of the 3D cube display (Figure 8). A test shows that the processor working on its own can man- age to compute around 2.7 frames per second. Using the ASP (that is, with the speed-critical functions implemented in hardware , the system runs around ten times faster, at approximate y 28 frames per second. ( 080625 - 1 ) NanoBoard Alongside the Altium Designer development soft- ware, which provides an environment for circuit design, the development of embedded software and the design of FPGA-based systems, Alti- um also offers a reconfigurable hardware plat- form called the 'NanoBoard' (http://www.altium. com/products/thenanoboard). A selection of plug-in peripheral boards supports a wide range of I/O and other hardware functions. Using swappable daughter boards various FPGAs and processors can be tested in the early stages of prototype system development. Figure 7. Altium Designer's Devices View, the 'cockpit' for the build and real-time verification process. Figure 8. Using C-to-Hardware synthesis can give a factor of ten increase in speed! 2/2009 - elektor 63 TECHNOLOGY PC PROGRAMMING Sharp PC programs using .NET and C# Part 1 Veikko Krypczyk (Germany) Electronics people often need to write short PC programs, for instance to evaluate test and measurement data. Windows PC users will find the .NET Framework particularly handy for this task. It works with various languages, eliminates most of the burden of programming and doesn't cost a penny — not even the development environment. Here's a basic introduction to the C# language and its many advantages. Today's electronics enthusiasts increasingly need to be soft- ware developers as well. An obvious situation is program- ming microcontrollers. Frequently the need arises for a short program written from scratch, perhaps for outputting con- trol data to an interface card or for displaying measure- ment data on screen. Alternatively, an existing program may need to be adapted or expanded. Software development is to a large extent bound up with the target platform and the operating system. In this series of articles we shall be looking at the development of pro- grams running under Microsoft Windows XP and Vista. The underlying foundation is a runtime library that goes by the name of .NET Framework (pronounced 'dotnet'), which is supplied with Vista and is offered gratis as a retrofit for XP. Anyone using older versions of Windows need not go away empty-handed, as the support pages of Microsoft may offer a solution. Finally, it's well worth mentioning that an Open Source version of the .NET Framework has appeared in the meantime and this so-called 'Mono' framework [1] even runs on Linux computers! Classes as programming modules The introduction of the .NET Framework brought a signifi- cant change to software development for Windows. Greatly simplified, we're talking about a powerful library of Base Classes, offering a wide variety of 'oven ready' approaches for setting problems and getting answers, saving program- mers a mountain of work. In the process the .NET Frame- work has averted a lot of long-winded discussion about the 'best' programming language. The choice of language has become a secondary consideration, as the Base Classes provide this themselves, and a common type system exists. Regardless of the language of the source code, a program is always translated into the same 'intermediate' code, which is subsequently executed by the .NET run-time envi- ronment (more correctly, it is recompiled when the program starts). The use of this 'Common Intermediate Language' brings with it security advantages and also enables pro- gramming that is substantially independent of the operating system. Porting across involves no more than changing the (lean) runtime environment. Variants of C from Microsoft For the.NET Framework there are languages like Visual Basic for .NET (from Microsoft) or Delphi for .NET (from Embarcadero Technologies). An overview of the languages compatible with the .NET Framework can be found for example at [2]. These two languages mentioned have been merely adapted for .NET (VB.NET is certainly not completely compatible with classic VB, although VB6 source code is fairly simple to adapt). On the other hand C# (pronounced 'C Sharp') has been developed by Microsoft from scratch specifically for the task. The complexity of the C and C++ languages, with their heavy learning curves, finds no place in C#. For example, pointer arithmetic (relished by few programmers) has fallen by the wayside. On the other hand, plenty of effective and user-friendly concepts from other languages have been incorporated. And another thing in favour of this variant of C: there exists an extremely compact .NET Framework for programming microcontrollers, which even includes a gratis compiler, in fact for C# [3]! Understandably this two-part mini series cannot be a com- plete training course on C# but it may well encourage read- ers like you to get deeper involved with C#. In this first 64 elektor - 2/2009 Some language concepts of G# Some of the language elements in C# may be familiar from other programming languages. All syntax questions can be resolved using the online help pages at [6]. 1 . C# treats upper and lower case letters as different, so the variable 'total' would be handled differently from the vari- able 'Total'. 2. Single-line comments are started with //, whereas /*...*/ indicates a comment with several lines of text. 3. Important fundamental data types include: byte, int, float, double, decimal and string. 4. Variables are declared and initialised by prefixing the data type: int Total = 5; string text ="one character string"; 5. Basic operators: +, -, *, / 6. The flowing loops exist: for, while, do and foreach. The last- named iterates for example Objects assembled in listings (Collections). 7. Selection instructions are: If, else if, else and switch (...) case. 8. User-defined data types are declared with the keyword 'struct' (user-defined Classes are introduced with Class): struct Dataset { int Alter; string Name; } part we shall develop a small program with the help of the Visual Studio development environment, which is free to download. The second part will take us into object orienta- tion, the foundation of the.NET Framework and 'made with C#'. Our practical example from the realm of 2-D graphics will create an application that should be particularly inter- esting for electronically-minded people. Debug I Debugging using the green arrowhead on the symbol tool bar, see Figure 2). Initially the application contains just an empty window. Nevertheless the neces- sary functions of a Windows application are already imple- mented. So you can for instance shift the window around the screen, minimise or close the application using the sys- tem menu. And off we go! To get developing, the first thing we need to do is make sure our computer is set up with everything we need. The only new item absolutely necessary is a C# compiler for trans- lating the source code and as a bare minimum an editor can suffice for compiling the code. Far more practical and convenient, however, is a dedicated tool for the job, the Integrated Development Environment or IDE. Here you have basically two options. The first is a Microsoft offering, its so-called Express editions of Microsoft Visual Studio, avail- able as a free download. The functional capability is some- what restricted compared with the professional versions but this should not cause any problems on small to medium- size projects. Express editions are available for each of the languages C#, Visual Basic for .NET and C++. For Web development there is a further tool available, Visual Web Developer Express. For our mini-series Visual C# Express in the 2008 Version is the correct choice. Information on the products mention and downloading details are all at [4]. A free Open Source alternative is Sharp Develop [5], which also enables programming in C# (among other languages). This option requires you to have the .NET-Framework SDK (Software Development Kit) already installed. Your first program To create our first application, we need to boot up Microsoft Visual C# 2008 Express Edition. You will be greeted by this development environment's start page, which among other things enables you to open the last project you worked on. To start a new project click on File I New I Project.... Out of the options offered select 'Windows Forms Application' (Figure 1). Your second task is to select a name for the project. After confirming with OK the IDE produces a frame code for this application. The result is displayed immedi- ately on your screen. You can confirm that this is already a complete application by making a first test run (start menu Figure 1. Constructing a Windows application (frame code) simply using the wizard. Forml.ts [OeskjTiJ r 1 O CT O X Figure 2. Starting an application in the development environment's Debug mode. 2/2009 - elektor 65 TECHNOLOGY PC PROGRAMMING Figure 3. Editing an Object's characteristics in the Properties window is a breeze. • three labels for the legend (descriptions); • a button to start the calculation. With the help of the IDE the formation proceeds apace. Call up the Toolbox (Appearance I Toolbox in the active form. Now you can select the elements of the panel using the mouse and place them on the form. There are guide lines to help you get everything neat and tidy. Once an element has been installed on the panel we can edit its characteristics (Properties). This is done with ease using the Properties win- dow (press the F4 function key for the Object highlighted). For example, we have assigned the tag 'textboxN umber' to the first text field's Property 'Name' (Figure 3). Figure 4. The first (extremely simple) application in action. L Ending the application reverts to the development environ- ment, enabling us to expand the template with the first ideas of our own. So here's a simple example of how this can be done, gathering and adding together two figures to produce an output of the result in a text field. We'll start with creating the top-level information panel for the user. We require: • three text fields for the figures and the result; Source code for the Button Ftaving designed the user panel it's time to start producing some code. The calculation needs to be performed when the corresponding button is clicked. A mouse click on this button while the program is running produces a so-called click event. It's the programmer's task to assign appropri- ate source code to events of this kind so that the code is then executed (in this case the addition of two numbers). To assist programmers the IDE produces the frame code automatically for the click event of a button, if the button is double-clicked during the development process. Inside the frame code we now enter: float numberll = float.Parse(textBoxNumberl .Text); float number2 = float. Parse(textBoxNumberl2. Text); float result = numberll + number2; textBoxResult.Text = result.ToString (); First the values of the text box (the type being a character string) are read out and converted into a number. This takes care of the Method 'float.Parse'. The addition follows next and finally the result is passed to the text box named 'text- BoxResult'. Described more accurately, the text box then displays the value of the result if the value 'result.ToString' is Activating interfaces Electronics people may be wondering how they would control the computer interfaces their hardware is connected to. Par- ticularly when a fundamental security principle of .NET (for desktop computers) states that interfaces cannot be activated directly by the application program. C#- or VB.NET applications tend to access the corresponding Windows driver and in most cases this must first be installed. With off-the-shelf hardware (including most test gear) this is generally supplied by the manufacturer. Programming a driver tends to be hardware-specific and un- der Windows C + + would be a good choice. For reasons of space we cannot go deeper into driver programming here. However, here is a small example of how an existing driver is called up. In this case it's for a parallel port interface, which is used in many hook-ups on account of its simplicity. This sample application is by Levent Saltuklaroglu [8] and uses the well-known driver inpout32.dll, which can be downloaded for free [9]: using System; using System. Runtime. InteropServices; public class PortAccess { [Dlllmport ("inpout32.dll", EntryPoint= "Out32")] public static extern void Output(/nf address, int value); } The Using directive incorporates important Base Class librar- ies. Access to the driver is encapsulated in a user-defined Class named PortAccess. This is where the 'Output' Method is defined with two parameters (parallel port address - for example decimal 888 for LPT1 together with the value to be output). The parameters within the Class are passed to the Out32routine of inpout32.dll, which finally places a byte at the parallel port. After implementing the Class it is easy to export data from the C# application program, for example using: PortAccess.Output(888, 255); Using the serial interface is even easier. Versions 2.0 onwards of .NET Framework provide the Class System. lo. Ports. Serial- port, which allows you to address the serial interface, without even involving a .dll file. Information on this is in the online documentation [10]. 66 elektor - 2/2009 delivered to its Property 'Text'. As you can see, we can alter the information panel's Properties both during the develop- ment process (as we have just seen) and from inside the program. These are indicated in the code following the name of the information panel with a dot and the name of the Property, for example, (textBoxResult.Text). So that the result of the test box (a floating-point number of the type Float) can be displayed, it must first be converted into a character string. To do this in the code we need to indicate the name of the Variable Result, followed by a dot and the name of the Method (ToString). To understand how to set the Properties and application of Methods of the Object 'textBoxResult' of the Class 'Textb' you do need some prior experience of object-oriented programming. Sorry, but it has to be like this, since object orientation is at the very heart of C# (and VB.NET). It's not only the top-level elements but all the variables that are objects! The next steps... After starting an application, the result should look like Fig- ure 4. If you feel like it, you could carry on programming such as a pocket calculator handling all the main types of calculation, which shouldn't be too difficult to turn into reality. If you are now taking a shine to C#, you should find plenty of technical literature in any decent bookshop, both at 'Dummies' level for newcomers and more advanced tomes for seasoned users. There are significantly more books on C# than for VB.NET (and classic VB, which VB.NET is increasingly supplanting). In developer periodicals and on the Internet, problem solutions in the .NET world are being written almost exclusively in C#. As already mentioned, the .NET programmer doesn't have to do all the work himself but can serve him/herself in a gigantic .NET Class library (all Objects are arranged in 'Classes' that determine which type of Properties and Meth- ods an Object has). There is also online documentation from Microsoft that you can use as a reference work at [6]. Assistance is also available in an offline version as part of Visual Studio (warning: this is extremely comprehensive!). For each Class, the help file shows all the elements (Meth- ods, Properties, Events) (Figure 5). Frequently, a sample application is given as well, structured according to the con- stituent programming language. Since there are frequently several ways of calling the Methods of a Class (so-called Overloads), a glance at the documentation is often abso- lutely necessary. So, for example, the 'Show' Method of the Class 'MessageBox' for displaying an information window) includes a total of 20 (!) call conventions. These vary in the parameters by which the calls must be passed. When you are inputting source code the 'IntelliSense' fea- ture of the development environment (Figure 6) can also be extremely helpful. As an example, when you are enter- ing the name of an Object in a specific Class, all the Prop- erties and Methods are indicated interactively. In the second part of this series we will make a quick inspec- tion into object-oriented programming. A section on 2-D vector graphic programming provides a practical task. Source code for the examples can be found on the Elektor project page [7]. ( 080668 - 1 ) , 3 K -1 Shew Mrfhod Ufc rm-hrip lMSDNQIR.*®. mlirri ‘edrtn. ► C-lkJc: tl" ► Ho-nMra: 5 huw AH W! MessageBon.-StiGW Mettwd rHniDi-it'.x 'LIiij Set Afafi jcii r-ctrlLni a htettMKBoi mytf'od Mfliptc LViVf J cihpwiIi^i HJUti Jliui inuiiH^n VL'lichild I ih [ H'i-ir Mctwqrt 45 ;:efi *&*■>** nunintafi Mru#^fleiOpbwri! empnemtayn Iki rf ’ *’ ibmi! Mnu^rfkiPM'iTTHim i Lm renfriKlpf piqptfbH MTwtm Ikri cm pdMrty property prepertj' hArvugcflcrf'*' «mr 1 m Ht+f^ jib properly 1 An-ugrf n i> j ’ ■ m ri ir- !. H ri p 1 c-p*: Id pr Mw ai&M iJTtfftfinJrpn pi£»pFfty Sh aw tSirafla * H a rfBi ra fl . & t 3 ♦ 5 4 6 * s « s * s Dew ripflrori frnc^cn.-* a mnupr box IKcrf Dffisiays a mesupe My Sha-I5irnj. a»ma. StswrlWiniJew. jlts-hl StnnaS StHtrfSinmL ftlHH, hteiHotB:.' !'”■:■ w ’ b'wmiW'.nitew. SB mu. Stoma. HcvMOiBflnlMtscU SfsnriStorai. Stoma. HcraiacDauBJlBri. Hnu* frMlirjiie. J---: C 1 HjrwiU jJVrefTHWrisw- artM. Swing. mamtaftaia. Dtioidp'i a mtssajt m J '.: fl : : ■ i : b pi* isaj« if«3 ret. ■' D ll'll! B TWEUgW' ks IhK rtr. ns ireht fM.plA.-t » nw-c«ii»- lac'i .ft (ID V Hid ln^- m mnjutn m Kg • rrmcMO*.. I «• bar t IJnsioCT I JltfMtpt h” ih* ■« L-ftal ■ OriMuT. inf Figure 5. The Help system provides a comprehensive reference work for the Base Classes. iid buctonl_Click (ob]5'jr sender. EveniArgi e)_ t l tun b uf 11 = 1 log L _ Carve I i number^ f Lnat .Pa L'Se ( T:eut.H£>KWi]m>fe r 1 > Xefci [nde^CTi v~ . i ] result numbeLrll + number^; / y liiytBp ixEesult .Text = result .Tost r in# () : ' ^J_ ^ Trxr.hiyn Te.vW.5tgnCh3ni^d TeMBChangsd re^;ELiy^th K'A.Teia . tiis fj BTfiril - next n rhp System nii^. 1 Figure 6. Interactive support for programmers with the help of 'IntelliSense'. Internet Links and Further Reading [1 ] www.mono-project.com/Main_Page [2] http://dotnetframework.de/dotnet/produkte/sprachen.aspx (all onward links are in English) [3] www.elektor.com/080450 [4] http://www.microsoft.com/express/product/default.aspx [5] www.icsharpcode.net/OpenSource/SD [6] http://msdn.microsoft.com/en-gb/vcsharp/default.aspx [7] www.elektor.com/080668 [8] www.codeproject.com/KB/cs/csppleds.aspx [9] http://logix4u.net/ [10] http://msdn.microsoft.com/en-gb/library/system.io.ports. serialport.aspx See also Wikipedia (http://en. wikipedia. org/wiki/C_Sharp_(pro- grammingjanguage)) for other background on C#. Also the tutorial on programming in C# at http://www.java2s.com/Tuto- rial/CSharp/Cata logCSharp.htm About the author Veikko Krypczyk studied Business Information Technology. An enthusiastic programmer, he has been involved with C# and the .NET Framework for several years. His special interest is in application programming and the development of 2-D graphics applications (you can follow up his current project at http://easy-grafiker.de/cms/index.php and select the English menu). As an electronics hobbyist he cannot resist picking up his soldering iron now and again to try out interesting projects. You can e-mail Veikko at veikko2000@yahoo.de. 2/2009 - elektor 67 INFO & MARKET EMC GUIDELINES EMC DIRECTIVE From 1 January 1996, home-made equip- ment must take into account emc Directive 89/336/eec (emc = ElectroMagnetic Compatibility). Basically, the directive states that no equipment may cause, or be susceptible to, external interference. Here, interference means many phenom- ena, such as electromagnetic fields, static discharge, mains pollution in the widest sense of the word. Legislation Home-made equipment may be taken into use only when it is certain that it complies with the directive. In the United Kingdom, the dti (Department of Trade and Industry) will, in general, only take action against offend- ers when a complaint has been made. If the equipment appears not to comply with the directive, the constructor may be sued for damages. ce label Home construc- tors need not affix a ce label to their equipment. 965001 - 1-52 Elektor Electronics and the Directive The publishers of Elektor Electronics intend that designs published in the magazine comply with the directive. Where neces- sary, additional guidelines will be given in the article. However, the publishers are neither obliged to do so, nor can they be held liable for any consequences if the con- structed design does not comply with the directive. This column gives a number of measures that can be taken to ensure that EE-designed equipment complies with the directive. However, these are needed only in some designs. Other measures, particularly in case of audio equipment, are not new and have been applied for some time. Why emc? The important long-term benefit for the user is that all electrical and electronic equipment in a domestic, business and industrial envi- ronment can work harmoniously together. Radiation The best known form of emc is radiation that is emitted spuriously by an apparatus, either through its case or its cabling. Apart from limiting such radiation, the directive also requires that the apparatus does not impart spurious energy to the mains — not even in the low-frequency range. Ferrite through-filters as illustrated are used for feeding cables through a panel. Immunity The requirements regarding immunity of an equipment to emc are new. Within certain limits of ambient interference, the apparatus must be able to continue work- ing faultlessly. The requirements are fairly extensive and extend to a wide range of possible sources of interference. Computers Computers form the prime group for appli- cation of the directive. They, and micropro- cessors, are notorious sources of interfering radiation. Moreover, owing to the way in which their internal instructions are carried out sequentially, they are also very sensitive to interference. The notorious crash is but one manifestation of this. Enclosures A home-made computer system can comply with the emc directive only if it is housed in a metal enclosure. A minimum requirement is that the underside and rear of the enclosure is an l-shaped frame. All cabling must con- verge on this area or be filtered. If there are connectors on the front panel, a u-shaped metal frame should be used. Even better results are obtained if a 20 mm wide, 1 mm thick copper strip is fixed along the whole width of the rear wall with screws at 50 mm intervals. The strip should have solder tags at regular distances for use as earthing points. A closed case is, of course, better than an l-shaped or u-shaped frame. It is important that all its seams are immune to radiation ingress. Power supplies In any mains power supply, account should be taken of incoming and outgoing interfer- ence. It is good practice to use a standard mains filter whose metal case is in direct contact electrical contact with the enclosure or metal frame. Such a filter is not easily built at home. It is advisable to buy one with integral mains entry, fuse holder and on/off switch. This also benefits electrical safety in general. Make sure that the primary of the fil- ter is terminated into its characteristic imped- ance — normally a series network of a 50 Q, 1 W resistor and a 1 0 nF, 250 V capacitor. Mains transformers must be provided with rc-networks at the primary and second- ary side. Bridge rectifiers must be filtered by rc-networks. The peak charging current into the reservoir capacitor must be limited by the internal resistance of the transformer or by additional series resistors. It is advis- able to use a 250 V, 2 W varistor between the live and neutral mains lines. At the second- ary side, it is sometimes necessary to use a transient suppressor, preferably following the reservoir capacitor. If the supply is used with digital systems, a common-mode inductor in the secondary a.c. lines may prove beneficial for limiting radiation. For audio applications, an earth screen between primary and secondary is advisable. This screen must be linked via a short wire with the earthing strip. The supply must be able to cope with a mains failure lasting four periods and with mains supply variations of +10% and - 20 %. Peripheral equipment and earthing All cables to and from peripheral appara- tus, such as measurement sensors, control relays, must be fed through the metal wall of the enclosure or frame. The earth lines of such cables must be connected directly to the earthing strip at the inside of the enclo- sure or frame via a wire not longer than 50 mm. When plugs are used, the cable earth, if any, must be connected to the earth pin or the metal surround of the connector. Basically, all non-screened signal lines must be provided with a filter consisting of not less than a 30 mm ferrite bead around the cable or bunch of wires. This bead may be outside the enclosure (for instance, around the pc-to-monitor cable). Leads that may have a resistance of 150Q must be provided with a 150Q series resistor at the inside of the connec- tor shell. If technically feasible, there should also be a capacitor from this point to earth. Commercial feed-through t-filters or 71 -filters may, of course, be used. In all other cases, screened cable must be used for connec- tions within the enclosure. Symmetrical lines must consist of twisted screened cable and be earthed at both ends. The earth plane of printed-circuit boards must be linked as firmly as feasible with the earthing strip, for instance, via a flexible flat metal strip or flatcable. Electrostatic discharge (esd) All parts of an equipment that can be touched from outside must preferably be made from insulating, antistatic material. All parts that can be touched and enter the enclosure, such as potentiometer and switch spindles, must be earthed securely. All inputs and outputs whose wires or connector pins can be touched must be provided with an earth shield, for instance, an earthed metal sur- round via which any electrostatic discharge are diverted. This is most conveniently done by the use of connectors with sunken pins, such as found in sub-d connectors, and a metal case. Audio equipment Immunity to radiation is the most impor- tant requirement of audio equipment. It is advisable to use screened cables through- out. This is not always possible in case of loudspeaker cables and these must, there- fore, be filtered. For this purpose, there are special high-current t-filters or 71 -filters that do not affect bass reproduction. Such a fil- ter must be fitted in each loudspeaker lead and mounted in the wall of a metal screen- ing box placed around the loudspeaker connections. Low-frequency magnetic fields Screened cables in the enclosure do not provide screening against the low-frequen- cy (< a few kHz) radiation of the mains transformer. Therefore, these cables must run as close as possible to the walls of the enclosure. Moreover, their braid should be linked at one end to the earthing strip. In extreme cases, the power supply should befitted in a self-contained steel enclosure. Special transformers with a shading ring that reduce the stray field can lower the hum even further. High-frequency fields High-frequency fields must not be allowed to penetrate the metal enclosure. All exter- nal audio cables must be screened and the screening must be terminated outside the enclosure. This again necessitates the use of all-metal connectors. All cable braids must be linked to the earthing strip inside the enclosure. Owing to the skin effect, it is important to choose an enclosure with a wall thickness >2 mm to ensure that internal and external fields are kept separate. Any holes must be either small (<20 mm) or be covered with a metal mesh. Heat sinks Heat sinks should preferably be inside the enclosure and be earthed at several points. Non-earthed heat sinks in switch-mode power supplies often create problems. If possible, place an earth screen between Standard mains filters built into a mains entry together with an on/off switch. The metal shell must be in firm contact with the enclosure. transistor and heat sink. Ventilation holes must be covered with metal mesh unless they are smaller than 20 mm. Ventilators should be fitted inside the case. Cables Cables often function as transmit/receive aerials. This applies equally well to screened cables. The braid of a coaxial cable must be terminated into a suitable connector such that it makes contact along the whole cir- cumference. The braid may be used as the return path to obtain r.f. magnetic screen- ing. For a.f. magnetic screening it is better to use twisted-pair screened cables. In a rib- bon (flat) cable, each signal wire should be flanked, if at all possible, by earthed wires. The cable should be screened along one surface or, preferably, all around. Cables that carry signals >10 kHz that are not fil- tered in the enclosure, must be provided with a ferrite bead functioning as a com- mon-mode inductance. Printed-circuit boards Elektor Electronics printed -circuit boards are provided with coppered fixing holes that are connected to the earth of the circuit. This arrangement, in conjunction with metal spacers, ensures good contact between the board and the circuit earth. Where this is important, boards have a special earth plane that can be connected, where fea- sible, to the earthing strip via a flatcable. These boards normally have no other earth- ing points and their fixing holes are, there- fore, not coppered. (960006) T-filters and k- filters ensure that interference cannot em te from, or enter, the equipment via signal lines. They are available in various cur- rent ratings and for various frequency ranges. 68 elektor - 2/2009 MINI PROJECT PRO Ton Giesberts (Elektor Labs), from an i dea by Karl Odenthal (G erman These days tiny FM radios are often integrated in many portable devices such as mobile phones and MP3 players. But why not make a simple receiver ourselves? There are currently several nice ICs available that contain a (nearly) complete receiver. For this project we cast our eye on the TDA7021T from ST-NXP Wireless (for- merly a part of Philips Semiconduc- tors), an IC that is well over 20 years old, but is still readily available. Good designs, apparently, have a much longer life than many modern ICs of which a new version seems to appear every few months. This project is a complete receiver cir- cuit with excellent receive and sound qualities. The only disadvantage of using this IC, from the DIY enthusiast’s perspective, is the fact that it is only available in a 16-pin SMD package. To make the construction easier we designed a small printed circuit board for this project. And to ensure that the completed circuit would be quite compact, the remainder of the circuit is also built using SMD parts, most of them 0805 size. The dimensions of this tiny PCB are only 3.2 x 2.7 cm! The circuit contains no difficult coils, only the VCO requires an air-cored inductor with only 4 turns. Inner workings Figure 1 shows a block diagram of the internals of the TDA7021T. This is a (nearly) complete integrated receiver circuit which has been specifically designed for portable radios and the like, requiring only a minimum of exter- nal components. As a result the final dimensions of the radio can be kept very small. The IC uses a frequency-locked-loop (FLL) system with an intermediate frequency of 76 kHz. The selectivity is obtained with the aid of active RC filters. The only ‘calibration’ adjust- ment in the circuit is the resonance frequency of the oscillator (for the tuning). The RF signal enters at pin 12 and is amplified first, after which it is trans- formed down by the mixer and passes through two IF filters. It is subse- quently limited in amplitude. The IF limiter also supplies a signal for the optional signal strength indicator (via pin 9). The limited FM signal then goes to the demodulator and the correlator which decides whether the signal is tuned in properly. The demodulated 1/2009 - elektor 69 MINI PROJECT flfM MUX Ail KF •fKji adVNLh Figure 1. The internal design of the TDA7021T. are entirely available. This is also the reason that it is not recommended to connect the audio output directly to the line input of an audio system. Circuit The complete circuit for the FM receiver is shown in Figure 2. The design is vir- tually identical to the test circuit shown in the datasheet for the IC, because this is difficult to improve even a little without adding a lot of additional elec- tronics. Now we only need a few resis- tors and capacitors plus a coil. In Figure 3 you can see the little PCB that we designed for this receiver. As mentioned earlier, SMD parts are used everywhere to keep the dimensions as small as possible. Soldering these small parts requires a bit of practice however. We have already explained how to deal with SMD components on several occasions in earlier issues of Elektor. For example, have a look at the articles ‘SMDs? Don’t panic’ in the January and February 2003 issues. signal now passes through a loop-filter and a mute controller and then finally arrives at the audio output amplifier. The output of the loop filter also gen- erates a control signal for the oscillator (VCO), which together with the exter- nal resonance network provides the tuning function. For mono audio, the output amplifier delivers enough power (via a resistor) for a set of small earphones. You can, however, also connect a decoder to this output to generate a stereo signal. The output signal on pin 14 is not limited in frequency, that is, both the 19-kHz pilot signal as well as the L-R signal Practical matters Moving on to a few practical instruc- tions for the construction: The inductor for the VCO is an air-cored coil with 4 turns. It is best if you use silver-plated wire for this. The easiest way is to wind 4 turns on a 4-mm drill and then stretch the coil slightly until the ends of the coil line up exactly with their respective mounting holes in the PCB. Place the coil a few millimetres above the board, so that you can easily adjust it slightly later on (by stretching or compressing) so that the tuning cir- cuit correctly covers the entire VHF FM broadcast band from 88 to 108 MHz. Tuning is done with trimmer capacitor C5. This does however require a small screwdriver and a little patience, but you generally tend to listen to one and the same radio station anyway. If you want, you can optionally (con- nected with wires as short is possi- ble) replace the SMD trimmer capac- itor with a proper tuning capacitor. Make sure you obtain the correct tun- ing range. This should be possible by changing the value of C4 and perhaps adding a series capacitor for C5. All connections to the board are made with 2- way pin headers, to which you can connect your own choice of con- K1 V R3 L2 l BT1 3V luH C11 In R2 T C14 47 u 10V CD C16 C15 C13 lOOn 3n3 220p in CO CM C12 R1 CIO rlli n 1n5 O a> IC1 TDA7021T C3 lOn CM Cl lOn C2 lOOn C6 lOOn m C8 820p C7 1n5 C4 33p' C5 25p LI 36nH 080556-11 Figure 2. The complete receiver consists only of the IC and a few passive components. 70 elektor - 1/2009 nectors. For the earphones you could use a stereo 3.5-mm jack socket, for example (with the L and R terminals con- nected in parallel). The output of the IC supplies sufficient power to drive several 32-Q earphones directly. A 390-Q resistor is connected in series with the output to prevent a short circuit of the output and prevent potential problems with longer screened cables. Because of this, resistor the output capacitor C14 can be kept quite small. There is also a connection (K2) for a simple signal strength meter. Via resistor R1 and decoupling capacitor C9, pin 9 supplies a DC voltage which is a measure of the received sig- nal strength. At 170 /JA the out- put current is too small to drive an LED, but you could connect an ‘old fashioned’ moving coil meter. For the antenna you can use a simple wire antenna of about 75 cm long, which is soldered directly to the PCB. Considering that the current consumption is only 6.3 mA, the circuit is eminently suitable to be powered from bat- teries. We decided to use two penlight (AA) cells here, but even using a lithium cell for the power supply will give nearly 20 hours of running time. It is also possible to use a mains adaptor. But note that the power supply voltage for the IC has to be between 1.8 and 6 V (most defi- nitely not higher!). Finally This receiver is, to be sure, a mono implementation, but at the output (as already men- tioned) the entire multi- plexed signal (up to 53 kHz) is available. By using a PLL stereo decoder, such as the TDA7040T, a stereo signal can be generated in a straightforward way from the output signal of the TDA7021T. We will describe this circuit in a future mini project. ( 080556 - 1 ) Advertisement Figure 3. The receiver can be built on this tiny circuit board. COMPONENT LIST Resistors (SMD 0805) R1 = 8kD2 R2 = 1 OkD R3 = 390D Capacitors (SMD 0805) C1,C3 = lOnF C2,C6,C9,C16 = lOOnF C4 = 33pF C5 = 25pF trimmer (Murata type TZB4Z250AB1 0R00) C7,C1 0 = 1 nF5 C8 = 820pF Cl 1 = InF Cl 2 = 68pF Cl 3 = 220pF Cl 4 = 47jL/F 10V (Nichi- con UWX1 A470MCL1 GB 5.5mmL chip type) Cl 5 = 3nF3 Inductors LI = 36nH (4 turns 0.5mm silver-plated wire, inside di- ameter 4mm; length 7mm) L2 = 1 yuH, SMD case 0805 (fres > 300 MHz) Semiconductors IC1 = TDA7021T (SMD in SOI 6 case) Miscellaneous K1 ,K2 = 2-way pinheader BT1 = 2-way pinheader + battery holder for 2-4 AA batteries Are 5,000 components too many for you? Just order the 580 your production run actually needs *iiifl 4 *ii 4 ii«vi«ti|*ivil 91 llt i RS Production Packaging rswww.com/electronics 08457 201201 2/2009 - elektor 71 MODDING & TWEAKING Opacity Measuremen Jose Luis Basterra (Spain) Opacity is a measure of impenetrability of objects or substances to radiation. Here, we are concerned with light, specifically within the spectrum visible to the human eye. In this month's instalment of the Modding & Tweaking series, we examine how the PC can do paper opacity measurements for us — all experimentally and on a budget of course! The (simplified) relative sensitivity curve of the human eye shown in Fig- ure 1 tells us that he eye is more sensi- tive to green light than to yellow. In order to be able to measure the vis- ual opacity we ideally need a photode- tector whose spectral sensitivity is sim- ilar to that of the human eye. A com- monly available photodetector like the BPW34 has good sensitivity within a part of the spectrum perceived human eye, although its response curve is dis- similar, see Figure 2. The response also depends on the type of light with which the object is illumi- nated. If we use a yellow LED we can look forward to an emission distribu- tion roughly as in Figure 3. The use of a yellow LED as the light source causes the detector to see the yellow part of the spectrum only, result- ing in a better approach of the spectral response of the human eye. The com- parison is illustrated by the graphs in Figure 4 and Figure 5. Possibly, the Figure 1. Plot human eye sensitivity as a function of light wavelength and you get a graph like this. use of mixed yellow and green light is even better although the results with yellow only are quite good. The electronics The opacity meter is based on fre- quency variation obtained from an oscillator that’s controlled by the intensity of light detected by a BPW34 photodetector. Figure 6 shows the schematic. The oscillator consists of a NAND gate from a 4093 package. Its frequency (10-100 Hz) is determined by C3 and R3, together with preset PI and the BPW34 (D3) in the feedback circuit. The ‘LCO’ (light-controlled oscillator) output signal is digitized by three more gates from the same IC. The oscillator and the LEDs (one yellow, one red) are powered by a voltage regulator around a 7809. The red LED is an on/off indi- cator and helps to position the reader unit over the paper surface. The circuit of the PC interface is shown in Figure 7. The interface with the computer is by means of the Centron- Figure 2. The response of the BPW34 within the spectrum seen by the eye is by no means flat. ics port and a series of optocouplers; four in the PC817 chip of which three are used. The connections between the circuit and the LPT1 (‘parallel printer’) port on the computer are as follows: Circuit terminal Pin no. on DB25 El 1 (/STR) E2 2 (DO) E3 3 (Dl) GND 25 (GND) The oscillator output signal enters the interface at Jl. The circuit charges a 47 ijF tantalum electrolytic capacitor (Cl) to about 4.5 V, at which level zener diode D2 starts to pass current, illumi- nating the LED in optocoupler IC2. This causes a logic Low at El, signalling to the program running on the computer to stop counting. The process com- prises the following phases. 1. By means of a High level supplied to input E2, the PC effectively blocks the arrival of oscillator pulses. Figure 3. Heavily simplified spectral distribution of light emitted by a yellow LED. 72 elektor - 2/2009 2. With Cl discharged, output El is held High i.e. deactivated. 3. Via E2, the software enables the arrival of oscillator pulses again. Figure 4. Response obtained from the combination: BPW34 + yellow LED. Figure 5. As Figure 4, but for the combination: BPW34 + human eye. 4. The period it takes for the capacitor to charge to 4.5 V and pull El Low rep- resents a time T, which is compared to a table entry in the program in order to determine the relative opacity value. The value so obtained will be a reason- able approach of the actual opacity in the majority of cases. The table stored in the program is calibrated for values of opacity between 78 and 92%. Software This series of articles being free from rocket science, the very simplest form of Basic was used for the control pro- gram. True to the Modding & Tweak- ing tradition, all readers are invited to improve the program, come up with alternatives, perhaps develop code for Linux, C, 32-bit ARM platforms, what have you! Here, only the nitty-gritty is shown to serve as an incentive. The BASIC program was written to measure, store and ‘graph’ instanta- neous and average opacity values of paper sheets. You can download the program as file # 080579-11. zip from the Elektor website. The address &H378 is the base address of printer port LPT1 on the 12-15V dc IC2 - Xo > o PI © IC1 R1 +9V -© R2 C2 ci © Tm Td2 r t I 10n ) __^^red^Jyellow R3 1M IC1.A D3 BPW34 IC1.B IC1.C IC1.D V 3 ■ 5 8 s 10 , 12 & & s 4 , & & ’ 6 ’ 9 M3 C3 lOOn IC1 = 4093 080579- 16 Figure 6. Schematic of the BPW34-controlled oscillator. PC; &H37A is the control register at [base + 2]. The first is used to send commands to the reader interface via LPT data lines DO and Dl, the second, for reading the capacitor charge sta- Figure 7. The PC interface consists mainly of optocouplers connected to Centronics port pins. tus using the /STR (inverted strobe) line (which is bidirectional). ( 080579 - 1 ) Figure 8. Internal view of the opacity reader. Figure 9. The face of the BPW34 photodetector protrudes from a small hole. Figure 10. The PC817 quad optocoupler is by far the largest part in the PC interface. 2/2009 - elektor 73 DESIGN TIPS No Varicap? Try a Schottky diode Martin Ossmann (Germany) Varactor diodes (Varicaps) along with many other exotic compo- nents which are often specified in HF and RF designs are sometimes difficult to obtain and in some cases may even have gone out of production. Not very encourag- ing if you had been planning to build a design that we featured in an earlier edition of Elektor. Anyone finding themselves in this situation may be surprised to learn that help may be on hand from an unexpected source... 400 200 a - 100 o o S 60 80 o CO a. (0 O 40 £ 20 o 10 0.1 Tj = 25° C 0.5 1 5 10 Reverse Voltage, V R [V] 40 60 100 080799 - 12 2 V CTRL R1 O h look \ Any general-purpose silicon di- ode has capacitive properties when reverse biased; the deple- tion region at the PN junction acts as a dielectric. Increasing the reverse bias widens the re- gion, reducing the capacitance. Power engineers are aware that high voltage rectifiers can store high levels of charge at their depletion region. This property is not beneficial in rectification applications but using a little lat- eral thinking and with the motto "It's not a bug... it's a feature" in mind, we can maybe use this characteristic to substitute a di- ode for a varactor. The datasheet of an SB 1 1 00 Schottky power di- ode indicates that at 4 V reverse bias the diode has a "total ca- pacitance" of 1 10 pF, and look- ing at the curve of this character- istic it is indeed proportional to voltage (see Figure 1). To test the idea a simple LC oscil- lator was built (Figure 2) around the crystal oscillator inverter cir- cuit integrated in an AtMega88 microcontroller. The application note AN456 Philips/NXP "Using LC oscillator circuits with Philips microcontrollers' ' [1] is a useful reference here. The finished volt- age-controlled LC oscillator (VCL- CO) actually works surprisingly well. The values of effective small signal capacitance (as measured on a capacitance meter) are giv- en in the Table along with the oscillator output frequency. The next time you are stumped for a varicap, instead of pulling your hair out it would be worth- while taking a look through your collection of power diodes, you may well find something suitable there. ( 080799 - 1 ) ATmega88 XTAL1 3—i XTAL2 9 10 Cl LI II II 2|iH loop D1 C2 C3 SB1100 22p 22p 080799-11 Internet Link [1] Philips/NXP Application note AN456: www.nxp.com/acrobat_down- load/applicationnotes/AN456.pdf Table V ctr , [V] Cef, [pF] F [MHz] 0 125 19.49 1 82 19.70 2 64 20.00 3 54 20.19 4 48 20.34 5 44 20.46 Three-from-four (an control Rainer Reusch (Germany) Most PC-motherboards have mul- tiple connectors for plugging in the cooling fans. These are in- creasingly frequently the four- way connectors. These connec- tors are mechanically and elec- trically compatible with the more common three-way connectors, which carry the power supply and tacho signal. On the fourth connection the motherboard sup- plies a pulsewidth modulated TTL signal, which is used to control the speed of the fan. A separate potentiometer or a temperature dependent speed controller to re- duce the noise of the fan is now really history. But the availability of fans with a four-way plug is still rather limited and these fans are generally also more expen- sive. With the small, additional circuit that is proposed here, it nevertheless becomes possible to use these cheap and ubiqui- tous fans with their three-way connectors. The transistor T1 , the Schottky di- ode, the inductor and the capaci- tor C2 are, just like the 'old-fash- ioned' speed control circuit, con- nected in series with the fan. A reasonably clean power supply voltage for the three-wire fan is generated from this PWM signal — and with good efficiency, we may add. The tacho signal gen- erated by the fan is routed direct- ly back to the motherboard. Building the circuit is not difficult. The capacitors must have a volt- age rating of at least 16 V and the inductor has to be able to handle a minimum of 200 mA. Obtaining the right four-way plug with the necessary crimp contacts could be a bit of a problem how- ever. As an alternative you could use the sockets that are designed to mate with the common pin- headers (2.54 mm pitch). If you decide to use these you will have to be careful and make sure you do not plug the connector in the wrong way around! ( 080377 - 1 ) 74 elektor - 2/2009 STU-UK-1 iscount! Software buijdt Secure a head start in electronics with a Student Subscription!* *Only available in UK. Ask for the conditions. [ Advantages to subscribers Students qualify for a discount of no less than 20% compared to the normal price of an annual subscription Subscribers get up to 40% discount on special Elektor products No queues, travelling, parking fees or ‘sold out’ Elektor is supplied to your doorstep every month Always up to date - read your copy before everyone else Electronics at all the right levels “Elektor is substance for professionals and those wanting to reach the level. The perfect entry to my studies!” Christian, 19, freshman - www.elektor.com/subs • Tel. +44 20 8261 4509 INFOTAINMENT PUZZLE MaYaHAkM Pu«lewithan I ivAOVJvixLI electronics touch This February edition of Hexadoku is again intended to try your patience and perseverance in solving a puzzle. Fortunately, looking at the vast number of correct solutions we get every month, lots of Elektor readers not only have a great time with Hexadoku, but also care to enter a prize draw for an E-blocks Starter Kit Professional and three Elektor Shop vouchers. The instructions for this puzzle are straightforward. In the diagram composed of 1 6 x 16 boxes, enter numbers such that all hexadecimal numbers 0 through F (that's 0-9 and A-F) occur once only in each row, once in each column and in each of the 4x4 boxes (marked by the thicker black lines). A SOLVE HEXADOKU AND WIN! Correct solutions received from the entire Elektor readership automatically enter a prize draw for an E-blocks Starter Kit Professional worth £300 and three Elektor SHOP Vouchers worth £40.00 each. We believe these prizes should encourage all our readers to participate! The competition is not open to employees of Elektor International Media, its business partners and/or associated publishing houses. 6 F 9 7 5 B 0 5 E 0 1 8 3 6 2 4 9 D 8 F D 5 A 2 B 7 2 5 4 A D 0 8 C 6 B 1 3 F C 6 2 B 1 F 3 E 8 9 7 3 F E C 5 A 2 1 4 6 F E 1 A 8 D B 7 2 6 B C F D 1 3 1 5 F 6 C 8 4 4 0 3 9 8 6 F 7 D 2 E 8 9 B 8 5 2 F C B 9 7 A D C 5 1 F B 2 1 9 A E 3 6 2 5 A 7 B D E (c) PZZL.com number of clues are given in the puzzle and these determine the start situation. All correct entries received for each month's puzzle go into a draw for a main prize and three lesser prizes. All you need to do is send us the numbers in the grey boxes. The puzzle is also available as a free download from the Elektor website PARTICIPATE! Please send your solution (the numbers in the grey boxes) by email to: hexadoku@elektor.com - Subject: hexadoku 02-2009 (please copy exactly). Note: new email address as of this month! Include with your solution: full name and street address. Alternatively, by fax or post to: Elektor Hexadoku Regus Brentford - 1 000 Great West Road - Brentford TW8 9HH United Kingdom - Fax (+44) 208 2614447 The closing date is 1 March 2009. PRIZE WINNERS The solution of the December 2008 Hexadoku is: E5071. The E-blocks Starter Kit Professional goes to: Nicole Stahlschmidt (Germany). An Elektor SHOP voucher worth £40.00 goes to: Pau Sastre (ES), Guido Claes (B) and Helmut Balcke (F). Congratulations everybody! 5 1 6 E 9 7 A D C 2 4 0 8 F B 3 4 7 C F B E 6 8 1 3 D A 0 2 9 5 8 9 2 3 1 4 C 0 5 B 7 F A E 6 D A 0 B D F 2 3 5 6 8 9 E 4 7 C 1 0 E D 9 7 C 5 6 8 F 1 2 B 4 3 A 7 4 F 1 3 8 2 9 B 6 A 5 E D 0 C 3 B 5 6 A D E 1 7 0 C 4 9 8 2 F 2 A 8 C 4 B 0 F 3 D E 9 6 5 1 7 9 5 7 0 2 6 D E A C B 1 F 3 8 4 F C E 2 5 1 9 B 4 7 8 3 D 0 A 6 6 3 1 B C A 8 4 0 E F D 7 9 5 2 D 8 4 A 0 F 7 3 2 9 5 6 C 1 E B 1 F 3 8 D 0 4 C 9 A 2 B 5 6 7 E C D 9 4 6 3 B 2 E 5 0 7 1 A F 8 E 6 A 5 8 9 F 7 D 1 3 C 2 B 4 0 B 2 0 7 E 5 1 A F 4 6 8 3 C D 9 76 elektor - 2/2009 RETRONICS INFOTAINMENT Elektor Digisplay (1976-77) Dirk Dral (The Netherlands) While cleaning out the instrument cabinet in our company shop, I came across a Digisplay unit that I built and used many years ago with considerable pleasure. At that time, I regularly put together circuits with gates, timers, counters and read- outs, and it was a godsend to be able to tap 14 to 16 signals at once with an 1C test clip and see the states of all these signals at the same time on a screen. In May 1976 Elektor pub- lished a circuit for connec- tion to an oscilloscope that allowed the values of 16 signals to be read on the screen in the form of 1 's and 0's. There was apparently a lot of demand for this circuit, since Elektor decided to develop and sell a PCB design for it (# EPS 9376) in 1977. At that time I was planning to build a new oscilloscope to replace my vintage 1965 kit 'scope, and I had already bought a DG 732 CRT for this purpose. Shortly afterward, Hameg came out with an attractively priced oscilloscope kit and I bought it right away, which meant I had a DG732 left over. It thus seemed like a good idea to build a Digisplay as a self-contained unit includ- ing the 'scope tube and fit- ted with only one control: an on/off switch. No need to make things complicated when I already had some- thing to sink my teeth into! The PCB was not espe- cially difficult, since the cir- cuit basically consisted of a 74150 TTL 1C that con- verted the 16 input signals into a BCD code. A pair of gates did duty as an internal clock generator, and a few counters, decoders and D/A converters generated the X and Y deflection signals for the 'scope tube. For the power supply of my simple oscilloscope, I used a design published in the Decem- ber 1 971 issue of Elektuur (Dutch edition). I designed a circuit board for this circuit with suitable trimpots for the adjustments. The X and Y amplifiers were a different story, and after a bit of searching I decided to copy the amplifiers in the Hameg kit. I made PCB designs for both cir- cuits using grid paper overlaid i i o i O f 0 * i 1 t ( i with tracing paper. The actual artwork was created using a few drawing pens. After this, every- thing was exposed on photo- sensitive PCB stock, etched and rinsed. Then it was just a matter of drilling the holes and fitting the components, and the boards were ready for use. The power transformer that I used had only two secondary s r *-■. j fLJfT W I ■tr--.;, .* i-. j- jU, V/;-. • . ■■■ windings: a 250-V wind- ing that provided 350 VDC after rectification, and a 6.3-V winding for the fila- ment current of the 'scope tube and the power supply for the main circuit board. During this process, I also managed to find a suitable enclosure: a Philips SQ4 case intended for audio equipment, which I had left over from some time earlier, was the right size to hold the tube, the power supply, and the circuit boards. I fitted a 22-way chassis-mount con- nector on the front panel for the 1 6 inputs, the four BCD outputs, and circuit ground. The tube shield was fash- ioned from the liner of an old recessed spotlamp fix- ture, and the handle/stand was a cut-down carrying handle from an old transis- tor radio. That's recycling at its best, and you should remember that many electronics hobbyists work this way - they never throw anything away, since they can always find a use for it. The exciting part was always trying out a new project: would everything work as you expected, or would it all go up in smoke? After a few minor adjust- ments, which didn't involve any disasters, I could see the ones and zeros on the screen. A little miracle, which I could share with my family. I was able to use the Digis- play several times in prac- tice to help sort out prob- lems with various circuits. However, I think that the greatest satisfaction lies in building something like this yourself, because you learn something new with each project and thus expand your knowledge. Another moment of satis- faction, and certainly not the least one, comes when you plug it in after 30 years, switch it on, and it still works perfectly! (080926-1) Retronics is a monthly column covering vintage electronics including legendary Elektor designs. Contributions, suggestions and requests are welcomed; please send an email to editor@elektor.com 2/2009 - elektor 77 ELEKTOR SHOWCASE To book your showcase space contact Huson International Media Tel. 0044 (0) 1 932 564999 AVIT RESEARCH www.avitresearch.co.uk USB has never been so simple... with our USB to Microcontroller Interface cable. Appears just like a serial port to both PC and Microcontroller, for really easy USB connection to your projects, or replacement of existing RS232 interfaces. See our webpage for more details. From £10.00. BETA LAYOUT www.pcb-pool.com Beta layout Ltd Award- winning site in both English and German offers prototype PCBs at a fraction of the manufacturer’s prices. of the usual ByVac www.byvac.com • USB to I2C • Microcontrollers • Forth • Serial Devices C S TECHNOLOGY LTD www.cstech.co.uk Low cost PIC prototyping kits, PCB's and components, DTMF decoder kits, CTCSS, FFSK, GPS/GSM, radio equipment and manuals. PCB design and PIC program development. DECIBIT CO.LTD. www.decibit.com • Development Kit 2.4 GHz • Transceiver nRF24L01 • AVR MCU ATmega168 DESIGNER SYSTEMS http://www.designersystems.co.uk Professional product development services. • Marine (Security, Tracking, Monitoring & control) • Automotive (AV, Tracking, Gadget, Monitoring & control) • Industrial (Safety systems, Monitoring over Ethernet) • Telecoms (PSTN handsets, GSM/GPRS) • Audiovisual ((HD)DVD accessories & controllers) Tel: +44 (0)1872 223306 EASYDAQ £ij\Q www.easydaq.biz • USB powered, 4 relays + 4 DIO channels • Will switch 240VAC @ 10 amps • Screw terminal access • LabVIEW, VB, VC • Free shipping • From £38 Design & supply of USB, USB Wireless, Ethernet & Serial, DAQ, Relay & DIO card products. info@easydaq.biz EASYSYNC / J http://www.easysync.co.uk EasySync Ltd sells a wide range of single and multi- port USB to RS232/RS422 and RS485 converters at competitive prices. ELNEC www.elnec.com • device programmer manufacturer • selling through contracted distributors all over the wc • universal and dedicated device programmers • excellent support and after sale support • free SW updates • reliable HW • once a months new SW release • three years warranty for most programmers YOUR ELECTRONICS OPEN SOURCE FTrsi Tropology Trbri-khs FIRST TECHNOLOGY TRANSFER LTD. http://www.ftt.co.uk/PICProTrng.html Microchip Professional C and Assembly Programming Courses. The future is embedded. Microchip Consultant /Training Partner developed courses: • Distance learning / instructor led • Assembly / C-Programming of PIC1 6, PIC1 8, PIC24, dsPIC microcontrollers • Foundation / Intermediate [ I I i I a El TTTff FLEXIPANEL LTD www.flexipanel.com TEAclippers - the smallest PIC programmers in the world, from £20 each: • Per-copy firmware sales • Firmware programming & archiving • In-the-field firmware updates • Protection from design theft by subcontractors FUTURE TECHNOLOGY DEVICES http://www.ftdichip.com FTDI designs and sells USB-UART and USB-FIFO interface i.c.’s. Complete with PC drivers, these devices simplify the task of designing or upgrading peripherals to USB LONDON ELECTRONICS COLLEGE http://www.lec.org.uk Vocational training and education for national qualifications in Electronics Engineering and Information Technology (BTEC First National, Higher National NVQs, GCSEs and GCEs). Also Technical Management and Languages. WWW. elektor. com http://dev.emcelettronica.com Website full of Projects and Resources for Electronics Engineers and DIY. • Tutorial • Hardware (Schematic & Gerber) • Firmware (Asm & C) • Reference Design Everyone can submit a story as a useful source! 'Share for life' LCDMOD KIT http://www.lcdmodkit.com Worldwide On-line retailer • Electronics components • SMT chip components • USB interface LCD • Kits & Accessories • PC modding parts • LCD modules 78 elektor - 2/2009 products and services directory MQP ELECTRONICS ^ www.mqp.com / p * = : • Low cost USB Bus Analysers • High, Full or Low speed captures • Graphical analysis and filtering • Automatic speed detection • Bus powered from high speed PC • Capture buttons and feature connector • Optional analysis classes ROBOTIQ http://www.robotiq.co.uk Build your own Robot! Fun for the whole family! ^ £ r • MeccanoTM Compatible • Computer Control • Radio Control • Tank Treads • Hydraulics OBD2CABLES.COM http://www.obd2cables.com • Thousands of 0BD cables and connectors in stock • Custom cable design and manufacturing • 0BD breakout boxes and simulators • Guaranteed lowest prices • Single quantity orders OK • Convenient online ordering ^ • Fast shipping Visit our website, or email us at: sales@obd2cables.com Internet Technical Bookshop, 1-3 Fairlands House, North Street, Carshalton, Surrey SM5 2HW email: sales@robotiq.co.uk Tel: 020 8669 0769 SCANT00L.NET http://www.scantool.net ScanTool.net offers a complete line of PC-based scan tools for under £50. • 1 year unconditional warranty • 90 day money back guarantee ROBOT ELECTRONICS http://www.robot-electronics.co.uk Advanced Sensors and Electronics for Robotics • Ultrasonic Range Finders • Compass modules • Infra-Red Thermal sensors • Mntnr flontmllpr^ " • For use with EOBD compliant vehicles • Fast shipping • Compatible with a wide range of diagnostic software N S Visit our website, or email us at: sales@scantool.net • Vision Systems • Wireless Telemetry Links ^ 1 jfe % • Embedded Controllers 1 www. elektor. com USB INSTRUMENTS http://www.usb-instruments.com USB Instruments specialises in PC based instrumentation products and software such as Oscilloscopes, Data Loggers, Logic Analaysers which interface to your PC via USB. VIRTINS TECHNOLOGY www.virtins.com PC and Pocket PC based virtual instrument such as sound card real time oscilloscope, spectrum analyzer, signal generator, multimeter, sound meter, distortion analyzer, LCR meter. Free to download and try. CANDO - CAN BUS ANALYSER http://www.cananalyser.co.uk • USB to CAN bus interface • USB powered • FREE CAN bus analyser • Receive, transmit & log. CAN messages • IS011898 & CAN 2.0a/2.0b compliant • Rugged IP67 version available ® nc :rpmc5 SHOWCASE YOUR COMPANY HERE Elektor Electronics has a feature to help customers promote their business, Showcase - a permanent feature of the magazine where you will be able to showcase your products and services. For just £242 + VAT (£22 per issue for eleven issues) Elektor will publish your company name, website address and a 30-word description For £363 + VAT for the year (£33 per issue for eleven issues) we will publish the above plus run a 3cm deep full colour image - e.g. a product shot, a screen shot from your site, a company logo - your choice Places are limited and spaces will go on a strictly first come, first served basis. So-please fax back your order today! _ n I wish to promote my company, please book my space: • Text insertion only for £242 + VAT • Text and photo for £363 + VAT NAME: ORGANISATION: JOB TITLE: ADDRESS: TEL: PLEASE COMPLETE COUPON BELOW AND FAX BACK TO 00-44-(0)1932 564998 COMPANY NAME WEB ADDRESS 30- WORD DESCRIPTION 2/2009 - elektor 79 BOOKS, CD-ROMs, DVDs, KITS & MODULES Going Strong A world of electronics from a single shop! 45 projects for PIC, AVR and ARM Microcontroller Systems Engineering This book is about a state of the art tool, Flowcode, and how you can use Flowcode to develop microcontroller applications. Flowcode is one of the world's most advanced graphical program- ming languages for microcontrollers. This book covers 45 exciting and fun projects for beginners and experts. Each project has a clear description of both hardware and software with pictures and diagrams, which explain not just how things are done but also why. The book starts very simply with a tutorial project and step-by-step instructions. As you go along the projects increase in difficulty and the new concepts are explained. You can use it as a projects book, and build the projects for your own use. Or you can use it as a study guide to learn more about microcontrol- ler systems engineering and the PIC, AVR and ARM microcontrollers. 336 pages • ISBN 978-0-905705-75-0 • £29.00 • US $58.00 From LED to graphical LCD Universal Display Book for PIC Microcontrollers This book begins with simple programs to flash LEDs, and eventually by stages to use other display indicators such as the 7-seg- ment and alphanumeric liquid crystal dis- plays. As the reader progresses through the book, bigger and upgraded PIC chips are introduced, with full circuit diagrams and source code, both in assembler and C. A tutorial is included using theMPLAB program- ming environment, together with the PCB design package and EAGLE schematic to enable readers to create their own designs. 192 pages • ISBN 978-0-905705-73-6 £23.00 • US $46.00 Silent alarm, poetry box, night buzzer and more PIC Microcontrollers This hands-on book covers a series of exciting and fun projects with PIC micro- controllers. You can built more than 50 projects for your own use. The clear expla- nations, schematics, and pictures of each project on a breadboard make this a fun activity. The technical background infor- mation in each project explains why the project is set up the way it is, including the use of datasheets. Even after you've built all the projects it will still be a valuable reference guide to keep next to your PC. 446 pages • ISBN 978-0-905705-70-5 £27.95 • US $55.90 V J V J Prices and item descriptions subject to change. E. & O.E 80 elektor - 02/2009 \ 5.0, 6.0, VBA, .NET, 2005 Visual Basic for Electronics Engineering Applications This book is targeted towards those people that want to control existing or self-built hardware from their com- puter. After familiarizing yourself with Visual Basic, its development environment and the toolset it offers are discussed in detail. Each topic is accompanied by clear, ready to run code, and where nec- essary, schematics are provided that will get your projects up to speed in no time. 476 pages • ISBN 978-0-905705-68-2 £29.95 • US $59.90 Compufor Villen rViinipLai Pta-riH* Principles and Practice Computer Vision Computer vision is probably the most exciting branch of image processing, and the number of applications in robotics, automation technology and quality control is constantly increasing. Unfortunately entering this research area is, as yet, not simple. Those who are interested must first go through a lot of books, publications and software libraries. With this book, however, the first step is easy. The theore- tically founded content is understandable and is supplemented by many examples. 320 pages • ISBN 978-0-905705-71-2 £32.00 • US $64.00 EMBEDDED UHW CONTROL CENTRE «h 1 PC e A DIY system made from recycled components Design your own Embedded Linux control centre on a PC This book covers a do-it-your-self system made from recycled components. The main system described in this book re- uses an old PC, a wireless mains outlet with three switches and one controller, and a USB webcam. All this is linked to- gether by Linux. This book will serve up the basics of setting up a Linux environ- ment - including a software develop- ment environment - 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. All software needed will be available for downloading from the Elektor website. 234 pages • ISBN 978-0-905705-72-9 £24.00 • US $48.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: sales@elektor.com 110 issues, more than 2,100 articles DVD Elektor 1990 through 1999 This DVD-ROM contains the full range of 1 990-1 999 volumes (all 1 1 0 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 comprehensive index enables you to search the entire DVD. The DVD also con- tains (free of charge) the entire 'The Ele- ktor Datasheet Collection 1 . . .5' CD-ROM series, with the original full datasheets of semiconductors, memory ICs, microcon- trollers, and much more. ISBN 978-0-905705-76-7 • £69.00 • US$109.00 Modern technology for everyone FPGA Course FPGAs have established a firm position in the modern electronics designer's toolkit. Until recently, these 'super components' were practically reserved for specialists in high-tech companies. The nine lessons on this courseware CD-ROM are a step by step guide to the world of Field Pro- grammable Gate Array technology. Sub- jects covered include not just digital logic and bus systems but also building an FPGA Webserver, a 4-channel multimeter and a USB controller. The CD also con- tains PCB layout files in pdf format, a Quartus manual, project software and various supplementary instructions. m ISBN 978-90-5381-225-9 • £14.50 • US$29.00 02/2009 - elektor 81 BOOKS, CD-ROMs, DVDs, KITS & MODULES More than 68,000 components ECD 4 The program package consists of eight databanks covering ICs, germanium and silicon transistors, FETs, diodes, thyristors, triacs and optocouplers. A further eleven applications cover the calculation of, for example, LED series droppers, zener diode series resistors, voltage regulators and AMVs. A colour band decoder is in- cluded for determining resistor and in- ductor values. ECD 4 gives instant access to data on more than 68,000 compo- nents. All databank applications are fully interactive, allowing the user to add, edit and complete component data. This CD- ROM is a must-have for all electronics enthusiasts. ISBN 978-90-538 1-1 59-7 • £17.50 • US$ 35.00 Embedded USB Know How USB Toolbox This CD-ROM contains technical data about the USB interface. It also includes a large collection of data sheets for specific USB components from a wide range of manufacturers. There are two ways to in- corporate a USB interface in a microcon- troller circuit: add a USB controller to an existing circuit, or use a microcontroller with an integrated USB interface. Both options are available on this CD-ROM. Included on this CD-ROM areUSB Basic Facts, several useful design tools for hard- ware and software, and all Elektor articles on the subject of USB. ISBN 978-90-5381-212-9 • £19.90 • US $39.80 y Prices and item descriptions subject to change. E. & O.E LED Top with Special Effects (December 2008) If you fit a line of LEDs on a circular PCB and power them on continuously, they generate rings of light when the board is spun. If you add a microcontroller, you can use the same set of LEDs to obtain a more interesting effect by generating a Virtual' text display. The article also de- scribes a simple technique for using the Earth's magnetic field to generate a syn- chronisation pulse. The potential appli- cations extend from rotation counters to an electronic compass. Kit of parts incl. SMD-stuffed PCB and programmed controller Art-Nr. 080678-71 • £39.00 • US $59.00 Remote control by Mobile Phone (November 2008) Remote control using mobile phones and SMS (Text Messaging) is in great demand but many systems on sale suffer from im- perfections. This ingenious new design combines powerful capabilities with low technical overheads. It has programma- ble AC mains switching outlets plus status reports by text message and alarm-acti- vated delivery of GPS data. Remote con- trol by mobile was never easier, cheaper or more reliable! Kit of parts, incl. PCB, programmed controller and all parts Elektor SMT Reflow Oven (October 2008) The Elektor SMT reflow oven will faithfully handle most if not all your soldering of projects using surface mount devices (SMDs). The oven is particularly suited for use not just in Colleges, workshops, clubs and R&D laboratories, but also by the ad- vanced electronics enthusiast. This pre- cious workbench tool is at home where SMD boards have to be produced to a variety of requirements on size, compo- nents and soldering materials. Size: 4 1 8x372x250 mm (16.5 x 14.6x 10 inch) Art. # 080663-91 • £962.00 (Exd. VAT) • US$1665.00 (Exd. VAT) Communicating with CAN (October 2008) The CAN (Controller Area Network) proto- col was originally developed for use in the automotive sector. It is now over 20 years old, but is still frequently used these days. It was specially designed for use in envi- ronments where you have a lot of elec- tromagnetic interference. Despite the fact that the CAN protocol is a serial protocol, it can't just be connected to (the serial port of) a computer. The all-round USB-CAN adapter described in last month's Elektor is a compact and simple solution. With the help of the accompanying software you can follow all data communications taking place and carry out operations such as fil- tering and storage at the flick of a (mouse) switch. PCB, partly populated Art. # 080324-71 • £54.00 • US $99.00 Art. #071 120-71 • £54.90 • US$109.80 82 elektor - 02/2009 ■\ February 2009 (No. 386) Model Coach Lighting Decoder 080689-1 PCB, long (I = 230 mm) 080689-2 PCB, medium (I = 190mm) 080689-3 PCB, short (I = 110mm) 080689-41 .... PIC12F683, programmed Transistor Curve Tracer 080068-1 Main PCB 080068-91 .... PCB, populated and tested January 2009 (No. 385) Radio for Microcontrollers 071125-71 ....868 MHz module ATM18on the Air 071125-71 ....868 MHz module Meeting Cost Tinier 080396-41 ....ATmegal 68, programmed Capacitive Sensing and the Water Cooler 080875-91 ....Touch Sensing Buttons Evaluation kit 080875-92 ....Touch Sensing Slider Evaluation kit Three-Dimensional Light Source 080355-1 Printed circuit board Moving up to 32 Bit 080632-91 ....ECRM40 module December 2008 (No. 384) PLDM 071 1 29-1 Printed circuit board Hi-fi Wireless Headset 080647-1 Printed circuit board: Transmitter 080647-2 Printed circuit board: Receiver LED Top with Special Effects 080678-71 .... Kit of parts incl. SMD-stuffed PCB and programmed controller November 2008 (No. 383) Motorised Volume Pot 071135-41 .... Programmed controller ATMEGA8-16PU Speed Camera Warning Device 08061 5-1 Printed circuit board 080615-41 ....Programmed controller PIC16F876A-I/SO.... Remote Control by Mobile Phone 080324-1 Printed circuit board 080324-41 .... Programmed controller ATMEGA8-16PU 080324-71 ....Kit of parts Tracking Hot Spots 080358-1 Printed circuit board AT meg a meets Vinculum 071152-91 .... VDIP1 module October 2008 (No. 382) Communicating with CAN 071 1 20-71 .... PCB, partly populated Elektor SMT Precision Reflow Oven 080663-91 .... Ready to use oven (230VAC only) Multi-purpose GPS Receiver 070309-41 .... Programmed controller PIC1 8F2520 ATM18 Relay Board and Port Expander 071 035-72 .... Relay PCB with all components and relays 071 035-95 .... Port Extension PCB, populated with SMD RF Sweep Frequency Generator / Spectrum Analyser 040360-41 ....Programmed controller ATmega8535 £ US$ 7.30 10.95 7.30 10.95 5.80 8.95 6.20 9.50 26.50 42.00 see www.elektor.com ...7.20 9.95 ,.7.20 9.95 ,.8.50 12.50 27.50 39.95 27.50 39.95 24.90 39.90 32.00 46.50 5.80 9.50 ,7.90 15.80 .7.90 15.80 39.00 59.00 ..5.90 11.80 15.50 31.00 11.80 23.60 17.80 35.60 ..5.90 11.80 54.00 99.00 ..9.10 18.20 22.50 45.00 ..54.90 109.80 962.00.... 1665.00 ..11.60 23.20 ..36.90 73.80 ..13.40 26.80 ..21.80 43.60 Bestsellers O od Universal Display Book £23.00. US $46.00 ISBN 978-0-905705-73-6.. Embedded Linux Control Centre ISBN 978-0-905705-72-9 E24.00.....US $48.00 PIC Microcontrollers ISBN 978-0-905705-70-5 E27.95.....US $55.90 Visual Basic for Electronics Engineering Applications ISBN 978-0-905705-68-2 E29.90.....US $59.90 Computer Vision ISBN 978-0-905705-71-2 £32.00. US $64.00 Elektor 1990 through 1999 ISBN 978-0-905705-76-7 £69.00 ...US $109.00 FPGA Course ISBN 978-90-5381-225-9 £14.50. US $29.00 £17.50. US$35.00 ECD 4 ISBN 978-90-5381-159-7 USB Toolbox ISBN 978-90-5381-212-9 £19.90. US $39.80 O r net Toolbox ISBN 978-90-5381-214-3 £19.50. US $39.00 LED Top with Special Effects Art. # 080678-71 £39.00.... US $59.00 Elektor SMT-oven Art. # 080663-91 £882.00 US $1525.00 Evaluation Kit CapSense Buttons Art. # 080875-91 £27.50 US $39.95 Evaluation Kit CapSense Sliders Art. # 080875-92 E27.50.....US $39.95 Remote control by Mobile Phone Art. # 080324-71 £54.00.... US $99.00 Order quickly and securely through www.elektor.com/shop or use the Order Form near the end of the magazine! September 2008 (No. 381) DCC Command Station 070989-71 .... Kit of parts incl. programmed ARM module 88.50 177.00 lektor SHOP Elektor Regus Brentford 1 000 Great West Road Brentford TW8 9HH * United Kingdom Tel. +44 20 8261 4509 Fax +44 20 8261 4447 Email: sales@elektor.com 02/2009 - elektor 83 INFO & MARKET SNEAK PREVIEW 4 to 16 — Port Extension for Micros Ever so often a microcontroller simply doesn't have enough ports to control all functions in your circuit. Our clever port extension boards provide the solution, requiring no more than 16 (SPI) control lines. The first board sports 16 digital outputs; more may be obtained by 'cascading' boards. The second, equally simple to drive board gives access to an HD44780 compatible LCD. The hardware is completed by free software examples for AVR controllers. i TinyBrick M16C Module The Ml 6C display board published in May 2008 got a good response and is now complemented by a small Ml 6 module with a DIL footprint called 'TinyBrick'. Like the display, TinyBrick is programmable in TinyBasic. For development purposes we also present a carrier board, and there's more: as an example of a real life application, we describe a home alarm system capable of sending SMS Text messages. From R8C to R32C The article series we published in 2006 on the Elektor 'Tom Thumb' R8C-base mini- ature microcontroller board was a resounding success and we now take the next step by presenting R32C, a Renesas micro with 32 bits architecture, floating point and 50 MHz clock. As with the R8C13 projects, the hardware consists of a carrier board containing the micro- controller, and an application board with various interfaces and a prototyping area. Brand new, we reckon, is the OLED display control developed for this system. Article titles and magazine contents subject to change, please check 'Magazine' on www.elektor.com The March 2009 issue comes on sale on Thursday 1 9 February 2009 (UK distribution only). UK mainland subscribers will receive the issue between 14 and 17 February 2009. w.elektor.com www.elektor.com www.elektor.com www.elektor.com www.elektorl Elektor on the web All magazine articles back to volume 2000 are available online in pdf format. The article summary and parts list (if applicable) can be instantly viewed to help you positively identify an article. Article related items are also shown, including software downloads, circuit boards, programmed ICs and corrections and updates if applicable. Complete magazine issues may also be downloaded. In the Elektor Shop you'll find all other products sold by the publishers, like CD-ROMs, kits and books. A powerful search function allows you to search for items and references across the entire website. Also on the Elektor website: • Electronics news and Elektor announcements • Readers Forum • PCB, software and e-magazine downloads • Surveys and polls • FAQ, Author Guidelines and Contact 3 Elcblar Products Tar f ItaHHjffi up Eft Wrtt 15 Products to cxom from Subject Area Art It Ini Subfd tM to our fm Eiiktu-r E-v.n r j litMctfebi Axkcm [dcntir«ciilen . I'CH- Ljr-iiyi -n EjtkdiiI Si;h-e fcr'ji! IllMOf * Wffiera 4. V < -s & ^PC&5 ^ PAgydLMKS idUfferj V IJettof Cndlti KUikl purpose and spensapie cp SVIlIrVdHHLBi .Kill rillllll V jV.I ! My I luktur Leg In Only for lubKTibin GvO H ElrhEu-cr 1MB Ihruugh I WO £15 Discount and Free P4Pt ClaktdT cornel to tha USA EtrkLur mayuinr lim mm iiaitr In Nnrth AirVm [jrwi Canada-]. Sutacnoe now! Soflci.l Chriutnu* QfTar he me enter yiHj * email sidrm. Seda! EEFRQMi Feature butt-ln KAC fsaK B artnin K ; Data*; fe anMBf ngfe vsnlr Hem AWS iSrvHiiieiHTt lad: F,r, P AVR Stt tkuril Visit China with Elektor! i Pirw -i I Ji. r Y bip ite-inl Worfeattop ■ H C [D pnnnp si «vi partite HjiLiteLri.% • MQb-End Valve flnpllften; Hare Piny l-TKIXX Bui* will IV Inner iJilp !m ceri. [bi :J 1 mn*i!eti:>- urv.nd annbquE Dekidf (icacer Offer; BAKO^-AVR prte redurtKHi 4 , l ilmnLHl.vF kilih jjj e Ipktnr IwnhWI pIptTrtinkit urarldwldp WWW.PC11CAKT.COM Hu-rne JJhyvs Mdiidtmv Shwv Sviburibti ii-pw ."vrwrn Eurmu Niwt 84 elektor - 2/2009 Description Price each Qty. Total Order Code Microcontroller Systems Engineering £ 29.00 DVD Elektor 1990 through 1999 £69.00 CapSense Buttons Kit(oso875-9i) j^rgTTl £ 27.50 CapSense Sliders Kit ( 080875 - 92 ) jjjl £27 ' 50 Universal Display Book for PIC Microcontrollers £ 23.00 LED Top with Special Effects (oso678-7i) £ 39.00 Free Elektor Catalogue 2009 Sub-total Prices and item descriptions subject to change. The publishers reserve the right to change prices P&P without prior notification. Prices and item descriptions shown here supersede those in previous issues. E. & O.E. Total paid Name Address + Post code Tel. Email Date - - Signature EL02 Yes, I am taking out an annual subscription to Elektor and receive a free 2GB MP3 player*. I would like: I I Standard Subscription (11 issues) Subscription-Plus (11 issues plus the Elektor Volume 2008 CD-ROM) * 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 EL02 METHOD OF PAYMENT (see reverse before ticking as appropriate) Bank transfer j Cheque (UK-resident customers ONLY) □ Giro transfer □ VISA □ Expiry date: Verification code: Please send this order form to* (see reverse for conditions) Elektor Regus Brentford 1000 Great West Road Brentford TW8 9HH United Kingdom Tel.: +44 20 8261 4509 Fax: +44 20 8261 4447 www.elektor.com sales@elektor.com *USA and Canada residents should use $ prices, and send the order form to: Elektor US PO Box 876 Peterborough NH 03458-0876 Phone: 603-924-9464 Fax: 603-924-9467 E-mail: custservus@elektor.com METHOD OF PAYMENT (see reverse before ticking as appropriate) Bank transfer | Cheque (UK-resident customers ONLY) □ Giro transfer Expiry date: Verification code: Please send this order form to Elektor Regus Brentford 1000 Great West Road Brentford TW8 9HH United Kingdom Tel.: +44 20 8261 4509 Fax: +44 20 8261 4447 www.elektor.com subscriptions@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 £11.00 (Priority) HOWTO 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. 40209520 held by Elektor Electronics with ABN-AMRO Bank, London. IBAN: GB35 ABNA 4050 3040 2095 20. 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. Giro transfer into account no. 34-152-3801, held by Elektor Electronics. Please do not send giro transfer/deposit forms directly to us, but instead use the National Giro postage paid envelope and send it to your National Giro Centre. 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. 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 guarantee 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 10% 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 responsibility 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 advertisements) 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 2009 SUBSCRIPTION RATES FOR ANNUAL SUBSCRIPTION Standard Plus United Kingdom £44.00 £53.00 Surface Mail Rest of the World £58.00 £67.00 Airmail Rest of the World £74.00 £83.00 USA £59.95 See www.elektor.com/usa Canada £70.95 for special offers HOWTO PAY Bank transfer into account no. 40209520 held by Elektor Electronics, with ABN-AMRO Bank, London. IBAN: GB35 ABNA 4050 3040 2095 20. 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. Giro transfer into account no. 34-152-3801, held by Elektor Electronics Please do not send giro transfer/deposit forms directly to us, but instead use the National Giro postage paid envelope and send it to your National Giro Centre. 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 stu- dentship signed by the head of the college, school or university faculty. A standard Student Subscription costs £35.00, a Student Subscription-Plus costs £44.20 (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 2009 tQisues , more than 2,100 articles This OVD- vO vA contains the full range of 1 990-1999 volumes (all issues) of Elektor Electronics magazine. 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 comprehensive index enables you to search the entire DVD. This DVD also contains (free of charge) the entire 'The Elektor Datasheet Collection 1 ...5' CD-ROM series, with the original full datasheets of semiconductors, memory ICs, microcontrollers, and much more. ISBN 978-0-905705-76-7 • £69.00 • US $109.00 Elektor Reg us Brentford 1 000 Great West Road Brentford TW8 9HH United Kingdom Tel. +44 20 8261 4509 L J Further information and ordering www.elektor.com «_ Index of Advertisers Antex Electronics Ltd www.antex.co.uk. 13 Avit Research, Showcase www.avitresearch.co.uk 78 Beijing Draco www.ezpcb.com 31 Beta Layout, Showcase www.pcb-pool.com 51, 78 ByVac, Showcase www.byvac.com 78 C S Technology Ltd, Showcase www.cstech.co.uk 78 Decibit Co. Ltd, Showcase www.decibit.com 78 Designer Systems, Showcase www.designersystems.co.uk 78 EasyDAQ, Showcase www.easydaq.biz 78 Easysync, Showcase www.easysync.co.uk. 78 Elnec, Showcase www.einec.com 78 EMCelettronica Sri, Showcase www.emcelettronica.com 78 Euro circuits www.eurocircuits.com 55 First Technology Transfer Ltd, Showcase . . www.ftt.co.uk 78 FlexiPanel Ltd, Showcase www.flexipanel.com 78 Future Technology Devices, Showcase. . . . www.ftdichip.com 78 General Circuits www.pcbcart.com. 41 Labcenter www.labcenter.com. 88 Lcdmod Kit, Showcase www.lcdmodkit.com 78 London Electronics College, Showcase . . . www.lec.org.uk 78 Microchip www.microchip.com/mtouch 3 MikroElektronika MQP Electronics, Showcase. . Netronics, Showcase Newbury Electronics Nurve Networks Parallax Peak Electronic Design Pico Quasar Electronics Robot Electronics, Showcase. Robotiq, Showcase RS Components ScanTool, Showcase Showcase USB Instruments, Showcase . Virtins Technology, Showcase www.mikroe.com 10, 11 www.mqp.com 79 www. cananalyser. co.uk 79 www. newburyelectronics. co.uk 17 www.xgamestation.com 17 www. parallax, com 23 www.peakeiec.co.uk 51 www.picotech.com 2 www.quasarelectronics.com 15 www. robot-electronics, co.uk 79 www.robotiq.co.uk 79 www.rswww.com/electronics 71 www.obd2cables.com, www.scantooi.net .... 79 78, 79 www.usb-instruments.com 79 www.virtins.com 79 Advertising space for the issue of 19 March 2009 may be reserved not later than 17 February 2009 with Huson International Media - Cambridge Flouse - Gogmore Lane - Chertsey, Surrey KT 1 6 9AP - England - Telephone 01 932 564 999 - Fax 01932 564998 - e-mail: p.brady@husonmedia.com to whom all correspondence, copy instructions and artwork should be addressed. 2/2009 - elektor 87 Our new autorouter will turn this... into this... in less than 5 minutes! All levels of the Proteus Design Suite now include a world class fully integrated shape based autorouter at no additional cost. The Proteus Design Suite also incorporates: ■ Professional schematic capture ■ Publication quality schematics ■ Fully configurable bill of materials ■ Large component libraries for both simulation and PCB layout Mixed mode SPICE circuit simulation ■ Co-simulation of PIC, AVR, 8051 and ARM7 microcontroller firmware ■ Automatic component placement and gateswap optimization ■ Highly configurable design rules ■ Interactive design rule checking ■ Polygonal and split power planes ■ RS274X, Excellon and ODB++ database export ■ 3D Viewer with 3DS and DXF export Prices start from just £1 50* - visit our website for full details or to download a free demo. www.labcenter.cam E 1 Irani 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 *exc. VAT & delivery