Silicon ChipRailpower Model Train Controller - September 2008 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Digital TV is being wasted
  4. Feature: The Basslink High-Voltage DC Power Link by Michael Goebel
  5. Project: Railpower Model Train Controller by John Clarke
  6. Review: Metrel Instaltest 3017 by Leo Simpson
  7. Project: Versatile LED/Lamp Flasher by Thomas Scarborough
  8. Project: Ultra-LD Mk.2 200W Power Amplifier Module, Pt.2 by John Clarke & Greg Swain
  9. Project: DSP Musicolour Light Show; Pt.4 by Mauro Grassi
  10. Project: LED Strobe & Contactless Tachometer, Pt.2 by John Clarke
  11. Vintage Radio: The Raycophone "Pee Wee" Midget by Rodney Champness
  12. Advertising Index
  13. Back Issues
  14. Outer Back Cover

This is only a preview of the September 2008 issue of Silicon Chip.

You can view 26 of the 96 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "Railpower Model Train Controller":
  • Railpower IV main PCB [09109081] (AUD $20.00)
  • Railpower IV front panel PCB [09109082] (AUD $15.00)
  • PIC16F88-I/P programmed for the Railpower IV [0910908A.HEX] (Programmed Microcontroller, AUD $15.00)
  • PIC16F88 firmware and source code for the Railpower IV Model Train Controller [0910908A.HEX] (Software, Free)
  • Railpower IV Model Train Controller main PCB pattern (PDF download) [09109081] (Free)
  • Railpower IV Model Train Controller display PCB pattern (PDF download) [09109082] (Free)
  • Railpower IV Model Train Controller panel artwork (PDF download) (Free)
Articles in this series:
  • Railpower Model Train Controller (September 2008)
  • Railpower Model Train Controller (September 2008)
  • Railpower Model Train Controller, Pt.2 (October 2008)
  • Railpower Model Train Controller, Pt.2 (October 2008)
Items relevant to "Versatile LED/Lamp Flasher":
  • LED/Lamp Flasher PCB [11009081] (AUD $7.50)
  • Versatile LED/Lamp Flasher PCB pattern (PDF download) [11009081] (Free)
Items relevant to "Ultra-LD Mk.2 200W Power Amplifier Module, Pt.2":
  • Ultra-LD Mk.2 200W Power Amplifier PCB pattern (PDF download) [01108081] (Free)
  • Ultra-LD Mk.2 200W Power Supply PCB pattern (PDF download) [01109081] (Free)
Articles in this series:
  • Ultra-LD Mk.2 200W Power Amplifier Module (August 2008)
  • Ultra-LD Mk.2 200W Power Amplifier Module (August 2008)
  • Ultra-LD Mk.2 200W Power Amplifier Module, Pt.2 (September 2008)
  • Ultra-LD Mk.2 200W Power Amplifier Module, Pt.2 (September 2008)
Items relevant to "DSP Musicolour Light Show; Pt.4":
  • dsPIC30F4011-30I/P programmed for the DSP Musicolour [1010708A.HEX] (Programmed Microcontroller, AUD $20.00)
  • dsPIC30F4011 firmware and source code for the DSP Musicolour [1010708A.HEX] (Software, Free)
  • DSP Musicolour User Manual (PDF download) (Software, Free)
  • DSP Musicolour Infrared Remote Control PCB pattern (PDF download) [10107083] (Free)
  • DSP Musicolour main PCB pattern (PDF download) [10107081] (Free)
  • DSP Musicolour display PCB pattern (PDF download) [10107082] (Free)
  • DSP Musicolour front & rear panel artwork (PDF download) (Free)
Articles in this series:
  • DSP Musicolour Light Show (June 2008)
  • DSP Musicolour Light Show (June 2008)
  • DSP Musicolour Light Show; Pt.2 (July 2008)
  • DSP Musicolour Light Show; Pt.2 (July 2008)
  • DSP Musicolour Light Show; Pt.3 (August 2008)
  • DSP Musicolour Light Show; Pt.3 (August 2008)
  • DSP Musicolour Light Show; Pt.4 (September 2008)
  • DSP Musicolour Light Show; Pt.4 (September 2008)
Items relevant to "LED Strobe & Contactless Tachometer, Pt.2":
  • PIC16F88-I/P programmed for the LED Strobe & Tachometer [0410808A.HEX] (Programmed Microcontroller, AUD $15.00)
  • PIC16F88 firmware and source code for the LED Strobe & Tachometer [0410808A.HEX] (Software, Free)
  • LED Strobe & Tachometer main PCB pattern (PDF download) [04108081] (Free)
  • LED Strobe & Tachometer switch PCB pattern (PDF download) [04108082] (Free)
  • LED Strobe & Tachometer photo-interruptor PCB pattern (PDF download) [04108083] (Free)
  • LED Strobe & Tachometer reflector amplifier PCB pattern (PDF download) [04108084] (Free)
  • LED Strobe & Tachometer front panel artwork (PDF download) (Free)
Articles in this series:
  • LED Strobe & Contactless Tachometer (August 2008)
  • LED Strobe & Contactless Tachometer (August 2008)
  • LED Strobe & Contactless Tachometer, Pt.2 (September 2008)
  • LED Strobe & Contactless Tachometer, Pt.2 (September 2008)

Purchase a printed copy of this issue for $10.00.

Into model railways? Then you’ll want to Build the RAILPOWER This ultra-high performance model train controller features infrared remote control. We believe it’s the best build-it-yourself train controller ever published! O nce upon a time model trains were every kid’s dream hobby – but nowadays they are much more likely to be the province of their dads and grand-dads. To a true model railway enthusiast, realism of rolling stock, track layout, scenery and train operation is paramount – and it’s not hard to spend up to a thousand dollars or more on a good loco. (Some model railway “widows” insist it’s the spender that’s loco!) Many model railway enthusiasts have permanent setups occupying vast areas of their homes – inside and out! We’ve heard of model railway enthusiasts who have bought a new house simply on the basis that it lends itself to their hobby. Bedrooms? Bathrooms? Kitchen? Who cares, as long as there 22  Silicon Chip is room for his “trains”! One thing that every enthusiast understands is that the old-fashioned rheostat-type controller is simply not up to the task – to achieve that realism we mentioned earlier, they must have a high-performance train controller, one that can vary the speed, direction and be able to simulate the inertia of a full-size train. And one with switchmode (pulse power) operation for really good low speed control. Finally, infrared remote control (so you can direct operations from anywhere on your layout) is practically essential – and not just on larger layouts. Railpower Mk IV Our latest Railpower train control- ler (actually the fourth one we’ve published in our 20+ years) is simply outstanding. The completely new design, based on a PIC microcontroller, provides all those wanted features and more. Those who have had a chance to try it out reckon it’s right up there with the best commercial controllers costing hundreds of dollars more. This latest Railpower design is packed full of features to enable a locomotive to be driven smoothly over its full speed range. And while all of the control features can be accessed from the handheld remote, there is also a large knob on the front panel to control the speed – for those who like to feel “in control”! There are also four pushbuttons on the siliconchip.com.au IV Design by JOHN CLARKE front panel to adjust all the settings as well as providing Direction, Stop and Inertia on/off. Infrared remote control A standard pre-programmed remote is used to access all the standard features such as speed, direction, braking (stop) and inertia on/off. And since we are using a standard remote control, we have allocated the standard buttons to control particular functions. For example, the volume up and down buttons control the speed, the mute button is used for braking (stop) while the channel up and down buttons select forward or reverse, respectively. Just like the real world, the direction siliconchip.com.au Features • Pulse power for extra smooth low spee • Back-EMF detection for speed regulat d operation ion • Infrared remote control • Front panel speed control • Speed setting displayed as bargraph an d percentage value • Actual speed bargraph display • Adjustable simulated inertia with on/of f control • Adjustable braking (stop) ine rtia • Forward and reverse lockout • Indication of stop, direction, inertia an • Overload protection with visual and aud lockout dible indication of the locomotive cannot be changed if it is running above a certain speed (which we call the “lockout” speed). So if you want to change direction you have to slow down the locomotive before the Railpower will let you change the direction. This prevents derailments which can be catastrophic if you are using a locomotive (or two/three) ahead of a long train. Using the Stop (Mute) function brings the locomotive to a stop when pressed and lets the train return to its original speed setting when pressed again. Just like in TV operation, if you have pressed the Stop (mute) button, pressing the Speed (volume up) button, returns the train to its original setting. However, if you have Stop pressed, you can also use the Volume Down button to reduce the speed setting while the train is stationary. Inertia Real trains have huge amounts of inertia. A big coal drag or iron ore train may be 20,000 tonnes or more and you can bet that when the driver calls for an increase in speed, nothing happens quickly. In fact, the driver of a real train must not apply full power quickly otherwise the train couplings can be easily broken. In the modelling situation we wish to simulate that huge inertia so that changes in speed setting are not immediately reflected by a change in actual train speed. We can adjust the September 2008  23 Specifications Output Voltage.........................16-17V pulse width modulated in 819 steps up to 80% duty cycle Output current..........................up to 6A Pulse Frequency.......................122Hz, 488Hz or 1953Hz Speed setting display...............60-step bargraph and percentage from 0-100%. Actual speed display................60-step bargraph Minimum speed setting...........adjustable Lockout speed setting..............adjustable Default speed setting...............adjustable Infrared remote codes..............Philips RC5; TV, SAT1 and SAT2 Infrared remote range..............8m (indoors) Inertia adjustment....................From 0-100 corresponding to about 1 to 100s (dependent on minimum and maximum settings) Stop adjustment.......................From 0-100 corresponding to about 1 to 100s (dependent on minimum and maximum speed settings) Back EMF Feedback control.....Adjustable from 0 to 100 corresponding to no back-EMF control through to a maximum Speed ramp rate.......................From 0 to 255 corresponding to the rate of speed setting change with remote control Bi-colour LED...........................Shows track voltage and direction amount of simulated inertia over a wide range, to simulate the effect of locomotive running in “light engine” (ie, no carriages or wagons) to that large coal drag we mentioned above. Simulating train inertia adds greatly to the operation of model trains. Instead of trains accelerating like jack rabbits or coming to a screeching halt (which surely would cause fatal injuries to passengers and a lot of rolling stock damage if duplicated in real life operation!) they move off slowly, or even ponderously, in case of long freight trains. Inertia can be toggled on or off with the remote control’s On/Off switch (normally used to turn the TV on or off). When you are running a train along a layout you will want inertia switched on but when shunting or other delicate manoeuvring, you will probably want to switch the inertia off. When inertia is set to off, the locomotive motor responds almost instantly to speed setting changes. Run & braking inertia Actually, the Railpower IV provides for two inertia settings. The first is for running a train, giving very gradual increase or decreases in train speed in response to a given setting. The second is braking inertia which means that the train can be brought to a stop smoothly and quickly when you press the Stop button. However, if you have the Inertia switched off, there is no braking inertia and the train will come to an immediate jarring stop if you press the Stop button. As we mentioned before, these and all the other settings can be adjusted via the front panel buttons. Pulse power Given the amazing control that the Railpower IV gives the model train enthusiast, there is certainly not much to it, thanks to the power of the PIC16F88-I/P. It is built on two PC boards (one for the display) and mounts in a 260 x 85 x 180mm ABS case. It offers both local and infrared control. 24  Silicon Chip Having realistic inertia counts for nothing if the train controller cannot provide smooth reliable acceleration from a standing start. To provide smooth low speed control and very smooth starts, you cannot use smooth DC or unfiltered DC operation. It just will not work properly and the result can be a locomotive which is stalled until you wind up the voltage to such a level that when the loco finally does move, it takes off like a startled rabbit and may even spin its driving wheels furiously. The only way to ensure reliable low speed operation, apart from havsiliconchip.com.au +5V IR DETECTOR λ +17V +5V LOCAL SPEED VR1 MOTOR Q1 Q2 REMOTE SPEED MICROCONTROLLER (IC1) LCD Q3 'H' BRIDGE Q4 OVER CURRENT BACK EMF SWITCHES MOTOR BACK EMF OVERLOAD SIREN Fig.1: the block diagram of the Railpower IV belies just how powerful this new train controller is. It’s by far the best we have ever published and is only made possible through the use of a PIC microcontroller. ing clean track and regularly cleaned locomotive wheels, is to use what railway modellers refer to as “pulse power” and what electronics people call switchmode or pulse width modulation (PWM). Whatever it is called, it involves driving the locomotive with high amplitude (typically 16-17V) pulses which easily overcome track/wheel contact resistance and motor stiction (static friction) to ensure smooth starting and low speed running. EMF of the locomotive motor. This is the voltage which opposes current flow through the motor due to the applied voltage. In permanent magnet DC motors, as used in most model locomotives, back-EMF is directly proportional to speed. Therefore, if we want the controller to maintain a set speed, we monitor back-EMF to provide a feedback signal to the circuit. It works very well. Speed regulation A 2-line Liquid Crystal Display (LCD) indicates train speed and speed settings, as well as direction, stop and The other way to ensure good low speed operation is to monitor the back- Liquid crystal display Railpower operation driving a 470W resistor load. The top (yellow) trace is the junction of Q2/Q4 with Q2 being driven by the pulse signal. The bottom (green) trace is the junction of Q1/Q3, with Q3 being turned fully on. The small amplitude signal is mostly due to the voltage across the 0.1W sensing resistor. The voltage across the motor (load) is the difference between the two signals. siliconchip.com.au whether inertia is switched on or off. The train and speed settings are shown as horizontal bargraphs. The speed setting is also shown as a percentage from 0 to 100%. The lower bargraph shows the speed setting while the upper bargraph shows the actual train speed. If the Railpower IV is overloaded or the output is shorted, the top line of the LCD shows ‘OVER’ in place of the direction arrow, padlock icon (lockout), S and I indicators. An internal overload siren also sounds and power to the motor is stopped until the current overload is ended. As already mentioned, you can change all the settings with the front panel switches below the LCD panel. We will discuss those details next month. The Railpower IV is presented in a large instrument case that houses the power transformer and circuitry. At the rear panel is the mains input and power switch and two terminals for connection to the track layout. Circuit details A block diagram of the circuit is shown in Fig.1. It comprises the PIC microcontroller and this drives the LCD module, the H-bridge and overload siren. It also monitors signal from the infrared detector, the front panel switches, the over-current monitor and the back-EMF from the locomotive motor. The H-bridge drive circuit com- This shot shows Railpower operation in the reverse direction. The top trace now shows a small amplitude signal with Q4 being turned fully on. The green trace shows Q1 being fed by the pulse signal. Note that both these scope shots show operation at 488Hz. Operation at the other frequencies of 122Hz and 1953Hz is similar. September 2008  25 26  Silicon Chip siliconchip.com.au SC 2008 E IRD1 2 3 A X1 2MHz K A K B C LED E C 1 6 15 Vss 5 1k AN4 PWM RB2 RB1 MCLR 4 13 17 18 2 3 9 8 7 RB7 12 RB6 11 RB5 10 RB4 RA0 RA1 AN3 IC1 PIC16F88-I/P OSC2 OSC1 AN2 RB0 14 Vdd 100nF 16 27pF 2.2k +5V BD649, BD650 27pF LOCAL SPEED VR1 10k 1N5404 1 100 µF 16V 100 µF 16V RAILPOWER CONTROLLER MK4 C BC337 GND OUT 7805 1 IN B 2 λ 3 IRD1 IR DETECTOR/ DECODER 470Ω +5V S1 10 9 12 13 S3 1k RS B 7 IC2b IC2a Vdd 2(1* ) E 1k B 2.2k Q9 BC337 C 100k 10k 10k A 10k 2 x 2200 µF 25V +17V * JAYCAR MODULE GND 1(2* ) 1k B VR3 10k Q3 BD649 K A K K A A K K A K λ λ E C 12V E C 240V 5.1k 15k K POWER S5 22 µF A K E C B E C _ + PIEZO SIREN +17V E N 240V AC A Q10 BC337 100k 2.2k F1 1A B B Q6 BC337 1k D6 1N4004 +5V B Q8 BC337 IN4004 A B LED1 DIRECTION T1 12V/60VA 10 µF 16V VR2 10k Q4 BD649 E C K A Q2 BD650 TO TRACK 10k 10k 2.2k Q1 BC650 A 1N4148 A E C C E +17V D1–D4: 1N5404 R/W 5 3 0.1 Ω 5W CONTRAST 10nF 10k E B Q7 BC337 C Q5 BC337 B E C 100nF LCD MODULE 6 3 100 µF 25V K D5 1N4004 D7 D6 D5 D4 D3 D2 D1 D0 14 13 12 11 10 9 8 7 EN S4 1k 6 4 A D7 1N4148 K 5 4 2 1 (OVER CURRENT) 100k 8 10nF IC2c IC2: 74HC00 11 GND IN UP/ SET/ SELECT/ DOWN/ INERTIA RUN DIRECTION STOP S2 1k 10M 14 IC2d (BACK EMF) 10 µF 16V OUT REG1 7805 Railpower operation with a 12V permanent magnet motor. The top (blue) trace is the pulse (PWM) signal from IC2a which drives Q6 and Q2. The yellow trace shows the voltage across the motor for a duty cycle of 30.7%. The back-EMF is the shelf part of the waveform corresponding to the low (off) times of the blue trace. In this case the back-EMF is being measured by the horizontal cursor at 5V. The same set-up as previously but with a PWM frequency of 122Hz instead of 488Hz. The PWM duty cycle is 50%. In this case the motor back-EMF is much higher, as would be expected with a high average driving voltage. In general, permanent magnet motors work better with lower pulse frequencies as their inductance has less effect. The uneven tops of the yellow trace are caused by 100Hz ripple on the 17V supply. prises four power transistors Q1, Q2, Q3 and Q4 which drive the motor (ie, locomotive) in switchmode as well as providing for forward or reverse operation. For forward operation, Q1 & Q4 are switched on while Q2 & Q3 are switched off, to provide current in one direction through the motor. Similarly, for reverse operation, Q2 & Q3 are switched on while Q1 & Q4 are switched off, providing current through the motor in the opposite direction. At same time, to provide the switchmode operation (pulse power), Q1 is pulsed on and off at the preset rate (which may be 122Hz, 488Hz or 1953Hz) while Q4 is switched fully on (forward operation). Similarly, for reverse operation, Q2 is pulsed at 122Hz etc while Q3 is fully on. A common sensing resistor, connected to the emitters of Q3 & Q4 is used to monitor the current drain by the locomotive motor. We also monitor the motor when all transistors are off (ie, in the off periods of the switchmode signal) to determine the back-EMF of the motor and thereby its loading. The full circuit is shown in Fig.2. IC1 is a PIC16F88-I/P microcontroller. We are using its PWM (pulse width modulation) output at pin 9 and three analog inputs to monitor the signals for over-current, backEMF and the front panel speed potentiometer VR1. The remaining input/output pins are used to monitor the infrared detector (IRD1), drive the LCD panel and piezo siren and to monitor the four front panel switches. Fig.2 (opposite): the circuit of the Railpower IV consists mainly of a PIC microcontroller and an H-bridge motor driver. The PIC also drives the LCD module directly. With the exception of the local speed control and direction LED, everything is mounted on two PC boards. You have the choice of complete remote control (with a range of up to 8m indoors) or “local” control with a speed pot and push-buttons on the front panel. Just to whet your appetites, here’s the Railpower IV mainboard which we will fully describe next month. Almost everything is mounted on this or the display board. The connections to this board are (clockwise from top right) 230V power from the mains input socket/ fuse/switch, earth connection to back panel, output to terminals on back panel, track direction LED and local speed potentiometer (both on front panel). siliconchip.com.au H-bridge drive IC2, a 74HC00 quad CMOS NAND gate and transistors Q1-Q8 provide the H-bridge drive. This is somewhat more September 2008  27 This scope shot shows the Railpower operating at full power, with a pulse duty cycle of 80.4% and pulse frequency of 122Hz. The back-EMF, measured in the off periods, can be seen to be quite high, as the motor will be running at full speed. complicated than the simplified schematic of Fig.1 but you can see the similarity, with Q1 to Q4 being the heavy-duty Darlington power transistors. The high gain of these transistors is further boosted by Q5 to Q8. The H-bridge drive circuit works as follows. Outputs RB1 and RB2 (pins 7 & 8) of IC1 drive NAND gates IC2d & IC2c which are then inverted by IC2a & IC2b. These gates drive Q5 and Q6 via 10kW resistors to their bases. Outputs RB1 and RB2 also drive the bases of Q7 & Q8, respectively. These outputs (ie, RB1 & RB2) work in complementary fashion so that when RB1 is high, RB2 is low and vice versa. So when RB1 is high, Q6 turns on Q2 and Q7 turns on Q3, giving the forward operation described previously. Similarly, when RB2 is high, Q5 turns on Q1 and Q8 turns on Q4, giving reverse operation. So RB1 selects forward operation while RB2 selects reverse operation. At the same time, the PWM output of IC1 (pin 9) is gated through IC2d and IC2c, depending on the state of RB1 and RB2. So the PWM signal provides switchmode operation of Q1 and Q2, as previously described. Note that, as well as providing considerable current gain in the Hbridge circuit, the eight transistors also provide voltage level translation between the flea-power 5V signals from the micro to the 17V pulses to 28  Silicon Chip Operation at the highest frequency of 1953Hz and with a duty cycle of close to 80% gives an apparently smoother waveform, since motor hash and power supply ripple are not evident. However, typical motors will run more slowly at this high pulse rate. the locomotive motor. Over-current monitoring The 0.1W 5W resistor provides motor current sensing. The voltage across this resistor is fed to the AN4 input (pin 3) of IC1 via a 10kW resistor while a 100nF capacitor filters the signal preventing transients from being detected. IC1 converts the voltage to a digital value and switches off power to the motor should the current exceed 6A. 6A corresponds to 0.6V at AN4. Power is switched off by taking both the RB1 and RB2 outputs low so that none of the transistors are on to drive the motor. But IC1 restores motor drive momentarily every 0.2s and if the sensed current is below the 6A, the motor is again allowed to run. If current is still over 6A, then the power to the motor is removed again. At the same time as an overload is detected, output RA1 (pin 18) drives transistor Q10 to sound the piezo siren which has an inbuilt oscillator. The RA1 output is also used to send data to the LCD module. To avoid turning on Q10 with the data signal, a 22mF capacitor at its base filters out the short periods of high data signal from RA1. So when we want to drive the transistor we must apply the high signal from RA1 for about 100ms before Q10 will switch on. Back-EMF monitoring Back-EMF from the locomotive motor is monitored using two 10kW And here’s the display board which mounts on the back of the front panel. This particular board has the Jaycar LCD; the white outline on the board to its right shows the mounting position for the alternative Altronics LCD. siliconchip.com.au Parts List – Railpower IV 1 PC board coded 09109081, 217 x 102mm 1 PC board coded 09109082, 141 x 71mm 1 12V 60VA mains transformer (2167L type) (T1) 1 LCD module, Altronics Z-7001or Jaycar QP-5516 1 front panel label, 243 x 76mm 1 plastic instrument case, 260 x 190 x 80mm 1 aluminium rear panel, 243 x 76 x 1.5mm 1 chassis-mount male IEC connector with fuse and switch 1 M205 1A fuse (F1) 1 IEC 3-core 240VAC mains lead with 3-pin plug 1 universal infrared remote control (see text) 1 PC mount piezo buzzer (Jaycar AB3458 or equivalent) 1 DIP18 IC socket for IC1 1 DIP14 socket cut to suit LCD connector 1 14-pin DIL header strip for Jaycar LCD module or 1 SIL 14-pin header strip for Altronics LCD module with 2.54mm pin spacing 1 3-way header strip with 2.54mm pin spacings 1 mini heatsink 19 x 19 x 9.5mm 1 2MHz crystal (X1) 1 2-way PC-mount screw terminals with 5.08mm pin spacing 2 binding posts 1 10kW linear potentiometer (VR1) 1 knob to suit VR1 4 SPST PC-mount tactile snap action switches (S1-S4) 2 10-pin IDC line sockets 1 10-pin IDC vertical header 1 10-pin IDC right angled header 1 200mm length of 10-way IDC cable 1 200mm length of 7.5A green/yellow mains wire 1 100mm length of 7.5A brown mains wire 1 150mm length of black hookup wire 1 150mm length of red hookup wire 1 150mm length of green hookup wire 1 150mm length of 0.8mm tinned copper wire 5 4.8mm female insulated quick connect spade connectors 1 6.4mm female insulated quick connect spade connector 1 chassis mount quick connect spade terminal (6.4mm) resistors connected to the collectors of Q3 and Q4. Depending on which direction the motor is running, the back-EMF will come from the collector of Q3 or Q4, whichever transistor happens to be off at the time. Note that the back-EMF signal will be attenuated by the 10kW resistor connecting to the transistor which happens to be on but this does not matter as we need to further attenuate the signal with trimpot VR2 anyway. This is needed to limit the back-EMF signal so it is below the 5V maximum to the AN3 input for IC1. However, there is a further condition to monitoring back-EMF and that siliconchip.com.au 2 5.3mm ID eyelet quick connector 6 100mm cable ties 4 M3 x 10mm screws 4 TO-220 insulating kits (silicone washer and bush) 5 M3 nuts 5 M4 x 10mm screws 5 M4 nuts 3 4mm star washers 6 No.4 self-tapping screws 4 M3 tapped x 6mm Nylon spacers 4 M3 tapped x 12mm spacers 4 3mm Nylon washers 12 M3 x 6mm screws 4 M3 x 6mm countersunk screws 4 PC stakes Semiconductors 1 PIC16F88-I/P programmed with 0910908A.hex (IC1) 1 74HC00 quad NAND gate (IC2) 1 infrared detector/decoder (IRD1) 2 BD650 PNP Darlington power transistors (Q1,Q2) 2 BD649 NPN Darlington power transistors (Q3,Q4) 6 BC337 NPN transistors (Q5-Q10) 4 1N5404 3A rectifier diodes (D1-D4) 2 1N4004 1A rectifier diodes (D5,D6) 1 1N4148 switching diode (D7) 1 dual colour LED with two leads (LED1) Capacitors 2 2200mF 25V PC electrolytic 1 100mF 25V PC electrolytic 1 100mF 16V PC electrolytic 1 22mF 16V PC electrolytic 2 10mF 16V PC electrolytic 2 100nF MKT polyester 2 10nF MKT polyester 2 27pF ceramic Resistors (0.25W 1%) 1 10MW 3 100kW 1 15kW 4 10kW 1 5.1kW 4 2.2kW 7 1kW 1 470W 1 0.1W 5W 2 10kW horizontal trimpots (code 103) (VR2,VR3) is that it can only be done while the motor is not being energised, ie, in the times when the PWM signal from IC1 is off. To that end, transistor Q9’s base is switched by the PWM signal so that it is on when the PWM signal is high. This shunts the back-EMF signal to 0V so that we are only monitoring “pure” back-EMF and not a mix of back-EMF and applied voltage. The signal from Q9 is fed via diode D7, filtered with a 10nF capacitor and passed to the AN3 input. D7 prevents the voltage at AN3 dropping to zero each time Q9 switches on. A 10MW resistor discharges the 10nF capaci- tor over a 100ms period so the input can respond to a falling back-EMF signal. IC1 converts the back-EMF signal to a 10-bit digital value and this is used to modify the PWM signal to the motor. If the back-EMF is falling, the pulse width (duty cycle) is increased in order to maintain the motor speed. Similarly, if the back-EMF increases (maybe when going downhill) the pulse width is reduced. Trimpot VR2 is adjusted to suit a range of locomotives that you might have on your layout. Potentiometer VR1 is the front panel speed control. It varies the voltage September 2008  29 At left is the rear of the Railpower IV case. It looks pretty spartan – but that’s deliberate. All you have is the switched and fused IEC mains input on the right and the two binding post terminals on the left which supply power to the track. Because the track polarity can be either way (as selected by the user) these are not colour coded. The bicolour LED on the front panel indicates direction. to the AN2 input (pin 1) between 0 and 5V. Again, this voltage is converted to a 10-bit digital value and sets the speed of the motor when the Railpower is set to “local” (ie, front panel) control. Switches and LCD drive The four pushbutton switches S1 to S4 connect to the RB4 to RB7 lines for IC1. Normally, the RB4 to RB7 lines are set (by the software) as inputs, with internal pullup resistors. When a switch is pressed, then the corresponding input is pulled to 0V and IC1 detects this event. The same RB4 to RB7 lines also drive the LCD and to do this they are set as outputs. 1kW resistors are included in series with the switches to prevent the RB4-RB7 lines becoming shorted to ground when a switch is pressed and when the lines are set as outputs. Driving the LCD occurs only momentarily at a slow repeat rate and so for most of the time the RB4-RB7 lines are ready to monitor the switches. The LCD data is sent in 4-bit wide words. The DB0-DB3 data lines are not used. The RA1 output from IC1 drives the register select input to the LCD while the RA0 line provides the enable signal. The display contrast is set with trimpot VR3. Note that the supply pin numbering is different for the Jaycar and Altronics modules. Infrared decoding IRD1 detects the infrared signal from the handheld remote. This is encoded as bursts of 38kHz signal. The IR detector converts each burst as low (0V) and high (5V) in the absence of 38kHz. The decoded signal is sent to the RB0 input of IC1. IC1’s software further decodes the signal sent by the IR remote and it will only accept encoding that is part of the Philips RC5 code. This encoding is set on your handheld remote when you select a Philips or an affiliated company’s brand of appliance. The software within IC1 will decode RC5 code for a TV, Satellite 1 and Satellite 2. This means that you could use three separate Railpower controllers with their own IR remotes on the one layout, in conjunction with block switching. Furthermore, an additional Railpower could be employed with local (ie, non IR remote) to give four controllers on a large layout. The Philips RC5 code for infrared transmission (also used with Marantz, Resistor Colour Codes o o o o o o o o No. 1 3 1 4 1 4 7 1 Value 10MW 100kW 15kW 10kW 5.1kW 2.2kW 1kW 470W 4-Band Code (1%) brown black blue brown brown black yellow brown brown green orange brown brown black orange brown green brown red brown red red red brown brown black red brown yellow violet brown brown 30  Silicon Chip    5-Band Code (1%) brown black black green brown brown black black orange brown brown green black red brown brown black black red brown green brown black brown brown red red black brown brown brown black black brown brown yellow violet black black brown Grundig and Loewe equipment) comprises 2-start bits and 1-toggle bit. The toggle bit alternates high and low on successive same key presses. The code includes five system address bits and six command bits for a total of 14 bits. It uses bi-phase encoding with a high to low transition equal to a low signal and a low to high transition equal to a high signal. Each bit is transmitted at a 1.778ms rate. The entire code is 24.889ms in length and the code is repeated every 113.778ms. IC1 operates at 2MHz using crystal X1. This frequency was chosen because it allowed the PWM frequency to be as low as 122Hz with 10-bit resolution. The crystal also provides an accurate source of timing so that the infrared RC5 code can be decoded at the correct rate. Power supply The Railpower uses a 12VAC 60VA transformer to drive a bridge rectifier comprising four 3A diodes. The rectifier output is filtered with two 2200mF capacitors to give about 17V DC (depending on the mains input voltage). This feeds the H-bridge driver for the motor. The 17V DC is also applied via diode D5 to 5V regulator REG1 which supplies IC1 and the rest of the circuit. Next month we will complete the description of the Railpower with all the construction details and the set-up procedure. SC Capacitor Codes Value 100nF 10nF 27pF mF Code IEC Code EIA Code 0.1mF 100n 104 0.01mF 10n 103 NA 27p 27 siliconchip.com.au