www.elektor-electronics.co.uk JULY/AUGUST 2007 £ 5.65 1 V 1 x '^Proved V>»/ for . / .2007 JF ung ' \ s Jacob's Ladder High Voltage Display Kit KC-5445 £11.75 + post & packing With this kit and the purchase of a 12V ignition coil (available from auto stores and parts recyclers), create an awesome rising ladder of noisy sparks that emits the distinct smell of ozone. This improved circuit is suited to modern high power ignition coils and will deliver a spectacular visual display. Kit includes PCB, pre-cut wire/ladder and all electronic components. • 12V car battery or >5Amp DC power supply required HIGH VOLTAGE Visit us at www.jaycarelectronics.co.uk and obtain your free copy of our 430+ page, full colour catalogue. We have an extensive range of electronics kits and the best in innovative gadgets. 4 Channel Guitar Amplifier Kit KC-5448 £28.75 + post & packing The input sensitivity of each of the four channels is adjustable from a few millivolts to over 1 volt, so you can plug in a range of input signals from a microphone to a line level signal from a CD player etc. A headphone amplifier circuit is also included for monitoring purposes. A three stage EQ is also integrated, making this a very versatile mixer that will operate from 12VDC. Kit includes PCB with overlay and all electronic components. POST AND PACKING CHARGES: Order Value Order Value £499.99 £30 £40 £20 - £49.99 £5 £200 - £50 - £99.99 £10 £500+ £100 -£199.99 £20 Max weight 121b (5kg). Heavier parcels POA. Minimum order £20. Note: Products are dispatched from Australia, so local customs duty and taxes may apply. How to order: Phone: Call Australian Eastern Standard Time Mon-Fri on 0800 032 7241 Email: techstore@jaycarelectronics.co.uk Post: PO BOX 6424, Silverwater NSW 1811. Australia Expect 10-14 Days For Air parcel delivery Stereo VU and Peak Meter Kit KC-5447 £20.50 + post & packing Accurately monitor audio signals to prevent signal clipping and ensure optimum recording levels. This unit is very responsive and uses two 16-segment bargraphs to display signal levels and transient peaks in real time. There are a number of display options to select, and both the signal threshold and signal level calibration for each segment are adjustable. Kit supplied with PCBs, LCD and all electronic components. Accuracy within IdB for signals above -40dB. • Case not included use 1 , HB-6082 £2.95 50MHz Frequency Meter MKII Kit KC-5440 £20.50 + post & packing This compact, low cost 50MHz Frequency Meter is invaluable for servicing and diagnostics. This upgraded version features an automatic indication of units (Hz, kHz, MHz or GHz) and prescaler. Kit includes PCB with overlay, enclosure, LCD and all electronic Requires 9-12VDC wall adaptor (Maplin #JC91Y £14.99) components. • 8 digit reading (LCD) • Prescaler switch • 3 resolution modes • Powered by 5 x AAA batteries or DC plugpack .'t / / Variable Boost Kit for Turbochargers KC-5438 £6.00 + post & packing It's a very simple circuit with only a few components to modify the factory boost levels. It works by intercepting the boost signal from the car's engine management computer and modifying the duty cycle of the solenoid signal. Kit supplied in short form with PCB and overlay, and all specified electronic components. ^Proved ^F \ s Q\4 PLOT mt fc*VI 1 -T-P fisr •STK 4 Channel BitScope Digital Storage Oscilloscope Up to 4 analog channels using industry standard probes or POD connected analog inputs. Mixed Signal Oscilloscope Capture and display up to 4 analog and 8 logic channels with sophisticated cross-triggers. Spectrum Analyzer Integrated real-time spectrum analyzer for each analog channel with concurrent waveform display Logic Analyzer 8 logic, External Trigger and special purpose inputs to capture digital signals down to 25nS. Data Recorder Record anything DSO can capture. Supports live data replay and display export. Networking Flexible network connectivity supporting multi-scope operation, remote monitoring and data acquisition. 2 Channel BitScope Pocket Analyzer BitScope DSO Software for Windows and Linux BitScope DSO is fast and intuitive multi-channel test and measurement software for your PC or notebook. Whether it's a digital scope, spectrum analyzer, mixed signal scope, logic analyzer, waveform generator or data recorder, BitScope DSO supports them all. Capture deep buffer one-shots or display waveforms live just like an analog scope. Comprehensive test instrument integration means you can view the same data in different ways simultaneously at the click of a button. DSO may even be used stand-alone to share data with colleagues, students or customers. Waveforms may be exported as portable image files or live captures replayed on other PCs as if a BitScope was locally connected. BitScope DSO supports all current BitScope models, auto-configures when it connects and can manage multiple BitScopes concurrently. No manual setup is normally required. Data export is available for use with third party software tools and BitScope's networked data acquisition capabilities are fully supported. Data Export Export data with DSO using portable CSV files or use libraries to build custom BitScope solutions. www . bltscope . com r lektor I ectronics leading -the way ©@Ofl0©OillO8 Colophon 6 Alphanumski Puzzle 140 Elektor SHOP 145 Sneak Preview 148 SENSORS A/D Converter for Robots 25 Bat’s Ear 30 CMUCaml Vision System 18 CO Sensor 35 Compass Sensor for Lego Mindstorms NXT 36 From Cassette Recorder to Robot Propulsion 26 An Inclinometer for your Robot 32 IR Close Object Detector 27 Light Sensing with an LED 38 Light-seeking Robot 29 An Obstacle Detecting Robot 10 Overheat Detector Alarm/Switch 21 PIC or Basic Stamp IR Telemeter 2 1 PIR Sensor 28 Positioning with Photodiode Arrays 33 A Robot that won’t lose its bearings 24 Sensor for Line Following Robots 20 Simple D/A Converter for Robots 1 7 Sound Activated Switch 23 Stereo Robot Ears* 13 Ultrasonic Distant Obstacle Detector 37 Whiskers on Robots 34 Wireless Pulse Sensor 12 ACTUATORS 12 V Bidirectional Motor Control 44 3 Amp PWM DC Motor Controller* 50 Catapult for Robots. . . or Other Uses 56 Complete Stepper Motor Driver 46 Controlling Servos 47 Driving Higher Power Motors 51 Driving Stepper Motors 59 Driving Stepper Motors: KISS 53 MotoBox* 40 PIC 12C508 Stepper Motor Controller 48 PIC Indicator Relay 55 Robot Footballer 54 Servo to Motor Conversion 58 zBot: 10-A Power Stage for DC Motor 45 MICROCONTROLLERS Low 2 Cost USB Demo Board 75 LPC900 Programmer* 72 Optimised STK200/300 Programmer 77 Propeller Prototyping Board for BoeBot* 69 CONTENTS Volume 33 July/August 2007 367 Satnav for Robots Serial Interface for the Propeller* Servo Control from a PC ‘Teaclipper’ Postage-Stamp Programmer Which Brain for my Robot? POWER SUPPLIES & CHARGERS 3-A Wide-input Adjustable Switching Regulator Deep Discharge Protection for Rechargeable Cells Dual Battery* Fast Charger for NiMH Batteries* LDO Regulator with Soft Start or Tracking Lithium Charger* Mini Power Inverter Multi-purpose NiCd & NiMH Charger Paralleling LiPo Batteries PWM Voltage Dropper Switch-Mode 555 Supply USB Converter* Voltage Stabiliser zBot: Solar/Battery Power Supply MECHANICS Antieu-robot Babybot Bolo Hunter Minimalist Motor Robot MOPS Torque is Cheap Trembly Tribot COMMUNICATIONS 2.4 GHz Antenna for Robotics Vehicles 110 IR Communications using a UART 113 IR Remote Control with the R8C 115 Radio Remote Control for PDAs and Smartphones 115 Receiver for RC5 Remote Controls 112 Removed Pulse Detector 114 Robot Voice 117 zBot: Wireless Link 114 TIPS & TRICKS Balancing Robot 118 DIY Wheels 120 R8C Measures Negative Voltages 121 MISCELLANEOUS Chaotic Fireflies 126 Clap Controlled Switcher 132 Colour Tamer 126 Football with Robots 138 Formula Flowcode Buggy 122 KiCAD: a high-level tool 134 New Lego Mindstorms NXT Motor Block 133 Philips ME Construction Kits 130 jj 'Tii a iVplj Sr*: A Robot with an Elephant’s Memory 1 3 1 Stepped Volume Control 1 27 Walking Works! 1 28 * PCB design included "B B ■*«! ■imw e lektor IjFrl Fonlri e lektor Advertisement lektor lectronics Volume 33, Number 367/368, July/August 2007 ISSN 0268/45 1 9 Elektor Electronics 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 Electronics (Publishing), Regus Brentford, 1 000 Great West Road, Brentford TW8 9HH, England. Tel. (+44) 208 26 1 4509, fax: (+44) 208 261 4447 www.elektor-electronics.co.uk The magazine is available from newsagents, bookshops and electronics retail outlets, or on subscription. Elektor Electronics is published I I times a year with a double issue for July & August. Underthe name Elektor and Elektuur, the magazine 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: Mat Fdeffels (m.heffels@segment.nl), Wisse Fdettinga (w.hettinga@segment.nl) Editor: Jan Buiting (editor@elektor-electronics.co.uk) International editorial staff: Fdarry Baggen, Thijs Beckers, Ernst Krempelsauer, Jens Nickel, Guy Raedersdorf. Design staff: Antoine Authier, Ton Giesberts, Paul Goossens, Luc Lemmens, Jan Visser, Christian Vossen Editorial secretariat: Fdedwig Fdennekens (secretariaat@segment.nl) Graphic design / DTP: Giel Dols, Mart Schroijen Managing Director / Publisher: Paul Snakkers Marketing: Carlo van Nistelrooy Customer Services: Margriet Debeij (m.debeij@segment.nl) Subscriptions: Elektor Electronics (Publishing), Regus Brentford, 1000 Great West Road, Brentford TW8 9 H H , England. Tel. (+44) 208 26 1 4509, fax: (+44) 208 26 1 4447 Internet: www.elektor-electronics.co.uk Email: subscriptions@elektor-electronics.co.uk Rates and terms are given on the Subscription Order Form Head Office: Segment b.v. PO. Box 75 NL-6 1 90-AB Beek The Netherlands Telephone: (+31)46 4389444, Fax: (+31)46 4370161 Distribution: Seymour, 2 East Poultry Street, London EC I A, England Telephone: +44 207 429 4073 UK Advertising: Fduson International Media, Cambridge Fdouse, Gogmore Lane, Chertsey, Surrey KTI 6 9AR England. Telephone: +44 1932 564999, Fax: +44 1932 564998 Email: p.brady@husonmedia.com Internet: www.husonmedia.com Advertising rates and terms available on request. International Advertising: Frank van de Raadt, address as Fdead Office Email: advertenties@elektuur.nl Advertising rates and terms available on request. Copyright Notice The circuits described in this magazine are for domestic use only. All drawings, photographs, printed circuit board layouts, programmed integrated circuits, disks, CD-ROMs, software carriers and article texts published in our books and magazines (other than third-party advertisements) are copyright Segment, b.v. and may not be reproduced or transmitted in any form or by any means, including photocopying, scanning an recording, in whole or in part without prior written permission from the Publishers. Such written permission must also be obtained before any part of this publication is stored in a retrieval system of any nature. Patent protection may exist in respect of circuits, devices, components etc. described in this magazine. The Publisher does not accept responsibility for failing to identify such patent(s) or other protection. The submission of designs or articles implies permis- sion to the Publishers to alter the text and design, and to use the contents in other Segment publica- tions and activities. The Publishers cannot guarantee to return any material submitted to them. Disclaimer Prices and descriptions of publication-related items subject to change. Errors and omissions excluded. © Segment b.v. 2007 Printed in the Netherlands 6 elektor electronics - 7-8/2007 With a PoScope USB instrument you get the features of an oscilloscope, spectrum analyser, chart recorder, logic analyser (with UART, SPI, l 2 C and 1 -wire serial bus decoding), pattern generator and Square- wavp/PWM generator. That’s equivalent to six pieces of test equipment for £99 including UK dbfecy and VAT. PoScope is a low-cost USB- based instrument that adds invaluable test equipment features to your desktop or notebook PC. Being PC-based, all measurements can be printed, copied to the clipboard and saved as text, bitmap or vector graphics for subsequent analysis or to import into other programs. PoScope is ideal for use by electronics hobbyists, students and engineers alike and is particularly suited to those developing with microcontrollers such as PIC and AVR. PoScope provides the following operation modes: • 2-channel oscilloscope with 100Hz to 200kHz sampling, -20 V to +20V input range, 10-bit ADC resolution, absolute, differential and external triggering, adjustable pre-trigger and marker measurements. • 2-channel spectrum analyser with klirr factor measurement, Hamming, Hanning, Blackman and Blackman-Harris FFT window functions. • 2-channel chaK recorder with 0.01Hz to 200kHz sampling, maximum, minimum and average voltage measurements for each channel and waveform record over several tens of hours. • 16-channel (8 when pattern generator used) logic analyser with 1kHz to 8MHz sampling, versatile triggering with adjustable pre-trigger, external clocking, preset pulse miss, preset bit sequence/edge, decoding of UART, SPI, I2C and 1-wire serial interfaces. • 8-channel 1kHz to 1MHz pattern generator with tabular waveform formatting or direct timing chart plotting on the screen. • Square-wave/PWM (pulse width modulation) generator. Compatible with Microsoft Windows ME, 2000 and XP, PoScope is supplied with easy- to-use software and a USB cable. Oscilloscope probes and logic analyser test lead/clip sets are available separately. Order now on Freefone 0800 612 2135 or online at www.paltronix.com PALTROniK EQUIPMENT FOR ELECTRONICS DEVELOPMENT, TRAINING & EXPERIMENTATION Paltronix Limited Unit 3 Dolphin Lane, 35 High Street, Southampton S014 2DF Telephone: 0845 226 9451 Facsimile: 0845 226 9452 Email: sales@paltronix.com Web: www.paltronix.com M CAT* Yi£A Electron All major credit and debit cards accepted IT! mikrollektronika J DEVELOPMENT TOOLS I COMPILERS I BOOKS PICFIash P wtlli mftralCD lupport SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD 8 elektor electronics - 7-8/2007 Dead fO\N E Quad w VB OTRad kDDad PI- KA8 28 B j wuaui i m tin 16 adfe&ad A ad “85b ■ eb b ad the nd $ lb (to b ^ - $n ERH ad ISH Bad )0 B ds Ibcad ■* Kpett ad a a ad a$& . a, © au i ad n s ad 6 Ep&ad fce^i ad D a JLBi fib I BB b L SL 1C D A£ 4 I 281 A£ o a % ) D gr MB DO fldfr D D D [P 1 ^) a a a D D SR§ad EavHB ad lleftd D / jniki^>BH,i*id mUkroPaseaJ mlkroC for PIC MCU Tor PIC MCU for PIC MCU TiL-JVXXt mikroBasic Tor daPIQQ >33 and PHC24 MCU mikroPaEcal Tor d*PIC3Q/33 Jftd PIC24 MCU rnlkroC Tor d»PIOO/33 And PIC24 MCU mlkroBasic TW AYR MCU mlkroPascaj Tor AYR MCU q* HE m QJ qa >,nath Tf> EE AVR t* D£ DA ra DanlU SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD 7-8/2007 - elektor electronics 9 C. Tavernier www.tavernier-c.com CB 220 module from Comfile Technol- ogy, allowing us to both write a very sim- ple program and build an equally simple electronic circuit, as you can see from the diagram. Ports PO and PI of the Cubloc are programmed as inputs and receive the information coming from the obstacle detectors. Normally low, they go high when one or other of the whiskers is activated, i.e., in the pres- ence of an obstacle. Ports P5 and P6 are programmed as outputs and drive the propulsion ser- vos. The choice of these ports is vital, as the Cubloc's PWM signal-generat- ing instruction we are going to be using only works with these. The servos are powered directly from the pack of four 1.5 V cells, while we use the Cubloc's VIN input so as to take advantage of its built-in dry cells (6V) rechargeables (4V8) i | rechargeables j 4VS -O | dry cells L 6V RIGHT R1 9 10 11 12 © VIN SOUT SIN RES ATN IC1 PO P15 pi P14 P2 P13 P3 P12 P4 P11 CB220 P5 P10 P6 P9 P7 P8 R2 J-X 23 SUB D9 ? 070298 - 1 1 When first trying our hand at robotics, we're generally in a hurry to build a mobile robot that has a degree of autonomy. It's with this aim in mind that we've produced this article, to enable you, in record time, to build a mobile robot capable of detect- ing and avoiding obstacles. Of course, given the relative simplicity of the solu- tions employed, it will be fairly easy to catch it out, but as long as you take a little care over the obstacles it might encounter, it'll still create quite an impression. And you'll be able to use this starting point as a springboard for your own developments. To deal with the mechanical issues that often pose problems for many amateur robot-builders, we're making use of a 'Rogue Blue' base (www.roguerobotics. com), sold as a kit and very easy to assem- ble without special tools. What's more, this kit is distributed in France by Lextronic (www.lextronic.fr), who can despatch to any of the neighbouring countries. As you can see from the photo, it con- sists of two pre-cut circular plates able to accommodate two radio-control servos, used as traction motors. Supplied with the base, these come already modified (as explained elsewhere in this issue) to enable them to turn continuously. Two wheels with large-diameter tyres are also provided, fixing directly onto the servo shafts, while the front and rear of the robot's lower plate have PTFE 'skids' tak- ing the place of a jockey wheel. Some self-adhesive Velcro lets us secure a battery holder for primary cells or rechargeables between the two circular plates, leaving the whole of the top plate free for the electronics. Given the supply voltage for the servos and the electronics, we have used a 4-cell battery holder that takes four 1.5 V AA (R6) cells, and will also take rechargeable NiMH batteries of the same size, in the event of intensive use. So as to get our robot up and running quickly, we've used a 'whisker'-type obsta- cle detector. To achieve this, we use two long-lever microswitches — or two ordi- nary lever-operated microswitches with a few centimetres of piano wire soldered to them - mounted on the top plate. They are positioned at an angle of around 45-60° to each other, with their centrelines intersect- ing on the robot's front/back centreline. This gives us one obstacle detector on the front right, and another on the front left. The robot's brain is entrusted to a Cubloc 5 V regulator. However, if you are going to use NiMH rechargeables instead of pri- mary cells, you'll have to use the VDD input to power the Cubloc, as in this case the voltage available is only 4.8 V. Connector DB9 is designed for connecting the Cubloc to a PC, to program it with the software we'll be suggesting in a moment. Given the simplicity of the circuit, it can be built on perforated prototyping board or on a CB220-Proto test board, which comes with this connector already pre-wired. The software needed to control the whole thing is very simple, even for someone with only faint notions about programming. The Cubloc's Basic language is both simple and very powerful. The source listing is avail- able on the Elektor website, as well as the author's own site (www.tavernier-c.com), but it's so short, you can also just type it yourself directly into the Cubloc Studio editor, which is the Cubloc's (free) devel- opment tool, and can be downloaded from www.comfiletech.com. The listing is very easy to analyse. After defining the type of Cubloc in use and the 10 elektor electronics - 7-8/2007 operating sense of the ports PO, PI, P5, and P6, we also define a variable 'obstacle'. The main program can then commence, in the form of a continuous Do Loop. We start by testing for one or other of ports PO or PI going high, and if this is the case, the robot is stopped by means of the two PWM instructions that follow. Given that we are using modified radio- control ser- vos, remem- ber they are stopped when they receive pulses of 1.5 ms; they rotate at full speed in one direction for 2 ms pulses; and at full speed in the other direc- tion for 1 ms pulses. Note too that, as the servos are mounted in reversed orientations in the Rogue Blue base, they need to rotate in opposite directions to make the robot go forwards or backwards. Because of the mechanical and electrical tolerances, 1.5 ms pulses don't always give exactly stop. So you may need to go back and tweak the first parameter of the PWM instructions (3410 in this example). Once the robot has stopped, we test to see if the left or right whisker has been activated, and set the variable 'obstacle' accordingly. One last test checks if both whiskers have been activated simultaneously, and if this is the case — meaning the robot has encoun- tered an obstacle directly ahead — reverse drive is applied (2 ms pulses to one servo and 1 ms to the other). The variable 'obstacle' is then analysed by means of a 'select' box that the Cubloc's powerful Basic has borrowed from C. If the variable 'obstacle' has a value of 0, no obstacle has been encountered and our robot sets off forwards. If the variable 'obstacle' has a value of 1 or 2, an obstacle has been encountered to right or left, and so a quarter-turn is made in the opposite direction. However, if the variable 'obsta- cle' has the value 3, an obstacle directly ahead has been encountered, and the robot does a complete U-turn. Watch out! Depending on what you call front/back and left/right on your particular robot, you may need to swap round the successive PWM instructions in the listing we've just given, so that they do indeed produce the movements intended. You might also need to tweak the first parameter of the various PWM instructions. We explained the reason for this above for stop, but the same thing happens for rota- Full source listing for obstacle-detecting robot management program ' Obstacle avoider robot on a Rogue Blue base Const Device = CB220 Dim Obstacle As Byte Input 0 Input 1 Low 5 Low 6 Delay 1000 Right whisker input Left whisker input ' P5 output for PWM ' P6 output for PWM Do If In ( 0 ) =1 Or In ( 1 ) =1 Then Pwm 1,3410,32768 Pwm 0,3410,32768 Pause 800 If In ( 0 ) = 1 Then Obstacle = 1 Else Obstacle = 2 ' Left End If ' Whisker activated? ' Servos stopped ' Right whisker? whisker ! If In ( 0 ) = 1 And In ( 1 ) = 1 Then Obstacle =3 End if Pwm 1,3590,32768 Pwm 0,3195,32768 Pause 1500 Else Obstacle = 0 End If ' Obstacle variable analysis Select Case Obstacle Case 0 Pwm 0,3590,32768 Pwm 1,3195,32768 Case 1 Pwm 0,3600,32768 Pwm 1,3600,32768 Pause 1000 Case 2 Pwm 1,3180,32768 Pwm 0,3180,32768 Pause 1000 Case 3 Pwm 0,3750,32768 Pwm 1,3750,32768 Pause 1500 End Select Loop ' Right and left whiskers? ' Backward No whisker activated ' No obstacle ' Forward ' Obstacle on the right side ' Slight turn to the left ' Obstacle on the left side ' Slight turn to the right ' Head-on obstacle ' Full half turn 7-8/2007 - elektor electronics 11 tion of the servos at full speed in one direc- tion or the other. If your robot fails to travel in a straight line when running forwards or backwards, it's just because the servos are not turning at the same speed for pulses of the same width. In this case, all you have to do is make minor adjustments to the first parameter of one or the other of the PWM instructions in order to get correct results. Don't be afraid to, the Cubloc's program memory is virtually infinitely reprogram- mable (a minimum of 10,000 cycles guar- anteed by the manufacturer of the micro- controller it's fitted with!) After a certain period of use, you'll doubt- less realize the limitations of this robot. Then it's up to you to develop it, by add- ing, for example, obstacle detectors of the same type, but to the rear, an ultrasonic distant obstacle detector, a line-follower function, etc. This issue of Elektor already ought to give you some good ideas to get you started. ( 070298 - 1 ) For robots and other control applications Markus Bindhammer This pulse sensor is designed to be used for communication between man and machine, giving a robot the ability to react to the pulse rate of its human mentor. The digital output of the circuit makes it useful in other applications as well. The sensor itself consists of an ordinary LDR (with a resistance when illuminated of 300 Q and a dark resistance of around 10 MQ) and a bright LED (D1). The LED must have an output of at least 1000 mcd as light from it must pass through the finger and illuminate the LDR. Now, when the heart pumps a pulse of blood through the blood vessels, the finger becomes slightly more opaque and so less light reaches the LDR. This can be converted into an elec- trical pulse. With each pulse the resistance of the LDR, and hence the voltage at the input to opamp IC1.A, changes. The gain of the opamp is set by potentiometer PI in the feedback path. The sensitivity of the circuit can be adjusted using potentiom- eter P2 at the input to comparator IC1.B. T1 forms an output driver that not only lights LED D2 to give a local indication of the detected pulse, but also powers up a standard squarewave oscillator circuit built around IC2, a 555 timer. At its output this produces a signal modulated by the pulse, with a frequency that can be set from 30 kHz to 40 kHz using potentiometer P3. A driver stage interfaces the output of the 555 to an IR emitter diode, which can send the modulated signal to IR receiver module IC3. The more power used to drive the IR LED, the greater the range of the link: R11 can be altered to achieve the desired LED current. The demodulated output of the receiver module can be fed directly to a microcontroller. The centre frequency of the receiver module used will determine the correct setting of P3. A pulse sensor can be made from a sim- ple 40 mm length of plastic tube, closed at one end, chosen to fit snugly over the fingertip. Holes to mount the LED and LDR are made 15 mm from the closed end, and the components are glued suitably into the holes so that they face towards the cen- tre of the tube. The connecting wires are isolated from one another and the whole sensor enclosed in a length of heat-shrink tubing to exclude external light from the LDR. If this construction seems a bit bulky, it is possible to reuse a clip from a com- mercial heart rate monitor. ( 070006 - 1 ) 12 elektor electronics - 7-8/2007 Get your robot to home-in on a sound source Claude Baumann & Laurent Kneip Service robots of the future will most likely need to act on spoken commands and be able to recognise voices. This article takes a look at one aspect of this behaviour namely locating the position of a sound source using the cross- correlation function. A technique is developed which drastically cuts down on the number crunching so that even a basic microcontroller fitted with binaural sensors can pinpoint a continuous audio signal with an accuracy of just 10 degrees. The GASTON Lego robot built in 2003 by the students at a school in Luxembourg [1] (main picture) has a number of interesting features the most obvious of which is its rudimentary 'face' which is used to express a limited range of emotions. In addition it is able to detect sounds and turn its head in the direction of the sound source. It uses an array of three microphones together with a microcontroller to make a simple 'precedence sensor' which measures the time difference produced when a sound pressure wave-front (made by a clap or fin- ger click) strikes the microphones. Figure The head acts as a low-pass filter attenuating frequencies above 1 kHz. The ear nearest the sound source will hear the sound louder than the far ear. Despite its impressive functionality, GAS- TON cannot work with a continuous audio signal let alone follow a moving sound source. This ability requires a more complex approach which we will go on to investigate here. How we track down sounds The human ear is an amazingly complex and sensitive organ. Together with dedi- cated regions of the brain it enables us to extract meaningful information from the general cacophony which is continually assailing our ears. Amongst other things it has been demonstrated that we are able to identify the bearing (azimuth) of a sound source with an accuracy of just 3°. Applying a crude analogy from engineer- ing systems we could say that the process of hearing uses a number of subsystems. Most obviously we, along with all other creatures (excluding mantids apparently) are equipped with two ears hence 'binau- ral' which in conjunction with dedicated regions of the brain we use to identify the direction of a sound source using several different methods: a. Interaural Level Difference — ILD Low frequencies have wavelengths which are greater than the diameter of the head; they extend around to the far ear with very little loss of amplitude. At frequencies above 1 kHz however the head acts as a low-pass filter providing up to 20 dB attenuation to the signal so there is a significant reduction in the sound level reaching the far ear (Fig- ure 1) which enables the brain to estimate the position of the sound source. b. Interaural Time Difference — ITD With a sound originating from one side the pressure waves arrive at the ears with a slight time difference. The brain interprets the two signals, applying a type of neural cross-correlation function. The phase shift between the two signals gives the angle of the sound source (the azimuth a). It can be seen from Figure 2 that sound emanating from any of the points M{u,v) lying on the hyperbola given by the equations u 2 /a 2 - v 2 /b 2 = 1 a - Ax / 2 b 2 = k 2 - a 2 where k is the half distance between the ears. These points produce exactly the same time difference at the ears. The term Ax is the distance the sound travels in the time At, with Ax = c x At. The speed of sound c equals 343 m/s at 25°C. The hyperbola approaches the asymptote given by: v = b/a x u where tan((3) = b/a. ( — arctan \ 1 A t 2 — \ -1 / For R (right ear): a = 90° - (3; for L (left ear) the corresponding a = -(90° - (3). 7-8/2007 - elektor electronics 13 The ear must also be able to determine if the sound emanates from in front of or behind the ear and also either from above or below. The points in three-dimensional space where a sound source will produce identical time differences in the left and right ear actually form the surface of a hyperboloid. It is thought that the brain can resolve these spatial ambiguities by detect- ing subtle changes in the signal spectrum caused by the outer ear shape, absorption/ scattering by the torso and head, localising by turning of the head and possibly also by detecting Doppler effects. Whatever processes the brain uses to resolve the left-right direction problem it is interesting to plug some values into the for- mula for a sound source positioned in front and to the right of the head. At a bearing a = 20° and assuming an ear separation of 17.5 cm, a time difference of 175 ps will be apparent at the ears. At an azimuth of just 3° the time difference will only be 27 ps. It is difficult to imagine how the brain (with a neuron switching time in the millisecond range) can resolve such short time differ- ences and gives us some insight into the complex processes it is capable of. The limits of ITD for localising a contin- uous tone are clear; a sound wave will Figure 2. A sound pressure wave from the side will not arrive at both ears at the same time. Points in space where a sound source produces identical delays at the ears are on a hyperbola (red) approaching the asymptote (white). The brain cannot identify the position but only approximate the direction of a sound source anywhere along this line. +5V 9 |R 3 CM CM H in 16V MICR D +5V 9 | RIO 16V MICL D R4 j R5 1 47k V © 'REF C2 R7 HE} R8 - | 100k h +5V © in 16V R6 © | R18 Tb19 [I R9 V REF X IC1 = LM324N R12 rii J {ItQ 10 © V REF SENSITIVITY R15 ^ -| 100 k | R17 / 100k 0 1 R20 JP1 17 18 JP2 7 7 s c 7 c c III r± 2 C8 lOOn 14 © MCLR RB7 RB6 RAO IC2 RB5 RA1 RB4 RA2 RB3 PIC16F88 RA3 RB2 RA4/T0CKI RBI RB0/INT OSC2 OSC1 CIO 22p 15 XI 20MHz 16 ) C9 22p K1 POWER C6 27 © 100^1 16V C7 2 ici 100n @ R2 +5V -© V REF © 13 12 11 10 C5 □ 22|i 16V 060040- 11 K2 O O o o o o 2 Q K3 O O TX K4 O O RX K5 O § <5 SO Figure 3. The circuit has two audio channels each with an electret microphone and two-stage amplifier. The two amplifier outputs are connected to the two A/D converter inputs on the microcontroller. 14 elektor electronics - 7-8/2007 take around 500 ps to travel the distance between the ears which equates to a half cycle or a 180° phase shift between the two signals. At frequencies of 1 kHz and above it is no longer clear if the signal in one ear leads or lags the other ear. c. The Precedence effect Strong reflections and standing waves produce localised highs and lows in sound pressure when a continuous tone is reproduced in an acoustically reflective enclosed space, making it almost impos- sible to pin-point the sound source. When the sound source is discontinuous however it has been shown that the brain is able to identify the source, using a modified ITD measurement it gives precedence to the arrival of the first sound pressure wave at the ears and appears to open a 'neural time window' of around 1 ms for this pur- pose, ignoring any subsequent echoes. The phase difference of the two signals gives the azimuth bearing of the sound source. The LEGO robot GASTON uses this tech- nique but it is not of much use for continu- ous sounds. Cross-Correlation When there are two identical signals shifted in time, it is common practice to apply the cross-correlation operation to them. Together with Fourier analysis these two operations form the backbone of tech- niques used in digital signal processing. The digital cross-correlation is derived from two continuous waveforms as follows: The value at At = 0 is found by sampling the waveforms at intervals t, multiplying the samples from the two waveforms together and then summing them and normalising the result. The cross-correlation at another position, say At = 1 ps is then performed in the same way except this time the sec- ond signal is shifted in respect to the first by 1 ps. The maximum sampling rate is chosen to ensure that the processor can perform the necessary calculations along with any other work it needs to do within the sampling time constraints. It can be determined by the resultant cross- correlation whether the two signals are 'correlated' for example if the first signal is not in phase with the second signal but otherwise very similar the cross-correlation function will show a marked peak corre- sponding to the phase shift between the two signals. Cross-correlation calculations involve many multiplications and addi- tions; it is hardly surprising that in the DSP world it has a reputation for being particu- larly processor hungry. Reducing computer loading In order to perform cross-correlation with a general purpose microcontroller it is necessary to find ways of reducing the number of computations that the processor is required to make. For this application it is valid to limit the number of phase shifted operations taking into account the distance between the two microphones. It can be shown also that maximising the product sum (cross-correlation function) is equiva- lent to minimising another function which is much simpler to calculate. For each phase shift the sum of the differences of both values (squared) can be transformed so that cross-correlation function y (t) in the equation /(D = 2[ x ^ _ tG + D] 2 = ^|^x 2 (0 + y 2 (t + r) — 2 x(t)y(t + r)J = ^x 2 (t) +^y 2 (t + r) - 2 YjX(t)y(t + r) y — ^ = c i ~2^x(0y(t + r) = c x — 2 • N • y(r) with y (t ) = (2 N)’ 1 [c 1 - f( x)]. The value of q is constant for every phase shift while the square of the values are added in each case irrespective of which phase position it is. (N is the constant geo- metric mean of all the signal values pro- duced by normalising y (x )). It is evident that when the cross-correlation value is at maximum it corresponds to a minimum of the deviation sum of f. The following expression is therefore valid for our appli- cation and makes fewer demands on pre- cious processor resources. g(r)='2 j \x(t)-y(t + r) This expression is a close approximation to cross-correlation. The two measured sam- ples are subtracted (ignore the sign) to give the absolute difference. Summing them produces a non-normalised value which is at a minimum when the waves are corre- lated. The technique requires far fewer cal- culations than the classic cross-correlation method and is at least 20 times faster. Construction of the binaural sensors The circuit in (Figure 3) could hardly be simpler. It consists of two audio channels each with own electret microphone and two-stage audio amplifier. Each audio sig- nal is then fed to two pins of a microcon- troller which have been configured as A/D converter inputs. A preset pot, R17, allows sensitivity adjustment. Bearing data is output every tenth of a second using several different interfaces, which gives the sensor the flexibility to be used in many different types of robot. The 8-bit bearing information is sent from TX serially using a UART (2400 1 N 8), it is also output as a 5-bit parallel digital value. A servo output (PWM/Servo) provides a signal with a width from 1 to 2 ms at a 50 Hz repetition rate suitable for driving a standard modelling servo. Jumper 1 (Hold) is provided for test purposes, it introduces a two seconds pause between readings during which time the last valid output is maintained. Jumper 2 (Relative) defines how the output behaves when the received sounds are too quiet to make a measure- ment; with it fitted the output returns to the middle position (azimuth a = 0), with it removed the output retains its last valid position. This gives the system a degree of flexibility, for example if the microphones are mounted on a robot which can turn and move toward the sound it is better to fit the jumper otherwise the robot contin- ues to turn when no sound is detected. When the microphones are fixed and the output is used to pan a webcam say, it is better to remove the jumper otherwise the camera continually pans back to the centre position when no sound is detected. The RX input can be used later for micro- controller firmware updates. A 100-kQ pulldown resistor is used to avoid a float- ing input. Timing and resolution For this application we will consider the frequency range from 200 to 1000 Hz that the processor calculates the ITDs (signal delays) it requires a sufficiently high sam- pling rate which could only be achieved by careful optimising of the program code. The PIC16F88 architecture is organised so that data from the two channels can be stored in two 96-byte banks (banks 2 and 3) as quickly as possible by switching a sin- gle bit and using indirect addressing. The PIC16F88 contains a 10-bit A/D con- verter but for this application the two least significant bits are ignored so that we use an 8-bit value. The sampling rate is 20 kHz. The values are smoothed by an FIR-filter. Any erroneous values detected by the program are over-written with the previous correct value. At a frequency of 1 kHz a 180° phase shift is measured after 0.5 ms i.e. the time taken for ten samples. The smallest detectable time difference corresponds to a minimum distance of: c/ min = 50 [ps] • 343 [m/s] = 1.7 cm This gives the optimum spacing between the microphones (2k) of: 2k = 10 [Samples] x c/ mjn = 17 cm 7-8/2007 - elektor electronics 15 Figure 4. Component layout of the binaural sensor PCB. The PCB files can be downloaded from (3). Figure 5. Resolution of the sound source bearing is a function of its azimuth. The average value is approximately 9°. Components list Resistors Rl,R5,R12 = 47kQ R2 = 33kQ R3,R10 = 22kQ R4,R11 = lkQ R6,R9,R13,R16,R18,R19,R20 = lOkQ R7, R14 = 2kQ2 R8, R15 = lOOkQ R17 = lOOkQ preset Rx = lOOkQ Capacitors 01,02,03,04 = lpF 16 V 05 = 22(j F 16 V 06= lOOpF 16 V 07,08= lOOnF 09,010 = 22pF Semiconductors ICl = LM324 IC2 = PIC16F88, programmed, order code 060040-41 from ElektorSHOP Miscellaneous Q1 = 20MHz quartz crystal DIL14 socket DIL18 socket SL1,SL2,(SL4),SL5,SL6,SL7 = 2-way SIL pinheader (SL4 bridged with a 100k resistor, see text) SL3 = 6-way SIL pinheader JP1JP2 = jumper MicR, MicL = CZ034 electret microphone insert PCB, ref. 060040-1, free artwork download from Elektor website Figure 6. The binaural sensor prototype. When the sound source is at the extreme right or left of the field (azimuth a = ±90°), a time difference of ±10 samples will be measured. A minimum of 20 calculations are made for the correlation calculation. When the microphones are mounted on either side of a (solid) head this has the effect of increasing the microphone spac- ing, the pressure wave from one side needs to travel around the curve of the head before it reaches the second microphone. Assuming a sphere with microphones mounted along an axis, the arc length is r x 71, where r is the radius of the head and should be chosen so that the arc length is not greater than 17 cm. The accuracy of the bearing calculation is a function of the azimuth of the sound source. It can be seen from Figure 5 that when the source is central in front of the microphones an accuracy of approxi- mately 5° can be expected while sound from the sides achieve around 11° and only 25° at the edge which all together gives an average figure of 9°. The highly direc- tional nature of the electret microphones response characteristics meant that further study the longitudinal response was not worthwhile. The PIC16F88 microcontroller used in this project was programmed using the Ulti- mate_PIC tools which are based on the Labview programming environment. The beta version of Ultimate_PIC is available from The Center for Engineering Educa- tion Outreach (CEEO) at Tufts University Massachusetts. The assembler and hex files for this project Binaural_v132.asm and Binaural_v132.hex can be freely downloaded from the Elektor Electronics website [3] where a pre-pro- grammed PIC controller can be ordered as 16 elektor electronics - 7-8/2007 an alternative from the SHOP section. The PCB layout and component placement is shown in Figure 4; the PCB artwork files are also available for download from [3]. Construction and Test A picture of the prototype is shown in Figure 6. Shielded cable must be used to connect the two microphones to the con- troller board to help reduce pick-up of electrical noise. The current consumption of just 1 0 mA can be supplied by almost any 5 V stabilised power unit. The microphones are mounted 17 cm apart, pointing forwards. A 500 Hz tone is an ideal sound source for test pur- poses but voice/music from a radio is also suitable. Turning the sensitivity preset to the left will increase the sensor sensitivity. A simple DC output level can also be achieved by connecting a 2 R/R resistor network to the 5-bit Digital output (Fig- ure 7). The resultant DC output level is buffered by IC1A. ( 060040 - 1 ) Web links (1) www.convict.lu/Jeunes/Roboticslntro.htm (2) www.ultimaterobolab.com (3) www.elektor-electronics.co.uk Figure 7. The resistor network functions as a simple D/A converter. Sensor output values: Sound direction (s+2) 8-bit-lnteger (TX) PWM/Servo (s+6) 5-bit-lnteger (Digital) Extreme right 22 2 ms 26 Central 12 1.5 ms 16 Extreme left 2 1 ms 6 Tilo Gockel Sometimes it's necessary to add a D/ A converter to a microcontroller for a specific application. This can be fairly simply accomplished by interfacing an off-the-shelf D/A converter to the microcontroller's bus. An even simpler and more cost-effective solution based on an application note from Microchip [1] is shown here. A microcontroller produces a PWM (pulse width modu- lated) digital output signal which is fil- tered by a low-pass RC filter. Although the PWM signal has a fixed repetition rate the on-to-off ratio is varied from 0 to 100 % which, after filtering gives an analogue output signal proportional to the ratio. A single digital output from a port pin (driven from an on-chip timer for example) can therefore form the basis of an analogue output signal. Guidelines to calculate values for the RC low-pass filter are given in the application note. Using the values suggested (3.9 kQ +10V and 1 0 nF) gives a -3 dB corner frequency of around 4 kHz. When driven by a PWM frequency of approximately 20 kHz the filter will be suitable for outputting audio tones and voice signals with a bandwidth of 4 kHz. This simple filter will attenuate the 20 kHz fundamental PWM frequency by 14 dB which may not sound like much but the human ear has its own high fre- quency roll-off (the characteristics of which change as we age) so frequen- cies this high will be barely audible. Any standard operational amplifier, for example the TL071 can be used in this application. Lower frequency signals all the way down to DC can also be handled by this circuit and in this case the low-pass filter corner fre- quency can be reduced further which will give better attenuation of the PWM fundamental and reduce ripple on DC output signals. One typical application of the circuit is speed control of a DC motor in accordance with the industry standard +10V. The circuit will connect to the motor via a suitable power driver stage. In this case the electromechanical proper- ties of the motor itself will act as a low pass filter. ( 070133 - 1 ) Web link (1) http://wwl .microchip.com/downloads/ en/AppNotes/00538c.pdf 7-8/2007 - elektor electronics 17 Seattle Robotics give BoeBot (and other robots) vision! ble. Plug in the hardware, upload the demo code then press the buttons and watch your BoeBot use its new vision system to "see" and respond to its environment. Purpose The CMUcaml AppMod™ vision system consists of a CMUcaml vision system mounted on a plug in AppMod board. Included on the AppMod board is a simple user interface consisting of two buttons, eight LEDs and one piezo speaker. The user interface serves these three purposes: 1) A simple menu selection system which works with the included demo code to allow you to select and run one of eight robot vision demonstration programs. 2) Provide visual feedback from the LEDs as the demo programs run showing where the CMUcaml is seeing the tracked target. 3) Indicate the colour of objects it sees by illuminating the corresponding LED (e.g., red LED for a red object). With some clever circuitry on the AppMod board the two buttons, eight LEDs and one piezo speaker only require four I/O pins on your Basic Stamp2 thereby conserving I/O pins for other uses. An 8-function demo With the CMUcaml AppMod Vision Sys- tem plugged into the BoeBot AppMod connector the next step is to program the main demo code from the CD-ROM to the Basic Stamp2. The demo code has eight functions, each of which demonstrating a Table 1 . Basic command set Command Parameter(s) Description 1 \r none The 'Enter' or 'Return' key. Set the camera board into an idle state. GM none (\r) Get the Mean colour value in the current image. LI value \r Control the green LED tracking Light. MM mode \r Controls the Middle Mass mode which adds the centroid coordinates to the normal tracking data. NF active \r Controls the Noise Filter setting. It accepts a Boolean value 1 (default) or 0. A value of 1 enga- ges the mode while a value of 0 deactivates it. PM mode \r Puts the board into Poll Mode. Setting the mode parameter to 1 engages poll mode while 0 (default) turns it off. RS none (\r) ReSets the vision board. Note, on reset the first character is a /r. SW (x y x2 y2) \r Sets the Window size of the camera. It accepts the x and y Cartesian coordinates of the upper left corner followed by the lower right of the window you wish to set. TC (Pmin Pmax C m j n G max Bmin BmaxAr Track a Colour. Accepts the minimum and maximum RGB (CrYCb) values and outputs a type M or C data packet (set by the MM command). TW none (\r) Track the colour found in the central region of the current Window. 1 Complete descriptions may be found in the user manual. Ken Gracey (Parallax, Inc.) BoeBot is a little robot vehicle designed and marketed by Parallax Inc. [1]. Boe- Bot's intelligence comes from another Parallax product, the Board of Edu- cation (BoE) which in turn is based on their renowned BASIC Stamp. Both the robot proper and the BoE have been graced by many publications in the elec- tronics press and on the Internet. Rightly so, as apart from their low cost the projects come with backup of a volume and level that make them perfectly suit- able for use in schools and, in general, for learning about robotics [2]. For the CMUcaml Vision System, Par- allax teamed up with Carn- egie Mellon University [3] through Seattle Robotics [4]. The product is how- ever only available from Parallax and their dis- tributors like Milford Instruments [5]. The CMUcaml BoeBot package includes 1. A CMUcaml mounted on an AppMod user inter- face board. 2. A printed user manual. 3. A CD-ROM that includes demo programs. The goal of the product is to give you as simple a plug & play experience as possi- 18 elektor electronics - 7-8/2007 Table 2. Advanced commands Command Parameter(s) Description 1 CR ( regl valuel (reg2 value2 ... regl6 valuel6) )\r Sets the Camera's internal Register values directly. The register locations and possible settings can be found in the Omnivision documentation. DF none (\r) Dump a Frame out the serial port to a computer. DM value \r sets the Delay before packets that are transmitted over the serial port. GV none (\r) Gets the current Version of the firmware from the camera. HM active \r puts the camera into Elalf-horizontal resolution Mode for the DF command and the LM com- mand when dumping a bitmap image. 11 none (\r) Uses the servo port as a digital Input. LM active \r Turns on Line Mode which uses the time between each frame to transmit more detailed data about the image. RM bit_flags \r Engage the Raw serial transfer Mode. It reads the bit values of the first 3 (Isb) bits to configure settings. SI position \r Lets you Set the position of servo 1. 0 turns the servo off and holds the line low. 1-127 will set the servo to that position while it is tracking or getting mean data. SM value \r Used to enable the Switching Mode of colour tracking. 1 Complete descriptions may be found in the user manual. capability of the CMUcaml . When you first turn on the BoeBot the eight LEDs on the AppMod interface board will flash several times, then the piezo speaker will beep indicating it is ready. Each func- tion starts with one audible beep and stops with two beeps. The LEDs flash during each function in different patterns to let you know how that function is operating. The eight functions of the demo comprise: 1. Calibrate Lighting - about 20 seconds are needed to allow CMUcaml to calibrate to the ambient lighting conditions. 2. Sample and Save Colour - it takes about a second to lock onto the colour of an object held in front of the cam; the LEDs will flash and the speaker will beep twice when done. The colour values are saved in the Basic Stamp2 EEPROM. 3. Track Colour - the robot moves for- ward, backward, right and left to follow the colour of the object saved during func- tion 2. 4. Move & Avoid - the robot will move forward and avoid objects using the vision sensor only. It works by sampling the colour range of the floor in front of the robot. 5. Adaptive Tracking - the robot locks onto the first colour it sees and tracks that colour (it only goes fwd, right and left, not bwd). If it loses the object for about five seconds it then locks onto the next colour it sees and tracks that until it loses that, etc. 6. Line Following - it is assumed a black line about 1.2 cm (.5 in.) wide is present on a white line tracking course. 7. Finger Point and Move - the robot will backup, turn right and turn left in rela- tion to finger pointing. This is done with the CMUcaml using the same downward facing angle as is used on all the other functions. 8. Show Colour - the robot will light up either all of the red, green or yellow LEDs in response to the colour of the object placed in front of it. This works well with 5-cm diameter coloured rubber ball or plastic block. For best performance with all of the above functions, the tilt of the camera should be pointing down looking just in front of the robot. Basic Stamp2sx and Basic Stamp2p This CMUcaml AppMod and demo code will also work with the more powerful 2sx and 2p versions of the Basic Stamp. Sepa- rate versions of the demo code for each Stamp can be found on the CDROM. The code changes are minor and related to the 2.5 times faster execution speed. You can do more with the CMUcaml and the 2sx and 2p Stamps due to their faster speed and larger memory. The Basic Stamp2 is limited to 9600 baud serial inter- face speed to talk to the CMUcaml but the 2sx and 2p can both talk to the CMU- caml at its maximum serial data rate of 115,200 baud. The CMUcaml is switched to the 115,200 baud rate by removing two jumpers that can be found on its board. The higher baud rate means BoeBot can respond much faster to the vision system. About the CMUCam and the module The CMUcaml is an SX28 microcontroller [6] interfaced with an OV6620 Omnivision CMOS camera [7] on a chip that allows simple high level data to be extracted from the camera's streaming video. The board communicates using a TTL level serial port and has the following functionality: • Track user defined colour blobs at 17 frames/s • Find the centroid of the blob • Gather mean colour and variance data • Arbitrary image windowing • 80x143 resolution • 9600 baud serial communication • Automatically detect a colour and drive a servo to track an object • Slave parallel image processing mode off a single camera bus (advanced function) • Ability to control one servo or have one digital I/O pin (advanced function) • Adjust the camera's image properties (advanced function) When using the camera outside, due to the sun's powerful IR (infrared) emissions, even on relatively cloudy days, it will prob- ably be necessary to use either an IR cutoff filter or a neutral density-3 camera filter to decrease the ambient light level. A lens taken from a cheap drugstore pair of sun- glasses when placed over the camera lens will allow the CMUcaml to work in sun lit conditions. Serial comms and command sets The serial communication parameters are as follows: 9600 baud, 8 data bits, 1 stop bit; no parity, no flow control (no Xon/Xoff or hardware). All commands are sent using visible ASCII characters, i.e., 123 is three bytes "123"). Upon a successful transmission of a com- mand, the ACK string should be returned. If there was a problem in the syntax of the transmission, or if a detectable transfer error occurred, an NCR string is returned. After either an ACK or an NCK, an \r is returned. When a prompt ('\r' followed by a ':' ) is returned, it means that the camera 7-8/2007 - elektor electronics 19 is waiting for another command in the idle state. White spaces do matter and are used to separate argument parameters. The \r (ASCII 13, carriage return) is used to end each line and activate each command. If visible character transmission exerts too much overhead, it is possible to use varying degrees of raw data transfer ('Raw mode'). The system supports two command sets — basic (Table 1) and advanced (Table 2). Utility programs Also included on the Seattle Robotics CD- ROM are the following utility programs. Test CMUcaml to BoeBot communica- tion. This program sets up a 9600-baud serial connection between the Stamp and the CMUcaml. It then tells the CMUcaml to blink its green LED. Display CMUcaml tracking data on debug screen. The first data packet dis- played by the Debug screen is the 'S' (Sta- tistics) packet which tells you the colour of the object it is tracking. This will let you evaluate the ability of your camera to track an object. Try different colour objects and different sizes to see the effects on the tracking data. This is an important program that you will re-use many times as you as you find more and more interesting things to do with your CMUcaml and BoeBot. This program allows you to see and under- stand exactly what your BoeBot can see with its CMUcaml vision system. A short video showing a CMUcam- equipped BoeBot locating a red object may be found at [8]. ( 070132 - 1 ) Web references (1) www.parallax.com (2) www.stampsinclass.com (3) www.seattlerobotics.com (4) www.cs.cmu.edu/~cmucam (5) www.milinst.com (6) www.ubicom.com/processors/sx/ sx_family. html (7) www.ovt.com (8) www.seattlerobotics.com/video.htm David Gustafik One of the traditional 'disciplines' in which robots are supposed to compete is the Line Follower Competition. Robots go along a predrawn black line (usually duct tape) on a white-ish surface (usually paper, cardboard or plastic). This discipline requires special sensors. Usually, these are made out of reflective optosensors (such as CNY70, LTH-209). This sensor contains a phototransistor and an infrared LED. These sensors are pointed at the surface on which the robot is sup- posed to show off its speed and agility. The LED emits infrared light on the surface and the phototransistor acts as a receiver. The black coloured line to follow reflects far less light than the white surface it is affixed on. The current that flows through a phototran- sistor depends on the intensity of the light detected. Therefore, more current will flow through the transistor when it is above a white surface. In this way, the sensor can also be used as a surface detector. The minimal count of sensors necessary for making a line following robot is... two — one on the left side and one on the right. It is advisable to use at least three sensors - one left, one right and one in the middle as a failsafe precaution against the robot dropping off a table edge. In this circuit, the voltage on the phototran- sistor is compared with a reference level set by PI. When IC2 is illuminated, the voltage on it drops. Comparator IC1 A compares the voltage against the set reference. If the ref- erence voltage is higher than that on pho- totransistor, the comparator's output is drops to (almost) zero. This occurs when there is a black line under the sensor. The output sig- nal from the comparator is then connected to either a microprocessor or any control logic that (hopefully) responds by adjusting the course of the robot . The circuits needs to be calibrated before use. The best method is to set the PI pre- set to the centre of its travel. Next, place the sensor above the surface it is supposed to detect, where it is white. Note that the height of the sensor above the surface is important. It doesn't matter that much when using for instance a CNY70, but an LTH209 for example only works in a very small range of heights (around 3.8 mm). If the response from the output of the com- parator is good (i.e., pin 2 High) move the sensor above a line. If the result is again as expected (pin 2 Low) you're done calibrat- ing the circuit. If not, repeat the process and adjust PI until the correct calibration is achieved. The schematic for only one of four chan- nels that can be made with just one LM339 1C. The pull-up resistor at comparator pin 2 is used because the LM339 has open-col- lector outputs. R3 determines the current going to the IRLED. Many comparators can be used, the LM339N just happened to be available. The same may apply largely to the opto- sensor, but note that many different pinouts exist so check out that datasheet. ( 070230 - 1 ) 20 elektor electronics - 7-8/2007 T. K. Hareendran At the heart of this circuit is a precision integrated temperature sensor type LM35 (IC1), which provides an accurately linear and directly proportional output in mV, over the zero to +155 degrees C tempera- ture range. The LM35 develops an output voltage of 10 mV/K change in measured temperature. Designed to draw a minimal current of its own, the LM35 has very low self heating in still air. Here the output of the LM35 is applied to the non-inverting input of a compara- tor wired around a CA3130 opamp (IC2). A voltage divider network R3-P1 sets the threshold voltage, at the inverting input of the opamp. The threshold voltage deter- mines the adjustable temperature trip level at which the circuit is activated. When the measured temperature exceeds the user-defined level, the comparator pulls its output High to approx. 2.2 V causing transistor T1 to be forward biased instantly. T2 is also switched on, supplying the oscillator circuit around IC3 with suf- ficient voltage to start working. The 555 set up in astable mode directly drives active piezoelectric buzzer Bzl to raise a loud alert. Components R7, R8 and C4 deter- mine the on/off rhythm of the sounder. A transistor based relay driver may be driven off the emitter of T1 (TP1). Similarly, replacing the piezo sounder with a suit- able relay allows switching of high-power flashers, sirens or horns working on the AC mains supply. ( 060349 - 1 ) with a PIC or a Basic Stamp C. Tavernier Although the simplest robots may be con- tent to simply detecting obstacles, many robots that require precision in their posi- tioning need to be able to measure dis- tances accurately. To achieve this, it is necessary to use a telemeter, which can be infrared or ultrasonic. IR is very suit- able for measuring short distances (a few centimetres up to a few tens of centime- tres), while ultrasound is more suitable for distances from a few tens of centimetres to several metres. Although it is still possible to construct a telemeter using standard resources, these days it's not really worthwhile because of the availability of ready-to-use integrated modules that are all relatively accurate, cheap, and compact. Taking a look at IR telemeters, the Sharp range is currently the largest and most readily available, insofar as we wish to stick with products at prices compatible with an 'amateur' robot. This range, whose part numbers all begin with GP2..., includes telemeters that pro- 7-8/2007 - elektor electronics 21 Listing 1 . Use of GP2Dxx with a Basic Stamp. Vin Vout Measr con 0 con 1 var Byte ' Definition of control input ' Definition of data output ' Allocation of one byte for the result Measr = 0 Read : Vin = 0 Wait : IF Vout = 0 THEN Wait SHIFTIN Vout, Vin, 2, [Measr] Vin = 1 Pause = 1 ' Initialization of variable « Measr » ' Validation of telemeter ' Wait until result is available ' Put telemeter to sleep ' Pause as a precaution ' The result of the measurement is available in the variable 'Measr' vide on/off outputs (though these aren't really telemeters as such!), information in analogue form, and information in digital form. Though the versions providing ana- logue information would appear to be the easiest to use, it's absurd to use them in a robot driven by a microcontroller, which will immediately convert this analogue voltage into a digital signal via its built-in converter so as to be able to make use of it. So it is better to have digital informa- tion available right from the outset, even if it might seem a little harder to read at the telemeter output. In these circumstances, two types are currently readily available: the GP2D02, capable of measuring from 10 cm to 80 cm approximately, and the GP2D021, capable of measuring from 4 to 30 cm approxi- mately. These two types are fully compat- ible both mechanically and electrically, and so everything we are about to write is equally applicable to both of them. The principle of an IR telemeter is relatively simple: an LED emits an IR beam that, if it encounters an object, is reflected back towards a photodiode. Left at that, such a system is an on/off type and is really more an obstacle detector than a true telemeter. Although certain of the Sharp telemeters do work along these lines, the two types we've chosen are capable of perform- ing true distance measurement, as the rays reflected by the object are no longer picked up by just a simple photodiode, but by a CCD array. As a result, the angle of incidence of the reflected beam reaching this array varies according to how far away the detected object is, and hence allows true distance measurement, provided there is a mini- mal amount of signal processing to exploit the information generated by the CCD sensor. This is the case in the Sharp telemeters of this type, the internal block diagram of which is shown in Figure 1 . In those telem- eters with a measurement validation input (as in the models chosen), the LED is only powered under its control, allowing a very significant reduction in quiescent power consumption. In the other telemeters, it's on all the time. The CCD sensor is followed by a signal processing circuit that allows an output to be generated as either an on/off type signal for the simplest telemeters, an analogue signal, or lastly, 8-bit digital information, as in the models that interest us. So as to be compatible with a maximum number of robotics solutions, we've opted to show you how to use such a telem- eter with either a Basic Stamp or a PIC microcontroller programmed in Basic or machine code. Listing 2. Use of GP2Dxx with a PIC controller. BCF PortA . 0 \ Validation of telemeter NOP Wait BTFSS PortA, 1 \ Wait until result is available GOTO Wait BSF PortA, 0 \ Vin goes High CLRF Measr \ Initialization of the variable MOVLW 8 \ Get ready to read 8 bits MOVWF Count BCF NOP Readbit Status , C \ Zero the carry BCF Porta . 0 \ Make clock Low NOP NOP RLF Measr , f \ Rotation of preceding bit BTFSC PortA . 1 \ Read data bit BSF Measr, 0 BSF PortA . 0 \ Make clock High NOP NOP DECFSZ Count, f ' Count down number of bi GOTO Readbit The result of the measure is available in the variable 'Measr 1 22 elektor electronics - 7-8/2007 3 The telemeter application circuit can be summed up as shown in Figure 2, whether it's with a PIC or a Basic Stamp. The GP2D02 or GP2D021 detector is powered all the time, but because it has a control input, it consumes virtu- ally nothing when there is no measur- ing taking place. A glance at the timing diagram in Figure 3 shows us that this input is used not just for validating the measurement, but also as a clock for transferring the reading to the V out ter- minal. Hence it needs to be controlled by the associated microcontroller, but as it must not be subjected to a voltage above 3 V, diode D1 isolates it from the microcontroller output when the latter is high. The timing diagram in Figure 3 should enable you to easily follow the listings of the very short programs we've writ- ten for using this sensor, whether in Basic, for the Basic Stamp and PICs pro- grammed in Basic, or in PIC assembler, for those of you who prefer machine code. As far as the Basic Stamp is concerned, just the instruction SHIFTIN is all it takes to read the result of the sensor's measure- ment. For the PIC, there will obviously need to be a few more instructions to generate the read clock and recover the relevant data. In both cases, these pro- grams provide the digital data returned by the telemeter following the meas- urement in the variable 'Measr'. Then it's up to your robot's manage- ment program to use this value directly, or to linearise it using a conversion table, if you want to perform actual distance measurement. In fact — and this is perhaps the sole shortcoming of these telemeters — the information they provide is far from lin- ear, as shown in Figure 4. ( 070235 - 1 ) White paper: KODAK made gray chart R-27 white surface (reflectivity: 90%) Gray paper: KODAK made gray chart R-27 gray surface (reflectivity: 18%) 20 40 60 80 100 120 140 Distance to reflective object L (cm) 070235- 14 Hesam Hoshiri Control by sound may be very useful, not just on a robot but also for a bit of home automation, for example a sound-activated light responding to a knock on the door or a hand clap. The light will be automatically switched off after a few seconds. An alternative use is burglar protection — if someone wants to open the door or break some- thing the light will come on, suggesting that someone's at home. The circuit can work from any 5- 12 VDC regulated power supply pro- vided a relay with the suitable coil volt- age is used. When you first connect the supply voltage to the circuit, the relay will be energised because of the effect of capacitor C2. Allow a few seconds for the relay to be switched off. You can increase or decrease the 'on' period by changing the value of C2. A higher value results in a longer 'on' period, and vice versa. Do not use a value greater than 47 pF. Biasing resistor R1 determines to a large extent the microphone sensitiv- ity. An electret microphone usually has one internal FET inside which requires a bias voltage to operate. The optimum bias level for response to sound has to be found by trial and error. All relevant electrical safety precau- tions should be observed when con- necting mains powered loads to the relay contacts. ( 060379 - 1 ) 7-8/2007 - elektor electronics 23 1 C. Tavernier Creating a robot capable of following an exact course without needing any external physical help — like a line marked on the ground for example — has for a long time been a very tricky operation to achieve. Thanks to the boom in amateur robotics on the one hand, and to the devel- opment of new sensors on the other, it is today possi- ble to make robots with func tions that only a few years ago would have seemed more like science fiction. And this is just what we're proposing now, with the construc- tion of a robot capable of detect- ing terrestrial magnetic North, and hence to follow any angular direc- tion with respect to that, exactly as you would find your bearings using a compass. To do this, it uses a suc- cessor to the good old needle com- pass, in the form of a module made by Devantech called a CMP03 (or CMPS03, depending on versions and documents). This module, supplied in the form of a small, ready-to-use PCB as shown in the photo, contains two Philips KMZ51 magnetic field sen- sors mounted at right angles, with their output signals processed by a suitably-programmed PIC16F872 microcontroller. It is capable of delivering angular position information with respect to terrestrial magnetic North with an accuracy of up to a 1/10°. This information is available in the form of a PWM signal where the width of the pulses represents this angle, though in this case the resolution is only 1°. It is also available via an l 2 C bus that, depending on which register is read in the module, can make this angle available in the form of a 16-bit word, offering a precision of 0.1°. If a robot is fitted with such a module, it's then possible at any moment to find out the angle its trajectory is making with mag- netic North, and hence to steer it exactly as you would yourself using a compass. The only 'problem' that may arise is the interfacing of the CMP03 module with the microcontroller fitted in the robot. So in order to cater for the greatest number of robotic configurations possible, we're going to show you how to employ both means of dialogue offered by the module: i_ 2 3 20 _ 1 9_ 1 8_ 17 _ 16 _ 1 5_ 14 13 21 © SOUT VIN SIN ATN RES IC1 P15 P0 P14 PI P13 P2 P12 P3 P11 P4 BS2 P10 P5 P9 P6 P8 P7 J- J- I 4 23 24 +U <±> 22 -o -To L -o _6 7 _8 _9 1° 11 12 L o SI O CMP03 or CMPS03 O H-O O 070304 - 1 1 <2> the PWM signals and the l 2 C bus. Figure 1 shows a circuit for using the PWM signals. It has been designed for use with a Basic Stamp II, but can be transposed for any PIC microcontroller programmed in Basic that does not have l 2 C functions. Interrupt SI, present on pin 6 of the CMP03 module, is not involved in the dialogue process, but makes it possible to calibrate the module as per a procedure given in the documentation, which we won't reproduce here, as it is perfectly straightforward. The information supplied by the CMP03 module is a succession of high pulses sep- arated by low states of 65 ms duration. The width of the high pulses indicates the angle of the principal axis of the module with respect to North, according to the follow- ing relationship: Position = (Width - 1) x 10 where: • Position is the angle in degrees with respect to magnetic North. • Width is the width of the high pulses in milliseconds. Reading such information with a Basic Stamp II or a PIC programmed in Basic amounts to just two lines of program: PULSIN 0, 1, PULSE POSITION = (PULSE - 500) / 50 The first line enables the instruction PULSIN to read the high duration of the pulse generated by the CMP03 module. The second line merely applies the above relationship, given that the resolution of the measurement per- formed by PULSIN is 2 jus in the case of the Basic Stamp II. So we then have the angle in degrees with respect to magnetic North in the variable POSITION. If you want greater precision, or if your microcontroller does have an l 2 C interface available, it's possible to use this interface to dialogue with the CMP03 module, as is shown by way of example in Figure 2. It has been designed for a Cubloc CB220 or a PIC programmed in Basic with a compiler that has an l 2 C library, which is the case for most of them these days. The only precautions to be taken with this circuit concern the l 2 C bus pull-up resis- tors, which do need to be fitted as they are not built in to either the CMP03 module or the microcontroller (whichever type it is). If you are using a PIC programmed in Basic, you also need to ensure you cor- rectly choose the ports intended to handle the SDA and SCL signals of the l 2 C bus, as certain Basic compilers impose restric- tions here. To be in a position to write the correspond- ing program, all you then need to know is that the l 2 C address of the CMP03 mod- ule is CO and that four main registers are accessible to us through this address: • register 0 contains the module's software version number; • register 1 contains the angle coded in one byte. Hence this value changes from 0-255 corresponding to a circle from 0-360°; • registers 2 and 3 contain the angle, 24 elektor electronics - 7-8/2007 coded this time in two bytes, in the form of a number between 0 and 3599 (expressed in deci- mal), which is in fact the angle in degrees multiplied by 10. From that point on, reading this information via an l 2 C bus is quite straightforward, as shown in the very short listing below, written for the Basic language of the Cubloc: I2CSTART Temp = I2CWRITE (&HC0) Temp = I2CWRITE (0) I2CSTART Temp = I2CWRITE (&HC1) Version = I2CREAD(0) Temp = I2CWRITE (&HC1) Position8 = I2CREAD(0) Temp = I2CWRITE (&HC1) Positions . bytel I2CREAD (0) Temp = I2CWRITE (&HC1) Positionl6 .byteO I2CREAD (0) The first three instructions address the module and select the first register to be read. The next instructions read the four previously-described registers in succession, thus making the software version number avail- able in the variable Version, the 8-bit coded angle in the var- iable Positions, and the 16- bit angle in the 16-bit variable i_ 2 3 5_ 6 _ 7_ 8 _ 9_ m 11_ 12 21 © SOUT VIN SIN ATN RES IC1 PO PI 5 pi P14 P2 P13 P3 PI 2 P4 P11 CB220 P5 P10 P6 P9 P7 P8 J- J- I 4 23 24 22 20 J 9 _ 18 17 J 6 IS 14 R1 R2 !* £ SCL 13 SDA SI -o ■o ■o L -o 4o -o -o 40 o +u <±> CMP03 or CMPS03 070304-12 < 2 ) Pin 9 - 0V GND Pin 8 - No Connect Pin 7 - 50/60 Hz Pin 6 - Calibrate Pin 5 - No Connect Pin 4 - PWM Pin 3 - SDA Pin 2 - SCL Pin 1 - +5V 070304- 13 Positionl6. The variable Temp is not used for anything, but is required by the particular syntax of the l 2 C instructions of the Cubloc's Basic. By the same token, the constant 0 that must be present in the I2CREAD instructions has no particular meaning. Hence if you use this listing with a PIC programmed in Basic, a slight adaptation might prove necessary, depending on the compiler you are using. So, whether you choose the PWM or l 2 C version for interfacing with the CMP03 module, it gives you position information about your robot's trajectory with respect to magnetic North. All that remains for you to do is to make good use of it so your robot won't 'lose its bearings'. ( 070304 - 1 ) Web Links Devantech http://www. robot-electro- nics. co.uk/shop/Compass_ CMPS032004.htm A little background reading: http://zedomax.com/blog/zedo- max-diy-hack-lets-make-a-digital- compass/ http://zedomax.com/ blog/2006/08/1 6/digital-compass- using-cmps03/ Tilo Gockel The TLC549CP analogue to digital con- verter (A/D) from Texas Instruments is a good choice for applications in the field of robotics (especially those using 8051 -com- patible microcontrollers). These particular converters are readily available, low-cost and easy to use. A quick look at the TLC549data sheet indicates the timing waveforms for the 1/ O Clock, DATA OUT and CS signals (Fig- ure 1). A circuit to test the converter was quickly constructed using a variable resis- tor as a potential divider. Figure 2 shows the simple interface between a TLC549CP and a 8051 -compatible microcontroller. A short function which reads the serial operating sequence i/o CLOCK tsu(CS) w punjn_pjnjnjHJ - | || Don’t -S 20 usek (50kHz) P3_B0 = 0; for (count = 0; count < 8 ; count ++ ) { addat = addat << 1; if (P1_B3 == 1) ++addat; P1_B2 = 1; / /_wait ( ) ; P1_B2 = 0; } return addat; } As an example two TLC549 A/D convert- ers can be wired to a microcontroller to measure the amount of light falling onto two Light Dependant Resistors (LDR). This application will require two of the inter- face connections shown in Figure 2. Con- nect the LDR either in place of the variable resistor or in parallel to it. ( 070134 - 1 ) B. Broussas There are currently three principal meth- ods for the propulsion of a mobile robot: the modified radio-control servo, the step- per motor, and the DC motor. All have advantages and disadvantages, which are important to be familiar with before mak- ing your choice. The modified radio-control servo offers numerous advantages, the main one being that it offers relatively high tractive power without needing a reducing gearbox, as this is already contained within the servo case. So all you have to do is mount it INI Q I) o IN2 © INI OUT1 IC1 H VCONT NC LB1630 IN2 OUT2 r S +6V 1 0(_i 16V 8 — ■ ■ M1 400mA max. 070303 - 1 1 < 2 > onto the robot and fix the wheels directly onto its shaft. What's more, a radio-control servo is powered from 4.8 V, which is par- ticularly handy for robots using four 1.2 V rechargeable batteries. The major drawback of the radio-control servo lies not so much in its pulse drive mode, for which various solutions are pro- posed elsewhere in this issue, as in the lack of precision in the behaviour of the servo with respect to the pulse width. Although theoretically the servo runs at maximum speed in one direction or the other for pulses of 1 or 2 ms and stops for pulses of 1.5 ms, experience shows that differences of 10-20% in the pulse width needed are sometimes encountered. These differences make it necessary to calibrate the propul- sion control programs of robots fitted with servos on an individual basis, thereby rul- ing out any reproducibility from one model of robot to another. Stepper motors do not suffer from these drawbacks, but don't usually include any built-in mechanical reduction, meaning you have to provide external reduction if you don't want to end up with too little torque. If you don't fancy building such a device yourself, it's possible to use the 'gearboxes' sold as kits by various robot- ics or modelling retailers, but experience shows these are usually designed for standard DC motors, and are unsuitable for comparatively bulkier stepper motors. Moreover, driving steppers obliges us to use either a specialized 1C, or a collec- tion of logic ICs in association with power transistors. So if you are forced to fall back on external reduction, for example because you don't want to use a servo, the DC motor then becomes the natural choice, especially since certain 'gearbox' kits are sold with such motors. So, all that remains is to drive them correctly. Although conventional transistor-based circuits are still usable, there is also one very simple solution, directly inspired by the (old) cassette recorders in which DC motors were widely used. It involves using an LB1630 1C made by Sanyo, which can be cannibalized from many cassette recorders that have been thrown out, or else bought new, from Lextronic for exam- ple (www.lextronic.fr). Available in an 8-pin DIP package, the 26 elektor electronics - 7-8/2007 Truth table for LB 1630 motor control 1C. INI IN2 OUT1 OUT2 Motor H L H L Forward run L H L H Reverse run H H HiZ HiZ Stop L L HiZ HiZ Stop LB1630 is ridiculously simply to use, as shown in Figure 1. In fact, all it needs to be able to work is one external decoupling capacitor. It's controlled by two logic signals, which are TTL-compatible when the circuit is powered from a volt- age of the order of 5 V. The supply must be between 2.5 and 6 V, and must not under any circumstances exceed 7 V, at risk of destroying the 1C. The current drawn by the motor being driven can be up to 400 mA maximum, though peaks up to 2 A are allowed, but only in the form of pulses whose duration may not exceed 50 ms at a duty cycle of 10 %. The protection diodes, vital when driving an electric motor using tran- sistors, are built into the LB1630 and so don't need to be added to the circuit shown. The two inputs INI and IN2 allow logic control of the motor, as per the Table. Inputs INI and IN2 of the LB1630 just need to be in opposite states for the motor to turn one way or the other. So it's very easy to control using two parallel port lines from any microcontroller. Independently of this 'on/off' type control to make the motor run in one direction or the other, the speed can also be control- led. All that is needed is to apply PWM pulses to one or the other of inputs INI or IN2. Figure 2 shows one way of performing this sort of speed control using a Cubloc CB220, which has the advantage over the many other microcontrollers that can be programmed in Basic of being able to generate continuous PWM signals. With such a circuit, all you have to do is write, for example: OUT 6,0 PWM 0, SPEED, 255 to make the motor run in one direc- tion at a speed that can be adjusted by means of the variable SPEED, which can vary from 0-255, and: OUT 6,1 PWM 0, (255-SPEED), 255 to make it run at the same speed but in the other direction. Note too that, given that INI and IN2 of the LB1630 are logic inputs, several of them can be connected in parallel, so as to control several motors in an identical manner. But watch out! If you're controlling two traction motors positioned back-to- back on either side of a robot, they'll need to turn in opposite directions to make the robot move forwards or backwards. In this case, you need to cross over the inputs to the LB1630s (INI of one goes to IN2 of the other and vice- versa) if you are controlling them together, or else wire the motors in opposite senses to the OUT1 and OUT2 outputs. ( 070303 - 1 ) B. Broussas Although ultrasound is well suited to detecting distant objects, it is quite unusa- ble for closer objects, i.e. when the detec- tion distance comes down to around a centimetre or less. Under these conditions, two solutions can be used: the bumper or similar device activating one or more microswitches — but that is still a mechan- ical solution — or the infra-red detector we're suggesting building here, combining the elegance of electronics with freedom from any moving parts. The principle of such a detector is very simple. A transmitting element, which here is going to be a simple LED, emits a more or less directional beam of IR. Posi- tioned next to this transmitter, a receiving element, which may be a photodiode or phototransistor, is suitably oriented so that under normal circumstances it doesn't receive anything. But as soon as an obsta- cle is present at a suitable distance, it reflects part of the light emitted by the LED back onto the photodiode or transis- tor; the presence of an output signal from the latter then indicates the proximity of this obstacle. The distance up to which this process works properly very clearly depends on numerous factors: the luminous power emitted by the LED, the sensitivity of the detector, but also — and above all — on the reflective properties of the obstacle. A black cat will be much less easily detected than a white wall! In answer to a question frequently asked in robotics classes, note that this principle works just as well using visible light, but the use of IR simply makes it possible to avoid, to some extent, the sensor is being dazzled by ambient light. Of course, if you use a robot fitted with such a sensor in full sunlight or beneath a halogen spot, this anti-dazzle effect probably won't be very effective, given the high level of IR radi- ated by such sources! Note too that this system is not a telem- eter, and so is unable to give the slight- est information about the distance of the obstacle. The only parameter that actually relates to this distance is the amplitude of the reflected signal, but this depends also, indeed to a very large extent, on the reflective properties of the particular obstacle (think again of that black cat and white wall). So, our detector is capable of operating over a range extending from a few mm to around 20 mm or so, depending on the type of sensor used. What's more, it's not confined to simple obstacle detection 7-8/2007 - elektor electronics 27 +u in the conventional sense. For example, in the case of a robot that's meant to stay on a table, all you have to do is judiciously position such detectors around the underside of the edge of the robot's chassis. As soon as it gets too close to the edge, the sensor stops receiving the signal reflected by the table, indicating that it needs to turn back. Construction of our IR obsta- cle detector is very simple, as the figure shows. Given the 1C used, it's possible to build two at once, which is not unhelpful. As the detection zone of such a system is relatively limited, we've planned to use two sen- sors that we've called R and L for right and left, though this doesn't bear any particular rela- tion to their actual positions on the robot. The figure shows the circuit of a single channel, the other is obviously identical; only decoupling capacitors Cl and C2 are common to them both. The LED in the sensor IC1 is permanently powered via resistor R1, while the collec- tor of the phototransistor in this detec- tor is taken to the positive rail via R2. So when the transistor is off, i.e. when it is not receiving any light, meaning there is no obstacle, we have a voltage at this point approaching the power rail. As the transis- tor starts conducting, that is, when a suf- ficiently reflective and/or close obstacle reflects the light emitted by the diode back onto the phototransistor, this level drops. This information is shaped by comparator IC2A, whose switching threshold can be adjusted using PI. In this way, the circuit can be adapted to different sensors and the detection range can be adjusted to some extent. The circuit output is TTL-compat- ible if it is powered from 5 V and, given the way IC2A's inputs are con- nected, it is logic high in the presence of an obstacle. Construction is perfectly straightforward, but the effec- tiveness of the circuit depends on the correct choice of sen- sors. We suggest three types that we've tried out, in a price range from around £ 1 to £ 8, but there's nothing stopping you — quite the contrary, in fact — from trying out other types, or even making your own sen- sor using separate IR LEDs and phototransistors of your own choice. The cheapest sensor is the CNY70 (around £ 1). It only detects at very short distances, of the order of 5 mm, and is easily dazzled by ambient light. At approximately four times the price, we found the HOA709- 001 from Honeywell, available from Radiospares, amongst oth- ers. It too can only detect up to around 5 mm, but with significantly better efficiency than the CNY70, and it proves harder to dazzle. Lastly, if you double the stakes again (i.e. eight times the price of the CNY70), you can use the HOA1180- 003, still from Honeywell, very hard to dazzle and which detects up to a distance of 15 mm. ( 070300 - 1 ) Abraham Vreugdenhil When designing a robot, a choice has to be made as to the types of sensors that it will have. This choice will be determined mostly by the purpose of the robot. But the degree of complexity required in using the sensor and the cost of the sensor also play a role, of course. Sensors that are favour- able in these respects are for example bumpers and feelers with micro-switches, IR distance sensors from Sharp and ultra- sonic sensors. If we want to detect mov- ing warm objects, such as people and ani- mals, then PIR (passive infrared radiation) sensors from Eltec, in particular, become a consideration, such as the Eltec-442. This is a very nice sensor, but the price is a problem unfortunately, more than 60 dollars. Conrad Electronics also have a PIR sensor available, the LHI958 (order number 1 78730) for just over £ 2.50. The disadvan- tage of this sensor is that an amplifier has to be added in order to obtain a usable 28 elektor electronics - 7-8/2007 2 Sig + output signal. The documentation for the sensor is not particularly clear about this. Another solution is a sensor that we often meet in daily life: the well-known move- ment detector for outdoor lighting, which is available from any builder's market or hard- ware store for a reasonable price. These are offered for sale at less than £ 7.00. After dis- assembly of the sensor, the main board with its daughter board remain (Figure 1). The daughter board contains the PIR sensor and accompanying electronics. The connection points for the power supply and output sig- nal can be found on the back (Figure 2). The sensor is normally powered from 8 V, but it still works well at 5 V. A robot will often be fitted with multiple PIR sensors that are mounted at different angles. To achieve this, we can mount three sensors on a piece of prototyping board and limit the view of each sensor with a short section of electrical conduit. The length of the conduit determines the field of view. The sensors on their own have a field of view of 140 degrees, so the shielding is definitely required. It is advan- tageous if the fields of view of the sensors overlap. In this way three sensors can be used to make five detection zones. It is of course also possible to use more sensors so that a greater resolution is obtained. In this manner it is reasonably cheap to build a nice PIR sensor unit. The one shown in the example (Figure 3) comprises three PIR sensors. This sensor unit is easy to build and works well. +6V B. Broussas Whatever the interest of the many types of robot that can be built today, the mobile robot is still an unmissable stage through which any robotics amateur has to pass, for at least two reasons. The mobile robot presents a concentration of the difficulties, and hence solutions, that may be encoun- tered in robotics. You have to deal with problems of mechanics and kinetics in order to manage its movements, problems of sensors, which can be extremely diverse depending on what we want to detect, or on the other hand avoid, behavioural intel- ligence problems for processing the infor- mation provided by these sensors, etc. But the second reason why the robotics amateur needs to pass through the 'mobile robot' stage is often much less prosaic, as it's simply aimed at impressing the peo- ple around you (parents, friends, girl/boy- friend). What could be more impressive than this 'thing' straight out of a 50s sci-fi movie, moving around all by itself follow- ing a line on the ground, avoiding chair legs, or responding to a signal from its master? So, robotics novices of all kinds, you will have realized that a mobile robot is what we're going to suggest constructing. And so you'll be able to see quickly just what your own hands are capable of creating, we've chosen some solutions that are sim- 7-8/2007 - elektor electronics 29 pie, but no less successful in producing a certain effect. Quite simply, it's a light-seeking robot — a sort of moth (on wheels) if you prefer, since, just like its counterpart in the liv- ing world, it is always going to head for the brightest source it can find in the room where you let it loose. To simplify construction and enable you to be up and running in just a few hours, or less, after reading this article, we suggest you take advantage of a mechanical base that's available in a kit. Having opted for propulsion using modified servo motors, we suggest two different bases: the Rogue Blue base from Rogue Robotics (www. roguerobotics.com) or the Carpet Rover 2 base from LynxMotion (www.lynxmo- tion.com). Of course, if you are good at mechanics, there's nothing to stop you building such a base yourself. It just needs to be propelled by two modified radio- control servos, and so will need a jockey wheel at the front and/or rear. The modification to convert the servos into propulsion motors is explained elsewhere in this issue, but if you have any doubts about doing it yourself, as of quite recently you can also now buy such servos already pre-modified by their manufacturer. Take a look at Lextronic for example for this (www.lextronic.fr). For our robot's 'brain', to show you it's not always necessary to use the very latest 32- bit microcontroller, we've decided to use the smallest of the Basic Stamps, the Basic Stamp I. The complete circuit looks like Figure 1. The two ports PO and PI of the Basic Stamp I are used to drive the right and left propulsion servos. The brightness is meas- ured using two photo resistors or LDRs (still called CdS cells in some literature) con- nected to ports P6 and P7 of the Basic Stamp I. The odd mode of connection used here makes it possible to use an instruction specific to the Basic Stamp I, the instruction POT, which measures the charging time of a capacitor connected to one of its ports, i.e. thereby the resistance of the LDR and thus the brightness falling on it. For the robot to be able to head towards the brightest part of the room where it is operating, these two LDRs must be mounted pointing forwards, separated from each other by a small piece of card- board or opaque PCB in such a way they can't both receive the same illumination. The assembly can be powered by four 1.5 V batteries. This voltage is applied directly to the servos and to the unregu- lated PWR input of the Basic Stamp I. Watch out! Under no circumstances con- nect the servo supplies from the Basic Stamp I's + 5 V output - its built-in 5 V regulator wouldn't appreciate it! The software part of our robot is at least as simple as the hardware part, as you can judge from the listing below: Listing PINS = 0 DIRS = %00001111 SYMBOL RightStop = 150 SYMBOL LeftSTop = 150 SYMBOL Move = 30 SYMBOL LightDif = b2 SYMBOL RightLDR = b6 SYMBOL LeftLDR = b7 Main : POT 7, 128, LeftLDR POT 6, 128, RightLDR LightDif = RightLDR - LeftLDR bO = RightStop + Move - LightDif bl = LeftStop - Move + LightDif PULSOUT 0, bO PULSOUT 1, bl GOTO Main This listing is very easy to analyse. After an initial phase to define the labels used and the reservation of the RAM in the Basic Stamp I, we go on to measure the light using the instruction POT. This instruction returns, in the variable LeftLDR (or RightLDR), a number representing the resistance of the LDRs connected to P6 and P7 divided by a constant called a scaling factor. You may need to adjust this parameter to suit the characteristics of the LDRs you use. The values thus obtained are subtracted one from the other to yield information about the difference in lighting between the two cells. The calculation of the pulse lengths to be applied to the servos can then be performed, noting that Right- Stop and LeftStop are the values mak- ing it possible to make the servos stop, and that Move is a parameter intended to set the basic speed of the servos, to which is added or subtracted the result of the dif- ference in illumination. Hence, for example, if LightDif has the value 50, bO will be 150 + 30 - 50, i.e. 130, while bl will be 150 - 30 + 50, i.e., 170. Given that the resolution of the PULSOUT pulse is 10 ps, the program will thus generate 1.3 ms pulses for one servo and 1.7 ms ones for the other, causing the robot to turn towards the direction of the LDR that is receiving the most light. So this program is fully functional, but, given the spread in the characteristics of both the servos, with respect to their drive pulses, and the resistance of the LDRs, it will undoubt- edly be necessary for you to tweak certain numerical parameters again to obtain satis- factory results. To do so, note that: • RightStop and LeftStop are equal to 1/1 0 of the pulse width that makes the right and left servos stop. • Move lets you define the rotational speed of the servos when the robot is going straight ahead. It is equal to 1/10 of the difference between the pulse width for stop and the pulse width desired for mov- ing straight ahead. • The coefficients 128 used in the POT instructions can also be adjusted between 1 and 255 in order to obtain satisfactory behaviour of the robot, given the LDRs used and the ambient light in the place where the robot is operating. Note too that if your robot seems to shy away from the light instead of moving towards it, you've probably reversed the wiring between the right and left servos or right and left LDRs (all this is relative, of course, depending on what you call front and back on the robot). Now it's over to you... ( 070306 - 1 ) Alexander Wiedekind-Klein Genau genommen ist To be precise, this ultrasonic distance measuring device is more than just an ear, since it generates pulses of sound at 40 kHz as well as lis- tening for their reflections. The circuit in Figure 1 is divided into two parts. At the top is the 40 kHz oscillator and a 'push- pull' output stage built around IC1.C and IC1.D. The oscillator is switched on and off according to the 5 V logic level on a control input (pin 2 of K1). PI is adjusted to set the oscillator frequency exactly equal to the resonant frequency of the ultrasonic transducer, nominally 40 kHz. Reflected signals are amplified by IC2.A and IC2.C, rectified by D1 and buffered 30 elektor electronics - 7-8/2007 by IC2.D. This circuit forms the analogue front end, and is connected to a microcon- troller for subsequent signal processing. We will look below at the factors that need to be borne in mind when considering the dig- ital signal processing algo- rithm to be used. R5 Cl US After a burst of ultrasound lasting approximately 2.5 ms is transmitted we sample the envelope of the received signal as delivered by the analogue front end for approximately 50 ms. In this time, sound travels approximately 16 m, and so we have a maximum range of 8 m, because the sound must travel to the distant object and back. Figure 2 shows a typical received signal. The green rectan- gular pulse represents the signal at the control input (pin 2 of K1), which switches on the oscillator for the 2.5 ms pulse period. During this time (t,) we can already see some signal at the output of the receiver, as it is impossible to avoid some direct reception of the transmitted pulse. This effect has to be taken into account in sub- sequent processing. The second peak in the signal, after time t 2 , is a reflection from an object. The time is proportional to the distance to the object. Measurement of time t 2 commences at the middle of the transmit burst (i.e., approxi- mately 1.25 ms after the oscillator is ena- bled), and finishes when the amplitude of the reflected signal reaches its peak value. In air the distance to the object measured in centimetres is easy to calculate: to a good approximation it is equal to the time to the reflection in milliseconds multiplied by 16. For example, a time of 10 ms for t 2 corresponds to a distance of 160 cm. If an object is very near, the reflected sound will be very loud and be received after a very short time, possibly while the pulse is still being transmitted (Figure 3). In this case it is best to measure the time taken for the received signal to reach half its maximum amplitude from when the oscillator is switched on. This time can then be used to form an estimate for the distance to the object. If there is a number of reflecting objects at different distances there will be several reflected pulses of different amplitudes +5V 0 GND CONTROL (Figure 4). In this case it quickly becomes appar- ent that if we used a simple threshold detector in place of the microcontroller it would be impossible to get reliable results. A microcon- troller with Intelligent' soft- ware could, for example, be programmed to calculate the distance to the nearest object or to report the dis- tances to several objects simultaneously. Since the only connections to the circuit are a +5 V sup- ply and ground, a control signal for the transmitter and the analogue envelope sig- nal returned by the receiver to the processing hardware, it is straightforward to wire up four copies of the circuit mounted at right angles to one another. In a robot- ics application this would give the robot the ability to detect objects in any posi- tion relative to itself. ( 070281 - 1 ) 7-8/2007 - elektor electronics 31 1 C. Tavernier www.tavernier-c.com If your mobile robot's sole function is to roam about the tiling or wooden floors of your home, it's not very likely to have much need of the sensor we're going to be describing in this article. However, if it has to confront the harsh realities of the ground of the outside world, with its holes and bumps, an inclinometer may prove extremely useful in order for it not to keel over at the first, ever so slight unevenness. Before electronics knew how to accomplish all the feats that we are used to today, an inclinometer was a purely mechanical system, with all the difficulties of implementa- tion, cumbersomeness, and lack of accuracy this implied. Might as well say that its use in an amateur robot was, if not impossible, at least very difficult. For a few years now, this has no longer been the case, thanks to the marketing by Analog Devices of 'solid state' accelerometers, i.e. produced in the form of ICs, with no visible moving parts. In fact, it's still impossible to meas- ure acceleration without employ- ing some kind of moving part, but nowadays this consists of a minute polysilicon structure suspended by four springs of the same material above the chip of the accelerometer 1C. When this mobile element is subjected to accel- eration, it deforms, and this deformation is revealed by a vari- ation in the capaci- tance between a plate located on the mobile element and two fixed plates on the chip itself. Two out- of-phase squarewave signals are applied to the fixed plates. When the mobile plate is subjected to accelera- tion and moves, these become unbalanced, and phase demodula- tion yields a voltage proportional to the acceleration. Of course, the user is quite unaware of all this going on, but has it r ' V DOC- I C4 lOn +6V...+12V -© IC2 = OP284 C2 47 n C3 47 n 070305-11 available at the accelerometer 1C out- put information reflecting the accelera- tion registered — in analogue or digital form, depending on the type of 1C chosen. For our robotics application, we have decided to adopt a relatively inex- pensive accelerometer in the form of the ADXL311 from Analog Devices. Do note right away, however, that this 1C is no longer being produced, but is still widely available from retailers. If it should eventually disap- pear completely, it could be replaced by the ADXL320, much more recent and electrically compatible, only the pin-out being different. The ADXL311 actually includes two highly sensitive accelerometers at right-angles, with positioning bet- ter than 0.1°. Because of this, and if it is placed parallel to the surface of the Earth, it is influenced by the acceleration due to the Earth's grav- ity, and so can indicate left/right inclination (roll) or forward/back- ward (tilt). In this way we create a dual- axis inclinometer. These inclinations can be exploited in an absolute form if we want to know exactly the angle between the inclinometer, hence the 1C carrying it, and the ground, or in a rel- ative form, if we want just a limit indication of what the robot can withstand before it top- ples over. In the case of the ADXL311 or the ADXL320, the absolute inclination is given by the equations: +6V...+12V Tilt = arcsin (A x /A xo ) and Roll = arcsin (A Y /A Y0 ) 32 elektor electronics - 7-8/2007 where A x and A Y are the analogue voltages supplied by the accel- erometer when it is inclined, and A xo and A yo the voltages sup- plied when it is per- fectly horizontal. As shown in Fig- ure 1 , the accelerom- eter application circuit doesn't amount to very much. The only important elements are in fact capacitors C2 and C3, which fil- ter the accelerometer output voltage. It actu- ally has a passband of several kHz, and can therefore react to very fast vibrations, not at all what we want in an application as an inclinometer. With the values chosen here, the passband is restricted to 100 Hz, eas- ily enough. The two op. amps arranged as followers avoid any external influence on these filter capacitors and allow the accelerometer to be connected without special precautions to any microcontroller or ADC input. The only minor problem you might encounter constructing this project is that the accelerometer is in an SMD package, which is not always easy for soldering onto an amateur PCB. There is now a module, ref. Accel, from Lextronic (www.lextronic. fr), that includes all the components in Fig- ure 1 mounted on a tiny 15 x 20 mm PCB (see photo). Using our accelerometer as an inclinom- eter involves measuring its analogue out- put voltages on both axes and subtract- ing from them the voltages at rest, that is, when the 1C socket is perfectly parallel to the ground. Figure 2 shows an example of the use of this inclinometer with a PIC microcontrol- ler with a built-in ADC, while Figure 3 shows the same type of circuit, this time with a Cubloc CB220. We are not giving you a program for exploiting the information supplied by the inclinometer as, in both cases alike, it takes just two instructions to access the tilt or roll information. So for example you would write tilt = Adin(0) tilt = tilt - 512 ' adjust accord- ing to the voltage output ' when the incli- nometer is horizontal to recover the tilt infor- mation using a Cubloc CB220. While you might write, for example, tilt = Adc _ Read(0) tilt = tilt - 512 ' adjust according to the voltage output ' when the inclinometer is horizontal to recover the tilt information with a PIC programmed in Basic (in this example, MikroBasic compiler and 10-bit ADC). The same instructions will obviously be used for roll, but using analogue channel 1 if you have adopted the circuit diagrams of Fig- ures 2 or 3. Then it only remains for you to exploit this data to prevent your robot's fall- ing over on terrain that's too steep for it! ( 070305 - 1 ) Pascal Choquet Industrial production-line robots require high-resolution sensors to measure the position of robotic actuators so that the tools can be accurately guided onto the work piece. A photo diode array together with an external light source is often used as a sensor in this application. This chip contains a line of photo diodes together with a series of sample and hold (S/H) cir- cuits which take a snapshot of the readings of each photo diodes at the same instant and then outputs these integrated analogue values serially from a single output. The S/ H circuits are important because the sensi- tivity of each element to the light quanta is dependent on the integration period; with- out the S/H the last element would show the highest sensitivity. The accompanying table lists the most important properties of some common arrays. The sensitivity is dependant on the active diode surface area and the integra- tion time. From the outside these arrays look very simple, apart from the two supply con- nections there are only three signals for connection to a microcontroller: A clock input (CLK), a start impulse (SI) input and an analogue output signal (AO). AO should be loaded with a 330 Q resistor to ground. To readout the array values the controller firstly generates the clock signal and then sets SI high (with sufficient set-up time) before a rising clock edge. On succes- sive falling clock edges the value of each individual pixel will be output at AO. The microcontroller reads each level and stores its value. A feature of the MLX90255 type array is that the first two values read out are dummies, the first of the 128 real values appears at the third clock edge. The two values after the 128 th value are also dum- mies, the read out therefore requires 132 clock edges in total to read all the data and the final 133 rd edge reinitialises the shift register. The gain of the pixels at either end of the array is about 15 % greater than those in the centre (cosine weighting) this compensates for the light loss experienced at the edges when the array illumination is provided by a single LED. The integration period begins at the 18 th 7-8/2007 - elektor electronics 33 0 IC2 A OUT SI CLK MLX90255 +5V © K1 a a- a- o- a- R1 R2 21 22 23_ 24_ 25_ 26_ 27 28 1 > pOOn 20 © MCLR/VPP IC3 RA5/AN4/SS/LVDIN RA4/T0CKI RA3/AN3/VREF+ RA2/AN2/VREF- RA1/AN1 RA0/AN0 PIC18F242 R B0/INT0 RC7/RX/DT RB1/INT1 RC6/TX/CK RB2/INT2 RC5/SDO RB3/CCP2 RC4/SDI/SDA RB4 RC3/SCK/SCL RB5/PGM RC2/CCP1 RB6/PGC RC1/T1 OSI/CCP2 RB7/PGD RC0/T1OSO/T1CKI J- OSC1 OSC2 J- 8 9 10 X i < ► CIO C9 15p 15p 18 17 _ 16 15 14 13 12 11 19 ^^00 n C3 01 f— in 25V 12 11 10 02 [— 1=1 in 25V V 25V v + C1 + © IC1 Cl- RIOUT RUN T1IN TIOUT T2IN T20UT R20UT R2IN C2+ MAX232 C2- V 16 13 14 15 C4 1 in 25V 4.9152MHz K2 O RX TX 070314-11 Photodiode Array properties Array MLX90255 TLS1301 TLS1401 TLS208R Pixel (* see text): 128 (+40 102 128 512 Pitch (DPI): 385 300 400 200 Weighting: Cosine Equal Equal Equal Length x width (|jm): 200x66 85x77 63,5 x 55,5 120x70 Output (V): 0.125-2.4 0-2.0 o C\i i o 0-2.0 clock edge and continues until the next SI signal. The output values are the result of the previous integration period so if the array is not continuously scanned then it is necessary to make two complete scans to get meaningful results. The first scan cycle after power up is used to initialise digital levels on the chip, the values read are invalid and should be discarded. The integration time is equal to the pixel count minus 18 divided by the clock frequency. The sensitivity can be easily controlled by the microcontroller. The circuit diagram shown here consists of the photodiode array together with a basic PIC microcontroller and a driver chip for an RS232 serial interface connection. The author has produced a program written in C which can be used in the controller. The source files (070314-11.zip) are available to download free of charge from the Ele- ktor Electronics website. A scan cycle is initiated using a terminal program by enter- ing 'Strg S'. The values are separated with semicolons so they can be easily used in an Excel table. Photodiode arrays can be used in robot- ics for imaging based on the pinhole cam- era principle, they have also been used in line-following applications where they offer good resolution and can be mounted relatively far away from the floor. Together with a prism or optical grating the array can be used to perform simple yet precise colour recognition. ( 070314 - 1 ) Alexander Wiede- kind-Klein Sometimes sophisti- cated sensors based on video cameras, infra- red or ultrasound are not quite up to the job, and we have to resort to somewhat more primi- tive switch-type sen- sors. These work like an animal's whiskers (or 'antennae' on insects), detecting nearby objects - in the environment. When disturbed, a sen- sor sends a pulse to the robot to indicate that an object is present. Sensors that are both sensitive and robust can be made using steel guitar strings. The material is very flexible as well as being conductive. The idea could not be more sim- ple: we pass the wire through a metal tube, and when the wire is in contact with an object in the environment it bends and the two make electrical contact. Responsiveness and sen- sitivity depend chiefly on the length and stiff- ness of the piece of gui- tar string used. Do-it-yourself construc- tion should not present great difficulties even to the most mechanopho- bic reader: see Figure 1. We proceed as follows. 34 elektor electronics - 7-8/2007 I within the tube using hot-melt glue. Be 1. Cut a length of steel guitar string (8 cm to 10 cm is enough), and saw off a length of about 2 cm of 4 mm diameter brass tube. Deburr the edges inside and out. 2. Solder a wire to one end of the brass tube and another wire to the end of the guitar string. Insulate the joint on the guitar string using heatshrink tubing. 3. Slide the string into the tube so that only about the first 10 mm from the end of the tube is insulated. Fix the string centrally careful not to allow too much glue to run down inside the tube. The result should look like Figure 2. Of course, you are free to experiment with variations on this construction! As we have described it this robot whisker is essentially just a simple switch contact. To ensure that even the gentlest collision does not pass unnoticed we recommend that you use the whisker to trigger a flip-flop as shown in Figure 3. The microcontroller in the robot can then read the state of the flip-flop at its leisure and then reset it. ( 070282 - 1 ) Can / Counterelectrode terminal Water 070187 - 12 Cap / Working electrode Active charcoal filter / terminal Gas inlet Gasket Gas diffusion control film Gas inlet Backing Catalyst Layer Layer Gas sensing layer Washer Separator (immersed by liquid alkaline electrolyte) Figure Internal structure of the sensor. The Figaro TGS5042 sensor is a carbon monoxide sensor that is used primarily in industrial applications such as smoke detectors, fire detection equipment and ventilation controllers for indoor car parks and the like. The sensor is quite suitable for use in battery-powered applications, and it has several advantages over conventional sensors. The electrolyte is environmentally friendly, and the housing is leak-proof. The sensor can measure CO concentration up to 1%, and it has a temperature range of- 40 °C to +70 °C. The housing has the same form as an AA battery. A few specifications: • Suitable for use in battery-powered equipment counter 070187 - 11 Figure 2. A simple sample application circuit. 7-8/2007 - elektor electronics 35 • High sensitivity and accuracy for CO • Linear relationship between CO concen- tration and output voltage • Low sensitivity to ethanol • Low sensitivity to other gasses that may be present Figure 1 shows the internal structure of the TGS5042 sensor. The gas-sensitive layer for CO is located between a stainless-steel ring (counter electrode) and a nickel-plated cap (working electrode). The cap is packed in a sort of film and several supporting lay- ers. All of this is packaged in a cylindrical stainless-steel housing. The lower compart- ment is filled with water, and the cap end is filled with an activated charcoal filter. Figure 2 shows the schematic diagram of a basic application circuit for the TGS5042. The sensor generates an extremely small current, which is converted into a voltage by an instrumentation amplifier formed by IC1 and R2. Resistor R1 is necessary to prevent polarisation of the sensor, which might otherwise occur when the circuit is switched off. It is essential to avoid applying a voltage to the sensor under any conditions. Doing so would permanently damage the sensor. The voltage across the sensor must always be less than 10 mV. Some potential applications for the sensor are: • Residential CO detectors • CO monitors for industrial applications • Ventilation control for indoor car parks ( 070187 - 1 ) Zeno Often A few years ago, a considerable amount of attention was devoted in Elektor Electron- ics to the construction of sensors for the intelligent control brick (RCX) from Lego Mindstorms [1]. There is now a successor. The NXT is the heart of the new Mindstorms. Using this system, computer hobbyists can develop, build and, in particular, program, numer- ous robots, to their heart's content . With the compass sensor that is described here the NXT can determine its direction with an accuracy down to a few degrees. This allows a robot to be built that's capa- ble of navigation. The company Devantec [2] supplies NXT4V3 04 O" l 2 CNXTSCL 05 0- l 2 C NXTSDA 06Q" +V +5V CMPS03 Robot Compass Module SCL GND SDA SCL SDA NXT GND 03 Q" GND 070156- 11 a ready-to-go compass module type CMPS03. Two mutually perpendicular Philips KMZ51 hall-sensors are used to detect the Earth's geomagnetic field. With a small PIC-controller a value between 0 and 360 degrees is calculated and made available in digital form at the output of the module. The communication with the outside world takes place via the l 2 C pro- tocol or via a PWM output. The module requires a 5 V supply voltage and consumes about 20 mA. This mod- ule is eminently suitable for use with the NXT. The new NXT has the option of connect- ing sensors that use the l 2 C protocol. This allows a sensor to be connected to the NXT using an RJ12 plug. The NXT does not have internal pull-up resistors on the l 2 C bus. So, these have to be added externally. Lego suggest resistors with a value of 82 kQ on both the data line (SDA) as well as the clock line (SCL). Software The standard Lego Mindstorms software is based in dragging graphical func- tion blocks. Only the parameters can be changed while the functionality of the blocks is fixed. Not Exact C (NXC) is a programming lan- guage for the NXT that has a strong resem- blance to C. This permits a much greater flexibility when programming. In particu- lar when it concerns hardware that is not officially supported by Lego, such as this compass sensor. The compiler (BricX) [3] can be down- loaded free, is simple to use and offers many options for programming the NXT. The program compass. nxc (which can be downloaded free from the Elektor Electron- ics website as file number 070156-11.zip) continually reads the compass sensor. The measured values are then processed by the robot who will sequentially 'point' to North, South, East and West. The values measured by the electronic compass can also be read from the display on the NXT brick. ( 070156 - 1 ) References (1) Compass sensor for Lego RCX, Elektor Electronics July/August 2002 (2) Devantec: http://www.robot-electronics. co.uk/shop/Compass_CMPS032004.htm (3) BricX: http://bricxcc.sourceforge.net/ 36 elektor electronics - 7-8/2007 B. Broussas The first sensor a robot usually gets fitted with is an obstacle detector. It may take three different forms, depending on the type of obstacle you want to detect and also — indeed, above all — on the dis- tance at which you want detection to take place. For close or very close obstacles, reflective IR sensors are most often used, an example of such a project appears elsewhere in this issue. These sensors are however limited to distances of a few mm to ten or so mm at most. Another simple and frequently-encoun- tered solution consists of using antennae- like contact detectors or 'whiskers', which are nothing more than longer or shorter pieces of piano wire or something similar operating microswitches. Detection takes place at a slightly greater distance than with IR sensors, but is still limited to a few cm, as otherwise the whiskers become too long and hinder the robot's normal move- ment, as they run the risk of getting caught up in things around it. For obstacles more than a couple of cm away, there is another effective solution, which is to use ultrasound. It's often tricky to use, as designers think as if they needed to produce a telemeter, when in fact here we're just looking at detecting the pres- ence or absence of obstacles, not measur- ing how far away they are. So here we're suggesting an original approach that makes it possible to reduce the circuit required to a handful of cheap, ordinary components. Our solution is based on the howlround or feedback effect all too familiar to sound engineers. This effect, which appears as a more or less violent squealing, occurs when a micro- phone picks up sound from speakers that are connected to it via an amplifier. Feed- ing back the output signal from the speaker into the input (the microphone) in this way creates an acoustic oscillator. Our detector works on the same prin- ciple, except that the microphone is an ultrasound receiver while the speaker is an ultrasonic emitter. They are linked just by a very easily-built ordinary amplifier. Feed- back from the output to the input occurs only when the ultrasonic beam is reflected off the obstacle we are trying to detect. As Figure 1 shows, the receiver RXUS is connected to the input of a high-gain amplifier using transistors T1 and T2. As the gain of this stage is very high, it can be reduced if necessary by pot PI to avoid its going into oscillation all on its own, even in the absence of an obstacle. The output of this amplifier is connected to the ultra- sonic emitter TXUS, therby forming the loop that is liable to oscillate due to the effect of feedback. When this takes place, i.e. when an obsta- cle is close enough to the ultrasonic trans- ducers, a pseudo-sinewave signal at their resonant frequency of 40 kHz appears at the amplifier output, i.e. at the terminals of the transmitting transducer. This signal is rectified by D1 and D2 and filtered by C3 and, if its amplitude is high enough, it produces a current in R6 capable of turn- ing transistor T3 on to a greater or lesser extent. Depending on the nature and distance of the obstacle, this process does not neces- sarily happen in a completely on/off man- ner, and so the level available at T3 collec- tor may be quite poorly-defined. The Sch- mitt CMOS invertors are there to convert it into a logic signal worthy of the name. So in the presence of an obstacle, SI goes high and S2 goes low. Powering can be from any voltage between 5 and 12 V. The gain, and hence the cir- cuit's detection sensitivity, does vary a bit with the supply voltage, but in all cases PI makes it possible to achieve a satisfac- tory setting. Although it is very simple, under good con- ditions this circuit is capable of detecting a normally-ultrasound-reflective obstacle up to around 5 or 6 cm away. If a smaller distance is needed, you simply have to reduce the gain by adjusting PI. Building the circuit is straightforward. Both transducers are 40 kHz types that can be found in any retailers, and the other com- ponents couldn't be more ordinary. How- ever, one precaution is needed when wir- ing up the transducers. Even though they aren't strictly speaking polarised as such, one of their terminals is common with the metal case, and this is the one that must be connected to the circuit earth, on both emitter and receiver. The circuit should work at once, and all you have to do is adjust PI to set the detection distance you want — but this is also dependent on the positioning of the transducers. For optimum operation, we recommend you angle them as shown in Figure 2. ( 070236 - 1 ) 7-8/2007 - elektor electronics 37 Andreas Grun Many robotic applications require a sen- sor to measure light levels. The conven- tional approach as shown in Figure 1 uses an A/D converter to measure the voltage drop across resistor R1 produced by the photo current through a photo transistor. The fixed value of R1 limits the light range which can be measured; a high resistor value is suitable for measuring low light levels while a low resistance is good in bright conditions. The resolution of the A/D converter also plays a part in deter- mining the range of light levels that can be measured. A little-used property of a standard LED 4 IN juC 070356-14 is its reverse-biased photocurrent mode. An LED also produces a light-induced photocurrent but at a much reduced value compared to a photo-transistor. Direct measurement of the current is not so easy but another property of the diode can be exploited which is described in [1]. In this paper it explains that a useful property of a reverse-biased LED is its relatively large capacitance, the technique is to charge up this capacitor and then allow the photo- current to discharge it. The time taken for the capacitor to discharge is dependant on the amount of light falling on the LED (Fig- ure 2). Charging and time measurement can be easily performed using a single I/O pin of a microcontroller and switching it between output mode and high-imped- ance input mode. The measurement is performed in two stages: 1. The pin is configured as an output and set to high to charge up the LED capaci- tance (Figure 3). 2. The pin is configured as an input Pin (any pull-up resistor is disconnected) and the time is measured until the input voltage level falls below the lower input threshold level (Figure 4). The Example program is a listing for an Atmel AVR processor which measures light intensity. The program toggles all the output bits from port A after each cycle so that it produces an output square wave with approximately 50 % duty cycle at a frequency proportional to the measured illumination. The frequency varies from millihertz (in a darkened room) up to sev- eral hundred kilohertz when light shines directly onto the LED. This measurement range would be difficult to achieve using an A/D converter. Narrow beam LEDs have a corresponding narrow 'detection angle' making them more directional which may be beneficial in some applications. Differ- ent LEDs are sensitive to specific colours which can also be useful in some robotic applications. ( 070356 - 1 ) Web link (1) www.merl.com/publications/TR2003-035/ Listing Example program: #include #include #def ine LEDPIN 0x40 // LED on PB6 int main() { unsigned char cr=0,cb=0; DDRB = DDRA = PORTA PORTB sei ( ) ; 0x0 0 ; Oxf f ; = 0 ; = LEDPIN; // PORTB input // PORTA output for display LEDs // off // PB6 hi while ( 1 ) { if ( ( PINB & LEDPIN) == 0) // discharge complete { PORTB = LEDPIN; // PB6 hi // multiple times to get enough charging time DDRB |= LEDPIN; // PB6 output and hi, charges LED DDRB j= LEDPIN; // PB6 output and hi, charges LED DDRB j= LEDPIN; // PB6 output and hi, charges LED DDRB j= LEDPIN; // PB6 output and hi, charges LED DDRB Sc= -LEDPIN; // PB6 input, still charging w/ pullup PORTB =0; // switch off pullup PORTA *= LEDPIN; // toggle PORTA for display LEDs return ( 0 ) ; 38 elektor electronics - 7-8/2007 SHOP ONLINE AT www. compact control.co.uk r Compact Control Design LJ Compact ConlroE Design has a range of off the shelf products designed to meet your control, monitoring and acquisition needs. All products use the latest technology to provide top performance in a small size and at a low cost We also provide a full hardware and software design service. woi uas pio USB £.0 interface. Can be bus powered or self powered. Powerful PIC14F4H0 W Til j u ul pliargg' programming environment Libraries and links r scripts Included te support awcmfeluf programs JMFLtbl ind popular cwnpHin. PHICE:£2G.0Q +■ VAT PGW Ucvgtopar Beard The P0704 developer board la an ideal way te get started wilh out USB-PIC module and motor driver modules. AFl of the USB-PlC module DO signals are available through screw terminals making connections to sensors, switches, lumps, relays etc. easy, forts e & E (11 I/O ilgniEi) can al so bn- configured with pull - ups and Input filtering suitable for connKiibn to limit swift has, home position ssniari etc. The board supports up lo 4 motor driver mod ules, ea c h module pas ilim ■CCtfA *lth*r a $t*pp*r mater module or a DC motor modulo. The board allows bus -powered or self powered operation Of 1 ho USB-PIC module S loctudes a F0316 mini f&gutaior so only a single power supply Ls required for the meter driver modules. AH options .it n ounUgurad ue*I ng Jumpers, and stepper motor drive current can be easily adjusted for each module by variable reftifttart. All connections are made by high quality screw terminals. The board has been designed to oceo*nmed*te otner driver PRICE £55.00 modules as they + VAT become available. EMiaJKJkjsr Pulse wldlh modulation control ter DC mown, tl*otr^m»gn«tt tic. Il has a motor supply vr'rage of It io 16V. Thi> maxi mum drive currant Is 2.5 Amp. There are pulse and direction inputs. The PWM eonlroJ I* up to IOCiKHj- Made Input far controlling motor braking and Sleep Inpul ter power saving. There is huill In abort circuit a nd over temperature protection, a fault outpMt pin activates If either of these is datocled. No boat sink Ls required. The board has dimensions Of GfoSOmm and Is 12mm high, There 1$ an adaple# available providing easy to use screw terminals for all connections. AH the control inputs air? opEo-isolatcd. EMI a Steppe r Motor Drlvar The unit ha? * motor supply VOtUg* tff & te 30V. The tnoAliaum drive current per phase if 73*roA. EE has current mod? control. The drive current k» coAolled wilh a rcsrihfoT, It has ■ selectable step size of tell, half, Irt * 1/B. There is ■ step freque ncy of 0 io 200KHa and reset end sleep inputs tor inKlillallM and power saving.. It is a compact sue with dimensions of 6GjtJ2mm by 12mm high. The Pfi6l2 does not require ■ hast link. There Is an adapter available which provides ea sy io use screw terminals ter all connsciiont. PRICED HM + VAT All the control Inputs ore opio -isolated. MonC dn MonCon is * product range interujori te form t tm iPFtelligeiice at the heart Of any uqu ipmqiit from bench- top scientific instruments, production equipment, ATE etc. irp to largo proco&s control systems. Thg MonCon range takes a hew approach lo monitoring- and control by using modules that encapsulate * complete task, such as I be stepper motor controller module that includes alt inputs and outputs necessary to form a complete vleppnr motor controllsrfdriwr Including encoder fwhdback. The general purpose modules, such as the Analogue input board arc designed lo be custom Izod al minimum t-otL We can supply such modules to your raqulr*m*nts mi lirilo at no additional coat. The MonCon range Is based on a cof lection of modules each performing specific- and well defined tasks. All module* plug Imo a bock plan* which provide* power distribution, intercommunication and Incor para tea the •necessary connecters- linking ifio MonCon system to the resl of the equipment. The moduias #nq backplane conrwcton have been designed to slm pllfy the in lore Grin action requlremehte within your equipment Most devices, such as stepper meters, sensors etc. am wired 10 t he Mon Con backplane diret Ely with no apliCOk Of links &0 Hm wiring loom I* limplifisd. c helper te manufacture and mom reliable. We understand dial many manufacturers would want to have full control Over critical parts of Eheir products, so we are happy te allow eurcutionwi te manuiaciure under been**. The product range curmnlly consists of The following - standard h mok plane? with 4, S pc # slot*, coni roller modules for stepper and DC motors, coni roller modules for valves and solenoids, pressure conlrof, Rnw control ole a USB interlace to allow connection te a PC clc. various I/O module*, Parallel I/O. relay output and Analogue UQ moduEw. The MonCun range tirt bmn daklgnad with Hejclbl lity In mind. Backplanes and modules to meat your requiramenl* cm generally be designed & lUbpJItt) within & weeks of receiving a lull specification. Compact Control Design Limited, 77 Woolston Avenue, Cong let on, Cheshire. CW12 3ED K UK Tel : (+44) 01260 2S1604, Fax : (+J4J D126D 50llS6 h E-mail ; sales^compactcontrol.co.-uk 7-8/2007 - elektor electronics 39 MotoBox Drives stepper, DC and servo motors Joseph Zamnit (MCAST, Malta) Before a robot moves, no matter if that’s walking, swimming, cruising a maze or tearing up asphalt, you need to address the interfacing and driving of different types of motors. Developing the relevant algorithms will increase project development time as tweaks and adaptations seem to be necessary for each new application. This project solves these issues by presenting a generic motor driver board that can drive three different types of motors, stepper, DC and servo, without having to program the algorithm for each motor. MotoBox is ideal for newcomers to robotics as well as for old hands who can use the board for prototyping and development. The board can also be used with two different types of motors simultaneously! The board is programmed by way of an RS232 interface. This is a common proto- col found in many microcontrollers. It can be driven from the serial port of a com- puter or via another microcontroller. The script used to control the motors is a very easy 6-character command set. It has been kept this way in order to have a very user- friendly interface. The script also allows the state of the board to be read back to the user. Additionally the board monitors the current taken by each motor driver and switches off the driver if a short-circuit is detected. The author is a professional engineer with many years experience is designing and constructing electronic circuits. His specialisation is planar antenna design and currently he is a Telecommunications lec- turer at MCAST, Malta. Circuit description Referring to the schematic in Figure 1, the heart of the circuit is a PIC16F628A which controls and monitors the motor drivers. The microcontroller is configured to use its internal 4 MHz oscillator, thus freeing the pins associated with the crystal to be used as the serial interface. PORTB is used as an output to drive the motor controllers, while PORTA is used for various functions, to read the value of the current, control the driv- ers and control the driver LED's. The MCLR pin is held High by means of R15 and D13. An ICSP programming connector is also included in order to program the device in place. The PGC and PGD lines are decou- pled by a lOOnF capacitor. The module is powered by a 12-V supply which is regulated down to 5 V by means of an 78L05. Power-On status is shown by the green LED D16. The module has been designed to operate from a maximum of 13.8 V from a freshly charged lead-acid battery and down to 7 V. It is important for the module not to share the power source used to drive the motor because of the cur- rent surges, spikes and noise induced by the motor. A MAX232 is used to interface the module to the serial port of a desktop computer or laptop. It is imperative that the MAX232 be included in the circuit or else make sure that RA7 (receive pin) is held Low when not used. A floating input will cause the microcontroller to interpret noise as data and may result in erroneous operation. The module can also be controlled by another microcontroller by using connector K2. The motors are driven by the power stages provided by the L298, each driving a single 40 elektor electronics - 7-8/2007 GND IC6 = LM358AJG +5V R16 C23 I lOOn R17 GND +5V R12 +5V O C9 K3 loTpsy* D Connector 9 GND 1ulU 25V 16 C3 100ni4 7 13 8 15 vcc □ a > IC3 C1+ C1- T1 IN T2IN RIOUT R20UT C2+ MAX232CPE GND m C2- LU > T10UT T20UT RUN R2IN C8 "Tu"D I 25V 1 C7 3^ 1u 25V 11 10 C6 J 1u 25 V GND GND C4 lOOn GND 17 -0+5V RA0/AN0 RA1/AN1 RA2/AN2/VREF a a > IC1 RBO/INT RB1/RX/DT RB2/TX/CK<| RA3/AN3/CMP1 p|C1 6F628-04/P RB3/CCP1 >RA4/T0CKI/CMP2 RB4/PGM RB5 RB6/T10S0/T1CKI/PGC<| RB7/T10SI/PGD RA5/MCLR/VPP RA6/OSC2/CLKOUT >RA7/OSC1/CLKIN tn > 10 11 12 13 GND D13 I 1N4148 HRIS +5V Vsup O O C19 lOOn GND D14 1 R11 10 R1 Is ^7o( GND D1 Vsup X D2 D3 D4 1A1 1A2 1EN 2A1 2A2 2EN o o o o > > IC4 L298KV 1Y1 1Y2 IE 2Y1 2Y2 2E Q Z CD GND C12 D5 fB D6 6x 1N5400 K6 Sir R13 +5V Vsup 0 O GND C16 D15 J? ^7oOn GND C11 lOOn 10 12 11 R2 CIS ^ToOn D7 D8 D9 DIO GND it. it it it Vsup X t— CM o o o o > > 1A1 1Y1 1A2 1Y2 1EN IC5 IE 2A1 L298KV 2Y1 2A2 2EN 2Y2 2E O Z CD CIO lOOn 13 14 15 GND C14 Dll fB D12 6x IN 5400 K5 K10 K9 +5V GND 070129 - 11 GND Figure 1. Circuit diagram of Motobox, the ‘one size fits all’ controller for motors typically used in robots. motor. The L298 is a dual half-bridge driver capable of 2 A per channel, with sepa- rate enabling and current sensing for each bridge. It is suited to driving different types of motors. In this project the L298 is ena- bled by the microcontroller and the Enable line is pulled Low on power-up to ensure that the 1C is disabled. Decoupling capaci- tors, 100 nF each are placed near the 1C. A DC amplifier is built around the LM358 which senses the voltage across the sense resistor. It is followed by a lowpass fil- ter and a buffer amplifier whose gain decreases with frequency filters any noise. DC motors generate spikes when the arma- ture makes contact with the commutator, which is reflected as a current spike and appears across the sense resistor. Cur- rent spikes may cause the microcontrol- ler to detect a short-circuit and thus stop the motor. The filter will smooth out any voltage spikes. In addition, an algorithm is implemented in the microcontroller firmware that detects an overcurrent con- dition for a specified time before switching off the affected channel. Construction Good news: the project does not have exotic components to source, with the possible exception of the clip-on heatsink — but then that's available from Mouser. Through-hole components are used in the project to simplify construction and all components are easy to obtain as well as Table 1 . Driver options chart Motor header function Output Motor 1 Motor 2 |jC Pin RB3 RB2 RBI RBO RB7 RB6 RB5 RB4 Header pin 2 3 4 5 2 3 4 5 Mode Stepper driver Each output drives a motor phase Each output drives a motor phase DC motor driver (1) / / / / Servo driver (2) A3) P(4) P(4) A3) A3) P(4) P(4) A3) (1) Differential drive (2) Use the ground pin on the connectors for the servo (3) Allows 2 servos to driven simultaneously with the same signal (4) Used to power servo motor 7-8/2007 - elektor electronics 41 mount on the PCB, of which the compo- nent overlay is shown in Figure 2. There's little to say on the components used except that the 0.22-Q resistor is preferably not of the wirewound type and the bi-colour LEDs have two pins, not three! If you do not envisage inter- facing the board to a PC, the sub-D connector may be left out. However, the MAX232 should always be present. Likewise, IC4 and IC5 should always be soldered to the PCB. Dry testing Once the circuit has been constructed it should be tested for correct operation. Power up the circuit with none of the ICs inserted. D16 should light up. Check if there is 5 V on the relevant socket pins for IC1, IC3, IC4, IC5 and IC6. The supply voltage should also be present on IC4 and IC5, socket pin 4. If this is correct, switch off and insert the programmed microcon- troller and the rest of the ICs. The micro- controller can be programmed in-circuit using connector K4. If the board is to be controlled from another microcontroller, connector K2 may be used. This is a straight through connec- tor and the Transmit/Receive signals must be crossed before being connected to the board. If the female sub-D connector is going to be used, the signals are crossed over on the board itself. Motors get connected... The best way to fully test the board is to connect it to the PC and use HyperTerminal to send commands. Attach a motor accord- ing to one of the configurations shown in Figure 3 in order to test the board. Use the motor driver options chart, Table 1, to con- nect the motor to the correct pins. Figure 2. Component mounting plan of the PCB designed for Motobox. The copper track layout is a free download from the Elektor website. an erroneous command. The command buffer is cleared and the board waits for a new command. The LEDs will turn light up when the system is working correctly and red when the motor driver has been turned off. ... and controlled As soon as the board is powered up cor- rectly, it will return the character 1' to the Host to signal that it's been initialised and is waiting for a command. All commands are six characters long, you can find them listed in Table 2. Let's assume a DC motor has been con- nected to the board. Lor the motor to turn in the forward direction the command 'DC1LOR' has to be typed in lowercase or uppercase. The software will convert all letters to uppercase. When the com- mand has been sent it will be executed, the character 'A' indicating that reception is acknowledged and the actual command is echoed. This is very useful when the board is used with a (dumb) terminal. If the command has been sent incorrectly, the letter 'E' will be sent back indicating Table 2. Command syntax Command Command Description 1 ST1FOR Stepper 1 cw 2 ST1BAK Stepper 1 ccw 3 ST2FOR Stepper 2 cw 4 ST2BAK Stepper 2 ccw 5 STBFOR Both steppers cw — simultaneously 6 STBBAK Both steppers ccw — simultaneously 7 STSYNC Get both steppers in same position in case of slip 8 AMSTOP Emergency stop. Stop All motors — e.g. overcurrent 9 ST1FXX Turn stepper 1 xx (999 steps max) positions cw 10 ST1BXX Turn stepper 1 xx (999 steps max) positions ccw 11 ST2FXX Turn stepper 2 xx (999 steps max) positions cw 12 ST2BXX Turn stepper 2 xx (999 steps max) positions ccw 13 DC2FOR DC motor 2 ON/cw 14 DC2BAK DC motor 2 ON/ccw 15 DC20FF DC motor 2 OFF 16 DC1FOR DC motor 1 ON/cw 17 DC1BAK DC motor 1 ON/ccw 42 elektor electronics - 7-8/2007 Even if steps less than 100 will be done the leading zero must be provided. The DC, servo motor and status commands are executed immediately, but the stepper motor commands are subject to a delay (default 20 ms) so the command will be acknowledged after the stepper motor has been actuated. Sending a command within this interval will cause it to get lost and will be not executed. The type of motor in use can be read back at any time using the command 'MTYPEX', which will return a character depending on the type of motor being used. Overloading, spikes, surges... Through the analogue comparator, the software section will continuously moni- tor the current consumed. The board will switch off the motors if the current con- sumption exceeds the specifications for the motor type in use. Simple filtering takes place so that the controller will not switch off the motors at 'just any' current spike. Rapid on and \ COMPONENTS LIST ] Resistors R1-R4,R6,R7 = lOkQ R5,R8,R15 = 4kQ7 R9,R10 = 0.22Q 5W RTLR13 = 330Q R12,R14 = 470Q R16 = 5kQ6 R17 = lkQ5 Stepper motor commands allow the spin- dle to be turned cw (clockwise) and ccw (counter clockwise) by a number of steps (maximum 999 steps). When this command is selected, a 3-digit number must pro- vided, for example 050 to move 50 steps. Capacitors Cl = 100 |jF 40V radial 02-05,010,011,013,015-019,021 = lOOnF C6-C9= l|jF 25V radial 012,014 = 220nF C20 = 47|jF 25V radial 022= 10|jF 25V radial 023= lOOnF Semiconductors D1-D12 = 1N5400 D13 = 1N4148 D14,D15 = bicolour LED, 5mm, 2 terminals D16 = LED, 5mm IC1 = PIC16F628-04/P, programmed, order code 070129-41 IC2 = 78L05 IC3 = MAX232 104,105 = L298N with heatsink for Multiwattl5 case (mouser.com) 106 = LM358 KLK5-K10 = 2-way PCB terminal block, lead pitch 5mm K2 = 3-way SIL pinheader K3 = 9-way sub-D socket (female), angled pins, PCB mount K4 = 4- way SIL pinheader PCB, ref. 070129-1 PIC source & hex code files, free download # 070129-11. zip from Elektor website. 18 DCIOFF DC motor 1 OFF 19 DCBFOR DC both motors cw 20 DCBBAK DC both motors ccw 21 DCBOFF DC both motor OFF 22 SV2FOR Servo 1 cw 23 SV2BAK Servo 1 ccw 24 SV2MID Servo 1 centre position 25 SV2HLD Servo 1 hold 26 SVIFOR Servo 2 cw 27 SV1BAK Servo 2 ccw 28 SV1MID Servo 2 centre position 29 SV1HLD Servo 2 hold 30 MTYPEX Return motor type 31 STDELX Configure stepper motor delay 32 ECHOST Configure echo. Default = ON 33 AMONXX All motors ON 34 MONOFF Do not monitor current consumption 35 CMONON Monitor current consumption 36 RESUME Enable Motors after overcurrent condition 7-8/2007 - elektor electronics 43 Power supply o o Serial input o- o- 2 3 Motor Board 4 5 Power supply Power supply Figure 3. How to connect up your motors. off switching of DC motors will cause large current spikes, which may cause the controller to shut down the partic- ular motor driver. You can disable the current monitoring but this is not rec- ommended. Overcurrent can cause the L298 to overheat and get destroyed. A 'RESUME' command has to be sent after the motor driver has been switched off to resume motor operations. A grace period is given to enable another command to be sent and try to get the motor unstuck from its current position. Software The source code and hex code for the PIC16F628A is available as a free down- load from the Elektor Electronics website. The file number is 070129-11.zip (July/ August 2007). ( 070129 - 1 ) Author’s websites and email address http://telecomms.no-ip.org www.mcast.edu.mt jozamm@gmail.com Web links www.microchip.com www.st.com/stonline/products/literature/ ds/1773.pdf 1 2 V Bidirectional Motor Control Stefan Brandstetter This simple circuit drives DC motors with a maximum current of 1 A and can be built with readily available components. The output voltage is adjustable between 0 and 14 V and the polarity can be changed so that not only motor speed but also rotation direction can be adjusted by turning a knob. The circuit is also ideal as a controller for a DC model railway or small low-voltage hobby tool. Power for the circuit is supplied by a 18 V mains transformer rated at 1 .5 A. Diodes Dlto D4 rectify the supply and capacitor Cl provides smoothing to give a DC output voltage of around 24V. A classic 'H' bridge configuration is made up with T1/T3 and T2/T4. Transistors T5 and T6 the current sense and limiting mechanism, transistors together with resistors R7 and R8 provide The maximum output current limit can be 44 elektor electronics - 7-8/2007 changed from 1 A by using different value resistors for R 7 and R8: / OUT - 0.6 V / R where R gives the value for R 7 and R8. For increased current limit the mains transfor- mer and diodes will need to be changed to cope with the extra current as well as the four transistors used in the bridge confi- guration. Motor speed control and direc- tion is controlled by a twin-ganged linear pot (PI). The two tracks of PI together with R1/R2 and R3/R4 form two adjusta- ble potential divider networks. Wiring to the track ends are reversed so that as the pot is turned the output voltage of one potential divider increases while the other decreases and vice versa. In the midway position both dividers are at the same vol- tage so there is no potential difference and the motor is stationary. As the pot is rotated the potential difference across the motor increases and it runs faster. The vol- tage drop across D5 and D6 is equal to the forward voltage drop VBE of the bridge transistors and ensures that the motor does not oscillate in the off position with the pot at its mid point. ( 070104 - 1 ) 10- A Power Stage for DC Motor In case of a software crash it could happen that two ore more MOSFETs are switched on ncor- Jens Altenburg If you look at the chassis of the zBot vehi- cle 1 , you'll find two parts requiring intel- ligent control: the steering servo and the DC motor. The so called H-bridge is the normal circuit for electronic control of revolution speed and direction. The DC motor of a Tamiya car is powerful enough to propel zBot at up to 20 miles per hour. The motor then consumes more than 10 A, so we choose high-current power MOSFETs for the driver stage. There are lots of different devices to choose from. The MOSFET we require has to supply the maximum motor current and, importantly, it has to be switched with gate voltages of about 5 V. In this case, the microcontrol- ler switches the power stage (low side') directly. For high side driving level shifters are necessary. The schematic of the H-bridge power stage shows a few inverters, NAND gates and two tri-stateable drivers. These logic func- tions are very important as the easier way, i.e.., directly controlling all four MOSFET has a fatal disadvantage. rectly, for exam- ple, T4 and T7. In that case, the current through the transistors is limited by the internal resistors of the MOSFETs (about 10 mQ) only. Such a fatal error would destroy the MOSFETs. The logic functions configured here effectively avoid illegal states. To control the DC motor, three signals are needed: DIR, PWM and STOP. DIR con- trols the direction of the motor revolution, PWM the speed, and STOP brakes the motor. The software module for the DC motor is called dcm.c. ( 070172 - 1 ) (1) The complete document called Zbot — the Robot Experimental Platform is available for free downloading from the Elektor Electronics website. The file number is 070172-1 1 .zip (July/August 2007). 7-8/2007 - elektor electronics 45 Complete Stepper Motor Ms Table 1 Step angle (degrees) Steps per revolution 0.72 500 1.8 200 2.0 180 2.5 144 5.0 72 7.5 48 15 24 Hesam Moshiri With this circuit you can make a stepper motor do just about anything it will need to do in robotics application: rotation to the left or right, in full-step or half-step mode. Stepper motors convert electrical pulses into mechanical movement. In applica- tions like hard disks, printers and photo- copiers (to mention but a few), stepper motors are used for rotation and/or accu- rate position control of mechanical assem- blies. Every stepper motor has one perma- nently magnetic axle called the rotor. This is surrounded by a fixed part called the stator. Usually, stepper motors have four stator wires with two or one common wire, which is normally connected to the posi- tive supply voltage. By applying a controlled sequence of pulses to the individual stator windings, the rotor will start to rotate. Stepper motors may differ in size, shape, power, supply voltage, cost, accuracy, and so on, but importantly in the number of steps that make up one complete spindle revolution. This property also determined the step angle as shown in Table 1. For example for a motor specified as hav- ing a 1.8-degree angle, 360 / 1.8 = 200 pulses for a complete spindle revolution. Two pulsing schemes are available to drive the motor: 'full-step' or 'half-step'. The two modes are summarized in Table 2 and Table 3 respectively. Applying half-step pulses to the motor will increase the accuracy at which the spin- Table 2. Full-step mode. Rotation to the right (cw) Step Winding A Winding B Winding C Winding D Rotation to the left (ccw) 1 1 0 0 0 t 2 0 1 0 0 3 0 0 1 0 4 0 0 0 1 Table 3. Half-step mode. Rotation to the right (cw) Step Winding A Winding B Winding C Winding D Rotation to the left (ccw) 1 1 0 0 0 + 2 1 1 0 0 3 0 1 0 0 4 0 1 1 0 5 0 0 1 0 6 0 0 1 1 7 0 0 0 1 8 1 0 0 1 46 elektor electronics - 7-8/2007 die can be turned. In the case of our 1.8- degree angle motor, half-step driving then requires 400 steps per revolution. Another important advantage of half-step pulsing is more motor power, which usu- ally translates in more torque. The circuit of the motor driver is designed around an Atmel microcontroller type AT89C2051 ticking at 12 MHz and one high voltage/high current Darlington tran- sistor array type ULN2003. The motor drive pulses generated by the microcontroller under firmware control are fed to the ULN2003 via four port lines PI. 4 through PI. 7. The motor's stator windings are connected to the corresponding output pins on the ULN2003. The ULN2003 can supply up to 500 mA on each output pin. Note that a 5-V stepper motor is used in this circuit. The source code file and the firmware (hex file) for the AT89 micro may be down- loaded free of charge from the Elektor website as archive # 070228-11.zip. After constructing your circuit, power it up. Press the Full Step or Half Step button. Then press Left or Right and you will see your motor start to rotate using the mode selected. You can change between full and half step at any time. All this is based on the assumption that you have wired up your motor correctly. The AT89 source code contains a number of directions to help you 'change wires' in software rather than by soldering and getting confused by the different wire colours. In practice, you will notice that full-step mode yields higher spindle speed with low motor torque, whereas half-step mode is good for increased torque and accuracy, at the cost of speed. That is why stepper motors powering wheels etc. are controlled such that they start and end their operation in half-step mode, with full step mode in between to achieve maximum speed. ( 070228 - 1 ) Using a PIC programmed in Basic, a Basic Stamp or a Cubloc C. Tavernier Through robotics, radio-control servos are currently experiencing a new lease of life, thanks to their characteristics, which although not originally designed for such applications, turn out in fact to be well suited to it. Current radio-control servos are very compact, bearing in mind they contain not only their own mechanism, but also dedicated drive electronics, which only need simple TTL or CMOS logic signals as an input. The power they are able to supply can be quite considerable, for the most powerful of them (originally intended for large' model planes or boats); and lastly, they are usually sup- plied with a host of accessories such as crank arms, perforated wheels, etc., making it easier to interface them with the elements to be operated. There are currently two fundamental ways of using a servo in a robot. The first, described elsewhere in this issue, consists of converting the servo into a propulsion motor, which admittedly is rather taking it away from its origi- nal function. The second, which we're going to be looking at here, involves its use for positioning. Whether in an arm, or to turn a platform carrying a camera, a telemeter, or any other unit, our servo is ideal for this. We won't insult you by telling you what a servo is like, since even if you aren't a radio-control enthusiast, you're bound to have come across them before. However, here are just a few pieces of information that it's important to be aware of so as to be able to make use of them. In electrical terms, a servo has just three colour-coded wires. The red and black wires are for powering it, at between 4.8 and 6 V. The third wire, yellow or white (or in practice any colour other than red or black), is used to convey commands to the servo in the form of pulse-width- modulated (PWM) signals. Figure 1 illustrates both the cod- ing principle of these pulses and the effect they have on the position of the servo. Note first of all that they must be repeated at such a rate that there is not more than 10-20 ms separation between two successive pulses. In theory, this repetition is not abso- lutely vital; but with it, the servo will be able to maintain the position set by the width of the pulses received. If the pulses do not repeat, the servo will indeed go to the position dictated by the last pulse received, but, as soon as that stops, the slightest force on its shaft will cause it to lose the position attained. Notice from the figure: • a 1.5-ms pulse places the servo in its position referred to as centred or rest; • a 1-ms pulse makes the servo turn to its maximum anti-clockwise position, which usually represents an angle of 45° with respect to its rest position; • a 2-ms pulse makes the servo turn to its maximum clockwise position, which too usually represents an angle of 45° with respect to its rest position. 7-8/2007 - elektor electronics 47 Intermediate positions can be obtained by varying the pulse width between 1 ms and 2 ms. For use in robotics, it is even possible to go further and apply pulses a little shorter than 1 ms or a little longer than 2 ms to the servo, thereby achieving a total angle of rotation of 180°. But watch out! At this point, we have gone outside the specifications for the servo, which is in danger of jamming in these extreme posi- tions, destroying its motor, its electronics — or if you're lucky, both at once! Connecting a servo to a microcontroller (Basic Stamp, PIC, Cubloc) is very simple, as shown in Figure 2. The only point to watch out for is the servo power supply. Given the relatively high current drawn by the servo when it turns, it's best to sup- ply it off a separate voltage rail from the microcontroller. Where this is not possible, you need to ensure excellent decoupling between them — for example, by supply- ing the servo and the microcontroller via two separate regulators. As far as the software is concerned, con- trolling a servo using a Basic Stamp or a PIC programmed in Basic requires only a very few lines of program. In fact, all that's needed is to call up the two instructions PULSOUTand PAUSE. Here, by way of an example, is a program that makes a servo turn slowly from its extreme position on one side to its extreme position on the other side, and so on. In Listing 1 ' Basic Stamp I and II or in Basic programmed PIC version loop: 0, b2 for b2 = 100 to 200 for b3 = 1 to 5 pulsout servo connected to port P0 pause 15 next next goto loop Listing 2 ' Cubloc Version Const Device = CB220 Dim Position As Integer Low 5 ' Servo is connected to port P5 Do For Position = 2300 to Position = 4300 Step 20 Pwm 0, Position, 32768 Delay 100 Next Loop this way it can, for example, move a sen- sor in one plane over a total amplitude of 90°, see Listing 1. The instruction PULSOUT generates pulses with a variable duration from 100 x 10 ps to 200 x 10 ps depending on the chang- ing value of the loop variable b2, while the spacing between these pulses is set at 15 ms by means of the instruction PAUSE. This program is written here in Basic Stamp I language, but transposing it for Basic Stamp II or for use with a PIC pro- grammed in Basic only requires modifica- tion of the end values and the loop vari- able b2 increment. The resolution of the instruction PULSOUT is now 2 ps instead of 10 ps, so the various values need to be multiplied by 5. Using a servo with a Cubloc from Comfile Technology is just as simple, but uses an instruction called PWM, as per Listing 2. In this type of application, the advantage of the Cubloc over the Basic Stamp is that the PWM command generates the pulses indefinitely, even if the program continues on to something else. In the case of the Basic Stamp, the instruction PULSOUT generates only one pulse, and so has to be called from a loop in order to pro- duce them continuously, preventing the Basic Stamp from doing anything else. If you don't want to use a Cubloc, another solution consists in using a specialized 1C, like the MIC 800 from Mictronics (www. mictronics.com), which can control up to 8 servos simultaneously in a stand-alone manner (if necessary, refer to the Elektor Summer Circuits edition 2006). ( 070238 - 1 ) C. Tavernier www.tavernier-c.com When we're not using a stepper motor to ensure precise positioning of a robot element, it can be used as a traction motor, in place of the stand- ard modified servos presented else- where in this issue. Under these con- ditions, there's no longer any need to 'count the steps' the motor has to make, as all we want is to make it rotate continuously in one direction or the other. Several solutions are open to us for driving the motor, a number of which are presented in this issue: using a specialized stepper motor driver 1C, using one or more suitably-pro- grammed microcontroller paral- lel ports, or building a driver based around conventional logic ICs. However, these solutions are far from satisfactory when using a stepper motor for traction. They all require pulses to be generated continuously for as long as we want the motor to run, either requiring an additional programmable oscillator, or using up resources from the robot's main microcontroller. So we've decided to suggest another approach with this stepper motor driver specifically designed for mak- ing the motor turn in one direction or another, under the control of a sim- ple logic level. And as the propul- sion motors in robots usually go in pairs, we're even going to offer a dual driver, by diverting a very common and inexpensive 1C from its original function. Since a stepper motor used for pro- pulsion doesn't need to be accurate 48 elektor electronics - 7-8/2007 in terms of positioning, and hence, in the precision of the steps, simple single-pole models are eminently suitable. So, our circuit is designed for motors of this type. This lets us control the motor via two TTL- or CMOS-compatible logic inputs. When these two inputs, labelled L and R, are logic high or floating (they have their own pull-up resistors), the motor stays still, but in braked mode, since it's a stepper motor. When the L input is taken to logic low, the motor rotates in one direction (arbitrarily, to the left, whence the label L) while if the R input is taken low, it turns the other way. If both inputs are taken to ground at the same time, the R input has priority, and so the motor turns in that direction. The motor's speed of rotation is fixed, but, since we are giving you the source listing of the software used for this application, it's very easy for you to modify this if it doesn't suit you, or indeed even to include the possibility of external adjustment if necessary. The circuit of the 'intelligent' part of our controller is shown in Figure 1, as you can see it uses a PIC12C508 microcontrol- ler from Microchip. Used here in internal clock and reset circuit mode, it needs no external components for these functions, so all its port lines are available. Parallel ports GP2 and GP3 are used as inputs, and as GP2 does not have an inter- nal pull-up resistor, this is performed by R1. Parallel ports GPO, GP1, GP4, and GP5 are used as outputs for generating the pulses for the motor windings. These can be amplified by two types of power stages, depending on the type and number of motors to be driven; we'll take a look at those circuits in a moment. The 12C508 needs to be powered from 5 V, derived from the motor supply by means of a conventional 3-terminal voltage regulator IC2. If the controller is only intended for a single motor, or if the motor to be driven draws more than 500 mA per winding, the power stage shown in Figure 2 can be used. It employs conventional bipolar transistors that, given their characteristics, are able to switch currents of 3 A. Diodes D1-D8 clip the spurious spikes generated by the abrupt switching of the current in the motor windings and protect the transistors. However, if the motor used draws less than 500 mA, and more importantly, if you need to drive two motors of this type, an elegant and ingenious solution exists, as I +u BD679 R1 GPO GP1 O— < 1k [ R2 O— I 1k H I T4 D8 <1 O D1 D2 BD679 T3 D7 D1...D8 = 1N4004 Ml BD679 GP4 GP5 R3 o-nzj R4 O— I 1k H T2 © D6 1 s ) 1 ji \ 11 BD679 T1 D5 +u M <2> 070302-12 <2> Table 1 . Programming step duration by modifying a constant used in the program. Binary Step constant duration 10010010 1 ms 10010011 2 ms 10010100 4 ms 10010101 8 ms 10010110 16 ms 10010111 32 ms shown in Figure 3. This uses a stand- ard ULN2803, usually used to drive relays, but which includes eight medium-power Darlingtons along with their protection diodes. So, this 1C is able to properly drive any kind of single-pole stepper motor, as long as the voltage required doesn't exceed 50 V and the current per winding is under 500 mA. In addition, as the ULN2803 contains eight identical stages, it can be pre- ceded by two controllers like the one in Figure 1 and in this way drive two robot propulsion motors: one on the left and one on the right, marked MA and MB in this figure. Constructing one or other of these versions is very straightforward. The PIC 12C508 needs to be pro- grammed with the file that you'll find in object form, as well as in source form, in case you'd like to modify it, on the Elektor website, as well as on the author's own site (www. tavernier-c.com). If you build the transistor power amplifier, note that T1-T4 don't need a heatsink as long as the motor con- sumption doesn't exceed 1 A. Other- wise, bolt them onto a small aluminium plate a few cm 2 . To simplify mechanical construction, it can be common to the four transistors, but in this case you'll need to use the standard insulating accessories of mica washers and shouldered washers, as the collectors of these transistors are con- nected to the metal parts of their cases. If you construct the ULN2803-based ver- sion, there are no special precautions to be observed, other than to not exceed the IC's maximum current capacity of 500 mA. As we are providing you with the full source listing of the software programmed into the 12C508, you'll be able to modify it to suit your needs. If you are unfamiliar with PIC microcontroller assembler, here are the details you'll need for the most important modification you might want to make: changing the speed of the control pulses to the motors, and thus, their speed of rotation. The control word may be found in Table 1. To do this, all you have to do is modify the binary constant on the line: MOVLW B' 10010101' just above the line containing OPTION in the source listing. With the original value, the duration of one step is 8 ms, but the table above indicates what constant to use according to the step duration that you may want. ( 070302 - 1 ) 7-8/2007 - elektor electronics 49 Rajkumar Sharma This circuit is intended for motion control applications, a common occurrence in robotics! This affordable PWM DC Motor controller can control any PMDC motor specified at 12 V to 30 V and 3 Amps max. Motor direction is controlled with a slide switch and motor speed, with an ordinary potentiometer. The circuit diagram in Figure 1 shows ICs type LMD18200 and SG3525 at the heart of the circuit. The SG3525 is a pulsewidth modulator control circuit and the LMD18200, an H-Bridge to enable the motor to be run in both directions. The SG3525 affords frequency control and duty cycle control. The oscillator fre- quency is determined by the components attached to pins 5 and 6. Preset P2 serves to adjust the frequency between 1.16 kHz and 35 kHz. Although it is generally rec- ommended to stay above 20 kHz as oth- erwise the motor will produce audible sound, in some cases that's just not pos- sible depending on the motor you're using. Pot PI determines the duty cycle, which can be adjusted from 10% to 100% to effectively control the motor speed.' Inter- nal transistors are used in a such a way as to obtain 100% duty cycle. The internal driver transistors are grounded by pins 11 and 14 for alternate oscillator cycles. Pin 16 of the 1C is the REF V terminal, which gives 5 V out. Resistor R1 feeds the sup- ply voltage to an internal open-collector transistor for TTL-level PWM output. Moving on to the LMD18200, slide switch SI (on header SI) governs the Direction control input (pin 3) to change the direc- tion of the motor from cw to ccw or vice versa. R4 is connected to thermal flag pin T (pin 9), which is not used here. The func- tion may be used to flag a warning when VCC1 O VCC2 o R4 33 10k 100k C3 VC OSC OUT IC1 IN+ OUT A IN- OUT B CMPEN DISC SG3525AN ct ss Q Z o IS 18n 11_ 14 GND 103 VfTI L7805ACV V S ) C1 VCC1 f. 1 i ( C8 l - C5 lOOu 63V lOOn ( i ( i 1? ^pOOn GND CO T > BS1 PWM IC2 OUT1 OUT2 D l R LMD18200 cs Q Z BS2 CD m 2 10 C2 II lOOn C4 lOOn K1 El GND VCC2 O K3 < > lOOu C6 63V C7 lOOn GND GND GND 060339 - 11 50 elektor electronics - 7-8/2007 the chip temperature is 145 degrees. The 1C is automatically shut down when 170 degrees C is reached. Pin 8 of the LMD18200 is the current sense input. R6 connects this pin to ground. The Brake input (pin 4) is hard wired to ground. C2 and C4 at the motor output are 'bootstrap' capacitors. Pins 2 and 10 are the H-Bridge outputs powering the DC motor. In the power supply section, capacitors C5 through C9 serve to suppress noise on the two supply rails. The L7805ACV voltage regulator for the logic supply accepts any unstabilised DC voltage between 7.5 V to 18 V applied to K2. The other supply con- nector, K3, is for the motor power. The capacity of the motor supply of course depends on the motor used. If the motor is specified at 12 V then R7 should be 1 kQ, and if it is 24 V then 1kQ5 should be fitted. If you want to use a heavy-duty motor consuming more than about 1 A, it may be worthwhile to strengthen the cop- per tracks to/from K2/K3 with lengths of 1.5 mm 2 solid copper wire. COMPONENTS LIST Resistors R1 = lOkQ R2,R4 = 18kQ R3 = 2kQ2 R5 = 330Q R6 = 2kQ7 R7 = lkQ5 PI = lOkQ potentiometer P2 = lOOkQ preset Capacitors 01,02,04,05,07 09, = lOOnF If you want to interface the driver with a source supplying 0-5 V, simply remove potentiometer PI and apply the analogue voltage to pin 2 of 1C. Figure 2 shows the PCB designed for the driver, which should fit many applica- tions at crucial locations in a robot. After all, most forms of motion of a robot will C3 = 18nF C6,C8 = lOOpF 63V Semiconductors D1,D2 = LED IC1 = SG3525AN IC2 = LMD18200 IC3 = L7805ACV Miscellaneous K1,K2,K3 = 2-way PCB terminal block, lead pitch 5mm SI = slide switch PCB, ref. 060339-1 from www.thepcbshop.com require a motor of some kind. The board has been designed for compactness whist using leaded components only, i.e., no SMDs in sight here. The copper track lay- out and component mounting plan are contained in free download no. 060339- 1.zip from our website. ( 060339 - 1 ) 1 control control 2 1 B. Broussas Driving the 'small' motors that may be used in robotics doesn't usually pose much of a problem. Servo motors actually have their own drive electronics, stepper motors can be easily driven by conventional power transistors or by ULN2803 ICs as has been shown elsewhere in this issue, as they rarely draw more than a few hun- dreds of mA. For small DC motors, simple transistors will suffice, unless you prefer for IN 4 IN 3 EN B example the LB1630 from Sanyo, though limited alas to a current of 400 mA and a voltage of 6 V. On the other hand, as soon as the motor starts drawing 1 A or more, or its supply voltage exceeds 20 V or so, the situation gets more complicated — all the more so because many of you don't much care for power electronics. So, this article hopes to give you a few ideas or research paths for driving such motors. The first method for controlling a higher- power DC motor is none other than the good old relay, or to be precise, pair of relays. As long as you wire them as shown in Figure 1 , you have control over the operating direction, depending on which relay is engaged and which is not, as well as a stop control that acts as a very effec- tive electrical brake, when both relays are in the same position. In this situation, the motor is short-circuited and is braked by 7-8/2007 - elektor electronics 51 +U|_ +Um its own back emf (electromotive force). Relays capable of switching 10 A and yet only requiring 5 V and a few tens of mA for their coils are commonplace nowadays (see for example the Finder relays) and so can be used in this way without difficulty. If you don't like this electromechanical solution, we recommend you to use the bridge power 1C, one worthy representa- tive of which is the L298 from ST Micro- electronics. As its internal block diagram shows (Figure 2), this 1C includes four bridge power amplifiers, preceded by logic control circuitry. Originally designed for driving 'big' stepper motors, this 1C is suitable for a host of other applications, of which here are a few examples. By virtue of the relative independence of the amplifiers it contains, it can be used to drive four motors, as long as you are con- tent with a single direction of rotation. It is then possible to take one of these motor connections to earth or to the supply rail, as indicated in Figure 3. By juggling with the combinations of logic levels on the control and enable inputs of the L298, you can even have two options for motor stopping, as indicated in the table below: the 'freewheel' or unbraked mode, or the braked mode, as seen previously with the relay circuit. Table 1 shows the relevant logic level combinations. If the direction of rotation of the motor has to be able to be changed, it is neces- sary to use a bridge or H connection, as shown in Figure 4. Note that it is possible to drive two motors in this way from one L298, since the 1C contains four amplifi- ers. So, a single L298 is usually enough for the right and left propulsion motors of a mobile robot. Although the circuit does have protection against overheating, be aware that you can increase its operating safety by moni- toring the current drawn by the motors. To do this, all that you have to do is to fit a very low value resistor between the SENSE A or SENSE B inputs and earth. All the current drawn by the motor con- nected to the corresponding amplifier will then pass through this resistance, and by simply applying Ohm's law and measuring the voltage at these inputs, it is possible to monitor this current. If you don't wish to use this monitoring, you +u L +u M 6 +U|_ +Um Table 1 . EnA(B) In 1(3) In2(4) Ml M2 H H H Braked Running H L L Running Braked L X X Freewheel stop Freewheel stop 52 elektor electronics - 7-8/2007 are recommended to protect the 1C against possible shorts of its outputs to earth, which are the most likely to occur in a robot (a motor terminal touching the metal chassis, for example!) In this case, STMicroelec- tronics recommends the circuit in Figure 5. This circuit trips in 10 jlls and resets by itself when the short disappears. The L298 is capable of withstanding a maximum supply voltage of 46 V and each of its power amplifiers can supply a current of 2 A, already a more than comfortable value, even for a relatively heavy mobile robot. If that isn't enough for you, it is also possible to connect the power amplifiers in parallel, as long as you go about it the right way. You then have a maximum out- put current of 3.5 A. To do this, you must adhere to the circuit in Figure 6 and no other; that is to say, you must only parallel amplifiers 1 and 4 on the one hand, and 2 and 3 on the other. Just before we reach the end of our arti- cle, do note that the L298 does not include built-in protection diodes, so it is vital to provide them externally as we have done in each of our figures, otherwise the L298 is guaranteed to be destroyed the first time the robot's wheels turn! This 1C is of course not the only one that can be used for driving higher-power DC motors for robotics applications. More recent and/or higher performance pack- ages do currently exist. But the L298 does have the advantage of being readily avail- able, inexpensive, and able to fulfil a wide range of needs, which to our mind more than justifies this presentation of its vari- ous modes of use. And if you are ever so slightly curious, you'll find copious appli- cation notes about it on the STMicroelec- tronics website (www.st.com), which will be a good source of additional ideas for implementing it. ( 070317 - 1 ) * +5V ©- +5V © IC3 50mA max DIR o ®-l STEP o- ®-4 © <> » C2 10^ 16V Cl lOn 78L05 4 <> • » C3 C4 □ 220n 1000|a 25V IC1.A =1 12 13 IC1.B + 11 =1 IC1.C 6 F .1 =1 4 — 1 ► 3N , IC2.A >C 5 K c s 2 k BD679 R1 R2 H 2k2 +5V BD679 © 4 IC1 = 4070 IC2 = 4027 D1...D8 = 1N4004 © IC1 IC2 BD679 "s: 9 10 F .i R 15 =1 10 — ( ► 13 |S , IC2.B >C 11 K c \ 14 IC1.D k t R3 12 R4 2k2 BD679 X +u motor ©o © 070299 - 1 1 Without using ◦ specialised 1C B. Broussas Used a great deal in robotics, where it is a direct competitor for DC motors and radio-con- trol servos, the stepper motor does however suffer from the comparative difficulty encoun- tered in driving it. Unlike its DC equivalents, which rotate as soon as power is applied, the stepper motor requires a succes- sion of pulses applied to its vari- ous windings to make it turn. On the other hand, and provided its mechanical capacities are not exceeded, the number of basic steps moved by the motor corre- sponds to the number of pulses applied to its windings. Hence in this way we have available to us virtually automatic position- ing information, impossible to obtain with a DC motor. In many robots we've seen, driving the stepper motor(s) was the job of a specialized 1C, one of the front-runners being the L293 from ST Microelectron- ics which, despite its age, is still very much current. Yet there are many other solutions, such as direct control by one of the ports of the microcontroller that runs the robot — or the one we are suggesting here, which just uses... two standard CMOS logic ICs! As you maybe already know, there are actually two types of stepper motor: single- pole motors and 2-pole ones. While the first only need single pulses sent to their four windings, the latter require inversion of the signal polarity applied to the wind- ings. So as not to complicate our circuit unduly, we have designed it for single-pole motors, the timing diagram for which is given in the table below. 7-8/2007 - elektor electronics 53 Reading the columns of this table from 1 to 4 corresponds to rotation of the motor in one direction, while going from 4 to 1 reverses the direction of rotation. Each column of this table corresponds to one mechanical step of the motor. These steps vary from 1.8° to 7.5°, depending on the type of motor chosen. So the circuit of our driver without special- ized ICs, shown in Figure 1, is very simple, since its Intelligence' is in fact confined to two logic ICs, IC1 and IC2, which are sim- ple exclusive-OR (XOR) gates and a dual J-K flip-flop, while the power stage is built around perfectly ordinary general-purpose bipolar transistors. The pulses to make the motor turn must be applied to the STEP input. Each pulse makes the motor turn through a single step in one direction or the other; this direction is determined of course by the state of the DIR input. This acts on exclusive-OR gates ICIa and ICId, used here as programmable invertors. Remember that an exclusive-OR gate can be regarded as a gate that inverts or not the signal from one of its inputs depending on the state of its other input. This is easy to see from the truth table in Figure 2. If input A is 'O', the output is the same as the signal applied to input B (0 gives 0 and 1 gives 1). However, if input A is T, the sig- nal applied to input B appears inverted at the output (0 gives 1 and 1 gives 0). Noth- ing very new there, but we did want to underline this interpretation of the truth table of the exclusive-OR used as a pro- grammable inverter, as we have noticed that many of you aren't familiar with it (or have forgotten!) The truly active part of the circuit is formed by the two J-K flip-flops IC2A and IC2B. Figure 2 sums up the truth table for these flip-flops, which is made simpler here because J and K are always both at the same level. When these inputs are '1', the flip-flops change state at each clock pulse, i.e. for each pulse applied to the STEP input. In the reverse situation, i.e. when J and K are both 'O', the outputs Q and Q remain in the previous state. If you still have doubts that this will indeed generate the timings in the table above, arm yourself with some graph paper, a pencil, and some patience, and draw out the timing diagrams of the signals supplied, when DIR is at some arbitrary level of your choice. The power stage is built using bipolar tran- sistors, protected from the voltage spikes generated by the current switching in the motor windings by diodes D1-D8. With the transistors used, it is possible to switch currents of up to 3 A, allowing plenty of flexibility in the choice of stepper motor. The logic side of the circuit is powered from a fixed 5 V supply, stabilized by IC3, making the STEP and DIR inputs TTL-com- patible. This supply may also be used to power the circuit prior to this driver, as long as you don't exceed around 50 mA with the regulator chosen. If your motor is powered at 6 V, it is advis- able to replace IC3 by an LM2936Z5, for example, which is a low-volts-drop 5 V regulator. For correct operation, the 78L05 originally specified for IC3 requires almost 2 V between input and output — clearly impossible to obtain with a motor supply of only 6 V. JK FLIP-FLOP CLK j K Qn Qn + 1 J i X 0 1 T X 0 1 1 T 0 X 0 0 I X 1 1 0 I 1 1 Qo Qo \ X X X Qn XOR A B s 0 0 0 0 1 1 1 0 1 1 1 0 070299 - 12 Table Step number 1 2 3 4 Winding 1 1 1 0 0 Winding 2 0 0 1 1 Winding 3 1 0 0 1 Winding 4 0 1 1 0 Still on the subject of the motor supply voltage, note that it can be up to 24 V if necessary. As long as the current drawn by the motor doesn't exceed 1 A, the transis- tors don't need a heatsink, but one is advis- able above that. It need only be a few cm 2 , since the transistors are operating here in switching mode and so dissipate relatively little power. ( 070299 - 1 ) Web Link L293 spec, sheet http://www.st.com/stonline/books/pdf/ docs/1328. pdf Robot Footballer by Julian Straub You will do doubt have seen pictures from 'RoboCup' showing robots booting footballs from one end of the pitch to the other. Building an electromechanical robot like this is entirely within the capability of the hobbyist with the help of a few cheap everyday items. In order to give the ball a good kick the robot's feet are powered by linear solenoids. Accelera- tion is more impor- tant than force, however, and so we eschew readily- available solenoids which generally operate on 12 V or 24 V and which, although power- ful, are much too slow for our purposes. The integral of force over time (or impulse) produced by a coil with an iron armature depends, disregarding constant factors such as turns count, coil geometry and perme- ability, on the change in the coil current. The faster we wish to change the current, the higher the voltage we will have to use. And so we need a high voltage supply. We can generate a high voltage using the flash from a disposable camera of the sort that can sometimes be had for free from photography shops. The camera elec- tronics includes a high-voltage cas- cade circuit with a storage capacitor for the flash. These components are ideal for pressing into service as part 54 elektor electronics - 7-8/2007 of a robotic footballer. Open the camera carefully. First remove the battery making sure not to burn your finger by touching the capacitor contacts. For safe- ty's sake discharge the capacitor using a resistor of a few kilo-ohms before removing the printed circuit board. Because we will later want the capacitor to be charged con- tinuously, bridge the power supply switch connections. The circuit in the camera tested by the author (made by Kodak) charges a 120 pF high voltage capacitor to 330 V in 16 s from a 1.5 V battery. Next we turn to the sewing box for inspira- tion. We need two cotton reels from which we will fashion inductors using enamelled copper wire. On the one hand it is advan- tageous to use wire that is very thin so that we can have as many turns as possible and hence a high inductance, while on the other hand the high ohmic resistance of this arrangement limits the maximum current that can be achieved; we need to find a good compromise. To simplify BT1 £ (5 ivs charger circuit from disposable camera THY1 TIC126D -►fcr R1 > o CO CO LI R2 LDR Cl 1 20 jj. 400V 070316-11 kicker coil making the windings with very fine wire, first wrap the coil former with a layer of thin double-sided adhesive tape. This will hold the wire in place as you wind the first layer. Use adhesive tape again after each successive layer of wire. Finally, wrap the finished coil in insulating tape so that just the two connection wires (with extra insu- lation) protrude. The two iron cores can with a little luck be found in the clearance bin at an electron- ics shop. If not, you can resort to do-it- yourself: the cores can be ordered from any metal warehouse that can supply steel rounds. Ensure that you do not buy vanadium steel or a non-ferrous metal. The size should be chosen so that the lengths of metal pass through the cotton reels without too much play. In each drill a hole in one end and fit a small washer to prevent the light com- pression spring from sliding down. The spring ensures that after each kick (Figure la) the foot will return smartly to its initial position (Fig- ure 1b). The cores are fitted into the coils and a plastic cylinder, which will be the part that actually makes contact with the ball, is attached to the free ends. Figure 2 shows how simple the drive cir- cuit can be. A type TIC126D thyristor wired between the high-voltage generator and the coil triggers the kick. The thyristor is in turn triggered optically via an LDR, which ensures isolation between the high voltage electronics and the control circuit. ( 070316 - 1 ) Herbert Musser Members of the motorcycling fraternity will welcome this design. Some types of motor cycle are notorious for having very short life expectancy of their filament indi- cator lamps. Vibrations transmitted through the frame are the culprit (especially if the indicators are mounted on the ends of long stalks). After-sales replacement LED lighting clusters are far more reliable but they cre- ate another problem: they draw less current than the filament lamp and cause the indicator relay to switch the indicators on and off far too quickly. The first attempt to solve the problem with an analogue electronic flasher circuit was not successful the first charge cycle of a capacitor was almost twice as long as successive periods, so the flash rate was not constant (maybe an integrator circuit would have given better results). A better solution was pro- duced using the mini PIC circuit and FET shown here. This design also has a built-in bonus feature; motor- cyclists are notorious for forgetting to can- cel their indicators so the circuit includes a time-out function (jumper selectable) which automatically cancels the indicator after 120 blink cycles. The circuit uses very few components and the finished circuit can usually be fitted into the existing indicator relay housing with a space of around 20 mm x 30 mm. The output signal from the PIC controls the driver (T1) which then switches the HEXFET power transistor (T2). The IRF4905 has an extremely low on-resistance of just 20 mQ and is capable of switching 74 A maximum. The supply (derived from indi- cator relay) is limited to 4.7 V by diode D1 and smoothed by Cl to reduce the effects of any interference from the motorcycle supply. Firmware for this design applicable to the PIC con- trollers 12F629, 12F683 and 12F675 is available to download free of charge from the Elektor Electron- ics website, look for file # 070090-11.zip. The finished circuit is reliable, impervious to vibrations, load current changes and best of all can be built for less than 7 pounds (approx. 10 euros). As a final thought you should check that traffic regulations allow the use of such home- made designs to be fitted to the motorcycle before it is driven on the road. ( 070090 - 1 ) 7-8/2007 - elektor electronics 55 Figure 1. The catapult electronics. Pascal Liegeois In this age of laser rays, it seems anachro- nistic to talk of catapults — but it's not as absurd as you might think. Many robot competition themes around the world have involved at some point picking up balls, of different formats according to the competition, and pro- jecting them into a receptacle, often at quite substantial distances for our little robots. There is one well-known type of very light ball, the ping-pong ball, that is very often used as a projectile in this type of competition. Besides picking up these balls, projecting them often poses a problem of accuracy and reliability. In this short article, the author is suggest- ing his own solution — not necessarily the best in the world, but at least it is proven. This catapult re-arms all by itself after each shot, within 2 seconds, and it's range can be adjusted by altering the ballistic curve, using just a single potentiometer. The very simple, cheap electronics don't require any programmable components, and have an output available to tell the carrier about the status of the catapult. Circuit The main element of the system is a per- fectly ordinary standard servomotor, as used in modelling. This type of actuator is a small marvel, containing as it does a position-servoed motor with step-down gearing, by way of a potentiometer and suitable electronics. A servomotor is controlled using a fixed frequency signal (50 Hz) whose pulse width is variable, generally from 1 to 2 ms. To produce this signal here, we use the famous NE555 (IC1) as an astable, wired in such a way as to provide the required frequency. Diode D1 in parallel with resis- tor R1 determine the duty cycle, and set the negative-going part of the pulse at around 18 ms. The width of the positive- going part is adjustable by means of R2 and PI or P2. The output of the 555 feeds the input to the servomotor. The 'electromechanical' part of the circuit is based on the use of a DPDT relay and two microswitches. Swl is used to trigger automatic re-arming of the catapult, while Sw2 fulfils two functions: it gives informa- tion about catapult re-arming, and once this re-arming has taken place, it lets us reposition the servomotor in the firing position. In the circuit diagram, Sw2 is shown oper- ated, corresponding to the catapult's re- armed position. Referring to the drawing in Figure 1, it's easy to follow the operation of the catapult. When the solenoid is briefly powered via the 'FIRE' input that controls transistor T1, the lever L is released, pulled up by spring R. This lever ends its travel up against the rubber stop G attached to the motor's servo arm, wheel P. In coming to rest against this stop the pro- jectile is fired, and the lever also operates Swl, energizing the relay RE1, which in turn latches via its contact relB and microswitch Figure 2. Operating diagram of the catapult. 56 elektor electronics - 7-8/2007 Sw2 (by this time returned to its rest state). The servo motor starts to turn clockwise and the rubber stop forces the lever back to its re-armed position. At the end of the travel, the lever hooks under the trigger catch; at the same time, Sw2 is operated, and unlatches the relay, which goes back to rest, commanding the servomotor to return to the firing position. Preset PI lets us adjust the upper position of the stop and thereby the range of the shot, as explained in Figure 3. P2 lets us set the latching point of the lever in the re-armed position. Figure 1 shows two firing positions (greyed) of the lever, and the corresponding positions for the rubber stop (numbered 1 & 2). To adjust the firing range, you simply need to know that, logically enough, in posi- tion 1 the ball will go higher, and in posi- tion 2 the ball will go less high. Everything depends on how it is being used: if you want to drop a ping-pong ball in a pocket in the ground, it's best to plan on getting there via successive bounces, and so to fire higher. On the other hand, if you are aim- ing for a basket high up, you need to aim 'spot on' into it, and so allow the lever to go higher. Once the adjustments have been set, you'll be amazed by the repeatability of this system. Construction Electronics The electronic part is relatively simple and can be built on a small piece of prototyp- ing board. The DIL relay RE1 can be fitted into a turned-pin DIP14 socket. The servomotor connector can be made using three sections (a 10 mm length) of 2.54 mm (0.1") pitch SIL pinheader strip. Mark the signal pin, so as to avoid any mis- takes when connecting the servomotor. The 1C can be fitted into an 8-pin socket. Presets PI and P2 should preferably be multiturns, horizontal or vertical. Check your wiring carefully. Power the cir- cuit without IC1 or the relay fitted. Check the supply rails to IC1 and to the commons of the switches, which will be connected to the circuit via wires of around 10 cm or so. Check the presence of +V CC on the central pin of the servomotor connector. Connect the 'FIRE' input briefly to +V CC and check that the solenoid operates. Mechanics Although not terribly complicated, the mechanics do require a little care all the same. The drawing in Figure 2 details the key parts and elements of the system. The chassis is made mainly from a piece of L- section aluminium angle, or an equivalent folded section. The servomotor, fitted with an approximately 35 mm diameter wheel as its servo arm, is mounted on the vertical plane of this angle. The pivot for the lever is slightly forward of the servomotor shaft. In my own case, I made this lever out of 5 mm square brass tube. This hollow section allows the lit- tle catch to hook into the lever once it is re-armed. This catch is operated by the solenoid via a small connecting rod. The solenoid is a 6 V type, mounted under the horizontal plane of our aluminium angle. The positioning of the microswitches is important, particularly that of Sw2, whose position is set once the optimum re-arm- ing position has been set. This setting can only be done once the electronics described above have been built. Sw2 is mounted onto the angle by way of a small bracket with two oblongs fixing slots, to allow the microswitch to be positioned. For Swl, two curved slots will need to be made in the vertical plane, where the ser- vomotor is mounted, so as to be able to adjust the firing range, in conjunction with preset PI. Once the mechanics have been com- pletely finished, the lever should be put into the lowest position, which will slacken the solenoid spring. Check that the catch hooks properly onto the lever by at least 1 mm. This action must take place without forcing, the solenoid spring must allow the catch to hinge to the right before hooking into the tube. Check that the solenoid is properly fitted with its return spring, which may be fit- ted between the coil and the armature, or actually inside the coil, within the space where the armature moves. The spring must push the armature lightly so that it comes back out of the coil once it has been activated. Adjustment Setting-up is easy. Don't fit the relay into its socket. Put the lever into the re-armed position and check that the catch holds it properly in the horizontal position. Release the catch and make sure the lever is pulled up properly by the firing spring. Apply power; the servomotor will take up a random position. Using P2, get the servomotor, via the rubber stop, to posi- tion the lever horizontally until the catch engages. Adjust the position of Sw2 so that it is operated by the small bracket attached to the lever. If the servomotor fails to oper- ate, check the circuit, the soldering, and that the servomotor connector is the right way round — i.e. that the signal and earth pins are not reversed. Turn off the power. Fit the relay into its socket. Re-apply power. The servomotor should take up some random position. Adjust PI to bring the roller into any fir- ing position (1, for example). Turn off the power and adjust Swl so it is operated by the lever in its upper position. Re-apply power. The catapult should re-arm all by itself and the servomotor should then return to the upper position as described above. Everything is now working. That's fine. Operate the solenoid to check that firing takes place correctly. You can now fit the lever with a support for the projectile (ball). It's worth noting that the unused NC con- tact of Sw2 carries +V CC indicating the catapult is re-armed... ( 070210 - 1 ) Figure 3. Mechanical construction details. 7-8/2007 - elektor electronics 57 Servo to Motor Conversion Paul Goossens Servos, originating from their application in model building, are usually used to ope- rate arms, feet and other 'tools' of a robot. In addition to these obvious uses they are also very suitable as a motor to drive the wheels of a robot, for example. To do this, the standard servo does need to be modi- fied first however. Servos have been used for a long time in the model construction arena. As a result they are readily available and often at attractive prices. Standard servo The purpose of a standard servo is to bring the shaft into a certain position and to keep it there. At the input the servo expects a train of digital pulses. The duration of these pulses determines the position that the shaft has to assume. The internal electronics uses a potentiome- ter which is mechanically coupled to the shaft to measure the position of the shaft. If the length of the pulses does not corres- pond with the present position of the shaft then the electronics will drive the internal motor. If the shaft is too far too the right then the motor will turn the shaft to the left and the other way around. The instant that the shaft reaches the correct position the motor will be turned off. Small adjustment A standard servo is therefore not suitable to turn wheels or similar things. However, with a little bit of tinkering we can make a servo suitable for this job. The trick is very simple. The potentiometer is replaced by a voltage divider with two 10 kQ resistors. In this way the electronics 'thinks' that the shaft is always in the cen- tre position. If we now give the servo a pulse of 1.5 ms duration then nothing happens. The servo will turn the motor off. If we make the pulse duration 1 ms then the servo will attempt to turn the shaft to the left-most position. To that end the servo will let the motor turn to the left. On its sensor input it continues to 'see' that it is in the centre position. The motor will therefore continue to turn to the left. To let the motor turn the other way we supply a pulse that lasts longer than 1.5 ms (2 ms, for example). The motor stops again when we make the pulse 1.5 ms long. Note that most servos have a mechanical end-stop, which prevents the shaft from turning any further. We have to remove these two end-stops first otherwise the motor will go up in smoke during testing! Mechanical This modification doesn't mean much from the electronics perspective. The skill is to do this in the small housing of a servo. As an example we use a cheap servo from Conrad (Figure 1). On the bottom of the servo are four screws that we remove first. After this, the bottom cover can be removed. Carefully loosen the cover plate. This con- tains a number of gears that can easy drop out. We need to know exactly how these are placed in the enclosure, because we need to put them back in the exact same place later on! Taking a picture of the inner works including the gears can be a very handy reference later one when putting the servo back together. Once that is done the servo looks like Figure 2. Remove the output shaft. This sits on the shaft of the potentiometer. This shaft is fitted with a ridge, which together with 2 ridges in the housing forms the mecha- nical end-stop. This is undesirable, there- fore remove this ridge with a sharp knife (Figure 3). The next job is to remove the PCB from the housing. Should this not come out easily, then a careful push on the shaft of the potentiometer usually ensures that it comes out of the housing after all. The motor should have a small gear. This will sometimes be caught by the housing. If that is the case you need to retrieve the gear and put it back on the motor shaft. The potentiometer and motor are easily recognised. We now replace the potentio- meter with two resistors. The resistors are each individually soldered to one of the outside connections, where the potentio- meter used to be. The other connections for both resistors are then soldered to the middle connection. Voila, the servo is now converted. If all is well, your servo will look about the same as our prototype in Figure 4. What's left to do is to put the servo back together. Make sure that all the gears are in the correct position and everything is free to rotate. Also check that the little gear on the motor is still in the right place. Finally we screw the bottom cover back in place. The servo is now ready for use, but now as a motor and no longer as a servo! ( 070358 - 1 ) 58 elektor electronics - 7-8/2007 © Basic Stamp or Cubloc PO pi +5V Stamp / Cubloc T ri Ir R2 Tr3 R4 T 9 DS 11 01 12 02 13 03 IC1 14 04 15 05 ULN2003 16 06 17 07 Gr sID vll 05 vjf Oi. 02 II 0£. +U motor (50V max) © Ml 070237 - 1 1 Using a Basic Stamp or a PIC programmed in Basic C. Tavernier When we want to motorize a robot, two main solutions are open to us: the DC motor, used alone or in a converted radio- control (RC) servo system, as explained elsewhere in this issue; and the stepper motor. Although the DC motor is very suit- able for everything to do with propulsion, the stepper motor is more suitable when it comes to performing precise positioning, as required for a robot arm, a sensor mov- ing in one plane, etc. But while controlling a DC motor is rela- tively simple (it turns as soon as it is pow- ered), controlling a stepper motor is a lit- tle more tricky. They only turn when their various windings receive pulses, which have to be presented in a quite specific order to make the motor turn one way or the other. Because of this pulsed drive, these motors don't turn continuously, but in fact advance at each pulse by one basic step — whence their name. The size of these steps can vary between 1.8 and 7.5°, depending per motor: single-pole and double-pole. The former are simpler to drive, as all you have to do is apply voltage or not to their windings, while in 2-pole motors, the volt- age applied to these windings has to be regularly inverted, slightly complicating the circuitry that's required. Table 1 indicates the order in which a sin- gle-pole motor's windings must be pow- ered to make it turn. Going through the columns of this table from 1 to 4, the motor turns clockwise, while reversing the order changes the direction of rotation. Each column of this table corresponds to one mechanical step of the motor — remem- ber, that's between 1.8 and 7.5 degrees depending on type. There are numerous specialist ICs on the market for driving stepper motors, and various solutions are on offer in this issue of Elektor, but if your robot uses a Basic Stamp or a PIC microcontroller pro- grammed in Basic, there is an extremely simple and cheap solution for making it drive this type of motor. All we actually need to do is use a per- fectly ordinary ULN2003 or ULN2803, Table 1 Step number 1 2 3 4 Winding 1 1 1 0 0 Winding 2 0 0 1 1 Winding 3 1 0 0 1 Winding 4 0 1 1 0 on the type of motor used. This stepped advance makes it possible in principle for the program controlling the motor to know its position very accurately. But for this to remain true, we have to take care not to exceed the motor's maximum allowable loading, as in that case the motor might fail to advance for every pulse received, and thus 'skip' some steps. Another far from negligible advantage of the stepper motor is that if it is powered but does not receive any pulses, it remains blocked where it is. So we have a sort of electric brake — though of course still on condition that the motor's load capacity is not exceeded, as mentioned above. There are currently two families of step- ' Control of a unipolar stepper motor ' The step number is put in wl ' The rotation direction is defined by bO ' Variable's definition Symbol direction = bO Symbol incr = wl Symbol index = w2 Symbol delay = b6 ' Initialization dirs = %00000011 pins = %00000001 bl = %00000001 ' Here the application program must initialize ' incr, direction and delay with the required values if direction = 0 then incrincr bl = bl * %00000011 incrincr: for index = 1 to incr pins = pins * bl bl = bl * %00000011 pause delay next 7-8/2007 - elektor electronics 59 respectively seven-way or eight-way inte- grated power Darlingtons normally used to drive relay coils. The required software is very simple, thanks to a couple of tips sug- gested by Parallax (the manufacturer of the Basic Stamp). The first is to note that the status of wind- ings 1 and 2 on the one hand, and wind- ings 3 and 4 on the other, is always opposite, as indicated in the attached table. Because of this, the motor can be driven using just two of the Basic Stamp outputs, as shown in the very simple circuit we are suggesting. Windings 1 and 3 are driven from two lines of the Basic Stamp port, after amplification by the ULN2003 (or 2803). Windings 2 and 4 receive these signals after inversion, performed using two of the spare ampli- fiers in the ULN2003 (or 2803), which is overkill but perfectly practical. Note the presence of the two essential 1 kQ pull-up resistors, connected to the outputs of the amplifiers in the ULN2003 (or 2803), as the Darlingtons are only open-collector. The second tip suggested by Parallax con- sists of directly calculating the sequence of signals to be applied to the Basic Stamp's P0 and PI outputs, rather than getting these data from a table. All that's actually being used and the load it is driving. To be as general as possible, note that this example of code has been written in Basic Stamp I language. So it is fully trans- posable, without restriction, to any other type of Basic Stamp, as well, of course, as to any PIC programmed in Basic, since the majority of Basic compilers for PICs are compatible with the Basic Stamp I lan- guage. It can likewise be easily migrated to a PicBasic or a Cubloc from Comfile Technology. ( 070237 - 1 ) needed is a simple XOR logic func- tion, as shown in the program listing. This short example of code may be included as is into a more complete appli- cation. As can be seen, it makes the step- per motor connected as shown in the figure turn through the number of steps previously loaded into wl. The direction of rotation is determined by the contents of bO. If bO is anything other than 0, the motor turns one way; if not, it turns the other way. This program also lets us define the wait time between each step, by means of the data used in the PAUSE instruction; the only proviso is not to reduce this delay too much, taking into account the motor 01 Number One Systems Easy- PC The World Beating PCB design software for Windows Version 1 1 features ■ Destgn re-viiion analysis ■ Sfcar/Deita points ■ Apply Iftyyut pattern & groups I P^jgri culcplfitort ■ Electrical rules check (ER€) ■ Shape editing: panel ■ M^rgi'/su hi r.ic t &h.Lpr- editing ■ Track, aoalysiv Plus many more CKciting features. The new Easy-PC reaches even higher! The breathtaking new Easy-PC for Windows Vers ion 1 1 is released. Winning accolades the world oven V 1 1 of the market leading Easy-PC delivers even more remarkable value for money and sets the new benchmark for performance in PCS CAD. Just try a demonstration copy of Easy- PC and prepare to be amazed... Easy- PC deliver* tl simple to understand, fully integrated Schematics & PCB layout in a single application. Design and rules check* at all stages ensure integrity at all times. Professional manufacturing outputs allow you to finish the design process with ease. Stop press... Stop pres*,.. Stop press... Easy-PC is supported running under Window* Vista Call for a brochure, prices S CD an +4^ (0) I6B4 or e-mail sniei@numberone.com you cn n alio down lend a demo frgfn www.NumberOne.com Oak lane. ry. Gl*£ GL20 7LK United Kingdom 60 elektor electronics - 7-8/2007 Low voltage Rail-to-Rail Op Amps Solutions for extended temperature applications Microchip’s Selected Extended Temperature Range Op Amps Part# GBWP IQ Typical (V A) Vos Max (mV) Temp. Range (°C) Supply Voltage Features MCP6275/85/95 2/5/10 MHz 170/230/445 3 -40 to +125 2.0 to 5.5V Rail-to-Rail Input/Output, Dual Connected with Chip Select Selected Standard Op Amps MCP623 1/2/4 300 kHz 20 5 -40 to +125 1 .8 to 5.5V Rail-to-Rail Input/Output MCP624 1/2/4 650 kHz 50 5 -40 to +125 1 .8 to 5.5V Rail-to-Rail Input/Output MCP600 1/2/4 1 MHz 100 4.5 -40 to +125 1 .8 to 5.5V Rail-to-Rail Input/Output MCP6271/2/3/4 2 MHz 170 3 -40 to +125 2.0 to 5.5V Rail-to-Rail Input/Output MCP601/2/3/4 2.8 MHz 230 2 -40 to +125 2.7 to 5.5V Rail-to-Rail Output MCP6281/2/3/4 5 MHz 445 3 -40 to +125 2.2 to 5.5V Rail-to-Rail Input/Output MCP6021/2/3/4 10 MHz 1000 0.5 -40 to +125 2.5 to 5.5V Rail-to-Rail Input/Output MCP6291/2/3/4 10 MHz 1000 3 -40 to +125 2.4 to 5.5V Rail-to-Rail Input/Output Do you need low power consumption and extended temperature range operation? Microchip has a broad range of extended temperature op-amps with Gain-Bandwidths from 300 kHz to 10 MHz, including many devices in ultra-compact SOT-23 and SC-70 packages. Microchip also offers the innovative MCP62X5 dual-connected op-amp family. microchip © Microchip www.microchip.com/opamps The Microchip name and logo, PIC, and dsPIC are registered trademarks of Microchip Technology Incorporated in the USA and other countries. All other trademarks and registered trademarks are the property of their respective owners. ©2006 Microchip Technology Inc. All rights reserved. ME145Eng/10.06 A mini practical guide C. Tavernier www.tavernier-c.com More than any other electronics project, these days a robot can virtually not manage without at least one microcontroller to run it. So of course this raises the question of how best to select one, and this article is here to help you in this delicate task. Although the simplest robots can get by with virtually any type of microcontroller programmed in the language of your choice, as the complexity of the robot increases, it becomes clear that certain ICs are more suitable than others for a purely robotic application. The information they furnish is most often digital, from the simple on/off information of an open or closed switch to the complex NMEA frames from a GPS receiver. A few, less common sensors also furnish informa- tion in analogue form, and it's important not to overlook these ones. So our robot's microcontroller must have numerous parallel port lines for on/off type information, but also asynchronous and synchronous serial interfaces (l 2 C, SPI, etc.) for sensors providing more complex information (electronic compasses, incli- nometers, etc.), along with at least one analogue-to-digital converter for analogue information. So far, everything we've been discuss- ing is still within the scope of all current microcontrollers, and it's not much help to us in choosing. But the situation is actu- ally more complicated than you might think from this discussion, which might be described as 'static'. When our robot is moving, there is a need to simultane- ously control its motors, interpret the infor- mation provided by the sensors, and take the necessary decisions that entails. On the simplest robots with a small number of sensors, all this can be managed using standard sequential programming; but as soon as the number or complexity of the sensors increases, the situation soon becomes unmanageable. It then becomes necessary to resort to multitasking, i.e. to a mode of operation in which the micro- controller handles the sensors, the motors, and the decision-making all together and 'at the same time'. Sadly, not all microcon- trollers or programming languages are able to manage this by a long way. The last particular feature of robots is that, unlike conventional electronics projects, they are often built by amateurs coming from backgrounds other than electronics. Mechanics, modellers, those who are sim- ply curious all get involved in designing robots. For all these designers, who con- tribute a great deal to the world of robot- ics as they have a different view from the electronics enthusiasts, the microcontroller needs to be simple to implement and pro- gram. This simplicity sometimes founders on the reef of the multitasking we've just been talking about, but we're going to see that, by judiciously choosing the micro- controller, it is possible to reconcile the irreconcilable. Ordinary or special microcontrollers? If electronics no longer holds any secrets for you and if you're not afraid of program- ming, you can obviously choose a standard microcontroller for your robot. PIC from Microchip, AVR from Atmel, etc. The list is long, especially as each manufacturer offers a wide range of ICs with a great vari- ety of resources. Hence from Microchip, the PIC18 family is gradually supplanting the PIC16 fam- ily that has been delighting amateurs for many years. These new ICs actually per- form better, are more powerful, and hardly any dearer. As for the development tools, the unassailable MPLAB, increasingly user- friendly and of course still free, works just as well for either, so the transition is a gentle one. And if the power of the PIC18 isn't enough for you, the PIC24 fam- ily is all ready to replace it, as discussed in Elektor issue 343's presentation of the Explorer-16. It's the same picture with Atmel, where The need creates the system Compared to a conventional electronic project, a robot possesses certain particu- lar features that have a direct influence on the choice of which microcontroller to fit it with. So whether it is fixed or mobile — and the first robots amateurs build are very often mobile, as these are admittedly the most spectacular — a robot always includes one or more motors. As you've been able to discover throughout this issue of Elektor, these may take the form of radio-control servos, stepper motors, or DC motors. None of these are controlled in exactly the same way, but all of them require the microcontroller to know how to generate pulses more or less repetitively. Our robot is obviously fitted with sensors. Although the simplest versions make do with simple 'whiskers' or contact-based obstacle detectors, as robots evolve, they become literally covered in sensors, some of which can be highly complex. So, after briefly discussing the special requirements typical of robots, we're going to present a certain number of microcon- trollers and try to highlight their strengths in a robotics context. 62 elektor electronics - 7-8/2007 the AVR ICs from the ATmega range — scarce and expensive just a few years ago — are now within everyone's pocket, with their innumerable internal resources and sometimes impressive memory capacities. Here again, the AVR Studio development tool is free and available from the Atmel website. In spite of all that, it's not these 'classic' ICs that we're going to be looking at — espe- cially since this subject has already been covered in Elektor (issue 322), but some 'special' microcontrollers that are prov- ing highly successful in robotics because of their easy implementation and the particular features of their programming languages. You're probably familiar with the oldest of them, none other than the famous Basic Stamp - but these days this is far from being the only one. Originally dreamt up by Parallax, this concept has had its imitators, and ever since we've seen numerous microcontrollers coming onto the market aspiring to be its descendants, while of course claiming to do much bet- ter. So these ICs are the ones we suggest you choose from. A forerunner that has aged well For those of you who might not already know it, the Basic Stamp, developed and marketed in 1993 in the United States by Parallax, is a microcontroller that behaves as if it were directly programmable in Basic — but this particular feature is far from being the only one to have ensured its success. It is also a ready-to-use micro- controller, needing neither a clock crystal, an external reset circuit, nor even a stabi- lized supply to operate. All this is already built in. Like any self-respecting microcontroller, the Basic Stamp has to be programmed, but this programming is done in Basic, easy to use and accessible to everyone, to the point it has almost become a standard upon which all its successors have been based. No programmer is required, as it only amounts to... a simple cable to link the Basic Stamp to the serial port of any PC, even an old or very basic model. The development tool, intended for program- writing, is completely free and available for download from the Parallax website. Even though the simplest of all the Basic Stamps, the Basic Stamp 1, can be used to drive a robot, we unhesitatingly advise using at least the Basic Stamp 2, to benefit from the more numerous resources and a fuller instruction set. What's more, many successors to the Basic Stamp 2 (referred to from now on as BS2) are pin-compatible with it, allowing for possible future upgrad- ing as a robot evolves, without needing to modify the associated electronics. Figure 1 show both the physical appear- Table 1: Pinout for the Basic Stamp 2 in the 24-pin package, adopted by many of its competitors (Basic Atom 24, Cubloc CB220, Javelin Stamp, among others). Name Pin no. Function SoUT l Programming output (PC serial port) S|N 2 Programming input (PC serial port) ATN 3 Programming input (PC serial port) Vss 4 et 23 Ground POa P15 5 a 20 Input/output ports Ydd 21 5 V stabilized output (input if VIN is too low) RST 22 Manual external reset input (if required) V|N 24 Unstabilized positive supply from 5-15 V (12 V for 2E, 2SX, and 2P24) ance of the BS2 and its pinout, while the functions of the various signals available are listed in Table 1. Like all its successors, the Basic Stamp is not a 'true' integrated circuit, but a tiny PCB the size of a 24- pin DIL 1C fitted with a number of SMD components, including a microcontroller, its clock and reset circuitry, an EEPROM memory for storing the program, and a 5 V regulator to power it. Based on an 'old' PIC16C57 at 20 MHz, the BS2 is programmed directly in Basic, sometimes called PBasic, and is capable of executing around 4,000 instructions per second, while its memory can store around 500 lines of program. Its planetary success, and the word is not too strong, has pushed Parallax to put onto the market other BS2s, whose strong points are summed up here rapidly. The first evolution to have seen the light of day, the Basic Stamp 2SX or BS2SX, is in fact a significantly faster version of the BS2. It executes on average 10,000 instructions per second, by replacing the BS2's micro- controller with a SX28 from Ubicom. The program memory is also larger, accepting around 4,000 lines of program. All this is of course transparent for the user and the BS2SX instruction set is identical the BS2's, apart from three new instructions to man- age this extra memory. The BS2SX and its relatively large program BS2-IC .62“ (16 mm) Figure 1. The physical appearance, dimensions, and pinout of the Basic Stamp 2 have been taken up by many of its competitors: Basic Atom 24, Javelin Stamp, Cubloc CB220 amongst others. memory created a demand among certain Basic Stamp users wanting to benefit from this much larger memory, but not needing the speed (and hence the price-tag!) of the BS2SX. So Parallax has offered them the Basic Stamp 2E — simply a 'degraded' ver- Photo 1 . Though it’s been a bit left behind now, here’s the father of all the Basic Stamps, the Basic Stamp 1. 7-8/2007 - elektor electronics 63 Table 2: Principal characteristics of the various Basic Stamps and the Javelin Stamp. Parameter Basic Stamp 2 Basic Stamp 2SX Basic Stamp 2E Basic Stamp 2P24 Basic Stamp 2P40 Javelin Stamp Microcontroller PIC16C57 SX28 SX28 SX48 SX48 SX48 Clock frequency 20 MHz 50 MHz 20 MHz 20 MHz 20 MHz 25 MHz Program memory (bytes) 2 K 8x2 K 8x2 K 8x2 K 8x2 K 32 K Program memory (instructions) 500 4 000 4 000 4 000 4 000 — Working memory (bytes) 32 32 32 38 38 32 K Scratch memory (bytes) — 64 64 128 128 — Speed (inst./sec.) 4 000 10 000 4 000 12 000 12 000 8 500 Number of Basic instructions 36 39 39 55 55 0 (Java) Parallel inputs/outputs 16 16 16 16 32 16 Max. source/sink current per output 20/25 mA 30/30 mA 30/30 mA 30/30 mA 30/30 mA 30/30 mA Max. source/sink current per chip / per group of 8 inputs/outputs 40/50 60/60 60/60 60/60 60/60 60/60 Programming interface PC serial port 9,600 baud PC serial port 9,600 baud PC serial port 9,600 baud PC serial port 9,600 baud PC serial port 9,600 baud PC serial port 28,800 baud Supply voltage 5- 15 V 5- 12 V 5- 12 V 5- 12 V 5- 12 V 5 - 24 V Operating current 8 mA 60 mA 20 mA 40 mA 40 mA 80 mA Stand-by current 100 pA 200 pA 100 pA 400 pA 400 pA stand-by mode sion, in terms of speed only, of the BS2SX. So, the Basic Stamp 2E has all the charac- teristics of the BS2SX, but offers the same program execution speed as the BS2. The Basic Stamp 2P24s and 2P40s offer more innovations, but can be presented together as their characteristics are iden- tical except for one detail well look at in a moment. Apart from being faster than the already fast BS2SX, achieving 12,000 instructions per second, they also have an extended instruction set. The 36 or 39 instructions of the BS2 or BS2SX increase to 55, introducing some very powerful and extremely handy instructions capable of directly driving an LCD alpha- numeric display, talking to peripherals over the l 2 C bus, or driving ICs with a Dallas '1- Wire' bus. This evolution is done cleverly, however, and the same 36 BS2 instructions are included within the 55 instructions of the BS2P24 and BS2P40. The BS2P24 uses a pinout compatible with the other Basic Stamps, while the BS2P40 uses the 40-pin DIL 1C format, allowing it to have 16 addi- tional parallel port lines compared with the 24-pin packages. To help guide your choice, Table 2 sum- marizes the most important details of the various versions of Basic Stamp. Note that, for reasons of convenience, it includes the Javelin Stamp, described later. All these Basic Stamps are wonderful in robots, as their instruction set has really been designed for microcontroller-ori- ented use. So to make parallel port P2 go high, we simply write high P2; to make it generate pulses we use the instruction pulsin; to receive data in asynchronous serial form, we use serin, while to make it output synchronous serial data we use SHIFTOUT. Because of the very simple and explicit syntax of these instructions, anybody can write programs for a Basic Stamp after just a few hours of practice and with no previ- ous knowledge of programming. Moreo- ver, given the seniority and success of the Basic Stamp, the library of programs avail- able is immense. You only have to do a bit of Googling to see for yourself. So in our opinion, the Basic Stamp is a good choice for someone wanting to make a start in robotics, even if it does present in our view two drawbacks, of unequal importance: it's still expensive compared to other similar ICs; and it doesn't support multitasking. This point must, however, be taken relatively, inasmuch that a number of microcontrollers that do support it are pin- compatible with the 24-pin Basic Stamps, allowing easy substitution in the event of your robot's evolving in this direction. Basic Stamp 'clones' The success of the Basic Stamp has clearly made some people envious, and various products have tried to imitate it, while seeking to overcome some of its short- comings. At least two products fall into this category: the Basic Atom 24 from Basic Micro and the PICBasic range from Comfile Technology. Based on a PIC16F876, the Basic Atom 24, pin-compatible with the 24-pin Basic Stamp 2s, has a program memory the same size as the BS2E. Faster overall, at around 33,000 instructions per second, it also offers more internal resources, includ- ing an ADC, two PWM ports, and up to a point supports interrupts. Its instruction set is also fuller than the 'classic' Basic Stamps, and is related to that of the Basic Stamp 2P, though is a little fuller because of the increased internal resources. So it may represent a worthwhile alternative to the Basic Stamp, especially since it's a little cheaper to buy. On the downside, we must note all the same that it isn't multitasking either, and its availability leaves something to be desired, as the product has clearly not enjoyed the success its designers were hoping for (or else it just came on the scene too late). As it is not used a great deal, the library of programs for it is nothing like that of the Basic Stamp. As for the PICBasic, it is, or rather was, an alternative to the Basic Stamp 2 designed by Korean company Comfile Technol- ogy. We won't talk about it here, as it's 64 elektor electronics - 7-8/2007 Photo 2. The Basic Stamp’s offspring. clearly on the road to extinction, if we are to believe Comfile's website, in favour of the Cubloc range from this same manufac- turer. When you discover in a moment the possibilities of the Cubloc, and given that a CB220 (entry-level Cubloc) costs virtu- ally the same as a PICBasic 2S, you'll easily understand why it's being dropped. A first step towards multitasking Once again, it is Parallax who made the innovation in terms of multitasking with two distinct products for completely dif- ferent purposes. The first, and also the old- est, is the Javelin Stamp, much less well known than the Basic Stamp. It has to be said that its price (around £ 45) might have something to do with this... So the Javelin Stamp is physically like a Basic Stamp 2, but is programmed in Java. Of course, it isn't just that which makes it multitasking, but the fact that it has two operating modes: a foreground mode, where it executes the main program written in Java, and a background mode where a certain number of tasks can be performed independently of, and hence at the same time as, the main program. These tasks are executed by means of vir- tual peripherals or VPs of which, as far as background mode is concerned, there are five: UART, PWM signal generator, 32-bit timer, 1-bit ADC, and delta-sigma ADC. So, for example, the background genera- tion of PWM signals proves very interest- ing for robotics applications, since many motors are controlled by signals of this type. So the Javelin Stamp can, for exam- ple, control a robot's motors and convert the analogue information coming from a sensor, while still continuing to execute its main program. Independently of these specific features, the Javelin Stamp uses a Ubicom SX48 processor operating at 25 MHz, giving it a speed of 8,500 instructions per second; its other key characteristics are summarized in Table 2, to let you make a quick com- parison with the Basic Stamps. So the partially multitasking character of the Javelin Stamp does make it an interest- ing processor for robotics applications, but in our view it suffers from two drawbacks: its excessive price, compared with 'com- peting' processors; and the fact that it is programmed in Java, which is quite a dif- ficult language to master for anyone who has never done any programming before. One microcontroller with two heads The Cubloc range from Comfile Technol- ogy is much more innovative in the area of multitasking. As seen in Figure 2, showing the Cubloc's internal structure, this micro- controller is in fact a twin one, including on the one hand, a processor programmed in Basic, and on the other, a processor controlled in Ladder. This language, which you may not have heard of, is none other than the language used for programmable automata. The Cubloc's twin processors can of course operate simultaneously, mak- ing the Cubloc truly multitasking — pro- vided of course we program in both Basic and Ladder. To make it easier to get to grips with, it is of course possible to only program it in one language or the other. If you choose Basic, the syntax is close to that of the Basic Stamp with, however, lots of new instructions making it easier to handle PWM signals, or drive an l 2 C bus, key- board interfacing, etc. Although the Cubloc rage currently com- prises four main models, whose key char- acteristics are summarized in Table 3, we recommend starting out with the CB220. Apart from being it's the cheapest of the Cublocs, it's also pin-compatible with the Basic Stamp 2, making it possible to develop a single-tasking application using the latter into a multitasking application, without needing to make the slightest mod- ification to the electronics. What's more, given that it's based on an ATmega128 at 18 MHz, it can execute around 36,000 instructions per second 7-8/2007 - elektor electronics 65 BASIC ih-fri9ro»' Prgctispr BASIC Program M*rnai> o Flash 4C»Kfl -ACK.E, LADGEA Pfftgf am Memory SHAM 1K&-1K6 r FLASH 40K€-*DKB BASIC C.ila Memory laode* O-aLi MviiKiry Figure 2. Internal architecture of the Cubloc CB220. Photo 3. The PicBasic (right) marked Comfile Technology’s entry into the world of these special microcontrollers. It wasn’t yet pin-compatible with the Basic Stamp 2 (left). bj** __e-ii I**! . hi _ t, i ft** 6^ r Figure 3. Internal architecture of the Propeller - impressive, and allowing true multitasking. and its program memory offers a very comfortable capacity of 80 kB. Note too that it has an 8-channel 10-bit ADC and a 3-channel, 16-bit DAC capable of generat- ing PWM signals. So the Cubloc CB220 seems to us a good choice today in terms of processors intended for robotics, as it combines lots of advantages in a single package: hard- ware compatibility with the Basic Stamp 2, the simplicity of Basic programming, and the possibility of multitasking; all this for a price that is still reasonable compared with the other products in this survey. And finally, some true multitasking Rest assured, Elektor readers, we have not been paid to write this article by Parallax, even though it's another of this company's products we're going to be talking about next: the Propeller. We have to admit that ever since the first Basic Stamp came out almost 15 years ago, Parallax hasn't been resting on its laurels. But while the previ- ous products were based on existing proc- essors, the Propeller is a real 'chip' devel- oped by Parallax. As Figure 3 shows, even at first glance it's an impressive product, consisting of no less than eight independent functional blocks, the Cogs, each comprising its own proces- sor and some RAM. These Cogs are linked via a bus managed by a Hub that takes care of synchronizing their exchanges. They all share the product's 32 uncom- mitted input/output lines. Very few specialized peripherals are built in to the Propeller, but this isn't a prob- lem, given that its programming language, called Spin, is in fact an object-oriented language. So if you need, for example, an RS 232 serial port, you only need to delve into the voluminous object library made available to you by Parallax to find what you're looking for there. You can do the same for generating PWM signals, driving an l 2 C bus, an LCD display, etc. Given that there are eight Cogs available, it's possible to run up to eight different applications simultaneously. So a robot fit- ted with this sort of processor has no dif- ficulty in managing its wheel motors, while analysing the data from several sensors and taking the relevant decisions. Of course, Spin is a little daunting and writing your first instructions is a bit of a pain for anyone who's never programmed before — but it's well worth all the effort. What's more, Parallax places at your dis- posal a forum and above all a space on its website where anyone can upload the various object modules they have devel- oped for the Propeller. This participatory library currently has over 75 object mod- ules covering the most diverse fields, and 66 elektor electronics - 7-8/2007 Table 3: Principal characteristics of the various Cublocs. Parameter CB220 CB280 CB290 CB405 Microcontroller ATmegal28 ATmegal28 ATmegal28 ATmega2560 Clock frequency 18.432 MHz 18.432 MHz 18.432 MHz 18.432 MHz Program memory 80 K 80 K 80 K 200 K Dynamic memory (RAM) 2 K (Basic) 1 K (Ladder) 2 K (Basic) 1 K (Ladder) 24 K (Basic) 4 K (Ladder) 51 K (Basic) 4 K (Ladder) 55 K (pile) Data EEPROM 4 K 4 K 4 K 4 K Speed (instr./s) 36,000 36,000 36,000 36,000 Inputs/outputs 16 49 91 (33 entrees, 32 sorties et 26 entrees/sorties) 64 Serial ports 1 RS-232 1 TTL 1 RS-232 1 TTL 1 RS-232 1 TTL 4 RS-232 ADC (10-bit) 8 channel 8 channel 8 channel 16 channel DAC (16-bit, PWM) 3 channel 6 channel 6 channel 12 channel External interrupts — 4 4 4 Fast counters 2 x 32 bits 2 x 32 bits 2 x 32 bits 2 x 32 bits Real-time clock — — Oui — Supply voltage 5- 12 V 5 V 5 V 5 V Operating current 40 mA 40 mA 70 mA 50 mA Package 24-pin DIL (BS2 compatible) 64-pin module 108-pin module 80-pin module is continually growing. So if you want to build a robot that requires true multitasking, the Propeller is currently one of the best solutions there is, all the more so because the price is only a quarter of that of a Basic Stamp, a Cubloc CB220, or similar product. An odd multitasking PIC We couldn't end this review of special proc- essors for robots without mentioning an 1C that's relatively unknown on this side of the world, despite its undeniable interest: the OOPic. As its name might leads us to suppose, this 1C is none other than a PIC microcontroller that can be programmed in object oriented language — 'OO' standing for 'Object Oriented' — but that's not all. . . The OOPic is in effect a PIC that you will be able to program in the language of your choice: Basic, C, or even Java — but this program will consist of simple scripts call- ing up objects. These objects, currently 130 of them, are capable of managing vir- tually anything you can imagine driving with a microcontroller, and, rather than list them here, we'll send you off to the OOPic website to discover them for yourselves. All these objects are able to operate simul- taneously and independently of each other as background tasks while the main pro- gram is running. So with an OOPic, it's very easy to produce a multitasking appli- cation. But the concept goes further than that. It's possible to link objects together to form what are called virtual circuits that perform complete functions. In con- crete terms, this means that objects can exchange data between them, as a back- ground task, without your main program even having to bother about it. Another advantage, and not the least, of the OOPic is the possibility of network- ing it; a maximum of 128 OOPics can be connected together to l 2 C ICs, thanks to a 3-wire bus and without any additional external components. So with the OOPic it's possible to create what is called semi- distributed robot architecture, i.e. to no longer do multitasking, but multiprocessor operation. One processor looks after the management of the propulsion, another this-or-that type of sensor, and so on, while a 'central' processor now only has to look after decision-making on the basis of the information sent to it. Of course, implementing such an archi- tecture is no longer within the grasp of a robotics novice, but after starting out with a Basic Stamp or a Cubloc, for example, it is still accessible to anyone who cares to take the trouble, especially since it needs no special investment, since the OOPic is programmed in the language of your choice and the objects are available to you free, and programming is done using 7-8/2007 - elektor electronics 67 Photo 5. The development tools for Basic Stamp and Cubloc include a very useful editing terminal. Photo 6. The Propeller development tool showing an example of Spin — not exactly a barrel of laughs, but the results are worth the effort! Photo 7. The OOPic development tool allows graphical interaction with the objects used by the program. a simple cable connected to the parallel port of any PC. Conclusion This overview is of necessity incomplete, especially when you think that the pro- gramming manual of just one of the ICs presented here runs to at least a hundred or so pages! But we hope that we have helped you discover or re-discover some of the processors that are particularly well suited to robotics and which, while being simple to implement, do not in any way sacrifice performance. ( 070319 - 1 ) Addresses URL Company Comments www.atmel.com Atm el Manufacturer of AVR microcontrollers www.basicmicro Basic Micro Manufacturer of Basic Atom www.comfile.co.kr/english2/ 'PicBasic' website Manufacturer of PicBasic www.comfiletech.com Comfile Technology General site Manufacturer of Cubloc www.microchip.com Microchip Manufacturer of PIC microcontrollers www.oopic.com Savage Innovations Manufacturer of OOPic www.parallax.com Parallax Manufacturer of: Basic Stamp, Javelin Stamp, Propeller www.tavernier-c.com — Author's website Bas Lijten Driving multiple servos via a microcon- troller can be quite a problem for many people. Fortunately, a servo controller is available which can be controlled from a PC: the SSC-32. The SSC-32 is an open-source controller which is connected to the serial port. It has 32 outputs, which makes it possible to control 32 servos simultaneously. Each out- put can also be used as a general purpose output with TTL levels. In addition, the microcontroller has four digital inputs and there is an extra socket for fitting an EEPROM. This was not being used at the time of writing, but it is likely that it will be used in future updates of the firmware. The servos that are connected to the controller can be controlled in a very sim- ple way. Only the numbers of the servos to be controlled, the pulse width (position) and the speed or time need to be known in order to make a servo move. If a speed is specified then the servo will move to the required position at that speed. If a time is specified then the servo will take that amount of time to move to the new position. The introduction already mentioned that the servos can be controlled simulta- neously. This is possible by means of a 'Group Move' command. This is done by setting the numbers of the servos, the 68 elektor electronics - 7-8/2007 pulse width and the time that the move- ment should take to reach the new position all in one command. In this way all servos move simultaneously. This Group Move feature can be espe- cially handy if, for example, you would like to make a robot arm move with a fluid motion. The controller carries out its own calculations, such as the speed at which the servos have to turn. The controller also contains functions to drive a hexapod, a robot with 6 legs. In this way there is no need to come up with an algorithm for the PC to let the robot walk, because the functions are already there to make the robot move its left or right side with a single command. The code is freely available since the microcontroller contains open-source software. As a result you can add, improve and remove functionality yourself. Not happy with the hexapod code? You can then 'easily' rewrite it. In the same way you can also add functio- nality. For example code to move a robot arm to a particular location in a Cartesian coordinate system. By doing so there is no need to control individual servos from the PC but simply send one coordinate to move the arm the correct way. Because the controller is both easy to drive and easily modified by an experienced programmer it is very suitable for anyone who would like to spend some time with robotics. ( 070373 - 1 ) Manufacturer of the controller: http://www.lynxmotion.com The Propeller chip made by Parallax Inc. is a bit of a strange animal in the world of microcontrollers. This 1C consists of eight 32-bit processor cores that are given access one by one to the peripherals and proc- essor memory. This makes the Propeller extremely fast and it can work without the use of an interrupt mechanism: tasks that used to require an interrupt routine can now be run in their own processor core (called a 'COG' in Propeller-speak). This processor is fast enough to directly drive a VGA monitor for example, and also per- form other tasks at the same time as well. We don't have enough space here to go into detail of the operation and the soft- ware for the Propeller. All this information and documentation, example applications and extensive development software can be freely downloaded from the Parallax website. BoeBot As you may know, Parallax is also the manu- facturer of the BoeBot robot kit, a frame with all the required hardware to make a mobile robot that can be equipped with various sensors. All this is controlled by a processor board using a Basic Stamp or Javelin Stamp. The BoeBot with the Basic Stamp was previ- ously covered extensively in a series of arti- cles in Elektor Electronics , but that was quite some time ago: end 1999 / early 2000 to be exact. But it's still going strong after all this time, since the BoeBot is even now widely used in education. That was the original purpose of this robot, since 'Boe' stands for 'Board of Education'. Upgrade It was only a matter of time before this robot was upgraded with a processor board for the Propeller chip. Parallax has recently brought out a prototyping board 7-8/2007 - elektor electronics 69 Figure 1: The circuit diagram of the Propeller prototyping board. that is made to measure for the BoeBot frame. It is noticeable that part of this board now has an ordinary prototyping area for the addition of extra electronics, whereas the 'old' Basic Stamp board came equipped with a mini breadboard. On the Propeller board we therefore have to solder any extra components, which is a bit more time consuming than simply inserting them into a breadboard, but it does make the robot more reliable. Despite being care- fully constructed and having well thought out software a robot can still bump into something or become a victim of a passing pet who suddenly discovers a new play- mate. When a breadboard is used, some components could become dislodged; with a prototyping board the chances of survival are greater. The prototyping board is well laid out, has everything you need and is reasonably priced, but we did see a potential disad- vantage (especially in education): both the processor as well as the EEPROM are SMD versions. If something is wrongly connected it could mean the end of the processor and in many cases also the end of the board. Not everybody will have the right soldering equipment to replace such parts. Parallax had no objections when we asked if we could design a version of the board for use with classic DIL ICs. Should some- thing go wrong with one of the ICs on this board it's just a question of simply plac- ing a new chip into a socket (after first finding out what caused the problems, of course!). These components obviously take up more room of the Boe-Bot frame than their sur- face mount counterparts. The DIL ver- sion of the processor in particular is much larger than its little brother in a LQFP pack- age. Because of this we have left out a few features that were present on the Parallax board, such as the combined VGA, key- board and mouse connector, since we felt that they're unlikely to be missed in a Components list Resistors R1 = 270Q. R2 = lOkQ Capacitors C1,C2 = 1 OjnF 16V radial C3,C4,C5 = lOOnF Semiconductors ICl = LM2937ES-5.0 IC2 = LM2937ES-3.3 IC3 = 24LC256 IC4 = Propeller chip P8X32A-D40 (Parallax) Miscelllaneous XI = 5MHz quartz crystal K2 = 5-way SIL pinheader K3 = 4-way SIL pinheader 51 = on/off switch 52 = 1 make contact 4 pcs 3-way SIL pinheader PCB, order code 070275-1 from Elektor SHOP Figure 2: The board layout is single-sided. If you expect to use the prototyping area a lot then a double-sided through-hole plated version would be preferable. 70 elektor electronics - 7-8/2007 mobile robot. Circuit diagram The circuit diagram (shown in Figure 1) is conspicuous by its simplicity. Two low dropout voltage regulators provide 3.3 V for the processor and the EEPROM, and 5 V for peripheral devices that require a higher voltage, such as the modified servo motors that propel the BoeBot. Remember that the input pins of the Propeller can't with- stand 5 V. Next to SI, the power switch, is a group of four three-pole SIL connectors for the connection of servos and other periph- erals that require a 5 V supply. A power source with a voltage between 5.5 V to 26 V should be connected to K1, but we would advise against using too high a voltage because of the heat dissipation in IC1. There are two different ways of implement- ing the programming interface to a PC: K3 is the connector for use with the Propeller Plug by Parallax, which uses a USB link. K2 is used for the simple serial interface that is described elsewhere in this issue. D1 indicates that the supply voltage is present, and S2 is the reset switch. Practical side The PCB is also very straightforward (see Figure 2). We have intentionally chosen a single-sided layout because this makes it easier to etch it yourself. Both voltage regulators are soldered on the bottom of the board. IC3 isn't strictly required to start using the Propeller. When the processor starts it runs its bootloader routine, which first checks if there is a communications link to the host PC and then waits for a program to be downloaded. The user then has the choice of either loading the program into the internal program memory of the Pro- peller or into the external EEPROM. Figure 3: This message confirms that the Propeller Tool has made a connection and the fun can begin! If no communications with a PC are pos- sible, the bootloader will attempt to load a program from the EEPROM; if noth- ing is found there either, the bootloader stops and the processor turns itself off automatically. A program can be directly transferred from the PC into the internal program memory and then executed, but remember that this memory is volatile. When the power is turned off, all memory contents are lost. The crystal can be left out as well, since the Propeller initially uses its internal RC oscillator that runs at a speed of 12 MHz, which is fast enough for most applications. XI will only be used once the program has set the relevant clock registers. Once power is applied to the processor and the circuit is connected to the PC, the 'Propeller Tool' should be started and the F7 key pressed (or from the Run menu choose the Identify Hardware option). The serial ports of the PC are then scanned one by one for the presence of a connection to the Propeller board and if everything is in order a message will appear like the one shown in Figure 3. The COM port number will obviously depend on which port the interface is connected to. Once this message has appeared we can get to work with the Propeller and explore the exiting world of this microcontroller. ( 070275 - 1 ) Web Link: www.parallax.com/propeller Richard Hoptroff The art of discrete electronics has, over the past decade or so, become subsumed by machine code inside microcontrollers. The firmware is the magic in today's electronic circuits, and rightly so. It's faster, cheaper, easier and more flexible than making changes to the hardware. Unfortunately, exchanging firmware between people remains in the Dark Ages. If you want to buy someone else's firmware, what can you do? At best you buy a pre-programmed chip from the creator or from a publishing service such as Elektor SHOP or www.hexwax.com. Worst case, you get a hex file and pro- gram the microcontroller yourself - pro- vided you have all the necessary equip- ment to do so. And if there's a bug in the firmware, it's not exactly easy to get an 7-8/2007 - elektor electronics 71 upgrade. If only firmware could be more like software. Software is so easy to deliver that we do it without thinking, and as such has generated one of the most profitable industries in the world. Having the size of a postage stamp, the TEAclipper from FlexiPanel Ltd (www.flexipanel.com) seems a step in the right direction. This microcon- troller programmer is an easy, reliable firmware delivery mechanism. It can be pre-loaded with firmware and mailed to a customer, or the customer can download firmware over the internet and send it to the TEAclipper via a USB adapter. The TEAclipper is then inserted into the target PCB and generates all the signals neces- sary to program the microcontroller. Connection is via a 5-pin header which also provides power to the TEAclipper. Since only a temporary connection is required, a socket is not necessar- ily needed. The pins can be pressed against plated-through holes in the PCB for the few seconds required for programming. The number of programming cycles can be specified, after which the memory self-erases. This allows firmware to be bought and sold in fixed quantities. TEAclippers are currently available for programming Parallax's BASIC Stamps and Microchip's PIC Microcontrollers, but sup- port for further microcontroller platforms is planned. ( 070117 - 1 ) Jurgen Wickenhauser The LPC900 family is the Swiss Army knife of 8051 -compatible microcontrollers. The 'LPC' in the part number stands for 'low pin count': the NXP (formerly Philips) LPC900 family [1] consists of a range of small and easy-to-use microcontrollers ideal for small-scale high-speed applica- tions. Since the LPC900 family is based on an 8051 core it is easy to learn how to use the devices. However, the LPC900 is more than just a slightly spruced-up version of the 8051. The most important features are as follows: • 2-cycle high-speed 8051 core (six times as fast as a standard 8051); • from 1 kB to 16 kB of flash memory with full ISP and IAP functionality; compatible mode, which brings many advantages. One important point to note in this regard is than on reset the ports are set to CMOS input mode, and must if necessary be suitably initialised before use. Otherwise the LPC900 is very easy to use. The datasheet is rendered almost super- flu o u s by the free 'Code Architect' software by Embedded Systems Academy [2]. This tool is capable of creating snippets of C source code directly (see Figure 1). Loading code into the LPC900 microcon- • internal precision 7.3728MHz RC oscil- lator, ideal for baud rate generation up to 115 kbaud without an external crystal; • CPUs available in DIL as well as tiny SMD (TSSOP) packages; • a minimum system requires a sin- gle capacitor as the only external component; [ COMPONENTS LIST Resistors R1 = 240Q SMD (0805) R2 = 390Q SMD (0805) R3 / R4 / R7 / R9 / R11 / R12 / R13 = lkQ SMD (0805) R5,R6,R8,R10 = 220kQ SMD (0805) T1 = BC857 SMD (SOT23) LEDUED2 = LED, red, SMD (0805) IC1 = LM317 SMD (S08) IC2 = 74HCT00 SMD (SOM) IC3 = MAX3232 (SOI 6) • wide range of on-chip peripherals: brown-out detector, watchdog timer, comparators, A/D converter; • operating voltage 2.4 V to 3.6 V. Capacitors Cl = 4|jF7 25V SMD (1206 or 1210) C2 = 10 |jF 6V SMD (1206 or 1210) C3= lOOnF SMD (0805) C4,C5,C6,C7,C8 = lpF SMD (0805) The only significant difference from the standard 8051 is the improved I/O struc- ture: they can now also work in a CMOS- Semiconductors D1 = GF1M Miscellaneous K1 = mains adaptor socket for PCB mounting K2 = 9-way sub-D socket, angled, PCB mount K3 = 5-way SIL pinheader PCB, ref. 070084-1, from www.thepcbshop. com 72 elektor electronics - 7-8/2007 trailer proceeds with a minimum of fuss. When the CPU receives a series of three pulses on its reset pin within a specified time window of being powered up, the CPU jumps to a bootloader, which then proceeds to communicate using the RXD and TXD signals. After code is downloaded these three signals are of course available for their normal use. A five-way cable is required for download. The hardware required is minimal, as the circuit in Figure 2 shows. This circuit is capable of supplying the LPC with power and also provides an RS-232 interface, ideal for use with a terminal program. The printed circuit board for the design is shown in Figure 3. Operation is straightforward. The CPU can be powered up and down using the DTR signal. The RTS signal functions as a switch: if RTS is active then signals from RXD are also presented to the reset pin of the CPU, and can thus be used to acti- vate the bootloader. Note that R13 ensures that the supply voltage to the target hardware drops rapidly when it is switched off. It is advis- able to limit the capacitance on the 3.3 V rail in the target hardware to approximately 10 pF, since other- wise the microcontroller being pro- grammed might not correctly execute a power-on reset. The free program 'Flash Magic', also from Embedded Systems Academy, can be used to simplify programming the devices. This will be familiar to Elektor Electronics readers from the RFID reader project [3]. This tool also includes a suitable terminal program. An optimising C compiler is also needed to write programs for the LPC900 family. There are various commercial products available; here we will briefly discuss how to use pC/51 [4]. For practically all LPC900 Figure 3. Layout and component mounting plan for the printed circuit board. Figure 1. ‘Code Architect’ is a free tool that makes using the LPC900 microcontroller very straightforward. family devices the free demonstration ver- sion of the compiler is entirely adequate. The only restriction of the free version is the 8 kB code size limit, but this is already enough to write very complex applications for an 8051 -compatible microcontroller, 7-8/2007 - elektor electronics 73 Figure 4. Initialisation specific to the LPC900 requires just five instructions. Figure 5. The pC/51 compiler uses a well-structured classical ‘make’ system. because the compiler produces very com- pact code. In particular, the compiler is very parsimonious with the limited inter- nal RAM in the microcontroller, using a graph-based optimisation algorithm to enable multiple re-use of memory areas. For example, even with this very tiny CPU we have a fully-featured 'printfO' function call. The system also includes a reliable and comprehensive floating-point library. The pC/51 system was developed as a tool for the company GeoPrecision [5], and has been used and maintained there for years. The software tools work very well together and make development very quick: there are just three steps from source code to working program. For demonstration purposes we used an 89LPC922 with an LED connected to port pin PI. 7. The listing shown (Figure 4) is an example project included with pC/51 since version 1.20.06. As can be seen from Figure 5, the compiler uses a well-struc- tured classical 'make' system. Download- ing a program to the microcontroller is an intuitive operation (Figure 6). It is recom- mended that you configure the terminal program embedded within 'Flash Magic' so that it is launched immediately the application is started on the LPC. Note in particular that the RTS and DTR signals must be correctly configured (both active): see Figure 7. ( 070084 - 1 ) References and links (1) http://www.standardics.nxp.com/pro- ducts/lpc900 (NXP, manufacturer of the LPC900 family). (2) http://www.esacademy.com (Embedded Systems Academy: Flash Magic, Code Architect). (3) ELEKTOR RFID Reader (using an LPC936), Elektor Electronics, September 2006, p. 26. (4) http://www.wickenhaeuser.de (pC/51 compiler, demonstration version). (5) http://www.geo-precision.com (geotech- nical research and development). Figure 6. Flash Magic is a free tool for programming LPC microcontrollers. 9 U e '■ Settings for the RTS and DTR signals in the Flash Magic terminal program. 74 elektor electronics - 7-8/2007 C your way through USB Martin Valle Slick graphics, reading analogue values and making them appear in graphs, cockpit-style meters and dials, all on USB... How do they do it? U SB CM** * ... ol so1WO' e D ,W " • f' oi6C ' SC ii ■ jj ; ' _ ■ , %■ ■ "Vp L-w #■* n ■ y i J frdjUUM I- H j J J.?i jL+ k>l -. j ■ ■ tpr IEEE k-r -mi -I ■■ .5p ** ±i A mart ■■ bj ■<: j ■ fit, l ^ ^ ^ ■ | a ■ oftttrt ■ At ::: * -- .j .*Mi 1 v , i J. >- ■ : 5-3 n.T« hi J Sirt— ir .-in J .« wii It k ki. vi ■ 1 Er-. 3 J | >4u p*' ■ rnj-n**-* p tfe I -h Jprt* a&. Trrjtvirjri a ■ ' « ns ■ drin- l 1 Figure 2. Device Manager showing the installation of the PICDEM FS USB Demo Board. 7-8/2007 - elektor electronics 75 the bootloader 'talker'. Project.zip contains all the files needed to build the project in Builder C++ 6. REQUIRED.zip contains the files of the project.zip that you have to copy if you want to make a new project. Without builder.zip contains all the files needed to run the .exe file without the Builder installed in the computer. Here's how to process the software. 1. Extract the file MCHPF- SUSB.zip to the C: root directory. Check that there is no duplicated folder MCHPFSUSB, like: C:l M CHPFS USB\ MCHPF- SUSB\folders_xx, instead of: C: I MCHPFSUSB I folders _xx. 2. Using a suitable program- mer, program the PIC18F4550 microcontroller with the file: C: I MCHPFSUSB I fw\_fac- tory_hex\picdemfsusb.hex. The chip is also available ready-programmed. Waking up the F4550 Once you have built the project and checked it for mistakes, you can connect the USB to the host. For the first time con- nection, Windows XP is rec- ommended. As soon as you connect the board to the host, FEDs DO and D1 will start to blink, then the host will detect the device as 'PIC- DEM FS USB Demo Board (C) 2004' and ask for the drivers. You should select the drivers located in: C: I MCHPFSUSB I Pc I MCH- PUSB Driver\Release\ Windows will nag that this device does not pass the Win- dows logo test. Ignore and simply continue the installa- tion of the device. You can check for the proper installation by exploring in the Device Manager window, it should look like Figure 2. Keep pushbutton S3 (RB4) pressed and the reset the microcontroller by pressing and releasing SI. This proce- dure takes the microcontroller into 'bootloader' mode. The host will detect a new device, and it is necessary to repeat the driver installation proce- dure with the same driver location: JWO|£pr.M{TMl FI Uifl (■*•*» l mI ■ Vui^n 1 1-115 S] CitAAdHEKF* U jn F* ca t!j fltodbftwite ti IjMlDiMOfli ^ Microchip ITtEJLM PJ UjU Mwfa Criv Hori (hen \t\& 9m l^weir j ifj* $ T HEHflCE - PrDiriFMiPD FLASH CtiFwkrtPd A C i'li Sri ng *r..i r l'OQ!'4nAl "f rt>jn T - - Add r* in n a? Kl UR r. U A7 “ HI on K Hi FHJiiHAI! HtWJHE: UOUBVU LI LF ■; 1 B ri a* Kfi Kfi fil fii XI XK IK IK KK Kfi flilUN ^ ll XI KX xi II IX KK Xfi Xfi XI xi XI ii II ■ Kfi Xfi u mi ii: 1 u xi fil ii II II IK Kfi KX XI fii XI XI nt IK Kfi Kfi i BABBS d XE II EI II EX IK XE ME EE EI El EM EM EM ME ME DAAU.B XI II XI II IX IX IX XX XI XX XI XI XX IX MX XX DVOEfrll KI fil XI XX IX IX Xfi Xfi XX fil XI XK XI II IX XX ItVH I fil fil XI Xfi Xfi Kfi Kfi Kfi Kfi fil fil fil fil IK IK Kfi ■»D7» II II II xtt IX IX XX Xfi XX XI XI XI 1* IX XX XX D«4U 8 KX XI XI XK IK KK Kfi KX fifi fil XI XI II IK IK KX : BABH A XE II El El IX IX XE XE EE EE EE El EM IM MM ME DfiBDTlB XI XI XI XI IK IK Kfi Kfi XI fil XI XI IK IK Kfi Kfi PflQPH ■ XI fil XI XI IK IK Kfi KX XX fil fil XI IK IK Kfi Kfi v Vundfi 1 U jCl Pl- r*rhr.-.-„> ire PflfJ. Figure 3. PICDEM FS USB tool showing the board (device) connected. C: I MCHPFSUSB I Pc I MCHPUSB Driver\Release\ From now on you can load new programs ■W- GKBIAflfTM) r £ Lttfl Cuts T»l - Yinfan 1. Si F ' > AMI HiSOfi UHiRGDIH ft UEAtttd TtClXM(^y50C(O9mg? tad tfM -UGH K UGW Ota r i / ' |] Si ■ " v l\ m cu (a acnuu'fd. ‘Jl'lflH I HC. T.vi I r-rl |M ursri hfljr'ri Ff^llEF - Fr-airjHlnfj H fiKrt KomLi'l Ml HEEIfiCE - Erj r >iri>| jr>il Proqrj mini FLfltlt,, Addr . QD PI K IK1 EM CV CV. Wf QV (HI MU HI PHOGfitlll Htm MO fl -Eld GAD Cl Of&DIQ fil B»D3H fil DAOfSis XX aOiMJ KX uriLiri'.Li XE ii su ui'i a xx DVffBSB XX BfiVBBB XX BAAMD XX IHAfrnhFtfw. FF ML XX XX XX IX XX XX XX XX EE XX XX IX XX XX XX IX Xi EX Ft IK XX xk ik XX XX XK IK XX XX XX XX XX XX xn xx XX XK i n ti xjc Ilf XI kk fix XX XX XK fix XX XE XI XI XI fil Kfi Kfi XK XI XE II XX XI IX IX fil fix IX II II II KX IX IX IE IE EX XE IX EX KX II II KI II IX XX II XI II IX IX IX xx ik II IK xi ik EX IX ex: ix IX IK IX IK ii iri IX XX XI XX Xfi Kfi XX Kfi KX II XX XI XI Kfi KX fifi KX XX XI XX XX XX XI fix fil IX II fil fil XE XE XE XE fiX fil fil fil IX II r*Ar^nGhl iS^rtUirww^ci T IfW' fflJM to the microcontroller via the bootloader, following the above sequence using the S3 and reset pushbuttons. The PC application that com- municates with the boot- loader is the executable file: C: I MCHPFSUSB I Pc I Pdfsusb I PDFSUSB.exe The Pdfsusb tool must show in the selection square the device connected just as in Figure 3. Demo mode and a small hurdle If you reset the board with- out keeping S3 pressed, the microcontroller will run the program loaded in memory (i.e., not the bootloader). The same if you click the V Execute' button in the appli- cation. That's why the first device detected by the host was not the bootloader — it was a program to test with the other part of the Pdf- susb tool (Demo mode), this is the upper left tab behind the Bootload Mode tab. This mode is shown in Figure 4. It allows read- ing an approximation of the position of the potentiometer connected to RAO, control the state of the FEDs connected to RD2 and RD3 and measure a temperature of an SPI sensor that's not actually connected to the board (so don't pay attention to the temperature readings). The Demo firmware uses a few pins to monitor the USB main voltage (this is not implemented in the sche- matic). It may happen that this check fails after connecting the device to the computer. Fortunately, the error applies to the Demo firmware only, not to the Bootloader. There is an easy way to avoid this — in every project contained in the MCHPFSUSB folder there is a file C:\MCHPF- SUSB\fw\project_name_ folder\autofiles\usbcfg.h. It contains the declarations that are causing the prob- lem. Just comment-out (//) the two SENSEJO definitions as shown Listing 1. Having done this you can reload the Demo project, or any project for that matter, and all should work fine. 05]!R Figure 4. Demo Mode of the Pdfsusb tool. 76 elektor electronics - 7-8/2007 Build it! Now, it is time to explore the example application. As before, reset the microcon- troller with S3 pressed, to run the Boot- loader and load the micro with the hex file located in: C: I MCHPFSUSB I fw\ Hid02/_output/ NICAPM.hex Then, run the program. You can run the PC application directly without C++ Builder 6 installed in the com- puter by using the stuff in the archive file called: without builder.zip. Obviously the microcontroller must be connected to the host and running the NICAPM firmware. The window of the demo application should look like Figure 5, showing the sig- nals of Channel 0 (ANO, pin 2) and Chan- nel 1 (AN1, pin 3). There's also the archive file called project.zip if you want to modify something in the PC project. If you want to make a new Builder project, you only have to look after two things: 1. Add the hid. lib file by doing: Project — ► Add to project — ► hid. lib 2. Change the Data alignment from Quad word to byte by doing: Project — ► Options — ► Advanced Options — ► Data alignment. ( 060342 - 1 ) Figure 5. Two ADC Channels and USB of the PIC in action. Listing 1. /** DEFINITIONS *****************************************/ #def ine EPO_BUFF_SIZE 8 // 8, 16, 32, or 64 #define MAX_NUM_INT 1 // For tracking Alternate Setting /* Parameter definitions are defined in usbdrv.h */ #def ine MODE_PP _PPBM0 #def ine UCFG_VAL _PUEN | _TRINT | _FS | MODE_PP //#def ine USE_SELF_POWER_SENSE_IO //#def ine USE USB BUS SENSE 10 for AVR Micros Hesam Moshiri The STK200/300 programmer is found in nearly every programmer software for Atmel AVR microcon- trollers. The programmer shown here differs from other, similar, circuits in not requiring any extra power supply for itself, while still offering STK200 as well as STK300 programmer functionality. In case you did not know, AVR microcontrollers can be programmed in-circuit with only five wires: Clock, MOSI, MISO, Reset and Ground. To these should be added the +5 V sup- ply voltage taken from the microcon- troller on the target board. The programmer schematic contains nothing more than one buffer 1C type 74HC244, one 25-pin male sub-D con- nector for hooking up to the parallel printer port ('Centronics') on the PC, a 100 kQ pull-up resistor on the MISO line and a .1 pF decoupling capacitor on the +5 V supply rail. With some tinkering, the complete circuit can be fitted in the sub-D con- nector housing. A short length of flat- cable and a 6-way IDC socket at the target board side complete the pro- grammer. After programming, you simply disconnect the programmer cable from the target board. The STK200 or STK300 programmer hardware is available in lots of micro- controller programmer software, for example, BASCOM and CodeVision. ( 060374 - 1 ) 7-8/2007 - elektor electronics 77 GPS guidance for autonomous vehicles Ulli Sommer A (frequently unfulfilled) ambition of every robot builder is to make their machine capable of autonomous navigation. This is an ideal application for a GPS receiver module: these have recently become very cheap to buy. Our GPS-based navigation system is built around an ATmega32, programmed using BASCOM BASIC. It communicates with the outside world using an l 2 C bus. Any robotics hobbyist would dream of being able to build a robot which, like the famous Mars Sojourner Rover, can auton- omously negotiate unknown terrain. Ide- ally one would just program in the coor- dinates of the desired destination and the little chap would make his own way there automatically. Although fully autonomous robots must remain a pipe dream for now, a solution is available to the navigation problem, as we demonstrate here with a circuit board designed to be added to a domestic surveillance robot (see large photograph). Rather than develop a navigation system from scratch ourselves we make use of low-cost receiver modules that receive and process signals from the GPS satellite positioning system. To this we add a mod- erately powerful microcontroller that can be programmed using free software. ATmega at the helm Our GPS-based navigation system is built around an Atmel ATmega32, which appears at the heart both of the circuit diagram (Figure 1) and of the prototype printed circuit board (Figure 2). The micro- controller is programmed in a dialect of BASIC using the BASCOM development system, which is widely used and availa- ble for free (for the demonstration version at least) download from the manufacturer [1]. Also, the source and object files for the navigation program are available for free download from the Elektor Electron- ics website. The file reference is 070350- 11 .zip. An ISP cable is also required, obtainable for example from [3]. Any commercial GPS 'mouse' receiver can be used as long as it has an RS-232 interface. If the interface uses TTL signal levels it can be connected directly to our printed circuit board; if, on the other hand, it uses standard RS-232 levels (up to +15 V) a MAX232 level shifter must be connected How to program track points Before attempting any autonomous journeys we must program a series of set coordinates ('track points') into the navigation system. The first step is to replace the GPS mouse with a (null modem) data cable, connected to a PC. On the PC, start up a terminal emula- tor program such as Hyperterminal. A terminal emulator is also included in the BASCOM package. The interface parameters must be set as for the mouse (i.e., to 4800 baud). When connection has been set up, press the reset and programming buttons simultaneously. Then first release the reset button and then the programming button around a second later. You should see a welcome message (which indicates how to get help) and a prompt on the terminal. The following commands are also available: 'Data' lists the stored CPS data; 'Input' allows the GPS data to be edited; and 'Reset' restarts the navigation system. The coordinates of the track points can be determined using a sep- arate CPS system; alternatively, the robot can be moved manually to each track point in turn and the coordinates read off the LCD. With the track point data programmed in, the robot can be left to its own devices! 78 elektor electronics - 7-8/2007 10 ble R23 K1 o a o a o a o o a ISP R14 R15 MISO SCK RST MOSI RXD TXD R16 S3 H RESET R24 S2 +5V © 14 15 16 17 18 19 R17 oNo p RG 20 R18 21 R22 32 10 30 AREF VCC AVCC RST IC1 PB0(XCK/T0) PB1(T1) PB2(INT2/AIN0) PB3(OCO/AIN1) PB4(SS) PB5(MOSI) PB6(MISO) PB7(SCK) (ADCO)PAO (ADCI)PAI (ADC2)PA2 (ADC3)PA3 (ADC4)PA4 (ADC5)PA5 (ADC6)PA6 (ADC7)PA7 ATmega32 PDO(RXD) (TOSC2)PC7 PDI(TXD) PD2(INT0) PD3(INT1) PD4(OC1B) PD5(OC1 A) PD6(ICP1) PD7(OC2) (TOSC1)PC6 (TDI)PC5 (TDO)PC4 (TMS)PC3 (TCK)PC2 (SDA) PCI (SCL) PCO GND XTAL1 XTAL2 GND omz siatm _l D6 D5 l_ ii C2 22p 13 XI I I 16MHz 12 dp Ann/ it I Cl 22p 31 40 39 38 o 00 CD o CM dc IT dc DC DC DC DC 37 36 35 34 eo E 33 10 11 12 29 28 27 26 25 K5 l 2 C - Bus K6 compass l 2 C LCD 16x4 D1 K7 +8V ... +15V + +5V © 24 r\_ +5V 23 SDA V R1 _/"V 2k2 22 SCL R2 _0- 2k2 GND A. _o_ l 2 C - Bus to main controller trackpoint assignment +5V 16 © P0 SDA PI SCL IC2 — P2 INT P3 PCF8574 P4 P5 A0 P6 A1 P7 A2 K4 15 14 13 O +5V SDA SCL GND +5V © CM CL "D n 10k 10k 10k R5 R4 R3 co Q. —> ADR n 1 o 1N4001 C4 d =1 ■ 47|i C6 C7 □ lOOn 1H flfiWU Figure 1. The ATmega32 communicates with the compass and the LCD over an l 2 C bus; the GPS mouse is connected via RS-232. The PCF8574 l 2 C interface chip takes on the task of accepting a control byte and making it available on pins 33 to 40 of the ATmega. compass direction of movement if its speed is more than about 3 km/ h to 5 km/ h . Since we wish to determine orientation even when stationary we require an additional 'electronic compass' (see block diagram in Figure 3). A suitable compass Figure 2. Prototype navigation system printed circuit board for autonomous robots. Of course we do not just want our robot to display where it is; we want it to make its module is, for example, the Devantech CMPS03, available from [4]. This compass is connected to the l 2 C port on our printed circuit board. If we want to display the position and ori- entation we will also need an LCD module. The microcontroller is rather lacking in I/O port pins, and so the most practical solution is to drive the display also via the l 2 C bus. There do exist LCD modules with built-in l 2 C inter- faces, but an alternative is to use an l 2 C interface chip such as the PCF8574 [5] (see Fig- ure 4). We will see another use of this device in our circuit later on. in between. Often a robot's main circuit board will already have a suitable level shifter 1C on it. The GPS mouse gives the exact geographic coordinates (latitude and longitude) in a defined for- mat: see text box. It can also deter- mine the Motor control 7-8/2007 - elektor electronics 79 compass l * 1 2 3 4 5 C GPS RS232 LEFT RIGHT RST o PRG O track P oint assignment {>— O go left £>-0 go right ■{>— O target OK 070350-13 Figure 3. Simplified block diagram of the navigation system. The buttons are used when programming. Commands for the motors are output on two port pins. way to our desired destination. In doing this the navigation system outputs direction control information on two pins. Output pins MotorJ and Motor_r combined give the desired direction of travel as follows: MotorJ Motor_r Function 0 0 STOP 1 1 straight on 1 0 turn left 0 1 turn right Now we need a way to tell the robot navi- gation system where we want it to go. To do this we first need to program a series of set coordinates (Track points') into the unit, which is done using the cable before attempting any autonomous journeys (see text box). In normal operation the navi- gation system then only needs to be told which track point it should try to visit next, which can, for example, be done by the robot's main processor. This second communications challenge is also solved using the l 2 C bus, which is easy to use from within BASCOM BASIC. A PCF8574 l 2 C interface chip takes on the task of accepting a control byte and making it available on pins 33 to 40 of the ATmega (see Figure 1). The software configures the device to run in input mode. For a simpler hardware design, it is of course possible to dispense with the interface chip and drive the port pins of the ATmega32 high and low directly and in parallel. To select, for example, track point 1 using the l 2 C interface we must send the number T to the PCF8574. In BASCOM BASIC this might be done as follows. I2cstart I2cwbyte &H7A (address of PCF8574 : see data sheet for addressing scheme) I2cwbyte 1 (track point number) I2cstop When the track point selection byte has been sent, the navigation system deter- mines the direction to the destination. This calculated direction is then com- pared to the current orientation of the robot (obtained from the compass). In this calculation we ignore the curvature of the earth, since we do not expect our robot to embark on long-distance journeys! If the desired and actual directions are in agreement, the robot advances in a straight line. If, as it moves, the robot should devi- ate from the line to the destination, the > < -I 9 IS o o z + (/)(/) (3 Ks lQ 9 9 Ql (C +5V © 16 (/)l>UJOi-CMco*frLocor^ (/> O > 0C OQOOQOOO > > cc c \ LC DISPLAY 16x4 V y 070350- 12 Figure 4. The LCD is driven over an l 2 C bus, the PCF8574 interface chip making a second appearance in the circuit (see Figure 1). navigation system swings into action and brings it back on course. If the quality of the GPS signal is too poor or too few satel- lites are visible the robot will wait until an adequate signal is available to recalculate the desired course. When the destination is reached the robot stops and takes the pin Dest_ok high. This signal can be used by the robot's main processor, for example to load up the next track point so that the machine traces out a predetermined course. ( 070350 - 1 ) Web links (1) http://www.mcselec.com (2) http://www.elektor-electronics.co.uk (3) http://www.kanda.com (4) http://www.robot-electronics.co.uk (5) http://www.nxp. com/cgi-bin/pldb/pip/pcf8574 GPS mouse data A typical data packet received from a GPS mouse using the simple SGPGGA protocol might appear as follows. SGPGGA. 191410 . 5212. 9324, N . 000 07. 593 O.E .l. 04. 4. 4. 11.5. M. 48 . 0,M, , *73 Protocol Latitude Longitude Time L no. of visible satellites L measurement quality (0=insufficient, l=ok) Flere 'SGPGGA' is the protocol type, '191410' the time, '5212.9324, N' the latitude, '00007.5930, E' the longitude, T indicates that the reading is valid and '04' is the number of satellites in view. As you can see, this covers all the information we need. All we need to do is switch the GPS mouse to the SGPGGA protocol and set the communication speed to 4800 baud. Other protocols should be disabled, and the reporting interval set to approxi- mately 1 s. The settings are made using the software provided with the GPS mouse. 80 elektor electronics - 7-8/2007 We have designed a small PCB for this Simple and inexpensive Luc Lemmens The Propeller prototyping board described elsewhere in this issue needs a program- ming interface, just like the board available from Parallax. The manufacturer offers the Propeller Plug and the Propeller Clip for this purpose. They can be used to link the board to a PC via a USB port. These mini-boards are fitted with an FTDI FT232 1C, which has appeared quite regularly in the magazine. The difference between the Plug and the Clip is in how they connect to the proces- sor board. The Plug connects to a 4-way SIL header, while the Clip connects to four sol- der pads at the edge of the board. The lat- ter type of connection was used in the first version of the Propeller demo board, and it is actually no longer relevant. The Propeller Plug is the right USB interface for the proto- typing board from Parallax and our proto- typing board. This little board costs around twenty euros, but if you want to save a bit of money and prefer to use the old faithful RS232 interface (and your PC has a serial port), you can build the simple serial inter- face described here. Three garden-variety transistors, a handful of resistors, and a capacitor are all it takes to let the Propeller communicate with a PC via the serial port. The interface actually consists of nothing more than three invert- ers and level shifters, which enable the Propeller board (which is powered from a 3.3-V supply) to talk to the COM port of a PC, which operates with ±12-V signals. Connector K2, which provides the link to the Propeller board, has intentionally been laid out with the signal lines in the same sequence as on the Propeller Plug, but here we need an additional line for the 3.3-V supply voltage. This makes it pos- sible to use the interface board with the Parallax board as well. However, in that case a small modification is necessary for the supply voltage connection. circuit, but of course it's no problem to build it on piece of perforated prototyping board instead. With a bit of effort, you can probably even make it so compact that the entire circuit fits in a plug housing for a 9- way RS232 connector. Fortunately, when you use this interface you don't have to worry about configur- ing all sorts of settings (baud rate, number of bits and so on) — the Propeller Tool development software does all this for you. Use a 1-to-1 cable for the serial link (not a crossover cable or null modem cable). ( 070276 - 1 ) 3V3 f COMPONENTS LIST I Resistors I R1,R2,R4,R5,R7 = 10k£2 | R3 = 4k^7 R6 = lkQ l Capacitors ■ Cl = 10nF Semiconductors T1J2 = BC547 T3 = BC557 Miscellaneous K1 = 9-way sub-D socket (female), angled pins, PCB mount K2 = 5-way SIL socket PCB, ref. 070276-1 from www.thepcbshop. com 7-8/2007 - elektor electronics 81 Jorg Schnyder Does this sound familiar: you buy a small piece of equipment, such as a programming & debugging interface for a microcontrol- ler, and you have to use a clunky AC wall adapter to supply it with power? It's even worse when you're travelling and there's no mains socket anywhere in sight. Of course, you can use the USB bus directly as a power source if the supply voltage is 5 V. If you need a higher voltage, you can use the USB converter described here. This small switch-mode step-up converter can gener- ate an output voltage of up to 15 V with a maximum output current of 150 mA. The LM3578 is a general-purpose switch- mode voltage converter. Figure 1 shows its internal block diagram. Here we use it as a step-up converter. The circuit diagram in Figure 2 shows the necessary compo- nents. Voltage conversion is achieved by switching on the internal transistor until it is switched off by the comparator or the current-limiting circuit. The collector cur- rent flows through coil LI, which stores energy in the form of a magnetic field. When the internal transistor is switched off, the current continues flowing through LI to the load via diode D1. However, the voltage across the coil reverses when this happens, so it is added to the input volt- age. The resulting output voltage thus con- sists of the sum of the input voltage and the induced voltage across the coil. The output voltage depends on the load cur- rent and the duty cycle of the internal tran- sistor. Voltage divider R5/R6 feeds back a portion of the output voltage to the com- parator in the 1C in order to regulate the output voltage. C5 determines the clock frequency, which is approximately 55 kHz. Network R4, C2 and C3 provides loop compensation. The current-sense resistor for the current-limiting circuit is formed by three 1-Q resistors in parallel (R1, R2 and R3), since SMD resistors with values less than 1 Q are hard to find. The output volt- age ripple is determined by the values and internal resistances of capacitors Cl 1 , C8, C7 and C6. The total effective resistance is reduced by using several capacitors, and this also keeps the construction height of the board low. L2, Cl, C9 and CIO act as an input filter. Ensure that the DC resist- ance of coil L2 is no more than 0.5 Q. Use a Type B PCB-mount USB connector for connection to the USB bus. A terminal strip with a pitch of 5.08 mm can be used for the output voltage connector. Of course, you can also solder a cable directly to the board. Two additional holes are provided in the circuit board for this purpose. As we haven't been able to invent a device that produces more energy than it con- sumes, you should bear in mind that the input current of the circuit is higher than the output current. As a general rule, you can assume that the input current is equal to the product of the output current and the output voltage divided by the input GROUND TIMING CAPACITOR PIN 3 PIN 4 +5V D- D+ GND USB 47|iH jo2 ns \2n2 <>— I < » CIO □ I 820 nH UIN IC1 +IN I LIM LM3578AM OSC E 100n 47n 16V 47ji 16V SK34SMD < > < > ( • C11 C8 C7 C6 d =i i _ =] 1 _ =1 1 _ b ■ 68^ 68^ 68^ 68^ —i 20V > < 20V J H -i 20V > — -< 20V > < C4 070119-11 R5 and R6 for other output voltages: 6V: R5 = 47k, R6 = 9,1k 12 V: R5 = 110k, R6 = 10k 15 V: R5 = 130k, R6 = 9,1k P N 8 1 .00V REFERENCE REGULATOR 1 1 0 mV ▼ 1 .6V INTERNAL SUPPLIES CURRENT LIMIT AND COMPARATOR PIN 7 GATE INPUTS P N 2 10 mV COLLECTOR 5 jxk 5 fj,A PIN 6 LATCH GATES AND DRIVER- EMITTER PIN 5 OSCILLATOR THERMAL LIMIT 82 elektor elector - 7-8/2007 3 voltage and divided again by 0.8. Specifi- cally, with an output current of 100 mA at 9 V, the input current on the USB bus is approximately 225 mA. Finally, Figure 3 shows a small PCB lay- out for the circuit. All of the components except the connector and the terminal strip are SMDs. ( 070119 - 1 ) Web link Author's homepage: www.systech-gmbh-de components list (for U Q = 9 V) CIO = 47|jF 16V Cll = 68 (jF 20V Resistors Inductors R1,R2,R3= IQ R4 = 220kQ R5 = 82kQ R6 = lOkQ LI = 820)jH (SMD CD105) L2 = 47|jH (SMD 2220) Capacitors (SMD 1206) Cl = lOOnF C2 = 2nF2 C3 = 22pF C4 = lOOnF C5= lnF5 (tantalum SMD 7343) C6 = 68|jF 20V C7 = 68(jF 20V C8 = 68(jF 20V C9 = 47pF 16V Semiconductors D1 = SK34SMD (Schottky) IC1 = LM3578AM (SMD S08) Miscellaneous K1 = 2-way PCB terminal block, lead pitch 5mm (optional) K2 = USB-B connector PCB layout, free download from Elektor website, 070119-1. pdf Jens Altenburg One of the most important problems of mobile robot platforms is associated with the power supply. With exception of some special systems, batteries, dry or recharge- Solar Panel 1N4001 POWER T9 O IC5 RFP30P06 R30 T C13 POWER _ TIP 3-ib-C) BC337 10n 25 V 10n 25 V <2) GND 10AT R29 R26 ^ — R24 o 1 0Q1 | — <> R22 D8 1 N5408 able, are the most commonly seen sources of electrical power in robots. The power supply system of zBot 1 consists of two parts, the main accumulator and the auxiliary battery. The main power source was realised with a NiCd or NiMH bat- tery pack. Its size was adapted to fit the battery holder of the Tamya chassis (six 1.2V/1400 mAh C cells). The main power is activated for DC motor driving and for the servos. The auxiliary system, two Alkaline AAA R27 CM CM VBATT i—O R28 VCC RG1 RG2 IC6 2 -| N.C. 1 C12 X-i lOOn SIGN MAX472 SHDN OUT GND SIGN o o V CHARGE R23 X 070171 - 11 batteries, is for the power supply of the microcontroller only. A third (optional) power source is the solar panel. It is not really necessary for initial experiments but it helps to keep the robot autonomous longer. The circuit of zBot's main power supply sys- tem includes a special feature: the charge control circuit based around a MAX472. For effective operation, we have to know the 7-8/2007 - elektor elector 83 exact capacity of the battery. Imagining the discharge voltage diagram, we know that the voltage is virtually stable for most of the discharge time and suddenly breaks down when the battery runs out of capacity. This time is very short, so it could happen that the robot could be lost. A simple voltage control doesn't give us the information we need. The only way to obtain exact values is monitoring the discharging. The MAX472 gives two values, the current through R24//R26 as a proportional voltage at pin 8, and the current direction through the resistors (SIGN). Both values allow cal- culation of the charging (solar panel) or dis- charging of the battery pack. The auxilliary power is shown in the CPU unit. The two alkaline batteries support the CPU, the wireless radio modem and the navigation system (compass) only. The reason for the division of the power supply is simple. With the help of the aux- iliary system, zBot communicates with the operator wirelessly. In this way, the inde- pendent power source increases the secu- rity of the system. ( 070171 - 1 ) (1) The complete document called Zbot — the Robot Experimental Platform is available for free downloading from the Elektor Electronics website. The file number is 070172-11. zip (July/August 2007). Device V Q (desired) (V) R set (standard value) (kd) V Q (actual) (V) V, range (V) 2.5 Open 2.5 7 to 25 PTN780x0W 3.3 78.7 3.306 7 to 33 5.0 21.0 4.996 7 to 36 12.0 0.732 12.002 14.5 to 36 12.0 383 12.000 15 to 36 PTN780x0H 15.0 15.0 14.994 18 to 36 18.0 4.42 18.023 21 to 36 22.0 95.3 21.998 26 to 36 If pin 4 is left open, the output voltage Luc Lemmens The PTN78060 is a series of high-effi- ciency, buck-boost, integrated switching regulators (ISR) from good old Texas Instru- ments (Tl). The caseless, double-sided package has excellent thermal characteristics, and is RoHs compliant. The PTN78060 devices operate from a remarkably wide input voltage range: Device v in o< C PTN78060Wa(x) 7 to 36 V 2.5 to 12.6 V PTN78060HA(x) 15 to 36 V 11.85 to 22.0 V PTN78060AA(x) 9 to 29 V -15 to -3V Note that the -A version supplies a nega- tive output voltage. The devices provide high-efficiency step- down voltage conversion for loads of up to 3 A. The PTN78060 devices are suited to a wide variety of general-purpose applica- tions that operate off 12-V, 24-V, or tightly regulated 28-V dc power, hence are ideal for running low-voltage electronics from a very high power 24-V battery unit salvaged from an electric wheel chair and migrated into a robot. The output voltage V Q can be set to any value over a wide adjustment range using a single external resistor R SET , using the equation Rset ~ 54.9kQx(1 .25 V/Vq-V M | N ) — Rp defaults to the lowest value. Limiting our- selves to the two positive-output regula- tors, for the -W version, V M , N and R p are 2.5 V and 6.49 kQ respectively; for the -H device, the values 11.824 V and 6.65 kQ should be used. For the output to remain in regulation, the input voltage must exceed the output by a minimum differential voltage. Another consideration is the pulsewidth modula- tion (PWM) range of the regulator's inter- nal control circuit. For stable operation, its operating duty cycle should not be lower than a certain minimum percentage. This defines the maximum advisable ratio between the regulator input and output voltage magnitudes. For satisfactory performance, the operat- ing input voltage range of the PTN78060x must satisfy the following requirements. 1. For PTN78060W devices supplying output voltages lower than 10 V, the minimum input voltage is (V 0 +2 V) or 7 V, whichever is higher. 84 elektor elector - 7-8/2007 2. For PTN78060Ws supplying output voltages of 10 V and higher, the minimum input voltage is (V 0 +2.5 V). 3. The maximum input voltage for PTN78060W is 10V o or 36 V, whichever is less. 4. For PTN78060H output voltages lower than 19 V, the minimum input voltage is (V 0 +3 V) or 15 V, whichever is higher. 5. For PTN78060H output voltages equal to 19 V and higher, the minimum input voltage is (V 0 +4 V). As an example, the Table gives the oper- ating input voltage range for some com- monly used output bus voltages. The modules are protected against load faults with a continuous current limit char- acteristic. Under a load-fault condition, the output current increases to the current limit threshold. Attempting to draw current that exceeds the current limit threshold causes the module to progressively reduce its out- put voltage. Current is continuously sup- plied to the load until the fault is removed. Once it is removed, the output voltage promptly recovers. When limiting output current, the regulator experiences higher power dissipation, which increases its temperature. If the temperature increase is excessive, the module overtemperature protection begins to periodically turn the output voltage off. The inhibit feature can be used wherever there is a requirement for the output volt- age to be turned off. The power module switches off the output voltage when the Inhibit control (pin 3) is pulled to ground, for example, by a switching FET. Finally, good attention should be paid to the quality of the capacitors on V, and V Q as they determine the regulator stability and overall performance to a substantial degree. Summarizing the extensive infor- mation on capacitor selection found in the datasheets, the minimum requirement for Cl is 2.2 pF (!) worth of ceramic capaci- tors for the -W device and 14.1 pF (!!) for the-H device. Tantalum caps are not recommended. Similarly, at the regulator output, C2 should be at least 100 pF worth of low- ESR electrolytics. ( 070115 - 1 ) Datasheets http://focus.ti.com/docs/prod/folders/print/ ptn78060h.html http://focus.ti.com/docs/prod/folders/print/ ptn78060w.html http://focus.ti.com/docs/prod/folders/print/ ptn78060a.html Paul Goossens LiPo (Lithium Polymer) bat teries have a number of advan- tages compared to NiCd and NiMH batteries. In addition to having a lower weight for the same capacity, LiPo batter- ies can also be made in various shapes. The first property is eagerly exploited by manufacturers of mobile phones, MP3 players and the like. Beside these advantages, LiPo batteries also have a few disadvantages. One of these disadvantages is that they are not able to supply the same amount of current as their NiCd and NiMH brethren. The maximum current is typically 10 C, where C is the nominal capacity. Newer versions are able to supply 15 C to 30 C continuously, but you will be paying a much higher price for those! Using a battery rated at 1000 mAh this means that a normal LiPo cell may be oaded at up to 10,000 mA or 10 A. The current is often allowed to be double that for short periods time, but that is not so ben- eficial to the life expectancy of the LiPo cells! There are many cases where we would like to draw more current from the battery. This can be done by connecting multiple cells in parallel. Current limiting Connecting multiple cells in parallel is, in principle, a simple soldering job. We don't have to waste any words on that! How- ever, we do have to make sure — before the cells are connected in parallel — that they all have exactly the same voltage across their terminals. If there is even only a small difference between the source volt- ages then during and after connecting the batteries in parallel a large equalising cur- rent can flow. This current will discharge the battery with the higher output volt- age and charge the battery with the lower voltage, until both voltages are the same. This equalising current obviously has to be smaller than the maximum charging cur- rent (typically 1 C). Before we can connect the cells in paral- lel we have to take measures to limit any equalizing current. The difference in volt- age is often so small that a simple current regulator does not work properly. How- ever, using a resistor we can limit this cur- rent quite easily. Manual control To do this correctly we need to know the maximum charging current for both bat- teries. We then measure the voltage across both batteries. The difference between these two voltage we call the difference voltage. The negative terminals can now be soldered together. Now we temporarily solder a resistor between the two positive terminals. The value of this resistor has to be at least the difference voltage divided by the maximum charging current. The battery with the greatest amount of charge will now charge the other battery 7-8/2007 - elektor elector 85 at a limited rate. The latter will therefore charge slowly. After a while the differ- ence voltage will reduce and therefore the charging current as well. If this process doesn't go quickly enough for your liking then you can adjust the resis- tor value from time to time to increase the charging current again. Both positive ter- minals may be directly connected together once the difference voltage has dropped so low that a resistor of 10 mQ would have been enough. A new and more powerful LiPo battery is now a fact. ( 070274 - 1 ) Martijn Geel This switch-mode power supply is built around a 555 timer 1C. It provides a maxi- mum output voltage of 40 V with a 12-V input voltage. The voltage can easily be set using a Zener diode, and it must be higher than the input voltage (the minimum out- put voltage is always 12 V). The NE555 is used in an unconventional way here. In the normal configuration, the output of the oscillator 1C is low longer than it is high. With the configuration used here, the output can be high for a shorter time than it is low. The NE555 switches FET T1 on and off. When T1 is conducting, energy is stored in LI. When T1 stops conducting, this energy is transferred to Cl and C2 via Schottky diode D1, so the voltage on these capa- citors rises. The voltage is limited by Zener diode D2. If the voltage rises above the Zener voltage, the current through the Zener diode causes T3 to conduct. This reduces the voltage on pin 5 of the NE555, which in turn decre- ases the relative duration of the high level on pin 3. T1 thus conducts for a shorter interval, so less energy is stored in LI and the output voltage is stabilised. Current limiting is provided by R6, R5 and T2. If the voltage across R6 is more than 0.6 V, T2 starts to conduct. This drives T3 into conduction, causing the voltage to decrease in order to limit the current. C5 and R7 provide a soft-start effect. The value of R1 can range from 22 kQ for an output voltage of 15 V to 10 kQ for an out- put voltage of 40 V. For the sake of safety, limit the Zener vol- tage to a maximum of 40 V. T1 and T2 can be rated for a maximum of 50 V. The FET is not critical; you may already have one in your spare parts bin that can switch enough current. If the coil becomes warm, the core is too small or the wire is too thin. The Schottky diode is the only component that is actually critical. Do not use an ordi- nary diode, since it will become much to hot. You're bound to find a Schottky diode in an old computer power supply (just check for a forward voltage of 0.2 V on the diode range of your multimeter). The supply shown here can deliver approximately 200 W. The input sup- ply voltage can range from 7 V to 15 V. Don't forget that the maximum voltage the NE555 can handle is 15 V. Finally, this power supply is not short-cir- cuit proof. A slow-blow fuse on the 12-V side is recommended. ( 070023 - 1 ) Alexander Wiedekind-Klein Electric motors used in robot applications often make sudden and heavy demands on their power supply. Although the bat- teries normally used have a low internal resistance, they nevertheless sometimes have difficulty maintaining their output under load and can be damaged by cur- rent spikes. Not all the electronics in the robot can cope with these effects, the volt- age regulation provided by ordinary three- terminal devices not always being up to the job. This electronic voltage stabiliser is a solution to that problem. The circuit is based around a compact switching regulator which is capable of 86 elektor elector - 7-8/2007 producing a steady DC voltage of 12 V at its output over input variations from 13 V to 25 V, at loads of up to 750 mA. Its three- pin form factor makes it a simple replace- ment for conventional three-terminal volt- age regulator ICs. The buck-boost switch- ing circuit uses an SMD power FET for T2, and to achieve high efficiency (approxi- mately 90 %) a Schottky switching diode for D1. The most specialised component is the miniature transformer designed for use in this type of supply. For the prototype we used a Coiltronics CTX50-4. The current limit is set by R4. The output voltage is scaled by the voltage divider formed by R3 and the series combina- tion of R5 and R2. The output voltage is controlled so that a voltage of 1.25 V appears across R3 and hence on the feed- back input (pin 5) of IC1. The circuit can be modified for different output voltages by changing the component values in the voltage divider. For lower output voltages the input voltage can also be reduced correspondingly. Gerber files for the prototype printed circuit board are available for free download from the Elektor website, ref. 070280-1.zip. The SMD components used have the following outlines: R1, R2, R3, R5, C3, C4 and C5: 0603; C2: 0805; IC1: SSOP-12; T1: SO-8. All the SMD capacitors are ceramic, and electrolytics Cl and C8 must have a low ESR. R4 is a 50 mQ SMD resistor rated at 1 W. ( 070280 - 1 ) Even robot systems occa- sionally need a negative supply voltage for some purpose or other, and in this kind of application in particular there is a need for an effective circuit that does not make greater demands then neces- sary in terms of current or space. If a low-current -5 V supply is needed and only +5 V is available, a natural manufacturer to turn to is Maxim, and indeed in this case they do not let us down. Alexander Wiedekind-Klein I — 100ja | 4 16V 1 C+ OSC MAX660 c- OUT - — 1 _n 3 2 V-/ JL Cl ■ d C3 d d C5 d 3 -o 1 100n i 1 4ja7 25V LI 1 * 100n 16V > 1 -TV 10|iH 070279- 11 The best-known integrated circuit made by this company is the MAX232, a level shifter for serial ports with an integrated charge pump that does not need an external inductor. Along the same lines, although with a more stable output voltage and higher efficiency, is the MAX660. The device can 'mirror' any input voltage between 1.5 V and 5.5 V. With a 5 V input the output is typically -4.7 V with a load of 100 mA. Efficiency at 10 mA is around 7-8/2007 - elektor elector 87 96 % and at 100 mA is around 88 %. With an open-circuit output the 1C draws a qui- escent current of just 120 pA. There is little to say about the circuit itself. The 0 Q resistor on pin 1 selects the oper- ating frequency. With R1 fitted, the circuit operates at 80 kHz; without it, at 10 kHz. The combination of LI and C5 slightly reduces ripple on the output voltage; the choice of inductor is not as critical as it would be if it formed part of the switch- ing circuit. Gerber files for the printed circuit board (which uses some SMD components) are available for download from the Elektor website, ref. 070279-11.zip. R1, Cl and C4 are 0603 SMDs and C3 is an SMD tanta- lum electrolytic capacitor. Either the MAX- 660CSA or the MAX660M can be used; both come in S08 packages. LI is a 10 pH SMD inductor rated at 300 mA. ( 070279 - 1 ) Table 1 . Paul Goossens Batteries based on Lithium, such as LiPo (Lithium-polymer) and Lithium-Ion ones are ideal candidates to supply a robot with power. Compared to other types of battery they are lighter, which results in a lower mechanical strain on the chassis. The avail- example we've used a resistor of 180 mQ. The charg- ing current is therefore: 185 mV/180 mQ = 1.02 A. If you want to use a different charg- ing current you can calculate the value for R5 using the formula: R5 - 185 mV / /charge- A pair of jumpers is used to select the number of cells in the battery. The four possible settings are shown in Table 1. POWER IN K1 0.v|b JP1 JP2 Number of cells Closed Closed 1 Open Closed 2 Closed Open 3 Open Open 4 CELL1 CELLO IC1 MAX745 1 1 0On LO CZ> CO — i ►— THM/SHDN REF SETI VADJ STATUS > _ o z o o z < o o o (D £9 cl BST DHI LX DLO CS BATT BAT54 GND C3 1 0On 2 ^pOu GND . 1 oo | jiA T1 = FDS6911 D2, D3 = MBRS540T3G « TIB R5 250mW | 1 % 1 K2 1 Accu GND 070273 - 11 ability is good as well, and they are manu- factured in many shapes and sizes. Charging The charging of Lithium batteries is a very exact science. If the wrong method is used there is a real chance that they'll burst into flames. Lor this reason it is only sensible that you always use a proper charger. With the use of a MAX745 such a charger can easily be constructed at home. During the charging process the charge current should not rise above 1C. This means that for a 1200 mAh battery it may not be charged with a current of more than 1.2 A! Lurthermore, the terminal voltage for this type of battery may never rise above 4.25 V per cell. In principle a lithium charger is nothing more than a cur- rent source with a (precision!) maximum output voltage. Charge controller In our case the charger uses a step-down converter. In this way very little power is wasted in the charger and it can operate without the use of a heatsink. The com- plete charge controller is inside IC1. A few external components are required for the step-down converter. These are LET T1 and its surrounding components. The battery voltage is measured via pin 14 (BATT). The voltage difference between BATT and CS is measured by the 1C to con- trol the charging current. The 1C tries to keep this potential difference to 185 mV. In our These jumpers tell the circuit how many cells are connected in series inside the bat- tery. This is very important, since it deter- mines what the maximum voltage may be across the battery. The maximum voltage per cell is adjusted via V adj - and can be set between 3.95 V and 4.45 V. Resistors R3 and R4 set the termi- nal voltage to 4.25 V in this case. Because V adj has a narrow operating range we have to use 1% (close tolerance) resistors to set the voltage very accurately! Construction Thanks to the use of a double-sided PCB the construction of this circuit is very sim- ple. All components are mounted on the top side of the board. When soldering the 88 elektor elector - 7-8/2007 \ COMPONENTS LIST Resistors R1,R2,R6= lOkQ (SMD0805) R3,R4 = lOOkQ 1% (SMD 0805) R5 = 0.18Q 0.25W (SMD 1210), e.g. Digikey P.18SCT-ND Capacitors C1,C2 = 1 OjllF 25V (SMD 12010) C3,C4.C5 = lOOnF (SMD 0805) C6 = 47nF (SMD 0805) Semiconductors D1 = BAT54 (SOT-23) D2,D3 = MBRS540T3G (SMC), e.g. Digikey MBRS540T3GOSCT-ND IC1 = MAX745 T1 = FDS6911 (SOIC12), e.g. Digikey FDS6911CT-ND Miscellaneous Ll = 22|jH (JW-MILLER PM21 10-220K-RC), e.g. Digikey M8760-ND JP1,JP2 = jumper with 2-way SIL pinheader PCB, order code 070273-1 from Elektor SHOP) coil it may be necessary to let the solder- ing iron heat up a bit more first. The con- necting leads are quite chunky and they require a fair amount of heat to raise them to the correct temperature. When all parts have been soldered and the circuit has been checked you can power the circuit via K1 with a DC voltage of no more than 24 V. You should always double- check that you have set the jumpers for the correct number of cells before connecting the LiPo or Li-Ion battery! With a charging current of 1 C an empty cell should be fully charged in about an hour and a quarter. ( 070273 - 1 ) © R1 D2 / D1 Z Jci .. inn {y 16V 10ja 25 V 2x 50k 1N4148 nr R2 HE D3 IC1.A & V3 C2 lOn 50V R4 R5 H 1k5 H IC1 © IC1 = 4093 IC1.B IC1.C STP20NE06FP 8 9 & \ 10 ll ll ii IC1.D 12 s 11 13 & 24V dc o C4 Th 220|a 63V T2 D4 I 16V R6 D5 75V R3 (^ R 7 1 I 070127-11 4W © typ. 12V © Von Stefan Brandstetter This circuit was developed to allow a car trailer, designed for 12 V operation, to be used as a trailer for a van with a 24 V supply. A number of copies of the circuit we made, for the left and right indica- tors, brake lights, number plate light and reversing lights, and these have been in trouble-free operation for several years. The advantage of this compact circuit is that it dissipates very little power because it uses pulse width modulation. In addi- tion, its quiescent current consumption is practically zero. A simple pulse generator is constructed using IC1.A, C2, R1 and R2. Normally (when T1 is not conducting) RC combi- nation R4/C3 ensures that IC1.B passes the square wave signal to FET switch T2. Shunt resistor R3 measures the output cur- rent. If the maximum safe output current is exceeded, T1 turns on and short-circuits C3; IC1.B no longer passes the square wave signal to the switching transistor. The output current falls to zero, T1 turns off and C3 is recharged via R4. As soon as the input threshold of IC1.B (half the supply voltage) is exceeded, the PWM signal once again starts to drive T2. Thus even if there is a continuous short circuit on the output there will be occasional pulses of output current. R5, D1 and Cl reduce the input voltage of 24 V to a value of 16 V more suitable for powering the CMOS 4093 Schmitt trigger 1C. D4 and D5 protect T2 from voltage spikes, which are practically unavoidable in this circuit because of the inductance of the wiring. Any standard N- channel FET able to withstand 100 V can be used for T2. With the component values shown the cir- cuit is suitable for use with 12 V lamps at up to 60 W. The current limit, set by R3 (47 mQ) is around 12 A. The current limit is essential because cold lamps present a very low resistance when voltage is first applied. The mark-space ratio is set to approximately 1:3 (25 % on-time) using PI. The circuit can be modified for use at higher currents, and it can also be used as the basis of a simple and efficient speed controller or light dimmer. ( 070127 - 1 ) 7-8/2007 - elektor elector 89 For enhanced operational reliability Paul Goossens Using rechargeable batteries to power circuits is a proven method for providing energy to mains-independent equipment. A major disadvantage of this is that the battery usually turns out to be empty at the most inopportune moment. As a user, you are unexpectedly confronted with the fact that the circuit suddenly doesn't work any more. Sometimes this is only a minor inconvenience, but at other times it can be a catastrophe. For instance, just imag- ine what happens to a model airplane if the radio receiver stops working in flight due to an empty battery. We can assure you that the consequences are anything but pleasant. Solution The solution to this problem is actually quite simple: use two batteries! When one of the batteries becomes discharged, the second one can take over and continue supplying power. Of course, all this must happen automati- cally, so we need a handy circuit that takes care of everything for us. The design presented here is intended to be used with circuits (such as receivers used in models) that use NiCd batteries composed of four cells. The circuit is quite compact, and thanks to the accompanying PCB populated with SMDs, it is easy to fit into existing equipment. Simple The operating principle is simple: IC2 measures the terminal voltage of battery A. If it drops below 4.38 V, the RESET output goes low, and otherwise it remains high. IC4 does the same thing, but for battery B. Both signals go to a flip-flop consisting of ICIa and IC3d, which determines which of the batteries is to be used. If the voltage across battery A is too low, the output of ICIa will always be high. As a consequence, battery B will be active. The same thing applies in reverse to the output of IC3d. When both batteries are discharged, they will both power the circuit, in keeping with the motto 'better a little bit of juice than no juice at all'. Components D3, R8 and C3 provide Vbat BAT54 IN BAT A K2 T1A * & T2B Cl * 7oOn FDV301N — r FDV301N ENABLE A Vbat L GND BAT54 IN BAT B K3 TIB « T2A @R®^' C2 * 7>0n FDV301N ' LM809M3-4.38 IC1D 13 12 D3 BAT54 R8 Tok IC1B C3 lOOn y GND /\ D4 BAT54 FDV301N |C1C ENABLE_B 10 GND IC3A IC3B IC3C 10 Vbat GND &"W. GND GND IC1A 1 A ok 2 IC2 Vcc RST GN GND IC3D 11 ^ &T\. 13 12 2 Bok Vcc RST GN K1 POWER OUT IC4 GND LM809M3-4.38 GND V X 3t T1, T2 = IRF7329 v IC1, IC3 = 4093 — r— r C5 © © R4 IC1E IC3E 100n (p (p C7 lOOn GND GND 070343-11 90 elektor elector - 7-8/2007 a switch-on delay that causes battery switch-on to be delayed somewhat. This is because it is undesirable to have both batteries power the circuit at the same time during switchover from one battery to the other. That would cause large equaliza- tion currents to flow due to the difference between the terminal voltages of the two batteries. Switch The best choice for the switching device is a FET instead of a bipolar transistor. This saves energy, since no base current is nec- essary. A disadvantage of a MOSFET is that it always has an intrinsic diode. This diode is quite annoying in this circuit, since the one battery can charge the other battery via the diode. A simple solution would be to wire a diode in series to prevent this. Unfortunately, a diode always has a voltage drop (approximately 0.3 V with a Schottky diode). To solve this problem, we use a second MOSFET wired in the opposite direction. The underlying trick here is that the chan- nel of a FET conducts in both directions when it is switched on. This eliminates the effect of the forward voltage of the inter- nal diode. LEDs D5 and D6 indicate which battery is in use. Use The circuit is very easy to use. Connect a four-cell NiCd battery to each of the bat- tery inputs (K2 and K3). Then connect out- put K1 to the circuit to be powered. Switch on the supply voltage with switch SI. The LEDs now indicate which battery is in use. If things every get so far that both batteries become deeply discharged (Heaven forbid!), this can be recognised by the fact that both LEDs are lit. ( 070343 - 1 ) Components list (all R and C: SMD 0805 case) Resistors R1,R2,R5,R6 = lOOkO R3,R7 = 1MQ R4,R8,R9 = 10k£2 R10,R11 = lkQ Capacitors C1-C6 = lOOnF Semiconductors D1-D4 = BAT54 (SOT-23) D5,D6 = LED rood (SMD 1206) 101,103 = 4093 (SOIC-14) IC2JC4 = LM809M3-4.38 (SOT-23) T1,T2 = IRF7329 (SOIC-8) T3-T6 = FDV301N (SOT-23) Miscellaneous Connecting wires PCB no. 070343-1 (see www.elektor- electronics.co.uk) C. Tavernier www.tavernier-c.com Unless your robot is frugal enough to make do with primary cells without breaking the bank, or is environmentally-friendly and runs off solar panels, it will probably need to use rechargeable batteries as its energy source. Although very many chargers are cur- rently available, they're not always suit- able for our needs, in terms of the types and number of batteries they can handle. What's more, certain of them do not take very good care of the batteries entrusted to them, which can seriously shorten their life. So this article proposes building your own tailor-made charger, using an 1C that's already old, but still very much current: the MAX713 from Maxim. As all robots are different, we're not going to suggest a completely finished circuit, but will instead explain how to adapt it to suit the charac- teristics of the batteries you'll be wanting to recharge. The MAX713's basic application circuit is shown in the figure, but as you can see, certain elements have no values shown. In addition, there are various configura- tion links. Via these various elements, the MAX713 lets you charge from one to 16 cells (a cell is a basic 1.2 V element), define the charging current, define the end-of-charge float current, and lastly, select the mode for detecting end of charge. As far as the latter is concerned, and so as to be compatible with any bat- teries you are likely to use in your robot, we've left out the temperature detection method, which requires a thermal sensor (NTC or equivalent) inside the battery. So resistors R4 and R5 in conjunction with the hard-wired links to inputs THI and TLO program the MAX713 into the mode that detects end of charge by voltage variation. So now let's see how to determine the other elements that are still open to you, so you'll be able to build a charger that's just right for your needs. Note right away that the configuration links can either be hard-wired on the PCB that you'll be designing for your charger, or else con- nected to multi-way switches to create a multi-purpose charger. You first need to decide l fast , the charging current for your batteries, whose capacity C is expressed in ampere-hours (Ah). This can be calculated from: / fast = C/t where t is the desired charging time in hours. Watch out! The MAX713 does not handle times over 4 hours. And take care not to pick a value for / fast above 4C, which is cur- rently the maximum current permitted for 7-8/2007 - elektor elector 91 fast-charging NiCad and NiMH batteries. If you are able to choose a lower current, so much the better, it will prolong battery life. Program this charging time by wiring pins PGM2 and PGM3 of the MAX713 as per Table 1. Then choose the number of cells to be charged at the same time. For block bat- teries, you can find the number of cells by dividing the nominal voltage of the battery by 1.2 V. So a 9.6 V battery will contain eight cells. If the number of cells is 11 or more, the circuit can't be used as is, and in that case it's better to charge your batteries in two goes. Program this number by wir- ing pins PGMO and PGM1 of the MAX713 as per Table 2. Then choose the unstabilized DC supply voltage for your charger (VA in the fig- ure) so that it is at least 1.5 V higher than the maximum voltage of the battery to be charged. If your battery has less than four cells, this rule no longer applies, as the MAX713 supply has to be a minimum of 6 V. Then determine the maximum power dissi- pated in T1 using the following equation: Pq — (K\ — ^BATTmin) X ^fast where is the minimum voltage of the battery to be charged. Choose T1 accordingly, if necessary fitting it with an appropriate heatsink. Then determine the value of resistor R1 so the current drawn by the MAX713 will be 5 to 20 mA, using the equation: R1 = {V A - 5) / / where / is between 5 and 20 mA. Lastly, determine the value of resistor R6 by using the equation: R6 = 0.25 / / fast and its power by using P R6 = 0.5/ fast (theoreti- cally 0.2 5/ fast in fact, but it's best to use a safety factor of 2, hence the modified equation). Your charger is now operational, and is extremely simple to use; but because of the processors inside the MAX713, it is essen- tial to make the connections to PGMO to PGM3 before applying power to the cir- cuit, otherwise they may not be taken into account correctly. This is no problem for a hard-wired circuit, but if your charger uses configuration switches at this point, you'll need to power down and power up again to confirm any configuration changes made via these switches. The LED lights when the charger is in fast- charge mode (at the current / fast determined above). It goes out when fast-charging is over and the charger goes into float charge mode. The current generated in this mode is sufficiently low that the battery may be left connected to the charger indefinitely if necessary. To make sure our explanation is crystal- clear, here by way of example are the cal- culations for a charger for a pack of four 1.2 V NiMH batteries with a capacity of Table 1 . Programming charge time via PGM2 & PGM3. Maximum charge PGM3 PGM2 22 V+ REF 33 V+ BATT- 45 o/c REF 66 o/c BATT- 90 REF REF 132 REF BATT- 180 BATT- REF 264 BATT- BATT- Table 2. Programming number of cells via PGMO & PGM1. Number PGM1 PGMO 1 V+ V+ 2 O/C v+ 3 REF v+ 4 BATT- v+ 5 V+ o/c 6 O/C o/c 7 REF o/c 8 BATT- o/c 9 V+ REF 10 O/C REF 11 REF REF 12 BATT- REF 13 V+ BATT- 14 O/C BATT- 15 REF BATT- 16 BATT- BATT- 92 elektor elector - 7-8/2007 1,800 mAh that we want to recharge in two hours. • Calculate / fast : / fast = C/t, i.e., 1.8/2 = 0. 9 A or 900 mA. • PGM2 and PGM3 connections: PGM2 tied to BATT- and PGM3 tied to REF, as we want a charge time of 2 hours, 1. e. 120 minutes (in fact, well get a maxi- mum of 132 minutes). • PGM0 and PGM1 connections: PGM0 to V+ and PGM1 to BATT- since our battery comprises four cells. • Determine V A : V A = 6.3 V minimum. Well choose 9 V, to obviate any problems with possible supply voltage variations. • Power dissipated in T1: P D = (9 - 4*) . 0.9, i.e. 4.5 W. So well choose, for example, a TIP32A, giving us an excellent safety mar- gin (P D max = 40 W). • fully discharged battery voltage estimated at 4 V. • Calculate R1: R1 = (9-5)/0.01**, = 400 Q. Well use the closest preferred value, i.e. 390 Q. ** : a current of 10 mA was chosen. • Calculate R6: R6 = 0.25/0.9, = 0.27 Q. • Calculate the power in R6: P R6 = 0.5 x 0.9 = 0.45 W. So a 0.50-W type is going to be fine. As you can see, it's taken us all of five min- utes to produce a charger tailored perfectly to our needs. Now it's your turn... ( 070301 - 1 ) Web Links MAX713 spec, sheet: www.maxim-ic.com/quick_view2. cfm/qv_pk/1666 Antoine Authier & Karel Walraven At the time of writing, the latest AA NiMH (Nickel metal Hydride) batteries have a capacity of up to 2900 mAh. Using an original-type conventional battery charger (supplying 125 mA), the charging time will be extremely long. The charger we propose here should accel- erate the recharging process of NiMH bat- teries, which hare becoming more and more common (we must do our bit for the environment). The design is based on the MAX712 made by Maxim (Integrated Products to be pre- cise, which was bought by Dallas Semi- conductor; quite a long story), operating in switched mode, it can supply a maximum fast charge current calculated as /charge = 250 mV 1 R1 or not less than 1 A if R1 = 0.25 ohms. Under these conditions, the battery will be charged in just over two hours. The Maxim circuit is not only intelligent, but it also includes an ADC (analogue to digital converter), a system to detect charge completion, a timer, and a tem- perature monitoring module. The four configuration pins that are included allow users to set the parameters as they please. These pins are used to set the parameters for the number of cells to be charged, the maximum charging period, as well as the method to detect when it is fully charged (inflexion point or negative slope). You can refer to the datasheet to find out more. The MAX712 is intended for NiMH batteries, with charge completion at the inflexion point of the voltage curve (dV/dt = 0). The maximum power supply voltage is 15 V. The power supply voltage must be at least 2 V above the maximum charging voltage in order to compensate for voltage fluctuations during charging. Therefore, for a maximum charging voltage of 1.6 V per cell, a 15-V power supply voltage is used to charge 8 series-connected batteries. A 12-V voltage level (supplied, for example, by a car battery) is used to recharge six cells. The power supply must be able to supply 1 A. It is important to be certain of its specification. If the requirement is not fulfilled, the integrated circuit will not oper- ate correctly and may not correctly detect completion of the fast-charge (entailing a risk of damage that could affect the con- nected batteries). Setting the circuit parameters • The PRGM0/PRGM1 pins are used to regulate the number of cells to be charged. A note concerning the use of a battery cra- dle: during recharging: each contact can represent a 1-Q series resistance, which is seen as a 1-V potential difference at 1 A. The power supply voltage may not be ade- quate for this configuration — therefore, it is preferable to verify this detail before beginning the project. • For security reasons, it is preferable to properly configure the maximum charging period with the PRGM2/PRGM3 pins. • On this setup, the temperature control circuit for the batteries is deactivated. At the end of the fast-charge, the circuit will power the batteries with a mainte- nance charge (trickle). Fet's examine the circuit's electronics. T1 is uses as a cur- rent source supplying the 8 mA necessary to power the MAX712. D3 ensures that the battery does not discharge into the circuit in case it is not powered. The FED D1 lights up when the circuit is in fast-charge mode. T5 may be mounted 7-8/2007 - elektor elector 93 on heatsink, if necessary. The characteris- tics of coil LI are not critical; a traditional 100 jiH/ 5 A suppressor choke will work fine. The same holds true for diodes D2, D3 and the MOSFET transistor T5; they too are not critical in this application. You can use any Schottky diode that can withstand 3 amps and include any MOSFET with a lower drain resistance. A compact PCB was designed for the cir- cuit. Mounting the components should be all plain sailing, but do not forget the two wire links on the board. Inductor LI is a toroid 'suppressor choke' with a good size. Connectors K1-K4 allow different charging parameters to be set up. Since the calculation principle is the same as for the NiCd charger in the MAX713 in the other article, we refer you to the cal- culation example proposed there. Use the same tables to set the parameters of this circuit as the ones given in that article. ( 070213 - 1 ) Components list Resistors R1 =0.22Q5W R2 = 68kQ R3 = 22kQ R4 = IkO R5 = 4k Q7 Semiconductors D1 = LED D2,D3 = PBYR745 T1 = BF245B or -C T2,T3 = BC547B T4 = BC557B T5 = IRF9520 IC1 = MAX712CPE Capacitors Cl = 220pF C2 = lOOnF C3,C4,C6,C7 = 1 OjllF 63V radial C5= lpF 25V radial Inductor Ll = 220|iH suppressor choke Miscellaneous K1-K4 = 5-way SIL pinheader K5 = 2-way PCB terminal block, lead pitch 5mm K6 = DC supply jack, PCB mount PCB no. 070213 - 1 , see ElektorSHOP Tilman Kupper With this circuit built into the power supply of a battery powered device, it will prevent the recharge- able cells from being completely drained when you forget to turn the equipment off. When the bat- tery voltage drops below a pre-set limit (9.5 V in this example) the cir- cuit will automatically disconnect the battery. Power is re-connected when the voltage rises above an upper threshold level (10.5 V here), this will typically occur after the equipment has been plugged into its recharging station. The circuit is designed to use as little power as possible. The ICL7665 from Intersil forms the heart of the circuit. This 1C contains two comparators together with a voltage reference and consumes just 3 pA. The circuit only uses one of the comparators, the values of resistors R1 to R3 shown in the dia- gram will cause the circuit to switch 94 elektor elector - 7-8/2007 at the levels mentioned above. The comparator output switches the P- channel MOSFET T1 which in turn controls power to the load R L oad- The switching threshold levels and hysteresis can be changed by using different values of resistor for R1 to R3. Increasing the value of R3 to 300 KQ will raise the upper thresh- old level to 12.5 V. The ICL7665 data sheet gives examples of suit- able resistor values that can be used here. The PCB layout uses SMD components so the finished circuit takes up very little space when installed in the equipment. A fine-tipped soldering iron should be adequate to mount the components and there shouldn't be any problems provided you do not choose to use very small resistor packages. Once the circuit has been tested the entire PCB can be protected by encapsu- lating it with a short length of heat shrink sleeving. ( 070087 - 1 ) Links Data sheet IRL7665: www.intersil.com/ data/fn/fn31 82.pdf Data sheet IRLML6402: www.irf. com/product-info/datasheets/data/ irlml6402.pdf Figure 1. Schematic of TPS74201, TPS74301 and TPS74401 (see text for values of R4 and C4). Dirk Gehrke (Texas Instruments Germany) The devices described here are tailored to fit the needs of modern DSPs, processors and FPGAs that require low supply volt- ages at relatively high currents, plus the capability of supply voltage ramp-up and sequencing in a defined manner. The lat- ter two requirements are not easily solved using discrete components. The TPS74x01 family fits the bill. At the time of writing the family consists of three parts, called TPS74201 (1 .5 A with soft-start), TPS74301 (1.5 A with tracking) and TPS74401 (3 A with soft-start). The family is expected to grow soon. Figure 1 shows a simplified connection diagram for the three devices. These reg- ulators require a low power bias voltage, V BIAS , and a power input voltage, V IN , from which V out will be derived. All three regu- lators are capable of providing output volt- ages down to 0.8 V and the device in the QFN package also includes an integrated supervisory circuit with open-drain out- put that goes to high impedance when the output voltage reaches regulation ('power good' or PG). The TPS74301 can pro- vide up to 1.5 A output current and has a TRACK pin which allows the user to input a ramp signal for the output voltage to follow, effectively implementing either simultaneous or ratiometric sequencing. The relevant connections are shown sepa- rately. The TPS74201 and TPS74401 can provide up to 1.5 A and 3.0 A DC current, respectively, and have an SS pin which allows the user to set the linear ramp rate of the output voltage. For the TPS74301, the value of R4 (in a voltage divider) allows the user to select either simultaneous or ratiometric sequencing. R4's value is calculated from the equations in the datasheet, assuming an external 3.3-V ramp signal is applied 7-8/2007 - elektor elector 95 Figure i Tracking LDO TPS74301 with simultaneous startup (R4 = lOkO). Timebase: 2 mV/div. a different soft-start time. Changing resistor R4 to a value of 1.78 kQ results in the TPS74301 output voltage reaching its regulated voltage at the same time the externally applied tracking signal reaches its maximum voltage (e.g., 3.3 V). This is called Ratiometric Sequencing (Figure 3). Although the external ramp signal and the TPS74301 will have differ- ent rates of rise, they will have the same soft-start time. Figure A Soft-Start LDO TPS74201 and TPS74401 with 1ms soft startup (C4 = InF). Timebase: 2 mV/div. Figure ; Tracking LDO TPS74301with ratiometric startup (R4 = 1.78kQ). Timebase: 2 mV/div. to the TRACK IN pin. When the value of R4 selected to be 10 kQ in this particular example, the output of the TPS74301 will follow the external ramp signal within a few millivolts until the TPS74301 reaches its regulated voltage. This is called Simultane- ous Sequencing (Figure 2). The TPS74301 output voltage will have the same rate of rise (dv/dt) as the external ramp signal but For the TPS74201 and TPS74401 the capacitor value can be used to program the soft-start ramp. In this example, values of 1 nF and 10 nF for C4 were used to real- ize ramps with 1 ms and 10 ms rise time respectively (Figures 4 and 5 respectively). With no capacitor attached to this pin the default soft-start time will be 500 ps. This 500-ps start up time is also valid for the TPS74301 when applying a voltage greater than 800 mV to the TRACK pin. ( 070231 - 1 ) Literature TPS74401 3.0A Ultra-Low Dropout Linear Regulator, Texas Instruments Literature # SBVS066C. TPS74301 1.5A Ultra-Low Dropout Linear Regulator with Programmable Sequencing, Texas Instruments Literature # SBVS065C. Figure 5. Soft-Start LDO TPS74201 and TPS74401 with 10ms soft startup (C4 = lOnF). Timebase: 2 mV/div. TPS74201 1.5A LDO with Programmable Soft- Start, Texas Instruments Literature # SBVS064C TPS74x01EVM-118 User's Guide, Texas Instru- ments Literature # SLVU143. Sequencing Power Supplies in Multiple Volt- age Rail Environments by David Daniels, Dirk Gehrke and Mike Segal, Texas Instruments Literature # SLUP228 or http://focus.ti.com/lit/ ml/slup228/slup228.pdf FORMULA FLOWCODE inci. DVD-ROM ■. mlntl rv * A riMQ) mac# nr l -v | A ffimfriMA KWuflJMi mhrt * i-tflprJrO * AS _ ■ L » hi -‘lOfrrtQ ,Wl ITi.-T. PTUlf* Ordering: Use the order form at the back or visit our online shop. Elektor Electronics (Publishing) Regus Brentford I 1000 Great West Road Brentford TW8 9HH I United Kingdom Tel. +44 208 261 4509 sales@elektor-electronics.co.uk Formula Flowcode Buggy USB-programmable robot vehicle ■ A complete solution: robot + software + curriculum ■ Line following and maze solving ■ High-tech specifications ■ Also programmable with C or ASM ■ E-blocks compatible Motivating for education and hobby Built and ready to use for only £ 85.00 /US$ 169.00 lectronics More information on www.elektor-electronics.co.uk 96 elektor elector - 7-8/2007 electronics The Electronic Specialists Since 1993 Quasar Electronics Limit PO Box 6935, Bishops Stc CM23 4WP, Tel: 0870 24 United Kingdp 61826 ed rtford m Fax: 0870 460 1045 E-mail: sales@quasarele Web: www.QuasarElectro ctronics.com nics.com ClBlil Postage 3-7 Day Europe SOrder We acc to Quas Call no project4 9$; & Packing Op Delivery - £3. (EU) -£6.95; R4 inline for reduo ept all major cr ar Electronics, for our FREE modules and W £9 ions (Up to 0.5 UK Mainland st of World - ed price UK Pd edit/debit cards Prices include CATALOGUE publications. : UK Standard ery - £8.95; I) | 1, take one step (sight = sight - 1 ). 3. Check for obstacles after each step. If an obstacle is detected, walk backward and then turn away from the obstacle, (sight = 6) 4. If sight < 5, check the PIR sensors. If something is detected, turn in the direction of the detected object. The options for the turning direction are: left, forward left, straight ahead (no turn, with sight = 6), forward right, and right, (sight = 6) Conclusion The objective was to build a four-legged robot with interesting behaviour. This objective was ultimately achieved, and with a reasonably limited budget. The microcontroller memory is pretty well filled by the current software, but it would still be possible to devise a more efficient behaviour algorithm. This means that there are plenty of options for experimenting with this robot. Thanks to the onboard ISP port, programming the robot is easy. This robot is a means, not an end. Let's hunt! ( 070283 - 1 ) Web Links (1) http://avrhelp.mcselec.com/Sample_ Electronics_cable_programmer.html (2) www.mcselec.com 106 elektor electronics - 7-8/2007 Markus Bindhammer MOPS is a small robot which generally bumbles around the floor and performs avoidance manoeuvres whenever it detects an obstacle in its path. MOPS uses a forward facing LED to illuminate its path and a phototransistor to detect light reflected from obsta- cles, as soon as an obstacle is detected MOPS goes into reverse and turns for a few seconds on its two wheels before setting off again in another direction. A look at the circuit diagram in Figure 1 indicates that MOPS is built (rare for this day and age) entirely from discrete components. Resistors R1 to R4 together with Cl, T1 and T2 form a multivibrator circuit which continually switches the LED on and off. On power-up current flows through R4 and the base-emitter junction of transistor T1.T1 is therefore conducting and current flows through R1 and the base of T2 which is also conducting. Cur- rent through the collector of T2 and R6 lights up the LED. During this time capaci- tor Cl is charging up and when the voltage level gets sufficiently high the base of T1 becomes reverse biased and T1 turns off. T2 will also turn off along with the LED. Cl begins to discharge until the base of T1 is low enough to begin conducting again. T2 switches on which reinforces the low base voltage on T1 via Cl and the cycle continues. The LED light source for obstacle illumi- nation does not need to flash, it can be lit continuously but there are two reasons for the flashing LED: firstly it conserves battery power, giving MOPS a longer range and secondly (and more importantly) a flashing light looks much more impressive than a boring old continuous light source. When reflected light falls on the pho- totransistor T3 a current flows through R5 to ground which produces a voltage at the base of T4 to make it conduct. The val- ues of R5, PI and R7 affect the switching threshold so adjustment of PI will help to reduce spurious detections caused by external light sources. Turning PI (a pre- set could be used here instead) so that it 7-8/2007 - elektor electronics 107 o Umi c O a a 3 ==: 3 z tx ID 0 E [Si E © © E 7 7 Z ^ B E ITT) : Um2 is 070143-13 increases its resistance will make T4 more sensitive and vice versa. T4 conducts in synchronism with the flashing LED so capacitor C2 acts as a reservoir capacitor to ensure that once T4 begins to conduct, sufficient energy is stored in C2 to ensure that T5 remains conducting continuously until the obstacle is out of range and T4 switches off. It takes a few seconds for C2 to discharge and during this time MOPs is performing its avoidance manoeuvre. T5 switches a double pole relay which has the effect of performing this manoeuvre. In normal forward motion the relay switches the positive and negative supplies to both motors and diode D2 is conducting. When an obstacle is detected the relay switches and reverses the polarity of the motor con- nections. D2 now becomes reverse biased and no current can flow through motor M2 while Ml goes into reverse. This gives MOPS the reverse and turn response to obstacles. A few seconds after the obsta- cle is no longer detected the relay switches back and MOPS carries on as before but in a different direction. Figure 2 shows a close up of MOPS's eye mounted in a tube which helps to make obstacle detection more directional and reduces the effects of external light sources. With this set-up it was possible to detect obstacles at a distance of 10 cm. The range depends largely on the reflective properties of the obstacle so darker objects will only be seen at shorter ranges. The cir- cuit can be modified to read microswitches connected to contact feelers mounted on the front of MOPS this will help avoid col- lisions with matt black objects. Figure 3 shows the layout of the two motor and gearbox assemblies. ( 070143 - 1 ) Web link www.elexs.de/robol .htm lectromcs 309 Circuits The present tenth edition of the popular £ 30x Circuits’ series of books once again contains a comprehensive variety of circuits, sub-circuits, tips and tricks and design ideas for electronics. These 309 Circuits offer a representative indication of present-day electronics. 309 CIRCUITS ISBN 978-0-905705-69-9 Approx. 432 pages £19.95 / US$ 39.95 Complete your 30x circuits series now! Regular £ 30x series’ enthusiasts will no doubt know what to expect: 309 Circuits contains many fully elaborated electronics projects. In addition, there are numerous ideas, each of which with a potential for use in your own research, projects and applications. Among many other inspiring topics, the following categories are well presented in this book: test & measurement, RF (radio), computers and peripherals, audio & video, hobby and modelling, microcontrollers, home & garden, power supplies & battery chargers, etcetera. Order now using the Order Form in the Readers Services section in this issue. Elektor Electronics (Publishing) Regus Brentford 1000 Great West Road Brentford TW8 9HH United Kingdom Tel. +44 208 261 4509 See also www.elektor-electronics.co.uk 108 elektor electronics - 7-8/2007 PCB Certified By UL, ISO And Over 1 ,000 Customers * In 39 Countrie$^=r- UpToSO Layers 2. 5mil Track/Space, 0-1 mm Holes Blind & Buried Vias &?! Lead-free, RoHS-compliant Flex, Mixed, Teflon, Rogers Quickturn Available $50 for5pc4”x4'2L $ 1 88 for 3pcs 4''x4" 4L $288 for 3pcs4"x4 M 6L Free Soldermask & Silkscreen www.ezpcb.com sales@EzPCB.com Schaeffer FRONT PANELS & HOUSINGS Cost-effective single units and small production runs Customized front panels can be designed effortlessly with the Front Panel Designer. The Front Panel Designer is available free on the Internet or on CD. • automatic price calculation • delivery in 5-8 days • 24- Hour-Service if required Sample price: 30,42 € plus VAT/shipping Schaeffer AG • Hohentwielsteig 6a ■ D-14163 Berlin • Tel +49 (0)30 8058695-0 Fax +49 (0)30 8058695-33 • Web info@schaeffer-ag.de • www.schaeffer-ag.de No Compromise Oscilloscope Other osdlkKCopes In ihi c v2 R28 R26 180k R27 PI 10k © DIS IC5 7555 TR OUT THR CV J. 18kHz C9 150p 5 CIO lOOn C11 II loop IC8.A 11 10N & t R 24 Jr R25 D18 16 © CTR12 IC8.B CT=0 IC7 CT 4040 0 1 2 3 4 5 6 7 8 9 10 11 & t=l — 5 6 D19 2 — D21 — ( 4 N 13 D22 ■ ^ 12 D23 *2 Id J_5 1 D24 M D25 IC6.B V JT> c 13 02 JT& 13 nr nr 100n 100n C4 47n C5 470p IC9.C 10 ^ &"W. 10 D26 D27 R29 X Reset 01 IC9.B IC9.A &T\. IC9.D oil. 12 13 D28 C8 47p +5V -© (16) IC1 © (16) IC2 © IC1, IC2 = CD4015 IC6 = CD4013 IC8, IC9 = CD4093 D17...D29 = 1N4148 G p R30 (14) (14) (14) IC6 IC8 IC9 © © © X Reset 02 D29 070089-11 Thomas Moll Software decoding of remote control signals using the RC5 protocol does not present a significant challenge to a modern microcontroller, while for a pure hardware solution specialised RC5 decoder ICs are available. Nevertheless it is interesting to look at how we might process RC5 sig- nals using ordinary components. This way not only do we learn about how the code works, but also the resulting circuit is eas- ier to adapt to different applications. Although the circuit was originally designed just to display the address and command emitted by a 'universal remote control' when each button was pressed, it could be used, for example, to add a remote control facility to an audio amplifier using a stand- ard remote control unit. Indeed, virtually any household appliance could be control- led in this way: just choose an address that is not yet allocated and define your own commands. The TSOP1736 infrared receiver inverts the bits in the received stream. T1 inverts them again so that they are now available with the correct polarity. The LED connected to its collector indicates when data bits are received. This signal is low (0 V) for the first half of the start bit and high (5 V) for the second half. This pattern represents a T bit, and FF01 (CD4013) will be set. The comple- mentary output of this flip-flop will there- fore be low, enabling the CD4040 divider. The 18 kHz square wave clock for this divider is generated by our old friend the NE555. At the same time, the differentiator formed by C11 and R23 generates a low- going pulse which is inverted by Schmitt trigger inverter ST8. The resulting high- going pulse is used to clear the CD4015 shift register. The Q4 output of the CD4040 (pin 5) carries a square wave at 1125 kHz, cor- responding to a period of 888.8 ps and a pulse width of 444.4 ps. Output Q5 (pin 3) of the CD4040 is inverted by Schmitt trig- ger ST4; the output of this gate is there- fore initially high. The diode matrix forms an AND gate which sets one input to ST1 high just as Q4 rises for the first time. Since the complementary output of FF02 is also high, a high-going pulse (inverted by ST2) is delivered to the CD4015 shift register, causing it to take one sample of the incom- ing data stream. This process is repeated 1.333 ps after the start of each bit period, or exactly three-quarters of the way into 112 elektor electronics - 7-8/2007 each bit. This is the key to the circuit: the value of the signal sampled at this point gives the encoded data bit. After 14 bits the RC5 packet is complete. At this point a diode matrix forming an AND gate at the outputs of the CD4040 sets FF02. Its output goes low and the clock to the shift register is blocked. One cycle of the transmit protocol takes 64 bit times. Q1 1 of the CD4040 counter goes high 32 bit times after the start of the RC5 packet, resetting FF01 and thereby stopping the counter. The data bits at the outputs will be held until a new packet from the trans- mitter sets FF01 again, whereupon the out- put is cleared and the bits read in afresh. The stop pulse on pin 11 of the CD4040 can be used to validate the output data. When building the circuit it is a good idea to fit a test point at the output of the NE555 so that the 18 kHz clock can be set accurately. All of the timing in the circuit depends on this signal. ( 070089 - 1 ) 1 2 max. 15mA 3 4 5 6 +5V © 7 8 d OQQOQQOQ K2 8x Ik *************** R8C/13 10 ii 12 13 14 15 16 RXD1 PO.O P0.1 RESET P0.2 P0.3 VSS MODE P0.4 VCC P0.5 PI .7 P0.6 PI .6 P0.7 PI .5 PI .4 P3.0 PI .3 PI .2 P3.1 P1.1 P1.0 P3.2 P4.5 P3.3 T1 €> :638 a 4 O o O' O' o- - O' O' O' O' o- - o - O' o- - O' O' 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 +5V -© 8x Ik K1 O O o o o o TSOP1736 JPl 0 O :: 2i green red 070191 - 11 G. van Zeijts Over the years various articles have appeared in Elektor Electronics about microcontrollers that pick up the pulses from an IR remote control and do some- thing with it. Unfortunately this capability was not avail- able for the R8C microcontroller until now. That is why the author plunged right in and created this capability, mainly for his own use but also made it available to others who may be interested. The functionality has been designed in such a way that it can optionally be used with either a Philips (RC5) or Sony remote control. The system provides a 7-bit code at an out- put port, to Inform' a computer or other microcontroller which button has been pressed. The 8 bits of the other output port can be controlled directly with the buttons 2 through 9 of the remote control. This allows 8 digital devices to be directly switched or controlled remotely. The program has been written in C using the HEW software and has the following functions. Depending on the position of jumper JPl, pulses from Philips (RC5) are decoded (open) or pulses from Sony (jumper in place). 1. Bit 7 of port P0 indicates whether RC5 or Sony pulses are being used. Bit 7 'High' = RC5 and bit 7 'Low' = Sony. 2. The code for the most recent button that was pressed is on port PO. Bits 0 through to 6 are used for this. Bit 7 is used to indi- cate RC5 or Sony. 3. The eight bits on port PI (output) are directly driven high or low with buttons 2 through 9 of the remote control. When the button is pressed for the first time the output goes high. The next press makes the output low. These eight buttons can therefore control eight digital things from a distance. The state of all the bits on port PI are not affected by pressing any of the other buttons on the remote control, with exception of the following three. Button '1' makes all eight bits of PI high. Button '0' and button 'off' make all eight bits of PI low. Eight LEDs indicate the present state of the eight bits — they load port PI with about 3 mA. Via connector K2, PI can therefore be loaded for 'heavier' purposes with a further 17 mA at the very most (but allow a margin just to be safe, so 15 mA max, for example). 4. If RC5 is selected with JPl (open) and the microcontroller receives pulses from a 'non-RC5' remote control (or the other way around) a short alarm signal results: - The red LED on P3.0 flashes briefly; - The outputs 0 to 6 of port P0 become '0' (= no standard code); - Bit 7 of port P0 gives a flashing signal; - Brief acoustic signal on pin 16 (bit P4.5). A short description of the schematic: The well-known TSOP1736 (infra-red detector) is directly connected to the input and its output is pulled high with a 2k2 resistor. A second input is used to read the state of jumper JPl (select between RC5/Sony). Output P0 is used to signal the RC5/Sony- code in hexadecimal form. These outputs can be directly connected to another computer or microcontroller through the 1 k resistors, with the intention that this computer/microcontroller can act on the received code. Output PI can be used by the user to switch a 'digital something' with an inter- 7-8/2007 - elektor electronics 113 face circuit that you have to build your- self. (K2 can be loaded with a maximum of 15 mA.) Low-power LEDs indicate the present state of the eight bits of port PI . The green LED on pin 20 functions as on/ off indicator for the circuit. It is of course also possible to use a piezo buzzer for the acoustic alarm on P4.5 (P4.5 may be loaded by up to 8 mA). The software for this project is a free download from the Elektor website — see archive file 070191-11.zip. ( 070191 - 1 ) Jens Altenburg There exist a lot of wireless communi- cation modules, all approved for use within the ISM radio bands (indus- trial/scientific/medical), for example, 433 MHz, 866 MHz and recently also 2.4 GHz. You get simple and cheap ones with low transmission data rates, and you can find excellent high-speed systems. "How much (will the thing set me back)?" is the most frequently asked question if you search for an RF module. Low-speed non-intelligent mod- ules are cheap; high-speed intelligent ones, pretty expensive. That's easy but it doesn't help. The CT-Video GmbH (www.ct-video.com) markets a special module with high-speed digital data transmission capability and no intelligence, at a reasonable price. The module is based on a fully integrated trans- ceiver with a digital interface. It is used in zBot 1 with good results. The module comes as a small fully assem- bled and tested board. The board includes the complete RF sections. It works in the 433 MHz ISM band and has a transmit power of 10 mW coupled with a receiver sensitivity of about -108 dBm. For implementing the module in your own projects, a software module is available, too. The module only needs a few resources of the micro, some GPIOs (general purpose input out- put pin) and one UART channel. The UART has to be programmed to give a baud rate of 76.8 kbits/s. The baud rate needs to be accurate, if not, you'll suffer an effect that manifests itself as low receiver sensitivity. The software module for the wireless radio is a file called rf433.c. ( 070173 - 1 ) (1) The complete document called Zbot — the Robot Experimental Platform is available for free downloading from the Elektor Electronics website. The file number is 070172-11. zip (July/August 2007). v cc Hesam Moshiri A detector to flag miss- ing pulses is among the more important circuits in robotics. When pulses are applied to the circuit shown in Figure 1, the output signal will be continuously High (i.e., nearly x = 1.1 RC V cc ) as illustrated in Figure 2. For the detector to operate, cer- taking into account that tain conditions in respect of pulse timing must be met. With reference to the timing diagram shown in Figure 3, the values of components R and C in the circuit may be calculated from 3 i N i input_ i_n_n_i 1.2 ! ! Deleted Pulse • M • 1 1 LT OUTPUT 070099- 13 114 elektor electronics - 7-8/2007 1 kQ < R < 1 MQ and M < T < N When a correct signal is being applied to the input (Figure 2) the circuit will be trig- gered by another pulse before the constant time (t) expires. Therefore the output sig- nal remains High. If one or more pulses are missing, for example, owing to a fault, a bash on the head from refbot Mathilda, or simply bad reception on the remote control channel, the output signal drops Low briefly. The resultant flag signal can be sensed by another circuit, for exam- ple, a microcontroller or another sensing that acts on the interruption in the pulse stream. If the worst comes to the worst, the autopilot should be switched on! ( 070099 - 1 ) Dominik Tewiele If you wish to set up a medium-range (5 m to 10 m) communication link between two robots or between a robot and a base station, infrared light can be an economi- cal alternative to using radio modules. Tried-and-tested standard protocols and supporting components are available for the modulation necessary to suppress the effect of ambient infrared light. Practically every modern microcontroller sports one or more asynchronous serial interfaces (UARTs), which make perfect partners for IR receivers and transmitters. An example of a suitable receiver is the TSOP17xx, where the 'xx' stands for the modulation frequency, measured in kilo- hertz. Its output can be connected directly to the RxD pin of a microcontroller. Because of the open-collector output stage, it is possible to connect several receiver modules in parallel to increase the area covered. The transmitter consists simply of an IR diode and a couple of discrete com- ponents. A timer in the microcontroller can PC5(ADC5/SCL) PC3(ADC3) PC2(ADC2) 1C PDO(RXD) PDI(TXD) PD2(INT0) PD3(INT1) PD4(XCK/TO) PD5(T1) PD6(AIN0) PD7(AIN1) AT mega8 PBO(ICP) PBI(OCIA) PB2(SS/OC1 B) PB3(MOSI/OC2) PB4(MISO) PB5(SCK) 28 26 25 2 3_ 4 5 6 11 12 13 14 15 !i 17 18 19 v cc 070170-11 be used to provide modulation, or alter- natively an external NE555 can be used. In this example we are using an ATMega8 with Timerl configured so that the output compare registers OCR1A and OCR1B control the frequency and pulse width of the signal on output PB2. The NPN transis- tor then applies the required modulation. Here again, we can wire several IR LEDs in parallel to increase the transmit range and coverage angle. The series current limiting resistor for the IR LEDs should be chosen with consideration for the desired range and the maximum pulse current that the LEDs can handle. This last figure can be found on the LED's datasheet, which will also help determine a suitable pulse width to set in the software. The maximum baud rate that can be achieved will depend on the receiver cho- sen. Using a TSOP17xx around 1200 baud is possible, which should be adequate for simple control commands. For bidirec- tional communication it will be necessary to build both a receiver circuit and a trans- mitter circuit at each end of the link. It is worth bearing in mind that because of the effect of reflections scope for full-duplex operation is rather limited. ( 070170-1 Peter Zirngibl On his website, under the title 'AVR Blue Remote', the author describes (in German) a Bluetooth-based remote control unit featuring six output relays and six sensor inputs. The site also includes Smartphone software (avrblueremote.exe) and micro- controller software (avrblueremote.hex). These can be used as the basis for projects such as a short-range (up to 10 m or so) remote garage door opener or a remote lighting controller. The software is free for use by private individuals. Any Smartphone running the Windows Mobile 5.0 operating system can be used as the transmitter. The receiver used is the postage-stamp-sized Blue Nice Com III Blue- tooth module with integrated chip antenna from Amber Wireless. The module is based around the LMX9820A from National Semi- conductor, and decoded messages are passed over a UART-like interface (TX and RX signals) between it and an Atmel AVR ATMega8L microcontroller. Connected to the outputs of the microcontroller is a ULN2803 octal driver which can comfort- ably switch enough current to drive power relays. Completing the circuit are a 3 V volt- age regulator (type LP2950-3V) and an ISP 7-8/2007 - elektor electronics 115 +3V © [r4~ K1 FBI O- FB2 O- p B3 O" FB4 O - FB5 O - FB6 O - o a o o o a ISP SCK MISO 19 18 MOSI 17 16 15 14 11 SI 12 JP1 6 6 \ |o| |o +3V ©■ vcc Jr2 Tr 3 " a o 1— CM CM 20 VCC PC6(RESET) AVCC PD3(INT1) PD4(XCK/TO) IC1 PB5(SCK) PB4(MISO) PB3(MOSI/OC2) PB2(SS/0C1 B) PBI(OCIA) PBO(ICP) PCO(ADCO) PCI(ADCI) PC2(ADC2) PC3(ADC3) PC4(ADC4/SDA) PC5(ADC5/SCL) PD7(AIN1) ATmega8L PD2(INT0) AREF PD5(T1) PDO(RXD) PD6(AIN0) PDI(TXD) GND XTAL1 XTAL2 AGND JP2 8 9 X i 10 < 1 > C4 C5 22p 22p 7, 3728MHz 21 2 22 RX O- TX O Tnl D2 v-*> ♦X - 5 \ 6 23 i 24 2 25 3 26 4 27 5 28 6 13 7 a R1 D3 D6 +5V -© RE1 m ^.mw 1N4148 ,10 +VS 11 01 12 > 02 13 IC2 03 14 04 15 05 ULN2803 16 06 17 07 18 08 VEE 08 0UT1 01_ 06 05 04 03 02 "O 0UT2 "O 0UT3 -Q 0UT4 -Q 0UT5 "O 0UT6 .11 16 GND RESET ENV1 CTS ENVO RTS LSTAT_0 TX LSTAT_1 RX Host_wu ISEL2 TX_LED ISEL1 VDDJDIGI VCC IC3 Blue Nice Com III Reset Bluetooth R7 ■un-i X +3V H±> 070126-11 (in-system programming) connec- tor. Four LEDs indicate the status of the connection: LED1 shows when the microcontroller has received data correctly and LED2 indicates when a timeout has occurred. The Bluetooth module's LEDs indicate the link status (LED3) and transmit mode (LED4). The printed circuit board layout for the circuit has to meet sev- eral constraints. For maximum range there should be no ground plane, conductors, components or other metal parts within 8 mm of the antenna; other require- ments are set out in the manual for the module. The microcontrol- ler can be programmed using the ISP interface: you must of course make sure that the pinout of the connector is compatible with that of your programmer. Suitable pro- grammer circuits can be found on the Internet as well as within the pages of Elektor Electronics , and further information is provided on Atmel's website. The sensor inputs can be used for any desired purpose or simply left floating. With the hardware built we next turn to the accompanying Smart- phone software. You will first need to install the appropriate version of Compact Framework 2.0 (available for download from Microsoft): • Windows Mobile 5.0 Pocket PC and Smartphone: NETCFv2. wm.armv4i.cab; • Pocket PC 2003 and 2003 SE: NETCFv2.ppc.armv4.cab; • Windows XP: netcfsetupv2.msi. Next, copy the file avrblueremote.exe to the target platform (for example onto an SD card for use with a Smartphone). The two Bluetooth devices, the Smartphone and the receiver board, now need to be 'paired' (which only needs to be done once). The pro- gram can now be started, and the COM port set with a click or two of the mouse on the upward- and downward-pointing arrows. The central square opens the interface, creating a connection with the receiver. The arrows now allow the outputs on the receiver board to be switched on and off; the sixth output is switched by pressing the space key. Towards the top of the display the six sensor inputs are represented as LEDs. If you should move out of range of the receiver, these LEDs will be extinguished and a timeout bar will appear. If the timeout period should expire without a valid signal being received the interface will be closed. ( 070126 - 1 ) Web links Author's website (in German): http://www.clipswitch.de/avrbluer- emote.html Bluetooth module information: http://www.amber-wireless.de/en/ produkte/bluetooth/default.php?fnum=l 09221360256 Bluetooth module manual: http://www.amber-wireless. de/pdf/OPCl 601 _MA.pdf LMX9820A datasheet: http://www.national.com/pf/LM/LMX9820A.html AVR programmer: http://www.atmel.com/dyn/products/tools_card. asp?tool_id=2726 AVR Studio: http://www.atmel.com/dyn/products/tools_card. asp?tool_id=2725 116 elektor electronics - 7-8/2007 Pascal Choquet Fans of the film '2001 a Space Odyssey' will no doubt recall the polite yet sinister voice of HAL, the ship's computer. It stands to reason that all proper robots need a (not necessarily menacing) voice. Those of you who imagine that a voice box would require a whole heap of ICs are mis- taken; the ISD2500 ChipCorder family of ICs from Winbond contains almost all the necessary hardware in a single 1C to record and playback audio messages. Included on the 1C is a microphone preamp and AGC suitable for a low-cost electret type micro- phone, an output amplifier to drive a loud- speaker, memory, an oscillator, an A/D and a D/A converter. There are four basic models; 2560, 2575, 2590 and 25120, the numbers following 25 indicate the avail- able recording time in seconds. The mem- ory capacity of each version is actually the same but longer recording times are achieved by using a lower sampling rate. The chip with the shortest recording time therefore offers the best audio quality. The simplest circuit required to use the device in playback mode only is shown in Figure 2, the only external components required are just two decoupling capaci- tors. This circuit can be used in the robot whilst the circuit shown in Figure 1 can be used for both recording and playback. A socket for IC1 fitted in both circuits will allow the chip to be moved into the robot once the sounds have been recorded. Recordings are made by following this sequence. First switch S3 to record mode (a low on pin 27). A press of S2 now begins the recording which is ended by another press on S2; a third press of S2 starts the next recoding period and so on. This can con- tinue until there is nothing more to record or when LED D2 lights to show that the memory is full. Playback can be performed by momentarily toggling SI and switch- ing S3 into 'play' mode, now with each press of S2 the recorded messages will be sequentially played back. The recordings can be overwritten by toggling SI, switch- ing S3 to record and then using S2 to start recording from the beginning again. Some flexibility in the playback mode allows individual messages to be linked together; each recorded message is termi- nated by an EOM (End Of Message) flag when it is stored in the chip. Instead of storing complete phrases like 'obstacle ahead' for example it is more efficient to store 'obstacle' then 'ahead', 'to the right', 'to the left' and 'behind' and likewise for numbers 'one', 'two', 'hundred' 'point' etc allows voicing of the complete range of numbers from these basic elements. The minimum playback circuit shown in uses the A0, PD, /CE and /EOM signals interfaced to the robot microcontroller. For playback PD is reset to '0' and to play the first message a low pulse is given on /CE. With A0 at '0' playback occurs at normal speed but with A0 at '1' the chip enters 'fast forward' mode where it advances through the message at 800 times its nor- mal playback speed. When the third mes- sage needs to follow the first for example, the processor sets A0 to '1' and pulses /CE low to fast-forward through the second message, waiting for the /EOM flag to go low. Once this occurs A0 is reset to '0' and a low pulse on /CE plays back the third message. The /EOM output pulse can be less than 10 ms wide so it is better to use it to inter- rupt the processor rather than just poll its status. An example C code listing has been written by the author for a 16-bit Texas MSP430 microcontroller interfaced to this chip and is available for free download from the Elektor Electronics website, ref. 070313-11.zip. ( 070313 - 1 ) Web link www.winbond-usa. com/mambo/content/view/1 53/283/ IC2 +U S4 o— < i < > — CIO C9 d b ■ 7805 >> t <2> 10|a 25 V lOOn f ? f vi C8 +5V -© C11 □ lOOn 10n 16V R6 +5V © R8 R9 SI \ R7 S3 S2 N R1 PD Play/Rec Next 1 Jc4 ^ToOn I 24 27 20 MIC1 22^T6V Cl — Ih lOOn C2 — Ih lOOn iL -T 21 17 18 lOOn R3 R5 11_ 19 C6 □ D2 16 |22 tf ^^00n 28 VCCA CE PD P/R ANAIN ANAOUT OVF IC1 VCCD A9 A8 A7 A6 A5 A4 A3 A2 A1 A0 MIC ISD2560 MICREF AUX IN AGC VSSA SP+ SP- EOM XCLK VSSD 4|i7 16V 13 26 10 12 1 9 8 7 6 5 4 3 2 1 14 15 ■1 25 M LSI 16Q 070313-11 7-8/2007 - elektor electronics 117 Balancing Robot David den Boer The most famous balancing robot, also viewed from the general public's perspec- tive, is the Segway, invented by Dean Kamen [5]. This little cart on two wheels is a mode of transport for people, and these days adorns the streets of many large cities. The principle of balancing on two wheels has inspired many robot builders to the con- struction of such a robot. A few other exam- ples are the NBOT built by D. Anderson [3] and 'Joe le Pendule' built by co-workers at the Polytechnic School in Lausanne [2]. This type of robot comprises a number of sen- sors and a drive circuit clustered around one or more microcontrollers (Figure 1). When building such a robot, a few significant hur- dles have to be surmounted. This article will hopefully help with this. The physics The principle of a balancing robot is obvi- ously to let the robot move forwards and backwards in such a way that the robot remains upright, the centre of gravity of the robot has to be always directly above the robot. A simple analogy is the balancing of a broom handle on the tip of a finger. This problem is sometimes also known as the 'inverted pendulum problem'. From your physics classes you will no doubt remem- ber that the period of the pendulum is the square root of the quotient of the length and gravity, a longer pendulum there- fore has a longer period (see Equation 1). Roughly, it can be deduced from this prin- ciple that a balancing robot with a high centre of gravity is more stable and thanks to the longer period is easier to keep bal- anced. A first simple step in obtaining a good functioning balancing robot is there- fore building a robot with a high centre of gravity. This can be done by building a tall robot, but also by the high placement of heavy parts, such as the batteries, or by artificially raising the centre of gravity with additional weights at the top of the robot. Control A number of variables need to be known to control the robot. The first variable is obvi- ously the angle of the robot: if the robot is not vertical it will continue to fall over. The speed at which this angle changes (angu- lar velocity) is the second variable that is important. If the robot moves through the balancing point with a certain speed, the angle of the robot at that instant is zero degrees. The robot is not stable however, it is, after all, moving through the balance point with a certain angular velocity. This has to be anticipated by the controller; so this angular velocity is also important when controlling the robot. Finally, the speed of the robot is of importance, since it is the intention to control the position of the robot. By feeding these three vari- ables back to the motors the robot can be controlled into a stable position (see Equa- tion 2). A mathematical/physical basis of this control strategy can be found in [1], among others, including the derivation of the relevant equations of motion. Sensors To determine the aforementioned variables an accelerometer and a gyroscope are usu- ally used. With an accelerometer the accelera- tion that the sensor is subject to can be measured. The direction of acceleration is also measured. A sensor that is fre- quently used is the ADXL202 from Analog Devices, which can measure acceleration in two mutually perpendicular directions. Because the sensor is also sensitive to the static acceleration due to gravity (g), the sensor can also determine the angle of the robot with respect to the Earth. The accel- eration observed by the sensor is shown in Figure 2 with the vectors ami and dm2. When the sensor is not subjected to any other acceleration, the sensor is only sensitive to the angle of the sensor with the direction of gravity (and gravity itself, which is constant). As soon as the sensor is also subjected to a dynamic acceleration (a), the sensor will observe this as well. This is the case, for example, when the robot is driving forwards or backwards. The resulting acceleration ami then depends on the dynamic accel- eration, gravity and the angle. This gives a direct insight into the problem: the instant that the robot moves, the sig- nal from the sensor cannot be used any more to directly determine the angle of the robot. Using a gyroscope, the angular velocity of the sensor can be determined. The output signal is directly proportional to the speed at which the sensor rotates around its own axis. By simply integrating this signal the angle of the robot can be calculated. The accuracy is a problem however. If the sen- sor has a small static offset of, for exam- ple, 0.1 °/s per measurement then the error after 100 times of measuring and integrat- ing has increased to 10 °. It is possible to build a balancing robot based solely on a gyroscope, but you will see however that after some time the robot will start to swing and become unstable. The small amount of drift that these sensors have is amplified by the process of integration. By combining a gyroscope an an acceler- ometer the disadvantages of both sensors can be compensated for. In general this is done with a so-called Kalman-filter. This sums the result from the gyroscope, the value from the accelerometer and the calcu- lated angle from the previous measurement cycle. These three values when summed 118 elektor electronics - 7-8/2007 are weighted with respect to each other. The weighing factors that are used are determined dynamically while bal- ancing. Because the weighing val- ues tend to quickly converge to a particular value, fixed relationships can also be used (Equation 3). The appropriate weighing factors can be determined during the calibration of the system. It is common practice for the motors in the robot to be fitted with encod- ers. These give pulses when the motor turns. By counting the number of pulses per unit time or measuring the time between pulses it is possible to determine the speed of revolu- tion of the wheels and therefore the speed of the robot. Which of these meth- ods gives the highest resolution is deter- mined by the number of pulses that are produced by the encoder for each turn of the heel. Actuators Another special point of interest are the actuators. While balancing the robot the motors have to be frequently switched into the forward and backward direction. However, the combination of motors and gearbox is not without friction or back- lash. When the voltage across the motors increases this does not immediately result in power from the actuators, there is a certain amount of offset. This is not a problem in many applications, but in the case of the balancing robot this null point is passed all the time; we are controlling around this null point after all. By com- pensating for this offset in software when driving the motors the stability of the robot will improve dramatically. Apart from that, the capability of the robot, the nimbleness in staying upright are also determined by the capacities of the motors and batteries. The greater the amount of power that the motors can deliver the better the robot is able to remain upright. Architecture In the control loop that is executed by the software in the microcontroller a number of things have to be carried out simultane- ously. The sensors have to be read, cal- culations have to be carried out and the actuators for the robot have to be driven. At the same time it is often also desirable to communicate with a PC for the purpose of data acquisition. For all this it can be a good idea not to use one relatively pow- erful processor but to use a number of smaller processors which send their data to one central processor. In this way the timing of measuring and controlling can T period (s) g gravitational acceleration (m/s 2 ) l length from pivot to centre of mass (m)) PWM = k l -6> + k 2 -0 + k 3 -v e Angle of the robot (°) • e Velocity at which the angle changes (°/s) PWM Drive for the motors 0-100% V Speed of the robot (m/s) Feedback factors, constant 0 B [n] = k 4 ■ 0 B \n - 1] + k 5 ■ d G \ri\ + k 6 ■ 6> v [n] 0 G [n\ Angular velocity measured by the gyroscope (°/s) e B \n\ Angle of the robot, calculated in measurement n (°) AM Angle of the robot, determined by accelerometer in measurement n (°) 0 B [n-l] Angle of the robot, calculated in measurement n-1 (°) ^4 • • constants 7-8/2007 - elektor electronics 119 be divided, which make the programming task a great deal easier. Sum of parts A balancing robot consists of a number of parts that together have to hold the robot upright: sensors, any filters, a controller and drive system for the robot. Putting all this together in one go is very ambitious, a better chance of success is obtained by first testing and calibrating the individual parts. A good method for this is the tem- porary addition of a small arm to the robot. This arm is attached to the robot so that it can hinge with the aid of a potentiometer, which functions as the hinge. The other end of this arm is fitted with a wheel that rests on the floor. When the robot loses its balance the position of the potentiometer changes and therefore also its output. The output of the potentiometer has a direct relationship with the angle of the robot and can be used for calibration purposes. Note that it is important to choose a potentiom- eter with a shaft that turns easily. The next step is the controller. Because of the arm, a read-out of the angle is available and this can be used to test and calibrate the controller for the robot. As already mentioned, feedback from the angle of the robot, angular velocity and speed of the robot are essential for the successful control of the robot. It is possible to calcu- late the necessary feedback factors math- ematically. However this makes a com- plete and detailed physical description of the robot and the behaviour of the motors essential. It is simpler to determine these factors experimentally. This can be done, for example, by connecting a number of digital or analogue potentiometers to the microcontroller. The program that runs in the microcontroller reads the position of the potentiometers and converts the rel- evant values into feedback values. The calibration can now be done with a lot of patience. A first step is to increase the feedback factor for the angle. If this fac- tor is too small then the robot will react slowly; if this is too large then the robot will quickly oscillate around the balance point. In the latter case the feedback fac- tor can be reduced and the feedback fac- tor for speed can be increased. In this way the robot will quickly gain in stability. A final step can be made by increasing the feedback for speed. This will result in bet- ter positioning for the robot. A feedback factor that is too large however will make the robot very unstable. A second step is the calibration of the sen- sors. The measurement values from the sensors (gyroscope, accelerometer) can be read into a PC via the microcontrol- ler. Sensors that provide a read-out in the form of a pulse width modulated signal are quite common. By comparing the meas- ured pulse width with the reading from the potentiometer that is mounted to the arm the angle and angular velocity can be easily derived. During the calibration, the drive for the robot can be switched off. By mov- ing the robot back and forth by hand the angle and angular speed are changed and the calibration can be performed. When calibrating the accelerometer it is impor- tant to move the robot back and forth very slowly, so that the dynamic acceleration is as small as possible and only the accelera- tion due to gravity is observed. A third step is the calculation of the angle and angular velocity: the results from the sensors have to be combined in such a way that the angle of the robot and the speed at which this angle changes is obtained. The calculation that makes this possible has been described above. The weighing factors can be determined by moving the robot for some time (1 minute, for exam- ple) and reading the values from the sen- sors (accelerometer, gyroscope and poten- tiometer on the arm). A spreadsheet on the PC can subsequently be used to analyse the values and determine the correct val- ues for the weighing factors. ( 070294 - 1 ) Web links (1) http://robotics.ee.uwa.edu.au/the- ses/2003-Balance-Ooi.pdf This docu- ment describes a final year project during which a balancing robot was built. The research is quite detailed with respect to the physical and mathematical model- ling of the problem. (2) http://leiwww.epfl.ch/joe/ Polytechnic school of Lausanne. The website is in French but there are a number of nice movies. (3) http://www.geology.smu.edu/~dpa- www/robo/nbot/ This is the web- site of D. Anderson who built the NBOT. (4) www.dena.demon.nl Dutch website on the construction of a balancing robot. (5) www.segway.com Importer of the Segway. (6) www.sparkfun.com DIY Wheels Marcus Bindhammer You don't have to reinvent the wheel for your robot, but you may have to make your own somehow if you can't or don't want to buy them ready made. The handi- crafts aspect of making your own wheels is relatively undemanding, and one hand (but not a left hand...) is enough. Use a compass to draw circles with a diameter of 50 mm on a piece of 5-mm plywood, and then cut or saw the discs out. Drill a 3-mm hole in the centre of each disc. As you can see from the drawing, an M3 screw with a length of at least 30 mm must be fitted in the hole. Now secure the screw using a washer and nut, and then clamp it in the chuck of a drill press. Using a small block of wood wrapped in sandpaper, you can quickly sand the disc into a nice cir- cular shape. Finally, fit a length of toothed rubber belt around the circumference of each disc (old video recorders are a good source) or glue flat elastic bands to the running surfaces. After you remove the screws, all you have to do is fit the wheels on the axles and secure them with a bit of superglue. ( 070145 - 1 ) 120 elektor electronics - 7-8/2007 Sven van Vaerenbergh UH Brussels, Radio Therapy Dept, The author had to design a monitor circuit for the so-called Hercules Table (an elec- trically movable platform) at the University Hospital in Brussels that would watch sev- eral operating voltages and could stop the table in case of emergency. The movement of the platform (up/down) is done with a DC voltage between +8 V and -8 V, where the magnitude of the volt- age determines the speed and the polarity determines the direction. There are also a number of fixed voltages that need to be monitored. An R8C module from Elektor Electronics was selected for the implementation of this project, because it is very easy to connect an LCD module to it and because it has a good A/D converter with 10-bit resolution on board. The connection for the LCD (2x16 char.) is identical to that of the application board in Elektor Electronics (March 2006, page 38). In addition to the controller, a multi- plexer of the type ADG 408 is used. This is required because we need to measure multiple voltages. An unusual requirement for this project is that both positive and negative voltages need to be measured. Normally, the A/D converter of the R8C can only measure voltages between 0 and 5 V. The solution was found by using a symmetrical voltage for the R8C module, that is, +2.5 V. These voltages are generated by an LM317 and an LM337. We normally connect ground (Vss) to pin 5 of the R8C module. In this case that becomes -2.5 V. In this way we can measure voltages from +2.5 V to -2.5 V. The only places in the schematic that are connected to ground are the voltage divid- ers for the two voltage regulators (R1 to R4) and the voltage dividers (R5 to R16, R19 and R20) for the signals to be measured (available at connector K1, where all the important signals from the Hercules Table are available). We can see that the schematic also con- tains a relay that can be switched by the R8C to immediately stop the table move- ment. This is optional. Now we have to take special care when we have negative voltages. The resolution of the 10-bit A/D-converter in the R8C amounts to 5 V/1024 = 0.00488 V per bit. Because of the symmetrical power supply, the converter will give an output value of 512 when the input voltage is zero volts. We can display a minus sign on the LCD when the value is smaller than 512. In C code it looks like this: if ( u < 512 ) // less than 0, then minus sign { lcddata (45); } We also have to adjust the voltage lev- els in software, because these have been lowered by the 6 voltage dividers. We also have to drive the multiplexer. In C code it looks like this: pd3 _ 3 = 1; //port 3.3 as output p3 _ 3 = 0; //port 3.3 => for channel selection via analogue MUX pd3 _ 2 = 1; p3 _ 2 = 0; //port 3.2 => for channel selection via analogue MUX Three channels are directly connected to the A/D-converter. One channel is multi- plexed for the voltages of +8 V, -8 V and 7-8/2007 - elektor electronics 121 A low-cost robot not just for schools & education Bart Huyskens, St Joseph's institute (Schoten, Belgium) Out of Belgian schools has arrived an £ 85 (125 €) robot buggy that the designer hopes can reverse the decline in the study of electronics and technology across Europe and, potentially, wider. Like many in the engineering teaching fraternity, the author is increasingly aware that electronics - and most engineering and sci- ence related activities - fail to attract young people. To people who have grown up with a fascination for technology this is a great shame and it really is very strange when you consider that young people are fascinated by all things electronic - like i-pods, digital cameras and mobile phones. But for some reason our schools fail to capitalise on this interest and attract young people to technical careers. Long and hard thought was given about how to solve this and what the real problems are (including the facts that electronics can be mathematical, parts of the subjects are difficult to under- stand, and it has a very dull image). All sorts of ideas have been tried, and some have partially worked, but not to our satisfaction. There is one exception that stands out - Lego. Lego's NXT robot looks cool, is cool, and is fun to use. But it is expensive, does not FORMULA FLOWCODE really teach anything about electronics, and you can't really 'get under the hood' and use it as a platform for learning more than just simple programming. About six months ago, during a conversation with engineers at Matrix Multimedia in England, we had an idea that might go some way to solve this problem - a programmable robot buggy of our own, with more functionality than the Lego NXT, that does have 'open architecture' which can be used for a wide range of teach- ing and learning activities in electronics and technology. In the six months since, we have been working hard to make these ideas come to life and we have called the project 'Formula Flowcode'. Formula Flowcode is a complete hardware and software robot- ics solution for learning about electronics and programming. This article describes what Formula Flowcode does, how it works, how we hope it can be used to learn all about robotics... f r 3 1 i 1. The brains of Formula Flowcode — a PIC18F4455 microcontroller 2. USB socket 3. Master reset switch 4. Programming LED 5. External 5V supply input 6. Power switch 7. Plastic chassis with battery compartment, motors with gearboxes, and 2 wheels. 8. Motor driver chip - a L293D 9. Microphone with sound level amplifier circuit 10. User definable press switches 1 1 . Distance sensor - right 12. Distance sensor - centre 13. Distance sensor - left 14. Light sensor 15. Line following circuit board 16. 8 user definable LEDs 17. Microphone volume control 18. Loudspeaker 19. E-blocks expansion socket Figure 1. Formula Flowcode functional parts. 122 elektor electronics - 7-8/2007 mcaer RM RAlJADCfl RA2 HA3>AOCl RWh©.-*-^ RA5WJK4 REt -@- fifil <£>-*□ REE'USB — vce gJJ GWft wen — — ea D5C2 Ftcfl .RCI-PWW <§> KC2PWM H VEISH RH REM Re? RHR RBS RH4 fifii'Ancs KD1‘INT2MjDC& fifljJSCL HB^SOA vcc GUO fiO? fiM UM HD4 RC7W0 EC&TTttn RCJ.UEEJ RCi^SS fiD3 fin? Figure 2. This diagram of the PIC18F4455 is purposely simplified, showing only the actually used functions of the pins of the PIC. D stands for ‘Digital I/O’ and A for ‘Analogue input’. And here it is Figure 1 shows a picture of Formula Flowcode and a list of the com- ponents and features on the buggy. But how does it all work? Let's start at the beginning. The whole Buggy is designed around the new and very powerful PIC18F4455 microcontroller from Microchip. This 40- pin device operates at 24 MHz and will execute programs at an amaz- ing speed of 6 MIPS. A meet & greet diagram of this CPU is shown in Figure 2. The device connects directly to your USB port and contains a bootloader program so that it can be programmed using a version of Flowcode 3 supplied free of charge with the buggy. The PIC18F4455 has two separate hardware PWM outputs, a UART, l 2 C, Analogue Inputs, Pin-, Port- and Timer Interrupts and a lot of Digital I/O. Driving DC Motors The two DC motors with separate gearboxes are powered by a classic L293D 1C with two full H-bridges, see Figure 3. The direc- tion and speed of each motor can be programmed separately in Flowcode and this makes the buggy capable of performing the craziest moves you can imagine. As you can see on the schematic, the L293D uses four PIC outputs for its control. Two outputs (REO and RE1) set the direction while two (hardware generated) PWM signals at RC1 and RC2 govern the speed of each wheel. DECGUPLiMa C.xP-A.-iTruq-S VILA X Figure 3. The L293D Double H-bridge motor driver circuit. SOI G t! C t> fcp O) MIN' |j!.: j h^j-j ¥ m2 PINI riilii Pi ha [ f’lHf | L-'-U WNS IrdV LEDs, Switches and E-blocks Expandability The schematic of the I/O hardware is shown in Figure 4. The eight LEDs and two switches at the front of the Buggy will come in handy for your first steps with Flowcode and will prove to be very useful when debugging your more complex programs on this 8-bit PIC microcontroller. In parallel with the eight LEDs, Formula Flowcode has an E-blocks connector. This will give the users the capability of very easily expanding the Buggy with standard E-blocks like LCD, Bluetooth and many more. Sound I/O and light sensor The buggy can react to sound (hand claps) using the amplified microphone circuit connected to RB2. As shown in Figure 5, this sound sensor may be used as a digital input, an external interrupt Figure 4. Two switches, eight LEDs and the E-Blocks D-type connector. Figure 5. The microphone, loudspeaker and light sensor circuitry. 7-8/2007 - elektor electronics 123 Q12.D i T1 ,17 Tl. B*»V11F 14J%n: BC44TB Figure 6. Distance measurement circuit on board the Formula Flowcode Buggy. and an IR sensitive photo transistor producing an analogue voltage that's inversely proportional to the amount of IR light reflected. Line following circuit Also on the front of the buggy is a small daughterboard that con- tains two l 2 C intelligent infrared transceivers capable of detecting black and white surfaces at distances from 1 mm up to 6 mm with- out any error. The circuit is shown in Figure 7. These sensors allow the buggy to follow lines on a table or mat. Power supply This section of the circuitry is shown in Figure 8, using a com- bination of pictorial elements and of course the schematic. The small chassis is powered from four NiMH AA rechargeable bat- teries which give between 4 and 6.2 V. The circuit board also has space for additional components that allow you to connect larger batteries to the chassis, using a 5 V regulator. Figure 7. Line follower circuit. or even as an analogue input. The buggy also includes a simple high impedance speaker that can be used to generate frequencies between 100 Hz and 17 kHz. At the front of the buggy is a small forward facing light sensor that allows the vehicle to measure light intensity in the forward direction. Infrared distance measuring circuit The buggy also includes three distance sensors on the front, left and right of the main circuit board. Figure 6 shows the circuit diagram. A single sensor is a combination of an IR LED that emits IR light, Figure 8. The simple but all-important power supply. Additional circuitry In addition to the standard circuitry discussed above, the chassis is also fitted with a fair number of expansion connectors. These include l 2 C expansion, wheel encoder inputs, servo inputs, and much more. Using Formula Flowcode By now you should have a good idea of how the hardware works and what makes it tick. But how is it programmed, how is it used, and how do students know what to do? The Formula Flowcode buggy is supplied with a free (reduced functionality) copy of Flowcode - a graphical software language for microcontrollers. Flowcode allows users to directly download a program to the buggy using the USB lead. On removing the USB lead and pressing the reset switch, the buggy starts to run the program. Courseware for pole position The new version of Flowcode released with the buggy includes a pulsewidth modulation (PWM) component for controlling the motors. As Flowcode is now available in around 10 languages (including Chinese) it will be usable by children as young as 12 virtually anywhere in the world. This robot buggy is officially named 'Formula Flowcode', after the Formula Ford where the cars are all identical and winning only comes down to the driver's skills. In this case, winning comes down to the programming skills of the user. As you might expect there are a number of separate 'courses' that users have to com- plete to increase their skills level. These courses start with getting a single FED to light up, and finish with full maze solving using a custom made chassis, using wheel encoders and what have you. This is the really clever idea behind Formula Flowcode — it is great for complete beginners to robotics and electronics, and it will also provide a considerable challenge to those with relevant degrees in electronics and computer science. The courses include such subjects as: • Fight a single FED; • Make a 'NightRider' effect on the FEDs on the front of Formula Flowcode; • Develop a program that uses the on-board light sensor to allow 124 elektor electronics - 7-8/2007 Formula Flowcode to steer towards the light from a Fiand Field torch; • Develop a program that allows For- mula Flowcode to 'dance to the music'. Every time you clap it must turn th rough 90 degrees; • Develop a program that allows Formula Flowcode to follow a 2-metre long line made up from a black insulating tape. Beat a time of 30 seconds; • Develop a program that allows For- mula Flowcode to solve a 64-cell maze using the left-hand wall follow- ing tecFinique. TFiese courses are all explained to students in the form of task-based worksheets. Some are competitive, in terms of time or function, and will form the basis for regional competitions that we hope will be run by Elektor and educational institu- tions across Europe. Other courses are just Figure 9. Typical line following exercise. Pit stop! How can you get involved? The Formula Flowcode robot buggy was purposely developed to motivate people to want to learn more about robotics and electronics - from 12 year old pupils who have a curiosity about the subject right up to those enjoying retirement and still wanting to learn and keep mentally active. In the USA the First Robotics programme (www.usfirst.org) has been quite successful at stimulating engineers in industry to collaborate with young people to compete in robotic events. We hope to achieve something similar here; by providing a low cost hardware software robot providing online support and quality curriculum. By running workshops and competitions we hope people will be captured by electronics. If you feel that our aims are worthwhile and achievable, if you want to take part in this programme, or if you are interested in the competitions and workshops then please let us know. If the level of interest is high then we can write more articles and issue special 'courses' for Elektor readers. The author and his colleagues can be contacted by email on barthuyskens@scarlet.be, or through Elektor. You can purchase a Formula Flowcode buggy from the Elektor SHOP at a cost of £ 85 or € 125 Including VAT. for fun or in-depth exploration of program- ming and hardware features. Support for all of this will be available on Matrix Multimedia's website forum acces- sible via www.matrixmultimedia.com where users ask each other questions and swap programs. We also plan to run work- shops on Formula Flowcode to get young people up and running and interested in technology. In addition to this Elektor will be publish- ing a book which will take users through the process of developing programs and additional circuitry for the buggy. This will form a complete suite of tutorials which will teach technology to budding electron- ics enthusiasts up to 16 years of age. ( 070323 - 1 ) Figure 10. Solving a simple ‘left’ maze. 7-8/2007 - elektor electronics 125 RGB LED adjustment Nivard van de Boogaard With this simple circuit you can easily control the three LEDs in an RGB LED. Each time switch SI is pushed we increase the (digital) value at the output of the coun- ter-IC, IC1, an HCT7493. So, with each button push, a different LED or combination of LEDs lights up; or, in the case of an RGB-LED, the LED produces a different col- our each time. After the highest value the counter will start from the beginning again. In this way all colour combinations will have their turn and there is also no need to build a separate reset- facility. Nice to embellish a robot with, but it also gives a nice effect for a modded PC. To prevent the outputs of IC1 from being overloaded, we have added T1 through to T3. As soon as an output from the counter- IC becomes active (high), it turns the cor- responding transistor on and current will flow though the LED. To limit the current through the LEDs we deployed R1 to R3. The type of transistor that is used for T1 to T3 is not very critical. Standard LEDs require relatively little current, about 20 mA. A BC337 will therefore work fine, as will a BC547. The power supply to the LEDs can be switched off with T4. This is handy when, for example, the circuit is built into a PC. As long is IC1 remains pow- ered it will remember its counter value and therefore also the cor- responding colour setting of the LEDs or RGB-LED. In this way it is not necessary to adjust the col- our every time the PC is switched on. T4 needs to be able to handle more current then T1, T2 and T3, but even a BC847 with its 100 mA maximum collector current rating is still below the limit with three LEDs. We use R4 to define the logic level (low) on the clock input when the switch is open. The HCT7493 is a 4-bit binary ripple counter, which internally consists of four master-slave flip- flops that form a divide-by-two and a divide-by-eight. RO(O) and RO(1) can be used to reset these two sections. We don't need the reset function for this application so we connected RO(O) and RO(1) to ground to prevent unwanted behaviour. If need be, the clock input \CKA could be connected to the power supply rail to make this input insensitive to noise. ( 070025 - 1 )) 070141 - 11 Jonathan Hare Here we couple LED oscillators together to produce some interesting effects for an exclusive optical touch to your robot. As seen in the circuit diagram in Figure 1, instead of using the discharge pin on a 555, the timing capacitor can be charged and dis- charged using the output (via a preset PI). If we assume the 555's output resistance is very low (i.e. use a bipolar rather than a CMOS 555) this circuit provides a 50:50 mark-space ratio whose output frequency is independent of load. However, if we deliberately increase the output resistance by using a series resistor (R1) the timing will now also be dependent on the current taken by the load (because R1 will effectively drop the available charging voltage to the P1/C3 timing circuit). Now, imagine a number of such oscilla- tors whose outputs are connected to each other via current limiting resistors and bi- colour LEDs (Figure 2). A possible constellation of oscillators and LEDs, each with their own symbol from 126 elektor electronics - 7-8/2007 Figures 1 and 2, is shown in Figure 3. Each oscillator's timing will be dependent on the state of the other oscillators because these will determine the current that flows through the LEDs. For example, if all the outputs are High (or all Low) there will be no potential differences and so no current will flow through the LED circuits. In this case, all the oscillators will be at maximum frequency. Other combinations of outputs will light some of the LEDs and these cur- rents will thus effect each oscillators timing. Chaos rules! The RIs therefore couple the oscillators to each other. A switch across each R1 allows control of the coupling. Setting the oscillator frequencies to about 2 Hz with the Pis shows the complex flash- ing of the LEDs switching between off, red and green. Sometimes the LEDs seem to set- tle down pulsing together. This is rather like an electronic version of what is observed in nature when a group of fireflies congregate in a bush — they pulse together and maybe our little circuit is a simple version of this rather complex natural feedback system. If the frequency is raised to ca. 100 Hz, var- ying mixing (beating) of the flashing red and green colours cause a 'wave' of changing colour to go through the array of LEDs. Including light dependent resistors (LDR) in series with R1 might be a way of making each of our LED fireflies 'see' each other. Even without the LDRs, with three or more coupled oscillators there might also be the intriguing possibility of observing chaotic behaviour of the oscillators. ( 070141 - 1 ) Raj K. Gorkhali Louder music, sirens or speech in response to higher ambient noise levels? This simple circuit has the answer, and it may enable your robot to be at least as noisy or loud- mouthed as the others in an arena. The circuit consists basically of a micro- phone, a level detector, a 4-state counter and four analogue switches connected to a resistive ladder network. Looking at the circuit diagram, the signal from electret microphone Ml is amplified by T1 whose collector voltage appears across a potentiometer. Ml gets its bias voltage through R4. Depending on the setting of PI, the 4040 counter will get a clock pulse when a certain noise level (threshold) is exceeded. The counter state determines the configuration of the four electronic switches inside the 4066 and so the series resistance effectively seen in the audio signal line. The circuit should be powered from a 9-V regulated supply or a battery and will con- sume a few milliamps only. Switch SI allows the counter to be reset, switching all 4066 switches to off, i.e., the highest attenuation will exist in the audio path as in that case none of the 1-kQ resis- 7-8/2007 - elektor electronics 127 tors are shorted out. To calibrate the circuit, disconnect the 4040 clock input (pin 10) from the wiper of PI, and temporarily ground it through a 100 kQ resistor. Now pulse the clock input by briefly connecting it to the +9 V line; you will see the counter outputs change state and with them, the bilateral switches in the 4066. ( 070034 - 1 ) dry cells (6V) rechargeables (4V8) 6 ! rechargeables I 4V8 O 1 dry cells o 6V see text 21 © VIN SOUT SIN RES ATN IC1 P0 P15 PI P14 P2 P13 P3 P12 P4 P11 CB220 P5 P10 P6 P9 P7 P8 -t- 1 7 -o 2 3 3 + ci 8 4 -o ¥ 20 _ 19 _ 18 17 J 6 IS 14 13 23 X -O 070353-11 C. Tavernier Although the major- ity of robots built by amateurs move around using wheels or cater- pillar tracks, two cat- egories occupy a place apart because of the spectacular way they move: the hexapod robot, also called spider robot (though spiders actually have eight legs!), and the walking robot. It may seem rela- tively easy to make the wheels turn using motors, which is the sole requirement in a conventional mobile robot, but reproducing walking, be it of an insect in a hexapod or of a human in a walking robot, might appear markedly more difficult. In this article, well see how to do this for a walking robot, which we've opted to buy in kit form for the mechanical part. Although these days any good handyman can build a 'conventional' mobile robot base, i.e. with wheels or tracks, the mechanical construction of a walking robot is much trickier, mainly because of the particular action involved in walking, which we'll be describing in a moment. To our knowledge, there are currently only two mechanical kits for walking robots sold at an affordable price: the famous Toddler from Parallax (www.parallax.com) and, closer to home, the Yeti from Arexx Engineering (www.arexx.com). As these two robots operate in virtually the same fashion, in terms of the principle of elektor electronics - 7-8/2007 their walking, we settled on the kit for the Yeti, distributed by Lextronic (www.lex- tronic.fr), as he is slightly cheaper than his brother from Parallax. But everything we say about one is going to be true, with only minor variations, for the other too. So, these walking robots both consist of two rigid legs, in the sense that they don't have a central articulation like our knee. They consist of two arms (that's a bit much for a pair of legs!) arranged to form a paral- lelogram, and have a foot articulated either side of the plane that forms. Although it might not seem very much, all it actually takes to make such a robot walk is two normal — i.e. unmodified — radio- control servos. The first, clearly visible at the front of the robot, controls the feet by means of two long connecting rods, while the other, fitted under the robot's belly, acts on the rear arm of each leg. So hav- ing thus set the scene, let's now see how such a figure is able to walk. To make it easier to follow our explana- tion, we're going to refer to 'right' and 'left', but obviously this is purely relative. When the robot is at rest, both feet are flat on the ground alongside each other. Then the foot servo turns in a direction that will make the robot's body lean over onto the left foot, which obviously has the effect of lifting the right foot off the ground. Then the leg servo turns too, making the right leg, free to move as its foot is now off the floor, move forward. Then the foot servo turns in the opposite direction, making the robot's body lean over onto the right foot, lifting now the left foot off the floor. The leg servo rotates again to make the left leg, itself now free to move, advance — and thus ends the first step. As you will note from reading this, or if you have already watched the videos available on both the Parallax website for the Tod- dler and on the Lextronic site for the Yeti, the robot is actually in a constant state of near imbalance throughout its walk, which can only work correctly if the robot's weight is correctly distributed... and if the servo movements are neither too abrupt, nor too large in amplitude. Even though these walking robot kits are also available with electronics chassis included, sometimes very elaborate as in the case of the Yeti with an ATMega8 proc- essor from Atmel and its C compiler, a sim- ple Basic Stamp II or a Cubloc CB 220 is enough for taking your first steps (literally as well as figuratively!) As shown in the fig- ure, which applies to both these microcon- trollers that are, don't forget, pin-compat- ible, apart from the microcontroller itself, no other active components are required to make our robot walk. The servo control inputs are connected from two parallel ports which can be any ones in the case of the Basic Stamp, but must be P5 and P6 in the case of the Cubloc CB 220, as its PWM instructions only work on these two. Capacitors Cl and C2 call for a comment: Cl and C2 only need to be fitted if using a BS II. If using a CB 220, Cl will be replaced by a wire link, and C2 will not be fitted, its two pads being simply left empty. All the rest is just a matter of programming, based essentially around the PWM instruc- tion in the case of the Cubloc and around PULSOUT in the case of the Basic Stamp. As you will have gathered from the expla- nation above, to make our robot walk, all we have to do is make the servos turn alternately in one direction or the other, in a well-defined sequence. We are offering you two complete source listings for making our robot walk, one for Basic Stamp II and one for Cubloc, on download from the Elektor website or from the author's own site (www.tavern- ier-c.com). Here are just a few comments to prove to you how simple they are and enable you to adapt them easily to your own needs. Let's start by recalling that in the Cubloc the instruction PWM is used as follows: PWM port, ratio, period This generates on the corresponding port (0 for P5 and 1 for P6) a PWM signal whose duty cycle is defined jointly by 'ratio' and 'period'. The advantage of the Cubloc is that this instruction lets us generate the rel- evant signal continuously, as soon as it has been called at least once. In the case of the Basic Stamp, the instruc- tion PULSOUT is used in the following way: PULSOUT port, duration This generates a pulse on the correspond- ing port for a period equal to 2 jis multi- plied by the value of the 'duration' param- eter. The drawback to PULSOUT com- pared with PWM is that this generation is not repetitive. So if we want to gener- ate repetitive pulses, we need to employ loops, making the Basic Stamp version of the program a little more complicated compared with the Cubloc version. Lastly, let's remember that a servo takes up the rest position when it receives 1.5 ms pulses, and moves towards its end posi- tions in one direction or the other for pulses of 1.0 ms or 2.0 ms respectively. Lrom this point on, it's easy to follow one or other of the suggested listings. To put the robot's feet into the rest position, for the Cubloc we write: PWM 0, 3150, 32768 PWM 1, 3150, 32768 And for the Basic Stamp II : FOR Pulses = 1 TO 100 STEP 5 PULSOUT TiltServo, 750 PULSOUT StrideServo, 750 PAUSE 25 NEXT In both cases, this causes 1.5 ms pulses to be generated for both servos, hence plac- ing them into the rest position. Note that, in the case of the Cubloc, it is necessary to adjust the 3150 parameters so that they take the servos correctly to the rest posi- tion, while for the Basic Stamp, it is neces- sary to adjust the two 750 parameters for the same purpose. To lift one foot, we will therefore write for the Cubloc: FOR Position = 3150 TO 2850 STEP -1 PWM 0, Position, 32768 DELAY 1 NEXT And for the Basic Stamp: FOR Pulses = 750 TO 620 STEP -5 PULSOUT TiltServo, Pulses PULSOUT StrideServo, 750 NEXT Note the increase in 'complexity' created by the fact that, unlike PWM, PULSOUT does not operate continuously. So we need to add into the Basic Stamp's 'lift foot' loop the generation of the pulses that will main- tain the leg servo in the rest position. In the case of the Cubloc, this generation is taken care of automatically by the PWM instruc- tion that originally put the servos into the rest position. We'll leave you to analyse the rest of these two listings for yourself — as you can see, they are in fact nothing but a succession of the groups of instructions we've just been looking at, with numeri- cal parameters each time appropriate for the pulses needed to move the servos into the required positions. Before ending, let's just clarify that these two listings are extracts only. The Paral- lax one, originates from the Parallax web- site (www.parallax.com), from where we strongly recommend downloading the document entitled 'Advanced Robotics with the Toddler Robot ' (available in PDL format) containing a very good survey of the various methods of programming the walk. Lor the Cubloc, the full program may b be found on the Lextronic website (www. lextronic.fr). We thank Parallax and Cubloc for their kind collaboration. ( 070353 - 1 ) 7-8/2007 - elektor electronics 129 Luc Lemmens Many of our readers — especially the older generation — will remember the legen- dary EE (Electronic Engineering) experi- menter kits. They were part of the Philips (not 'Phillips') product line for many years, from 1963 until well into the 1980s. Many electronics professionals owe their interest in the field to these kits. The first kits were primarily intended to promote Philips electronic components among hobbyists, but in the later years, the complexity of the designs increased and the range of kits was oriented more towards edu- cational use. In the late 1980s, Philips sold the electronic experimenting kits business to the German firm Schuco. It continued to sell them until the mid-1990s. The ME (mechanical engineer- ing) experimenter kits from Philips are much less well known, but they were only available for around five years in the 1960s. It would appear that the ME series was much less successful than the EE series, which is why they were only available for a relatively short time. Anyone who ever tried to work with them — such as the author — will certainly know why they weren't a resounding success like the EE boxes. The ME kits couldn't compete with other mechanical construc- tion systems that were very popular at the time, such as Meccano and Fisher. Many of the parts were much too fragile for clumsy children's hands, and in some cases the proposed structures did serious damage to the components. In particular, the pins that were used for gearwheels and all sorts of connections between axles were subjected to heavy loads in these designs, and they could head straight for the rubbish bin after the project. Fortunately, these pins and other parts could be obtained as spare parts at that time. No matter how nice some of the projects looked on paper, they were often not espe- cially solid or robust. As a result, many hours of painstaking assembly work were often rewarded with a mechanical construction that was quite capable of self-dem- olition. The ME kits used only clamped connections, and in many cases they were not good enough to accommodate all the mechanical forces. But the nice thing about the ME system was the enormous vari- ety of structures you could make with them — from mechani- cal clocks to real water pump- ing installations. There were also construction projects that used parts from the EE series in a combination of mechanical and electronic engineering. An example is the car in the photo. It stops automatically when it drives on top of a dark surface. Nowadays this is a very simple application with quite simple technology, but it had a certain magic for a small boy! Philips also tried to get even younger children interested in mechanical engineering and thus create a pool of new cus- tomers for the ME kits. Philo- form, a construction system that 130 elektor electronics - 7-8/2007 strongly resembled Lego Technic and could be used together with ME, was introduced in 1968. However, the end of the line for these mechanical construction materials from Eindhoven came in 1970. Incidentally, the first ME kit, the ME1200, had a very strong feature with regard to mechanical engineering. The mechanical parts were housed in a wooden box with a sliding lid. Probably for this reason, they have survived the years relatively intact, and you can regularly find complete or practically complete kits offered on Ebay and similar auction sites. They usually change hands for around twenty to thirty pounds, naturally depending on their gen- eral condition. Just as with all old things, there are collectors who are interested in them, and there are various websites where you can find more information. ( 070277 - 1 ) Web Links http://ee.old.no/mechanics http://sharon.esrac.ele.tue.nl/~paOib/bouw- dozn/index.html www. hansotten.com/philipsmel 200.html www.girdersandgears.com/norelco.html 2_ 3_ 4 5_ 6_ 7_ 8 9 10 13 14 19 20 21_ 22 _ 21 _ 28 11 32 © © MCLR/VPP RAO/ANO RA1/AN1 RA2/AN2 RA3/AN3 RA4/T0CKI RA5/AN4/SS RE0/RD/AN5 RE1/WR/AN6 RE2/CS/AN7 0SC1/CLKIN 0SC2/CLK0UT RB7/PGD RB6/PGC RB5 RB4 RB3 RB2 RBI RBO RC0/T1CKI RC1/CCP2 RC2/CCP1 RC3/SCK/SCL RC4/SDI PIC18Fxxx RDO/PSPO RC5/SD0 RD1/PSP1 RD2/PSP2 RD3/PSP3 RD4/PSP4 RD5/PSP5 RC6/TXD RC7/RXD RD6/PSP6 RD7/PSP7 12 31 4° 39 38 37 36 _3S 34 33 15 16 17 18 23 24 25 26 29 30 +5V (±> C2 U±3 10|a < 2 > Cl 220n | R6 R4 R CO CO CO CO CO CO ITT C3 U±3 10n SD cart in SPI mode viewed on contacts 070318-11 B. Broussas Although 'just for fun' robotic applications can usually make do with the few bytes to few hundred bytes of Flash memory that's available in most current microcontrollers, certain more 'serious' or more complex applications do need much greater mem- ory capacities. A mobile robot may hold in its memory a complete mapping of an area in the form of co-ordinates like those provided by a GPS, for example. Alterna- tively, it may be required to collect a large quantity of data furnished by its sensors. Faced with such a situation, it is of course possible to produce one or more special memory cards using the high-capacity Flash EEPROM packages available on the market today. However, this approach fairly soon comes up against numerous problems. The first is making the necessary PCBs. Most memories of this type are only available in SMD packages, and their close pin spac- ing makes producing a PCB a tricky job for amateurs, not to mention the difficulty you then have soldering such ICs correctly. The second problem is that as these memories are intended above all for the professional market, they're sometimes very difficult for amateurs to get hold of. So in this article we're proposing an origi- nal solution to this problem, provided your robot is fitted with at least one PIC microcontroller and you don't mind pro- gramming it in Basic. You'll agree these are relatively minor constraints, especially when you think that by doing it this way you'll be able to give your robot a gigabyte or even more of memory for just a few tens of pounds! The memory we've adopted is quite sim- ply the memory sold in the form of SD cards (Secure Digital), originally intended for digital cameras and portable music devices. This memory is very inexpensive today (around £ 7 for 1 GB at the time of writing), very compact, and unwaveringly reliable, provided you do not exceed the maximum number of write cycles, which is however hundreds of thousands, or even millions, depending on how optimistic the manufacturers are... The hardware interfacing of such memory with a PIC microcontroller is relatively easy, as the SD-type memories' mode of operation is compatible with the SPI-type synchronous serial interface available in these microcontrollers. The only thing to watch out for is the electrical levels, as these memory cards work on 3.3 V while the PICs in our robots are most often pow- ered from 5 V. The figure suggests a circuit that can be used with all PIC microcontrol- lers in the PIC18 family from Microchip. However, the problem is noticeably trick- ier when it comes to the software for managing these memory cards. Contrary to what we might at first think, these are not just simple EEPROM Flash memories with serial access, but modules that have their own internal intelligence. So it's not possible to read or write directly to these memories as you would do with an ordi- nary serial access EEPROM like a 24C16, for example. The dialogue has to respect a precise pro- tocol, as the card only recognizes and responds to a certain number of com- 7-8/2007 - elektor electronics 131 mands. We also have access to various internal registers with quite specific pur- poses. Lastly, the location of the data in the card is not just 'any old how', but follows a principle similar to that found on diskettes and hard disks, using in particular a FAT (File Allocation Table) that shows where the data, contained in files as a result, are stored. Even though it is possible to manage all this information by writing the necessary sub- routines yourself in machine language, this is a long, tedious, and error-prone task. Very fortunately, if you're interested in using such a memory card in your robot, there is one Basic compiler (for PIC micro- controllers only, at the time of writing) that has a full management library available for SD-type memory cards wired as shown in our figure. This is the MikroBasic compiler from Mikroelektronika, which you can find on the publisher's website (www.mikro- electronika.co.yu), with a working demo version allowing you to try it out before buying. Apart from those standard func- tions available in all Basic compilers for PICs worthy of the name on the market today, it has a full management library for SD-type memory cards (also for Compact Flash types, but they're not the subject of this article). We're not going to detail here the sixteen instructions available for manipulating SD cards, especially since you can download the manual for this compiler free of charge from the publisher's website. Just be aware that using this product makes the manage- ment of such cards ever so much easier, to say the very least! So for example, if you have filled a buffer and want to now store it onto the SD card, all you have to do is write: status = Mmc _ Write _ Sector (number, buffer) where: • status is a variable containing a numeric code returned by the command indicating the outcome of its execution (0 for successful, 1 for an error sending the command, 2 for an error during the writ- ing proper). • number is the number of the SD memory sector we want to write to (we explained above that the data storage is similar to that on a hard disk, and now you can see this in practice). • buffer is the label marking the start of a buffer able to hold up to 512 bytes, which is the size of the SD card sectors. Reading the information stored on the SD card and transferring it to the robot proces- sor's RAM is just as simple, and amounts to a single line of code: status = Mmc _ Read _ Sector (number, buffer) where: • status is a variable containing a numeric code indicating the outcome of the execution of the command (0 for suc- cess, 1 for failure). • number is the number of the SD mem- ory sector we want to read. • buffer is the label marking the start of a buffer whose size must be at least 512 bytes; this buffer is going to receive the data read from the selected sector on the card. As you will note, it would be difficult for things to be much easier, even though in this article, by nature only a summary, we have not said anything about the card's FAT management instructions. However, the latter are much less frequently used, once the structure of the card is defined, and a detailed, annotated example about these is given in the compiler manual. So then, if your robot needs lots of mem- ory, lend it the SD card out of your camera and pay a visit to Mikroelektronika (www. mikroelektronika.co.yu). ( 070318 - 1 ) Raj. K. Gorkhali The circuit presented allows you to control home electri- cal appliances like TVs, fans, lighting, etc. by clapping your hands. Four different electrical equipments can be controlled using changeover contacts on relays. The circuit diagram shows a condenser (electret) micro- phone Ml connected to the input of preamplifier T5. The sound picked up by the microphone is preamplified and fed to the input (pin 2) of a 555 timer 1C set up in monostable configuration. The output of the 555 is con- nected to the clock input of a 7490 counter. Whenever a pulse arrives at the clock input of IC2 (pin 14), it produces a 4-bit binary equivalent code at its four outputs. As an exam- 132 elektor electronics - 7-8/2007 pie, when the first pulse is applied to the 555's TRIG input, the binary coded output on the 7490 will be 0001, for the second pulse the output will be 0010, and so on. For the 15 th pulse, the output will be 1111. On receiving the next pulse, IC2 automati- cally cycles back to state 0000. The counter's four outputs control driver transistors T1 through T4. These, in turn, control the four relays RE1 through RE4, and their contacts, the equipment to be controlled. Four rectifier diodes, D1 through D4, are connected across the four relay coils to prevent back-emf surges upsetting the operation of the circuit. The circuit can be tested in a simple man- ner. Power the circuit from a regulated 5 V (or 6 V) supply. Temporarily disconnect the CLKA input of the 7490 from the 555 output. Solder a wire on the CLKA input and use it to touch the positive supply rail. Each time a clock pulse is applied in this way, RE1, RE2, RE3 and RE4 should ener- gise or de-energise in one of 16 different configurations. Re-establish the connection between IC1 and IC2 and clap your hands near to the microphone. The relays should respond as with the clock pulse test. Finally, con- nect four electrical devices to the relay contacts. The use of a 5 V regulated supply is rec- ommended for this circuit. The relay con- tacts should be rated for 230 VAC as well as for the maximum current the electrical equipment is likely to draw. All relevant electrical safety precautions should be observed when connecting mains powered loads to the relay contacts. ( 070092 - 1 ) Antoine Authier In 2006, the Lego MINDSTORMS® RCX blocks became NXT blocks. They have a quite surprising avant-garde shape — in place of the traditional compact RCX block, for the NeXT generation motor the Lego engineers have opted for a 'pistol' profile. This block comprises a motor, a rotary encoder, and a step-down gearbox. Its weight is all of 80 g! The DC motor seems to be a standard type. It is located in the larger-diameter light-grey cylindrical part, under the Lego logo. Powered from 9 V, it draws 60 mA off load with a speed of 170 rpm (360 rpm and around 3.5 mA for an RCX motor). The internal step-down gearing increases the torque available at the output disc, which is great for power applications. On the other hand, the slower rotation will be seen as a drawback for speed applications. The data provided by the rotary optical encoder allow the NXT unit software to determine the angle of rotation to the near- est degree. Not having dissected the block, we can only surmise how this precision is obtained from the encoding disc that only has 12 slots. The block contains two electronics assemblies: one is the module that conditions the signal from the optical detector, the other protects against poten- tial overloads. This comprises over-current protection in the form of a resettable Polys- witch® fuse, and a 15 V surge limiter. At one end of the block is the orange drive disc. At the other end is the RJ11 power input and data output connecter. It has a key to avoid confusion with a standard tel- ephone cable. Interested readers will find the character- istics and views of the innards of the block on Philo's web pages [1], [2]. ( 070371 - 1 ) Web links (1) Philo's NXT® motor internals: http://www.philohome.com/nxtmotor/nxt- motor.htm (2) Lego® 9 V Technic Motors characteristics compared: http://www.philohome.com/motors/motor- comp.htm 7-8/2007 - elektor electronics 133 I t . KH.^J iJappLn,' h rt>,T f u.l il> t I mini - ;s! m| LtF E’ f V'.VE- Pvi'V' IMJEL ■■ X 1 I 1 !. -j* ("Vf DEstru £j ; i- i «yi manual j|| -jjm *1 n\±H [r-*irt 3 P^S5 3 |Mrt d I 3 z 7* X4 ms tdmh ■ ■ ■ > v? : Electronic CAD available to all Remy Halvick For the month of November, 2005, we had electronic CAD as the theme of Elektor magazine. The issue came with a free DVD packed with software, most of it operating as a Windows demo version. One of the programs stood out due to several unique features. Actually, KiCad is a software package distributed for free under a GPL license, operating in Linux, Windows and Mac OS X environments. As an added treat, this marvel is available in a remarkable number of languages! Things have greatly changed since the time when electronics hobby- ists (professional and/or amateur), peered over schematic diagrams for many hours, drawing circuits with pencil and paper, then pro- duced it all over again for a 'clean' version. Businesses were the first to have the means to utilise CAD software such as Oread or Protel, on powerful systems with staff especially trained for this task. For a long time, this was too expensive for amateurs. Electronics fans today are much more spoiled — they can utilise programs that use little resources, at reasonable prices; some even come as light' version for free, but with restrictions that seriously limit would-be users. KiCad was of course included on the free 'Kaleidoscope' DVD. It was developed by a professor/researcher, Jean-Pierre Charras, from the Joseph Fourier University in Grenoble, France, in order to learn programming in C++, as he claims. The first rough drafts were begun in 1992 in DOS, the most recent versions are avail- able as downloads on the university website (see the links at the end of this article). The supported OSs are numerous in addition to Windows (2000, XP, and W98 with slight restrictions), the oth- ers were delivered, tested and ready to operate with Mandriva and Cen- tOS distributions. It also was just inte- grated into the Debian distribution, thanks to the efforts of a few dynamic volunteers. Users have also compiled sources in numerous other OSs: Sola- ris, FreeBSD, etc. Mac OS X remains an exception, because, even if KiCad can be compiled on these machines, its operation is currently still hampered by a bug from the Open Source wxWidg- ets graphic library, used by KiCad. Let's hope that this problem will be resolved soon: the new version will be distrib- uted as soon as that happens, and the same is true for those that operate in Linux and Windows. KiCad is available in the following languages: French (original language), English, German, Spanish, Portuguese (Brazilian), Italian, Slovenian, and Hungarian for the user interface (GUI). The user manuals are available in the primary four languages. Ver- sions in German, Hungarian, Polish, Korean and Russian are at various stages of translation. Tutorials are also appearing in several languages: French, English, Brazilian. All of these documents have are created by volunteers who believe in Open Source and free software. If the price of this software package defies all competition, that does not mean that you will have an 'inferior' tool. Even though KiCad is far from being an overly complicated software package like Oread and Altium, its qualities are nonetheless remarkable: you can judge by the screenshots. The graphic interface, simple and very easy to learn, is intuitive and powerful, thanks to one of the many features that uses a 3-button mouse. The keyboard shortcuts are limited in number but efficient. The various output formats (printer, Postscript, Gerber, hole-making and automatic placement files) are flawless and adapt to all printers, as opposed to some DOS software. This software package is composed of: • KiCad: project manager, from which one can launch the follow- ing programs. • EeSchema: simple or hierarchical schematic capture. • CVPCB: used to link components with their schematic footprints. • PCBNEW: design of printed circuits. • Gerbview: display of Gerber files. Installation KiCad is available on the DVD that accompanied Elektor Electron- ics , November 2006. More recent versions can be downloaded from the websites devoted to KiCad (see links 1 and 2). At the time this article was written, the current version is dated August 28, 2006. Archives in .tgz or .zip format are about 70 MBytes. To install the software package, you just need to decompress the 134 elektor electronics - 7-8/2007 archive in C:\Program Files\ or /usr/local for Linux users, and to place a link pointing to the executable KiCad file in the sub direc- tory X:\kicad\winexe or /usr/local/kicad/linux. That is the extent of it — no further torture will be inflicted on your precious PC. KiCad The KiCad project manager (Figure 1) allows you to create or select a project; meaning mainly schematics and a printed circuit. In this way, you also have access to the language selection options for the graphic interface and online help. EeSchema EeSchema (Figure 2) lets you input a simple or tree (hierarchical) structure. The screenshot is used to get an idea of the simplicity of the interface which does not, however, sacrifice functionalities. The menu toolbar only has three sections: File, Preferences, and Help. In addition to the traditional open/save/print options, the File menu allows you to generate drawing files in PostScript, HPGL, and SVG formats. In Preferences, you can select which libraries to be used (which will appear when adding components), as well as various options: colour, display and grid pitch (scale), orientation and incremental values for repetitive tasks; all of these options may be modified, of course, if the need should arise, although the default options satisfy most needs. The help menu is very standard. Three icon bars give you access to most of the tools which you will need. The one on the left lets you manage the graphic look': grid display, its pitch, measurement units (millimetres or inches), cursor shape, orientation of the lines (by 45° increments or any orientation); the icon (A) lets you display the hidden power con- nections to the parts. Due to their small size , we propose icons in a magnified version in Figure 8 with the reference letter. The icon H is actually a double icon. The upper bar has various tools: file manipulation (open, save); button (B) allows you to choose the page format (A4 to AO and A to E, as well as a custom format defined by the user) and to fill in the various sections of the of the schematic. The next version of KiCad, which apparently is about to be released, will add an Undo/Redo function to EeSchema. The next two icons relate to the Libedit component display /editor (Figure 3); in fact, you can create any special symbol that you might need for your schematic. The CVPCB and PCBnew icons follow after the traditional editing tools (cut, copy, paste) and print; we will examine their role a lit- tle later. The 4 following tools deal with display: + and - zoom, drawing refresh and auto zoom which lets you have a better look by reframing the entire schematic. These functions are also acces- sible from the FI to F4 function keys. When the diagram becomes cluttered, sometimes it is difficult to find R59 or U12; you can then use the search tool by clicking on (C). The following icon (D) allows you to generate a netlist in different formats; you can even have yours by creating a plug-in! Before arriving at this point, you would have taken care to number the components, thanks to the automatic annotation tool (E). The next-to-the-last tool in the top toolbar (F) is very useful: it deals with verifying that the electrical rules are respected or DRC (Design Rules Check). The principle is the following: each component pin is defined while it is being drawn as input, output, open-collec- tor, 3-state, etc. The DRC tool will carry out various plausibility checks: output connected to the power supply, unconnected gate input and others; you can define the checks as well as their result: error, warning or no error in the options tab. This is used to avoid gross errors and forgotten connections. The last icon is for generating the list of components (BOM = bill of material), which will help you with your shopping, especially if you export it to a spreadsheet in order to optimise supply sources. Figure 1. KiCad is project-based, just like similar products on the market. Figure 2. EeSchema: easy schematic capture. Figure 3. If you haven’t found the component you need on the Internet, there is nothing to stop you from designing it with Libedit! 7-8/2007 - elektor electronics 135 tual menus, with one right mouse click. That is one of the strong points of Kicad, which, by proposing the tools at the time they are needed, makes it possible to preserve a clear and easy to grasp interface. Nothing like those heavyweights with their dreadfully cluttered user interface, almost impossible to master by anyone who is not a specialist. These contextual commands are depend- ent on the part you choose to click on, using the right button. For example, clicking on a component opens the following possibili- ties: move, orient, edit, copy, or delete the component, front/rear zoom, auto function, recalculate the drawing, select the scale. The menu is adapted depending on whether you clicked on a compo- nent, a wire, a text field, etc. The mouse also makes it possible to display a zone that you will select by clicking with the wheel: without a doubt, efficient and practical! The status bar, at the bottom of the window, gives you the follow- ing information: zoom factor, absolute and relative coordinate of the cursor and measurement units (inches or millimetres). Figure 4. CVPCB: choice of component case. Figure 5. Design PCBNew printed circuits. The right icon bar groups the different drawing tools: adding com- ponent (the gate), connection by wire or bus, labels, commentar- ies and other embellishments that will improve the presentation of your schematic. The rest of the required commands are accessible from the contex- Figure 6. 3D display of the capacitance meter as described in Elektor. CVPCB CVPCB, accessible from EeSchema or KiCad, makes it possible to link a case to each component from the net list that you will have created in EeSchema (Figure 4). There, also, in addition to the print libraries that come as standard (through-hole or SMC components), you can download many others on the Internet. If you use KiCad intensively, you can eventually use the automatic association sys- tem component case that makes it possible to automate this task. PCBNew You gain access to PCBNew from the KiCad project manager (rec- ommended), or directly using the icon (G) (Figure 5). This printed circuit design software is made in the image of EESchema: simple, easy to get used to and easy to use; that does not mean its per- formance is lagging, here are some examples: 16 copper layers, 12 technical layers (lithography, resist coating, dimensioning, etc.) components, through-hole or SMC, work done to one/ten-thou- sandth of an inch, dynamic rats-nest, Design Rules Check, ground plane, and it has a very capable high-performance internal router that can operate in a single-sided layer! What more can an ama- teur ask for? And a 3D view of the board surface just for the visual pleasure. It is shown in Figure 6! But let us begin by the beginning: PCBNew. The general philoso- phy of this graphic interface is the same as the one for EeSchema: simple, easy approach, but also as efficient, thanks to an intensified utilisation of the mouse and the contextual menus, and the defin- ing of the two operating modes: placement (FI left) and routing (H right). These two modes will affect the contextual menus that will be shown. We will not insult you by reviewing file menus and preferences, except to remind you of the output formats: PostScript, HPGL, Gerber 274X, and Excellon, in addition to your favorite printer. The 'Dimensions' menu is used to define... the dimensions by default of the traces, vias, pads and texts. The 'Miscellaneous' section groups 1C detailing accessories. The post processors enable the automatic placement file generation of components and hole-making files. This gives you the possibil- ity of having your 1C made by a professional, by sending him the necessary files. The '3D' and 'Help' menus speak for themselves. Under the different menu bars you will find scrolling lists that allow you to easily change the width of the trace, dimensions of the vias, grid pitch number of the layer and zoom. The icons located on the left of the window are related mainly to what is represented on the screen: display of the polar coordinates in the status bar, measurement units, shape of the cursor, display of the rats-nest (representation by segments of the connections to be routed), 136 elektor electronics - 7-8/2007 automatic erasing of traces that you have re-routed, display of pads and traces in full lines or in contours, in high-contrast display. The upper icon toolbar, just like in EESchema, groups the file com- mands and the selection of the sheet format. The next icon allows you to access the module editor (or footprints) of the components in the unlikely case that the libraries supplied and those available on the Internet are insufficient. Its operation very much resembles the one of the LibEdit component editor, which means you should feel more comfortable with it. We have no specific comment on the following print and tracing icons except that they resemble the ones in EESchema. (D) is the starting point for designing a printed circuit: reading the netlist. Your components are found In bulk' next to your sheet. To spread out the components in order to be able to then gather them, go to placement mode (I). With one right click, do global move and place -> Move all of the modules: and all of your com- ponents will be carefully aligned. If you prefer, after having defined the contours of your printed circuit (select the PCB contour layer and define a closed figure that pleases you), then Global move and place -» Autoplace all of the modules. It will do half of your work by optimising the length of the connections. Any intermediary state is conceivable with the interactive auto placement options. It is already time to move from placement mode to routing mode with the icon (J). With one right click, do Global autorouting -» Select layer coupling. It usual to choose a one-sided circuit board; in other words, the top layer will be in copper, just like the lower layer. The autorouting feature (global autorouting -» Autoroute all modules), will greatly lessen the work, if it does not route your entire board. All that remains is to finish in manual mode, or to move a few components and re-route the overall project. Manual routing is accomplished, of course, with the mouse, and you will quickly notice that PCBNew knows how to place your traces in a well-disciplined fashion, without laboriously defining the smallest change in orientation. Displaying the rats' nest (K), (see Figure 7) enables quick and reliable work. If straps are required, they will be shown on the traces on the component layer (in red on Figure 6). Once the routing has been finished, you can add centring targets, dimensioning, and any other graphics such as a logo, copyright symbol, etc. A wise precaution consists of carrying out a DRC check, in order to ensure that no routing error or short-circuit still exists. All that is left is for you to do is to print or plot, to start with on paper, in order to determine the factor of the precise scaling, setting it to the scale requested by your printer. You can then print a transpar- ent to isolate your 1C or to generate the files requested by your supplier. Of course, professionals may demand much more from KiCad; a certain number of companies are already using it around the world. Figure 7. The rats’ nest in white lines. Internet links (1) Kicad 1 homepage www, lis.inpg.fr/realise_au_lis/kicad/index.htmlx (2) Kicad 2 hmepage iut-tice.ujf-grenoble.fr/kicad/index.html (3) An active group! http://groups.yahoo.com/group/kicad-users/ (4) Libraries, user guides http://www.kicadlib.org/ (5) KiCADWiki http://kicad.bokeoa.com/wiki/index.php/Main_Page (6) Utilities http://www.rohrbacher.net/kicad/quicklib.php (7) Goodies from Brazil: footprints, utilities, etc. http://www.reniemarquet.cjb.net/kicad.htm (8) KiCAD, from the professional point of view http://xtronics.com/reference/kicad.html (9) Developers http://developer.berlios.de/projects.kicad (10) Kicad hosted in a free world http://kicad.sourceforge.net/en/index.shtml In conclusion KiCad is a real windfall for the creative electronics fans among you. It thus becomes possible to create, exchange and modify schemat- ics and printed circuit board designs at will. No more searching for a jack connector with unobtainable placement or 'butchering' a circuit in order to adapt it ever so slightly. With KiCad, you have total freedom, especially if, as we hope, electronic magazines pub- lish more or less finalised versions of schematics and/or PCBs of proposed projects on the Internet, rather than a fixed PDF. That would signify that anyone and everyone can adapt, convert or even transform them at will (maybe with a simulator in the future?.. But hush! nothing has been done on that yet!). Better yet, be assured that in case of problems, help will be available to you rapidly on the user's forum (link [3]). ( 060373 - 1 ) (11) Kicad, from the Russian point of view. http://ru.wikipedia.org/wiki/Kicad Figure 8. The main icons on a large scale and in low resolution (the originals are a standard size, 16 x 16 pixels). 7-8/2007 - elektor electronics 137 In this Summer Circuits issue with robots as its theme, we can hardly afford to overlook the RoboCup. The RoboCup is a collective international project with the objective of fostering research in artificial intelligence, robotics and related fields. Football has been selected as the basis, and the ulti- mate objective is to have a team of fully autonomous humanoid robots in 2050 that can defeat the world football champions. Four leagues are open to participants: the simulation league, the small and mid- sized league, the four-legged league, and the humanoid league. A team from Philips is participating in the mid-sized league (MSL). The robots in the MSL must be DIY con- structions and must be autonomous. This means that all their intelligence must be on-board, and nobody is allowed to con- trol the robot from the sideline. The Philips robots are equipped with the following components to enable them to play football: • two Vision cameras (one fixed camera at the front and one omnidirectional camera) • a PC • a PLC controller • a wireless network interface • four wheel units • four sensors for detecting the white lines • a ball handler • a shooting mechanism • batteries The Vision cameras are the eyes of the robot. The robot filters the incoming images, using colour to recognise the ball, the goals, the corner posts and other robots. The camera at the front helps with precise orientation. The robot uses the omnidirectional camera, which is oriented upward toward a special mirror, to keep an eye on its surroundings so it can see where it is and what is happening around it. The PLC controller monitors the status of the robot: are the batteries still OK, is the shooting mechanism working properly, etc. The robots on the team communicate with each other via the wireless network, so they don't try to steal the ball from each other. The built-in PC runs on Linux and proc- esses all the data used by the robot to determine where it is and what its best plan is for getting the ball and scoring. The white-line sensors help the robot deter- mine where it is. The PC drives the four wheels of the robot via a special module. Each wheel can be turned and driven independently. This means that the robot can make a pirouette while heading toward the ball. The purpose of the ball handler is to keep the ball as close to the robot as possible without actually grasping it. Grasping the ball is against the rules. The ball handler lets the robot move sideways and back- wards without losing the ball. It also helps the robot shoot the ball straight forward. It holds the ball directly in front of the shoot- ing mechanism, which can 'kick' the ball at approximately 30 km/hr. The energy for the shot comes from a spring, which can be wound up in a couple of seconds and is released when the software gives the order to shoot. A total of eight robots participate in each game (four on each side). They play on a field with dimensions of 8 by 12 metres, and the game begins with looking for the ball after the referee gives the starting sig- nal. After the ball is found, the trick is to travel toward the opponent's goal in order to score, and of course to try to avoid los- ing the ball to an opposing player. Natu- rally, the robots also try to steal the ball from the robot of the opposing team before it can score a goal. As the robots operate entirely autono- mously, their behaviour must be pro- grammed in advance. A collision is pun- ished by a yellow card, and a repeat offence yields a red card, which means the robot has to leave the field. The robot shoots at the goal as soon as the goal opening is large enough. However, win- ning takes more than just firing off hard shots; speed and tactics are at least equally important. ( 070359 - 1 ) 138 elektor electronics - 7-8/2007 ancrc uxwa-TJHt 'b A b Ajv/ jl a / AfiON DM-fili lil*F"l«l trr tlW Atnrt «M>, )A». fJndplF « f ppctnim. AK*U*G*nm40*t(4! ljtahn flTKf-flr-aiEP how rn fj i i.-j o ±MP 0*1* WIVW OurtT p*ji*%3x h*? c^w* t*w tNftt I MFG* - ' J v ' ' fj- f. -- n lml*k*d Sr» 1 <- Ell'.Hlr/n f .WLv. Uni' WWW. I AME S' "ATION, PH! ? SS- .7-36-- -E u L ?tJ j r.ij P^qffrfej NL^Hvq.NErr r — C* 1 ■ tjVl L :x T0 ll 01 635 40347 NiTf/liity FlpclEi3:iic$ I NE hu: JltfXi 3E1TJ FJOdJj IfcM UMtfert takl idlt i*D f-m»i circrnitfiAfAbtirf tum,w;uk c u A SERVICING YGUR COMPLETE PROTOTYPE NEEDS 1 EUROCARD (160 x 100 mm) + Tooling + Photoplots + VAT €49 ~. Price example Any size and contour possible! Optional: • Soldermask • Fast-turnaround • Silkscreen • 4-Layer Multilayer • 6-Layer Multilayer tmtitifo \t> dm Freephone 0800-3898560 frhrjd B « ^9 Simply send your files A/* A A/l/1 # /*/lj|J| and order ONLINE: rV0"rVlfi«V Uiwi ClmScan 5 USB Scon Tool Diagnose any car with EOBD Based on the ELM327 1C Supports all EOBD and OBD-II protocols ✓ ISO 1 5765-4 (CAN) ✓ ISO 1 4230-4 (Keyword 2000) ✓ IS09 141-2 s JI850 VPW SJI850 PWM 9600 or 38400 baud Supported by more software than any other OBD interface Inexpensive Full Speed USB 1.1 Automatic protocol detection Package includes cables, software CD, and Quick Start Guide Buy from your local UK distributors! Your price conscious PCB supplier CIRCUITS Online price calculation Online ordering Online order tracking Online 24/24H and 7/7D Interested? Contact u*: +44 ZOBB 167 006 E- ma If £ c u ro@cu r oci rcu its .coni www.eu rocircuits.com Verified m pooling for standard boards up to € layers from 1 to 1000 pieces from 3 working days onwards - pooling weth more options - up to € layers - from 1 to 10 00 pieces - from 3 working days onwards your boards gur challenge up to 16 layers from t piece onwards front 3 working days onwards 7-8/2007 - elektor electronics 139 In this bumper double issue of Elektor, staunch supporters of our monthly Hexadoku puzzle (their numbers growing steadily) find themselves confronted with a horrific attack on patience, intuition and intelligence, by a monster puzzle baptised 'Alphanumski' by its creator. The method of solving the 36x36 cell Alphanumski puz- zle shown here is basically the same as for a 9x9 cell Su- doku, a 16x16 cell Hexadoku or even last year's 25x25 cell Alphadoku. This month we're using all letters of the alphabet (A through Z) and all numerals (0 through 9) to be entered in the cells that make up lines (1x36 horizontally), columns (1x36 ver- tically) and boxes (6x6). In Alphanumski, all letters of the alphabet (A through Z) and all numerals 0 through 9 should occur only once in every line (1x36), every column (1x36) and every box (6x6; iden- tified by red outlines and a background colour). A number of clues are given in the puzzle and these repre- sent the start situation. All correct entries received for the puzzle go into a draw for a main prize and three lesser prizes. All you need to do is send us the combination of seven letters and nu- merals in the grey boxes. The puzzle is also available as a free download from our website.. ( 070151 - 1 ) A R 3 D 1 Z W D 6 L 3 T 1 Q 5 G J A 2 0 H E 6 7 0 K U Y 7 0 s L P 6 H Y 2 N 9 I Q 6 Q N B J I E 8 V 4 5 D 3 L C Y I Z s K N E X 7 R 1 B J X T s 0 V 5 I L M Q A D 0 8 u 2 Y 9 V 8 c 2 4 5 M 6 R 0 B 6 0 E T w B Q 9 N X F 3 1 J 3 O 6 w E I L T K A 6 u V I P D J N G 8 W 1 5 F J 6 0 P 9 4 I 2 3 V 7 8 O W H N P L u S 9 N 6 D U B 5 M E Y K u M C X R 4 A D G N 3 P 2 0 D E Y S Q K T 6 Y Q R X 9 2 K 7 A F 0 H 0 s K 5 D 2 Y R G H V I T M A I N u 1 C W Z B 8 Y 9 F L 2 0 Q Z T E D i U E P N 0 L F 4 2 5 X 6 B 6 H T X 3 L 0 P A z 4 8 D A 7 6 V N J Q U 8 2 4 V Y 0 N K J Z A Q w P B S T L V u Y 2 4 H Q F 3 6 2 M D B E i T 7 I w P A R F X s 6 9 U 0 D 0 c 3 6 P I K V F L J u J Y H K 5 z A I D 0 M F 8 H Y R i J 3 7 w D G R J 3 M B D Y P L 6 E B s Q X w P 0 T i 0 3 I 5 T 6 S 7 W 2 Q 8 c 2 A K L 6 Q u N R 4 L i 7 2 H V 8 9 O A I B X 140 elektor electronics - 7-8/2007 Y M 7 I J 6 6 X F Q L 8 c B 8 S 0 I E 0 N D i J I F P L R X 9 S A 0 u T B 3 W z E 6 J 1 R 0 s 9 X W 7 T 2 A H Y C L 2 4 9 D 0 5 U P H B 6 E 8 Q 5 L I 0 9 7 6 R w F T R N P 7 X E 0 I L 3 Y N A F 0 K D 1 J Z C V H Y 4 D K U 2 I 6 0 D s 2 8 M B A 0 B 9 2 i X E Z M L c N M H E X A D 0 K U V L T 6 2 Y D K 0 B 5 9 i 6 J c z X H 0 7 2 P A R s F 9 V s T Q 0 w 0 i 6 2 7 A 0 5 4 U J 6 B N X Z L M 1 E c 4 S N 6 I p 8 5 E p X w L 8 N C 4 T 6 H J L 5 Y 9 6 D E 2 0 A 3 P 7 4 W 8 u J M W c Y D z V T J H 6 R 8 F 7 K Z 0 2 u Q M 5 9 i s 2 5 T 6 E K 0 M C L X P B 3 s X u 6 C I F 6 i w 6 7 3 F 0 E 8 A 9 Y 4 0 I R X H N K A Z S J 5 0 H Q 2 Y 3 K U A 2 5 Q W s Y 1 B N 7 N R p 9 6 4 W M 6 0 2 X V 5 s B P L A Q 0 H 8 I z 0 F N i T c 5 u X N R 9 M A 2 Y 7 H L 8 D L 6 K X J N 0 3 3 J w B 0 D V S H T M K u D T S c M 6 5 J W 6 E R Y Solve Alphanumski and win! Correct solutions received enter a prize draw for an E-blocks Starter Kit Professional worth £248.55 and three Elektor Electronics SHOP Vouchers worth £35.00 each. We believe these prizes should encourage all our readers to participate! Participate! Please send your solution (the numbers in the grey boxes) by email to: editor@elektor-electronics.co.uk Subject: Alphanumski 07-2007 (please copy exactly). Alternatively, by fax or post to: Elektor Electronics Hexadoku Regus Brentford 1 000 Great West Road Brentford TW8 9HH United Kingdom. Fax (+44)(0)208 2614447 The closing date is 1 September 2007. The competition is not open to employees of Segment b.v., its business partners and/ or associated publishing houses. Prize winners The solution of the May 2007 Hexadoku is: B789E. The E-blocks Starter Kit Professional goes to: Michele Casartelli (I). An Elektor SHOP voucher worth £35.00 goes to: David Meiklejohn (AUS) ; Tomas Bakke (N) and Franz Klein (UK). Congratulations everybody! 7-8/2007 - elektor electronics 141 ELEKTOR SHOWCASE To book your showcase space contact Huson International Media Tel. 0044 (0) 1 932 564999 ATC SEMITEC LTD www. atcse m itec . co . u k Thermal and current-sensitive components for temperature control and circuit protection; • NTC Thermistors • Current Diodes • Thermostats • Re-settable Fuses • Thermal Fuses • Temperature Sensors Call today for free samples and pricing Tel: 01 606 871 680 Fax: 01 606 872938 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 £15.00. BAEC http://baec.tripod.com "The British Amateur Electronics Club Archive Website. Archiving extracts from 140+ Newsletters from 1966- 2002. Currently have interesting and useful selected articles from 1 2 Newsletters. Also a section about built electronics projects with schematics and photos. Plus useful info., downloads and links. NO ADVERTS!" 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 cost of the usual manufacturer’s prices. ■i li DECIBIT CO.LTD. www.decibit.com Smallest 2.4 GHz ISM band MCU embedded transceiver modules. Complete tiny solution, ready to transmit RF data by only attaching as example a CR2032 coin cell to it. EasyDAQ www.easydaq.biz We design & supply low cost USB/RS232 based data acquisition, automation & control products: • USB connected & powered, 8 opto isolated voltage inputs chans, 4DI0 & 4 onboard relays capable of switching 240V@10A. With Labview, VC & VB examples - £60 EASYSYNC 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. FUTURLEC http://www.futurlec.com Save up to 60% on • Electronic Components • Microcontrollers, PIC, Atmel • Development Boards, Programmers Huge range of products available on-line for immediate delivery, at very competitive prices. 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 Advanced Qualifications). Also Technical Management and Languages. H TlvV • ELNEC www.elnec.com • device programmer manufacturer • selling through contracted distributors all over the world • 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 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 First Tvchnaiogy Tfdrtsfer 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 MODular ElecTRONics www.modetron.com • Plug and Program • FREE application s/w • Hobbyist ease-of-use • Professional finish with enclosure and LEXAN faceplate • We will design and brand your custom application • Growing range of PSU’s, i/o modules, displays and microcontrollers MQP ELECTRONICS www.mqp.com • 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 NEW WAVE CONCEPTS www.new-wave-concepts.com Software for Hobbyists: • Livewire - circuit simulation software, only £34.99 • PCB Wizard - PCB design software, only £34.99 • Circuit Wizard - circuit, PCB and breadboard design software, only £59.99 Available from all Maplin Electronics stores and www.maplin.co.uk 142 elektor electronics - 7-8/2007 products and services directory PCB WORLD http://www. pcbworld.org . uk World-class site: Your magazine project or prototype PCB from the artwork of your choice for less. Call Lee on 07946 846159 for details. Prompt service. ROBOT ELECTRONICS http://www.robot-electronics.co.uk Advanced Sensors and Electronics for Robotics • Ultrasonic Range Finders • Compass modules • Infra-Red Thermal sensors • Motor Controllers • Vision Systems • Wireless Telemetry Links • Embedded Controllers SOURCEBOOST TECHNOLOGIES http://www.sourceboost.com Next generation C compiler and development products at highly affordable prices: • C, C++, and Basic compilers for PIC1 2, PIC1 6, PIC18 • Modern IDE, with PIC simulator, source level debugger and virtual devices. • RTOS for PICmicro. • PIC based controller and Development boards. • Download and try for Free from http://www. sourceboost.com SYTRONIC TECHNOLOGY LTD USB INSTRUMENTS www.m2mtelemetry.com Supplier of wireless modules and accessories for remote monitoring M2M applications. •GSM/GPRS TCP/IP modules • Embedded GSM/GPRS modem • Development Kits • GPS modules • GSM/GPS antennas • Adapter cables Online ordering facilities. Tel: 01728 685802 COMPONENTBIN.COM www.componentbin.com Kickstart your development with modules and parts from componentbin.com • ARM7 modules • Ethernet modules • Superb Graphic LCD displays (all with example software) and much much more... Online ordering and great prices! ULTRALEDS U1 trzl eds.^ jftT ■ j. , . , . http://www.ultraleds.co.uk tel: 0871 7110413/01625 576778 Large range of low cost Ultra bright leds and Led related lighting products. Major credit cards taken online with same day depatch. 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. WWW. elektor- electronics. co.uk 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 £220 + VAT (£20 per issue for eleven issues) Elektor will publish your company name, website address and a 30-word description For £330 + VAT for the year (£30 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 £220 + VAT • Text and photo for £330 + 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 7-8/2007 - elektor electronics 143 Electronics at all the right levels “Elektor? Fun in finding solutions for my electronics hobby. Never failed to impress my boss or my wife.” -Thomas Gosling, 38, electronics enthusiast- e lektor SHJIS2-- ft >.U«4V« * pBDUl EKFlO ^ . profit*^ f * 51 IT. milling m a u Secure a head start in electronics with a subscription! iiru' Advantages to subscribers Cheaper than 1 1 issues from the newsstand ✓ ✓ ✓ ✓ Subscribers get up to 40% discount on special Elektor products As a welcome gift you get a free 1GB MP3 player worth £ 34.50 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 www.elektor-electronics.co.uk/subs Tel. +44 (0) 208 261 4509 Or use the subscription order form near the end of the magazine. 144 ^lektor L the world-leading network for electronics elektor electronics - 7-8/2007 lektor Order now using the Order Form in the Readers Services section in this issue. CD-ROM BESTSELLERS Ethernet Toolbox This CD-ROM contains all essential information regarding Ethernet inter- faces! To help you learn about the Ethernet interfaces, we have compiled a collection of all articles on this topic that have appeared in Elektor Electronics and complemented them with additio- nal documentation and links to intro- ductory articles on Ethernet interfaces. It includes a collection of data sheets for dedicated Ethernet interface ICs from many different manufacturers. The CD-ROM provides a wealth of information about connectors and components for the physical layer (PHY) and specific software tools for use with the Ethernet (Software). ISBN 978-90-5381-214-3 I £18.90 (US$ 37.90) Elektor 2006 This CD-ROM contains all editorial articles published in Elektor Electronics Volume 2006. Using the supplied Acrobat Reader program, arti- cles are presented in the same layout as originally found in the magazine. All free, printed, supplements our readers got last year, like the Visual Basic, C and i-TRIXX booklets are also contained on the CD. The Elektor Volume 2006 CD-ROM has a rather different look and feel than previous editions. It’s gone through a makeover in more than one way! ISBN 978-90-5381-207-5 I £16.25 (US$ 28.75) Robotics A large collection of data- sheets, software tools, tips, tricks and Internet links to assorted robot constructions and general technical infor- mation. All aspects of modern robotics are covered, from sensors to motors, mechanical parts to microcontrollers, not forgetting matching programmingtools and libraries for signal processing. ISBN 978-90-5381-179-5 I £12.05 (US$ 21.25) ,p.i \ 1 * S;.; jjl Jl fS .s g|i 1 i j m.*? * mk r t fir I 1 Elektor Electronics (Publishing) Regus Brentford 1000 Great West Road Brentford TW8 9HH United Kingdom Telephone +44 208 261 4509 Fax +44 208 261 4447 Email: sales@elektor-electronics.co.uk More information on www.elektor-electronics.co.uk Microcontroller Basics Microcontrollers have become an indispensable part of modern electronics. They make things pos- sible that vastly exceed what could be done previ- ously. Innumerable applications show that almost nothing is impossible. There’s thus every reason to learn more about them. This book offers more than just a basic introduction. It clearly explains the technology using various microcontroller circuits and programs written in several different programming languages. In the course of the book, the reader gradually develops increased competence in converting his or her ideas into microcontroller circuitry. Visual Basic for Electronics Engineering Applications This book is targeted towards those people that want to control existing or home made hardware from their computer. 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 necessary, schematics are provided that will get your projects up to speed in no time. Mkrwqntkclur Gtf its T LJ ISBN 978-0-905705-67-5 230 Pages £18.70 (US$ 33.70) Wsaai Basic A* ** »U, Kl Mr lleoEranbcg [figlNitrkifl RiJEtiltlllm I 1: ISBN 978-0-905705-68-2 476 Pages £27.50 (US$ 51.50) BESTSELLING BO Visual Basic for Electronics Engineering Applications ISBN 978-0-905705-68-2 £27.50 (US$ 51.50) *2) Microcontroller Basics ISBN 978-0-905705-67-5 £18.70 (US$ 33.70) 3 s ) PC-Interfaces under Windows ISBN 978-0-905705-65-1 £25.95 (US$ 52.00) V) Modern High-end Valve Amplifiers ISBN 978-0-905705-63-7 £25.95 (US$ 52.00) 308 Circuits ISBN 978-0-905705-66-8 £18.20 (US$ 37.00) More bestsellers on www.elektoi^electronics.co.uk lektor © Order now using the Order Form in the Readers Services section in this issue. Order o www.elektor-el Stand-Alone OBD2 Analyser (June 2007) Software Defined Radio (May 2007) Kit of parts, incl. case, cable, front panel foil and mounting materials 070038-72 £ 51 .70 / US$ 97.50 Free downloads: Online simulator examples (070038-21) Manual (070038-W1) See www.elektor-electronics.co.uk Ready-populated and tested board 070039-91 £ 72.45 / US$ 1 26.50 Speedmaster (May 2007) The circuit voted winner of the R8C Design Competition! Ready-populated and tested board (excl. R8C module) 070021-91 £ 51 .70 / US$ 97.45 No. 367 JULY/AUGUST 2007 £ $ Dual Battery 070343-1 PCB, bare 5.20 9.75 Fast Charger for NiMH Batteries 070213-1 PCB, bare www.thepcbshop.com Lithium Charger 070273-1 PCB, bare 8.90 12.95 Low2 Cost USB Demo Board 060342-81 CD-ROM, project software 5.20 9.75 060342-41 PIC18F4550, programmed 15.15 28.50 LPC 900 Programmer 070084-1 PCB, bare 6.90 12.95 MotoBox 070129-1 PCB, bare www.thepcbshop.com 070129-41 PIC16F628-04/P, programmed 14.80 27.95 Propeller Prototyping Board for BoeBot 070275-1 PCB, bare 11.00 20.75 Satnav for Robots 070350-81 CD-ROM, project software 5.20 9.75 070350-41 ATmega32, programmed 16.50 31.15 Serial Interface for the Propeller 070276-1 PCB, bare www.thepcbshop.com Stereo Robot Ears 060040-1 PCB, bare www.thepcbshop.com 060040-81 CD-ROM, project software 5.20 9.75 060040-41 PIC16F88, programmed 10.00 18.85 No. 366 JUNE 2007 2.4 GHz WiFi Spectrum Analyser 070040-1 PCB, bare 8.25 15.50 070040-1 1 CD-ROM, Linux & Windows software 5.20 9.75 Coil Clinic 060195-1 PCB, bare 7.60 14.25 060195-11 CD-ROM, project software 5.20 9.75 060195-41 Atmega48-20PU, programmed 5.20 9.75 Linux Oscilloscope 060241-11 CD-ROM, project software 5.20 9.75 060241 -W Program listing free download Stand-Alone OBD2 Analyser 070038-72 Kit of parts, incl. case, cable, front panel foil and mounting materials 51 .70 97.50 070038-21 Online simulator examples free download 070038-W1 Manual free download Whistles from on high 060044-1 PCBs, bare; set for TX and RX 060044-11 CD-ROM, project software 060044-41 ATtinyl 5PC, programmed 12.00 22.75 5.20 9.75 10.00 18.75 No. 365 MAY 2007 Software Defined Radio 070039-91 Ready-populated and tested board 070039-11 CD-ROM, project software Thank your for Flying USB FliteSim 060378-1 PCB, bare ' 060378-41 PIC18F2550I/SR programmed Universal JTAG Adaptor 060287-1 PCB, bare, with programmed microcontroller 060287-41 EP900LC only, programmed Magnetometer 050276-1 PCB, bare Speedmaster 070021-91 Ready-populated and tested board (excl. R8C module) 72.45 126.50 5.20 9.75 www.thepcbshop.com 15.50 29.25 11.00 20.75 P&P only P&P only www.thepcbshop.com 51.70 97.45 Seismograph 060307-1 PCB, bare 060307-11 CD-ROM, project software 060307-41 ATTiny45, programmed ATtiny as RDS Signal Generator 060253-41 Attiny2313-20, programmed www.thepcbshop.com 5.20 9.75 10.35 19.50 4.20 7.80 No. 364 APRIL 2007 Battery Charge-n-Check 050073-1 PCB, bare, main board 050073-2 PCB, bare, display board 050073-11 CD-ROM, project software 050073-41 ST7FMC2S4, programmed 10.30 19.50 10.30 19.50 5.20 9.75 16.90 31.85 nline at ectronics.co.uk Due to practical constraints, final illustrations and specifications may differ from published designs. Prices subject to change. See www.elektor-electronics.co.uk for up to date information. Wireless USB in miniature (March 2007) iDwarf -168 Transmitter module (built & tested) 050402-91 £ 24.10 / US$ 45.45 Elektor Electronics (Publishing) Regus Brentford 1000 Great West Road Brentford TW8 9HH United Kingdom Tel.: +44 (0) 208 261 4509 Fax: +44 (0) 208 261 4447 Email: sales@elektor-electronics.co.uk Kits & Modules g-Force on LEDs (April 2007) PCB set, bare, incl. 2 MMA7260 sensors, BDM cable parts 060297-71 iDwarf Node Board (built & tested) 050402-91 £ 1 7.20 / US$ 32.45 £10.00 /US$18.85 USB Stick with ARM and RS232 (November 2006) iDwarf Hub Board (built & tested) 050402-93 £ 1 7.20 / US$ 32.45 Assembled and tested board 060006-91 £79.90/ $149.95 g-Force on LEDs 060297-71 PCB set, incl. 2 MMA7260 sensors, BDM cable parts 060297-11 CD-ROM, project software Programmer for Freescale 68HC(9)08 060263-1 PCB, bare A Simple Mains Inverter 060171-1 PCB, bare Very Simple Clock 060350-1 PCB, bare E-blocks Light Chaser Squared 075032-1 PCB, bare No. 363 MARCH 2007 AVR drives USB 060276-1 PCB, bare 060276-11 CD-ROM, project software incl. source code 060276-41 ATmega32-16PC, programmed Wireless USB in Miniature 050402-1 PCB, bare, iDwarf prototyping board 050402-91 iDwarf -1 68 Transmitter module (built & tested) 050402-92 iDwarf Node Board (built & tested) 050402-93 iDwarf Hub Board (built & tested) Mobile Phone LCD for PC 060184-1 PCB, bare 060184-11 CD-ROM, project software 060184-41 ATmega16-16PC, programmed Scale Deposit Fighter 070001-1 PCB, bare No. 362 FEBRUARY 2007 ... 3, 2, 1 Takeoff! 050238-1 Transmitter PCB, bare www.thepcbshop.com 050238-2 Receiver PCB, bare www.thepcbshop.com MP3 Preamp 060237-1 PCB, bare www.thepcbshop.com A Telling Way of Telling the Time 050311-1 PCB, bare www.thepcbshop.com 050311-31 CPLD, programmed 35.50 66.95 FPGA Course (9) 060025-9-11 CD-ROM, course software incl. source code Explorer-16 Value Pack 060280-91 Four components packaged together in a single box 5.20 122.90 9.75 232.50 No. 361 JANUARY 2007 Sputnik Time Machine 050018-1 PCB www.thepcbshop.com 050018-11 CD-ROM, project software (incl. source code) 5.20 9.75 050018-41 AT89C2051 , programmed 3.40 6.45 Very Simple Clock 060350-1 PCB www.thepcbshop.com 060350-1 1 CD-ROM, project software (incl. source code) 5.20 9.75 060350-41 PIC1 6F628-20, programmed 5.50 10.35 FPGA Course (8) 060025-8-1 Software (incl. source code) 5.20 9.75 No. 360 DECEMBER 2006 Shortwave Capture 030417-1 PCB, bare (receiver board) www.thepcbshop.com 030417-2 PCB, bare (control & display boards) www.thepcbshop.com 030417-41 AT90S8515-8PC, programmed 11.40 21.45 No. 359 NOVEMBER 2006 USB Stick with ARM and RS232 060006-1 PCB, bare 11.00 20.75 060006-41 AT91SAM7S64, programmed 27.60 51.95 060006-91 Assembled & tested board 79.90 149.95 060006-81 CD-ROM, all project software 5.20 9.75 No. 358 OCTOBER 2006 PIC In-Circuit Debugger/Programmer 050348-1 PCB 5.20 9.75 050348-41 PIC16F877, programmed 17.90 33.75 050348-71 Kit, incl. PCB, controller, all parts 34.50 64.95 Products for older projects (if available) may be found on our website www.elektor-electronics.co.uk 10.00 18.85 5.20 9.75 www.thepcbshop.com www.thepcbshop.com www.thepcbshop.com www.thepcbshop.com 10.00 18.85 5.20 9.75 8.95 16.85 8.30 15.60 24.10 45.45 17.20 32.45 17.20 32.45 www.thepcbshop.com 5.20 9.75 8.95 16.85 www.thepcbshop.com home construction = fun and added value Equipment Test: audio amplifier modules Home construction of power amplifiers remains a popular activity among audiophile electronics enthusiasts. Besides the high-end audio construction projects Elektor has become famous for, you may also consider using one of the power ampli- fier modules available commercially either ready-built or as a kit. These modules require only a power supply and an enclosure to make an audio amp. We have collected a number of interesting AF power modules and put them through their paces in our audio lab. The test results are presented in the September issue. INFO & MARKET SNEAK PREVIEW ■4J. FREE LED DRIVER with every issue! With preassembled components! Experiment with white LEDs! GPS Tracker Ten years ago a technical novelty, now dead common: positioning systems using GPS (Global Positioning System). GPS- based navigators are extremely popular, especially among motorists. However, a GPS receiver is not just suitable for determining one's own location on the globe, but also that of an object, for example, your car! Elektor's GPS Tracker was developed specifically for that purpose. It's a small circuit comprising a GSM modem, a GPS receiver and a mini- ature antenna. When the GSM modem is texted (by SMS), the receiver will return its current coordinates. This allows you to track the object the circuit is attached to. RESERVE YOUR COPY NOW! The September 2007 issue goes on sale on Thursday 23 August 2007 (UK distribution only). UK mainland subscribers will receive the magazine between 1 8 and 21 August 2007. Article titles and magazine contents subject to change, please check www.elektor-electronics.co.uk. NEWSAGENTS ORDER FORM SHOP SAVE / HOME DELIVERY Please save / deliver one copy of Elektor Electronics magazine for me each month Name: Address: Post code: Telephone: Date: Signature: Please cut out or photocopy this form, complete details and hand to your newsagent. Elektor Electronics is published on the third Thursday of each month, except in July. Distribution S.O.R. by Seymour (NS). elektor-electronics.co.uk www.elektor-electronics.co.uk www.elektor-electronics.ct Elektor Electronics 33 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 down- loads, circuit boards, programmed ICs and corrections and updates if applicable. Complete magazine issues may also be downloaded. In the Elektor Electronics 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 Electronics website: • Electronics news and Elektor announcements • Readers Forum • PCB, software and e-magazine downloads • Surveys and polls • FAQ, Author Guidelines and Contact 148 elektor electronics - 7-8/2007 Please supply the following. For PCBs, front panel foils, EPROMs, PALs, GALs, microcontrollers and diskettes, state the part number and description; for books, state the full title; for photocopies of articles, state full name of article and month and year of publication. PLEASE USE BLOCK CAPITALS. Description Price each Qty. Total Order Code 309 Circuits £ 19.95 Formula Flowcode Buggy 85.00 CD-ROM Ethernet Toolbox fTjjH £ 18.90 CD-ROM Elektor 2006 £ 16.25 Visual Basic for Electronics Engineering Applications £ 27.50 METHOD OF PAYMENT (see reverse before ticking as appropriate) Bank transfer □ Cheque (UK-resident customers ONLY) □ Giro transfer □ VISA Expiry date: Prices and item descriptions subject to change. The publishers reserve the right to change prices without prior notification. Prices and item descriptions shown here supersede those in previous issues. E. & O.E. Sub-total P&P Total paid Name Verification code: SWITCH ONLY: Start date: Issue number: Please send this order form to * (see reverse for conditions) Elektor Electronics (Publishing) Regus Brentford 1000 Great West Road Brentford TW8 9HH United Kingdom Address + Post code Tel.: +44 208 261 4509 Fax: +44 208 261 4447 www.elektor-electronics.co.uk. sales@elektor-electronics.co.uk Tel. Email Date - - 2007 Signature EL07/08 *USA and Canada residents may (but are not obliged to) use $ prices, and send the order form to: Old Colony Sound Lab P.O. Box 876, Peterborough NH 03458-0876. Tel. (603) 924-6371, 924-6526, Fax: (603) 924-9467 Email: custserv@audioXpress.com Yes, I am taking out an annual subscription to Elektor Electronics and receive a free 1GB MP3 player. I would like: I I Standard Subscription (11 issues) Subscription-Plus (11 issues plus the Elektor Volume 2007 CD-ROM) * Offer available to Subscribers who have not held a subscription to Elektor Electronics during the last 12 months. Offer subject to availability. See reverse for rates and conditions. Name Address + Post code Tel. Email Date - - 2007 Signature * cross out what is not applicable EL07/08 METHOD OF PAYMENT (see reverse before ticking as appropriate) □ □ □ □ Bank transfer Cheque (UK-resident customers ONLY) Giro transfer Expiry date: Verification code: SWITCH ONLY: Start date: Issue number: Please send this order form to Elektor Electronics (Publishing) Regus Brentford 1000 Great West Road Brentford TW8 9HH United Kingdom Tel.: +44 208 261 4509 Fax: +44 208 261 4447 www.elektor-electronics.co.uk. subscriptions@elektor-electronics.co.uk ORDERING INSTRUCTIONS, P&P CHARGES Except in the USA and Canada, 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. On-line ordering: http://www.elektor-electronics.co.uk Readers in the USA and Canada may (but are not obliged to) send orders, except for subscriptions (for which see below), to the USA address given on the order form. Please apply to Old Colony Sound 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: UK: £4.00 Europe: £5.00 (Standard) or £7.00 (Priority) Outside Europe: £8.00 (Standard) or £12.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 (Publishing) / Segment b.v. 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 (Publishing) / Segment b.v.. 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-1 52-3801 , held by Elektor Electronics (Publishing) / Segment b.v. 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, Access, MasterCard, JCBCard and Switch cards 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 Electronics 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 Electronics (Publishing) 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 Electronics (Publishing) 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 Electronics (Publishing) 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 Electronics (Publishing) other than to supply goods as described or, at the option of Elektor Electronics (Publishing), 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 Electronics (Publishing) shall be determined in all respects by the laws Of England. January 2007 SUBSCRIPTION RATES FOR ANNUAL SUBSCRIPTION Standard Plus United Kingdom £41 .90 £48.80 Surface Mail Rest of the World £54.50 £61.40 USA & Canada US$ 95.50 US$106.50 Airmail Rest of the World £68.90 £75.80 USA & Canada US$120.00 US$131.00 HOWTO PAY Bank transfer into account no. 40209520 held by Elektor Electronics (Publishing) / Segment b.v. 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 (Publishing) / Segment b.v.. 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 (Publishing) / Segment b.v. 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, Access, MasterCard, JCBCard and Switch cards 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 perma- nent 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) reduc- tion in current rates, must be supported by evidence of studentship signed by the head of the college, school or university faculty. A standard Student Subscription costs £33.50, a Student Subscription- Plus costs £40.40 (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 2007 {.IvkiCT Pfi igBVir'l CdiflfUlAkW! 2 lectromcs ISBN 978-90-5381-214-3 £18.90 / US$ 37.90 ethern CD-ROM Ethernet Toolbox Software Tools en Hardware Tips This CD-ROM contains all essential information regarding Ethernet interfaces! To help you learn about the Ethernet interfaces, we have compiled a collection of all articles on this topic that have appeared in Elektor Electronics and complemented them with additional documen- tation and links to introductory articles on Ethernet interfaces. •Controllers & Microcontrollers •Boards with Ethernet connectivity ► •Serial to Ethernet •CAN to Ethernet •Connectors •Physical Layer Tranceiver •IEEE 802® standard It includes a collection of datasheets for dedicated Ethernet interface ICs from many different manufacturers. To help you with your own projects, the CD-ROM provides a wealth of information about connectors and components for the physical layer (PHY) and specific software tools for use with the Ethernet (Software). All of the documents are PDF files. Order now using the Order Form in the Readers Services section in this issue. Elektor Electronics (Publishing) Regus Brentford 1000 Great West Road Brentford TW8 9HH United Kingdom Tel. +44 208 261 4509 See also www.elektor-electronics.co.uk Index of Advertisers ATC Semitec Ltd, Showcase www.atcsemitec.co.uk 142 Avit Research, Showcase www.avitresearch.co.uk 142 BAEC, Showcase http://baec.tripod.com 142 Beijing Draco www.ezpcb.com 109 Beta Layout, Showcase www.pcb-pool.com 139, 142 Bitscope Designs www.bitscope.com 3 Compact Control Design www.compactcontrol.co.uk 39 Decibit Co. Ltd, Showcase www.decibit.com 142 EasyDAC, Showcase www.easydaq.biz 142 Easysync, Showcase www.easysync.co.uk 142 Elnec, Showcase www.elnec.com 142 Eurocircuits www.eurocircuits.com 139 First Technology Transfer Ltd, Showcase . www.ftt.co.uk 142 Future Technology Devices, Showcase . . . www.ftdichip.com 142 Futurlec, Showcase www.futurlec.com 142 Jaycar Electronics www.jaycarelectronics.co.uk 2 JB Systems, Showcase www.modetron.com 142 Labcenter www.labcenter.com 152 London Electronics College, Showcase . . www.lec.org.uk 142 Microchip www.microchip.com 61 Mikro Elektronika www.mikroe.com 8, 9 MQP Electronics, Showcase www.mqp.com 142 New Wave Concepts, Showcase www.new-wave-concepts.com 142 Newbury Electronics www.newburyelectronics.co.uk 139 Number One Systems www.numberone.com Nurve Networks www.xgamestation.com Paltronix www.paltronix.com PCB World, Showcase www.pcbworld.org.uk Peak Electronic Design www.peakelec.co.uk Pico www.picotech.com Quasar Electronics www.quasarelectronics.com . Robot Electronics, Showcase www.robot-electronics.co.uk. Scantool www.ElmScan5.com/elektor . Schaeffer AG www.schaeffer-ag.de Showcase SourceBoost Technologies, Showcase . . . www.sourceboost.com Sytronic Technology Ltd, Showcase www.m2mtelemetry.com . . . Tsien (UK) Ltd, Showcase www.componentbin.com . . . Ultraleds, Showcase www.ultraleds.co.uk USB Instruments, Showcase www.usb-instruments.com Virtins Technology, Showcase www.virtins.com 60 . . . .139 7 . ... 143 6 . ... 109 97 . ... 143 . . . .139 . . . .109 142, 143 . ... 143 . ... 143 . . 6 , 143 . ... 143 . ... 143 . ... 143 Advertising space for the issue of 24 September 2007 may be reserved not later than 28 August 2007 with Huson International Media - Cambridge House - Gogmore Lane - Chertsey, Surrey KT 1 6 9AP - England - Telephone 01 932 564 999 - Fax 01 932 564998 - e-mail: aerrvb@husonmedia.com to whom all correspondence, copy instructions and artwork should be addressed. 7-8/2007 - elektor eledronics 151 NEW IN DESIGN SUITE 7: NEW: Redesigned User Interface includes modeless NEW: Simulation Advisor includes reporting on selection, modeless wiring and intuitive operation to simulation problems with links to detailed maximise speed and ease of use. troubleshooting information where appropriate. NEW: Design Explorer provides easy navigation, NEW: Trace capability within both MCU and design inspection tools and cross-probing support to peripheral models provides detailed information on 9 prove quality assurance and assist with fault system operation which allows for faster debugging ■ of both hardware and software problems. NEW: 3D Visualisation Engine provides the means to NEW: Hundreds of new device models including preview boards in the context of a mechanical design PIC24, LPC2000, network controllers and general prior to physical prototyping. purpose electronic components. Electronic Design From Concept To Completion Labcenter Electronics Limited Registered in England 4692454 Electronics E-mail: infn@ > labcenter.coiii Tel: +44 (O) 1 756 753440 Fax: +44 (O] 1 756 75E857 Registered Address: 53-55 Main 5treet, Grassington, North Yorks, UK, BD23 5AA