Silicon ChipVersaTimer/Switch With Self-Latching Relay - June 2011 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Let's forget aobut a carbon tax and concentrate on the environment instead
  4. Feature: The FutureWave Energy Saver by Ross Tester
  5. Feature: Rescuing Electronic Gear After The Flood by Robert Googe
  6. Project: 20A 12/24V DC Motor Speed Controller Mk.2 by John Clarke
  7. Project: USB Stereo Recording & Playback Interface by Jim Rowe
  8. Project: VersaTimer/Switch With Self-Latching Relay by John Clarke
  9. Review: Marantz CD6003 CD Player by Leo Simpson
  10. A Handy USB Breakout Box For Project Development by Jim Rowe
  11. Vintage Radio: Radio manufacturing in 1925: the Wells Gardner story by Kevin Poulter
  12. Book Store
  13. Advertising Index
  14. Outer Back Cover

This is only a preview of the June 2011 issue of Silicon Chip.

You can view 28 of the 104 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 "20A 12/24V DC Motor Speed Controller Mk.2":
  • 20A 12/24V DC Motor Speed Controller Mk2 PCB [11106111] (AUD $12.50)
  • 20A 12/24V DC Motor Speed Controller Mk2 PCB pattern (PDF download) [11106111] (Free)
Items relevant to "USB Stereo Recording & Playback Interface":
  • USB Stereo Record/Playback PCB [07106111] (AUD $15.00)
  • USB Stereo Recording & Playback Interface (PDF download) [07106111] (PCB Pattern, Free)
  • USB Stereo Recording & Playback Interface front panel artwork (PDF download) (Free)
Items relevant to "VersaTimer/Switch With Self-Latching Relay":
  • VersaTimer/Switch PCB [19106111] (AUD $10.00)
  • PIC16F88-I/P programmed for the VersaTimer/Switch [1910611A.HEX] (Programmed Microcontroller, AUD $15.00)
  • Firmware (ASM and HEX) files for the Versatimer/Switch [1910611A] (Software, Free)
  • Versatimer/Switch PCB pattern (PDF download) [19106111] (Free)
  • Versatimer/Switch front panel design (PDF download) (Panel Artwork, Free)
Items relevant to "A Handy USB Breakout Box For Project Development":
  • USB Breakout Box PCB [04106111] (AUD $5.00)
  • USB Breakout Box PCB pattern (PDF download) [04106111] (Free)

Purchase a printed copy of this issue for $10.00.

1 F 100nF 10k Vdd 2 RA0 RA7 RB4 RA1 RB5 RB3 RA3 0nF AN5 Q5 BC547 AN6 AN2 Q1 BC327 B 16 C A C B E 7 8 220nF C Q2 BC327 K C X Y C B E E 10k 15 9 TIMER X PULSE VR3 10k 12 + VR2 10k COM NO Y TP3 13 SINGLE COIL LATCHING RELAY +11.4V 1 1k RB1 LK4 POWER UP + + 0–5H 2 10nF 0–50s BOTH OPEN = 0–5m X Y By JOHN CLARKE VersaTimer/Switch RB2 RA4 Vss 5 3 Q6 BC547 B 11 6 1k TO RELAY COIL(S) A RB0 A Q4 BC337 TP2 470k  LED2  Q3 BC337 2x470 10 LED1 K C E IC1 PIC16F88-I/P 1 1k MCLR RA6 1k 10k 4 A 18 RESET S2 14 17 +5V 1 1k LK3 OPERATION DOUBLE COIL LATCHING RELAY MOMENTARY 2 10nF NC COM NO NC COM NO (NOTE: Q1, Q2, Q5 AND Q6 NOT REQUIRED FOR DOUBLE COIL RELAY) TOGGLE BOTH OPEN = FOLLOW LEDS Use it as a micropower switch, programmable timer and/or 12V battery protector K A D4: 1N4148 A K MCP1703T BC327, BC337, BC547 IN Do you have a D1-D3 switching application ZD1 that calls for a relay but B GND A current K needs very low drain? You won’t get satisfaction if you OUT E A K use a conventional relay – it pulls too much current. You need this circuit board which uses a 12V latching relay. As a bonus, it functions as a programmable timer and battery protector. T HIS PROJECT WAS first conceived to update the DC Relay Switch from our November 2006 issue. That project would operate a high-current relay in response to any DC or pulse signal and it also employed an optocoupler to provide full isolation between the control signal and the circuit being switched. Now while that project was OK there has been an increasing need for a relay switching circuit which consumes the 62  Silicon Chip very minimum of power, whether or not the relay is energised. The problem is that all conventional relays draw some current continuously when they are energised and that can be a major drawback in battery-operated circuits. The current through the relay coil depends on the particular relay. For 12V relays, the coil current can be as low as 12mA for a 500mA reed relay, 30mA for a 3A relay and more than 100mA for a 30A relay. This coil cur- C rent must be continuously applied to keep the relay contacts closed. The solution: use a latching relay. This type of relay only draws a brief pulse of current when its relay contacts are changed from the closed or open condition. At all other times, it draws no current at all. So how does a latching relay work? Well, instead of just using a moving armature (to operate the contacts) together with a coil wound on a steel siliconchip.com.au core (an electromagnet), a latching relay has a couple of bar magnets and these hold the relay contacts in one position (eg, closed) or the other (eg, open). The electromagnet effectively toggles the relay contacts from one position to the other just as you do when you operate a light switch in your home. However, in the light switch example, the switch is held in the open or closed position by spring action. By contrast, the latching relay uses magnets to do the same job. But while latching relays are good (ie, they don’t draw current continuously), they are much more difficult to drive than conventional relays. The circuitry required to drive them is more complicated as we shall see. Multiple functions As indicated, this “VersaTimer/ Switch” circuit drives a latching relay. It also provides a useful timer function which can provide latched or momentary operation and can switch power on for a predetermined period or switch it off after a predetermined period. Or it can switch on and off alternately, according to your settings. To top it off, it also provides a battery protection feature, preventing the battery from being too heavily discharged. This is important in circuits which run from lead-acid and particularly sealed lead-acid (SLA or gel) batteries. All these features are provided by a small PIC microcontroller. Now before you fall about laughing or reel back in dismay, stay with us while we give you the reasons for using a micro rather than a bunch of transistors and maybe a logic IC or two. Well that says it all really because a bunch of transistors and logic ICs would end up being a lot more complicated and provide less functions than our circuit. Nor would a discrete version have the low power consumption of this circuit. Latching relays use either one or two coils to drive the relay into each state. For a single coil type, you need a pulse of current to switch from one state to the other and then a pulse in the opposite direction to change state again. A double-coil latching relay requires a pulse of current in one coil to provide the set (on) position for the contacts and then another pulse of the same polarity to be applied to the second coil to produce the (off) reset condition for the contacts. There is more discussion on latching and non-latching relays in a siliconchip.com.au The circuit is housed in a standard IP65 case (115 x 90 x 55mm). Two versions can be built – one to switch the mains (as shown here) and one to switch voltages up to 30V DC <at> 2A. separate panel at the end of this article. The VersaTimer/Switch has been designed to suit both types of latching relay, ie, single or double-coil. The double-coil relay has DPDT 2A contacts and the single coil relay has SPST 60A (or 80A) contacts. The drive circuitry is also suited to other latching relays that may not necessarily fit onto the PCB for the VersaTimer/Switch. Because latching relays have differing pulse length requirements when switching relay states, the pulse duration can be adjusted to suit the relay specifications. Isolated triggering For most uses, a trigger signal is required for the VersaTimer/Switch. This trigger signal can be 0V for one relay position and 5V for the alternative relay position. For example, the trigger can be obtained from a circuit that drives a LED or from any other suitable voltage signal. In addition, the input trigger signal Main Features • • • • • • • • • Very low current drain Electrically isolated control input Low battery protection 60A (or 80A) 250VAC SPST relay or 2A 30VDC DPDT relay Relay options include input follow, alternate or momentary Adjustable input switching sense High, low or high and low switching with momentary action Adjustable relay drive pulse duration Timer periods from seconds to 5 hours Main Uses (1) Standalone timer (2) Low battery power switch or battery isolator (3) Low power relay control from DC or pulse signal June 2011  63 Specifications Specifica tions Supply voltage ....................................................................................................................12V nominal Relay type ...........................................................................................................................12V latching Relay drive pulse ....................................................................................................1-500ms adjustable Pulse current at 12V ........................15mA (<at>25ms) for SY-4060, 85mA (<at>60ms) for JMX-94F-A-Z Low battery threshold ............................................................................................. <11.5V (adjustable) Low battery upper threshold (switch back on) .............................................................................>12V Battery voltage monitoring ............................................................................................ 6ms every 10s Timer function ...........................0-50s (200ms minimum, ~200ms steps), 0-5m (8.4s minimum and 36 x 8.4s steps) or 0-5h (2.38m minimum and 127 x 2.38m steps) Isolation ..................................................2500VAC between coil and contacts for 60A and 80A relays Trigger input isolation .................................................................. up to 50V maximum recommended Quiescent current ..............................................................17µA maximum, 13.3µA measured at 12V; add 10.6µA when RB2 is low and add 0.6µA during any timing period Low battery quiescent current .......................................................................................................17µA Maximum trigger voltage ......................................................... 35V with 10kΩ 0.25W resistor for R1 Minimum input voltage ......................3.25V for R1 = 10kΩ (alternative R1 for lower voltages: 1.5kΩ for 1.5V, 3kΩ for 2V, 6.2kΩ for 3V) Minimum input trigger current at In+ and In- .............................................................................225µA Maximum input trigger current ................................................................................................... 60mA is optically isolated and can operate from a floating potential. Triggering can also be from a momentary pushbutton switch or toggle switch, depending on the application. When used as a replacement for a non-latching relay, the VersaTimer/ Switch responds to follow the input signal. So when the input signal is off, the relay is set to one state (for example, with its contacts open) and when the trigger signal is on (ie, trigger voltage is present) the relay is switched to its alternative state with its contacts closed. You can select which relay state occurs with which input signal. Low voltage monitoring This function is independent of the input triggering function. In addition, the typical current drawn by the VersaTimer/Switch is very low at around 13.3µA. Timer function The VersaTimer/Switch can be set to switch on or off with a trigger signal for a period from seconds through to five hours. It can be triggered from a high to low signal (eg, 5V to 0V), a low to high signal (eg, 0V to 5V) or from both voltage edges. Circuit description Refer now to Fig.1 for the complete circuit for the VersaTimer/Switch. It’s 64  Silicon Chip based on a PIC16F88-I/P microcontroller (IC1) which monitors the input trigger signal and drives the latching relay via transistors Q1-Q6. It also monitors the inputs that define all the circuit functions, including low battery protection. The trigger input is via IC2, a 4N28 optocoupler. This comprises an infrared LED and phototransistor in a 6-pin DIP package. When the infrared LED is not driven (off), the phototransistor is off. When the LED is on, the phototransistor is switched on. It can be driven by either AC or DC signals, since the internal LED is shunted with diode D4. The optocoupler provides isolation for the trigger input. This isolation allows the input LED to be driven from a signal that is not referenced to the supply ground of the VersaTimer/ Switch. We recommend a maximum of 50V between the LED drive signal and the supply ground for the VersaTimer/Switch. The input trigger current is typically 400µA when 5V is connected between the input “+” and “–“ terminals. This current is set by the 10kΩ limiting resistor (R1) and the 1V drop across the infrared LED. Minimum input trigger current is 225µA and so the input voltage can be as low as 3.25V, with a 10kΩ resistor. For lower input voltages, R1 can be changed to 1.5kΩ for 1.5V, 3kΩ for 2V and 6.2kΩ for 3V. The phototransistor inside IC2 is tied to the high (+5V) RB1 output of IC1 via a 470kΩ resistor. A 220nF capacitor keeps RB2 low when a lowvoltage 50Hz AC signal is applied to the trigger input. The 100Ω resistor is included at the emitter of the optocoupler transistor to limit the current when discharging the 220nF capacitor. S1 is included as a test switch to check the operation of the relay switching. Power saving strategies There are a number of aspects of this design which are included to save power. If the battery voltage is low, the 470kΩ pull-up resistor at RB2 is tied low via the RB1 output. This reduces the current flow should the phototransistor within IC2 be conducting due to infrared LED current. This feature reduces the supply current by 10.6µA when IC2 is conducting. While IC2 provides isolation of the input trigger signal, optocoupler IC3 is included simply to save power. IC3 is turned on when the RA0 output of IC1 goes high, to drive the internal infrared LED. This turns on IC3’s phototransistor to connect the voltage divider comprising the 22kΩ resistor and VR1 across the input supply, so that it can be monitored by the AN2 input. If this divider were permanently connected, then the current would be 363µA. By turning on the optocoupler for just 6ms every 10 seconds, we use 6.4mA to briefly drive the optocoupler LED but the average current to monitor the battery voltage drops to just 4µA. Power is also saved by running IC1 at 31.25kHz using an internal oscillator and divider. At this frequency, the microcontroller itself draws a mere 35µA. That’s pretty good but IC1 is also placed in sleep mode for most of the time, so that its current drain reduces to just 11µA (maximum). It’s awakened every 40ms for a short duration In addition, REG1 is a low quiescent power regulator that draws a mere 2µA. Further power savings are achieved by ensuring that IC1 applies voltage to trimpots VR2 and VR3 only at power up and when switch S2 (Reset) is pressed. These trimpots are used for setting the timer functions and are monitored by the AN6 and AN5 inputs of IC1. IC1 only needs to check these settings at power up as they do not change during operation. When the reset switch is pressed, siliconchip.com.au siliconchip.com.au June 2011  65 R1 10k  D4 A K 470 2 1 K 10 A K 2 1  IC2 4N28 4 5 TPG TP1 100 LOW (BOTH OPEN = HIGH & LOW) LK2 EDGE HIGH TRIGGERING LK1 COIL POLARITY ZD1 16V 1W S1 TEST 10nF 2 1 2 1 IN +5V 1 F VERSATIMER/SWITCH 4 5 IC3 4N28 22k A D1 1N4004 OUT 1k 8 7 1 2 18 17 1 F 100nF 470k A 220nF 10nF GND 14 4 RB2 RB1 AN2 Vss 5 RA4 RB0 AN6 AN5 RB3 RA6 RB5 RB4 RA7 MCLR IC1 PIC16F88-I/P RA3 RA1 RA0 Vdd 10k 3 6 13 12 9 15 11 10 16 A TP2 TP3 K 10k A VR3 10k 2 1 2 1 B MOMENTARY OPERATION E C C E A A ZD1 A Q3 BC337 K K D4: 1N4148 TOGGLE BOTH OPEN = FOLLOW LK3 0–50s BOTH OPEN = 0–5m 0–5H B Q1 BC327 B LK4 POWER UP VR2 10k E C 1k PULSE Q5 BC547 2x470 +5V TIMER 10nF 10nF D1-D3 1k 1k S2 RESET 10k D2 A K  K D3 Y Y X +11.4V + E C C E B B Q2 BC327 1k GND OUT IN MCP1703T K E B C BC327, BC337, BC547 A LEDS (NOTE: Q1, Q2, Q5 AND Q6 NOT REQUIRED FOR DOUBLE COIL RELAY) DOUBLE COIL LATCHING RELAY + + NC COM NO NC COM NO COM NO B Q6 BC547 100 F 16V 10k E C 10k SINGLE COIL LATCHING RELAY Y X A Q4 BC337 K  LED2 A 2.2k TO RELAY COIL(S) X LED1 K +11.4V Fig.1: a PIC16F88-I/P microcontroller (IC1) is used to control the latching relay via switching transistors Q1-Q6 (or Q3 & Q4 only if a double-coil relay is used). IC1 also monitors the trigger input via optocoupler IC2 (ie, at its RB2 port), while other ports monitor the trimpot and link settings to set the edge triggering and relay modes, the timer and the power-up defaults. Optocoupler IC3 is included as a power saving measure – it turns on only when IC1’s RA0 port goes high and applies voltage to VR1 so that the PIC microcontroller can monitor the input supply rail. 2011 VR1 20k SC  0V – INPUT + V+ 0V +12V REG1 MCP1703T-5002E/CB 0V 10k 1k S1 S2 TP2 IC2 VR3 VR2 100Ω Q5 470Ω 220nF 4N28 TP GND D3 4004 10k 2.2k LED2 LED1 10k TP3 4148 D4 4004 2 10k 1k IC1 PIC16F88-I/P – LK3 2 1 LK4 2 10nF RELAY 11160191 IC3 4N28 1 + 10nF IN 100 µF 1 100nF LK1 Q2 K 1k 10k TP1 470k V+ 1 LK2 2 1k 10nF 0V D2 10nF 470Ω +12V 10k K VR1 22k CON1 Q1 H CTI WS YALER G NI H CTAL D1 4004 (UNDER PCB) 1 µF CER 1k 16V 10Ω REG1 1 µF CER ZD1 470Ω Q4 Q3 WIRED FOR SINGLE COIL LATCHING RELAY 4148 D4 TP GND S2 TP2 100Ω VR2 VR3 D3 4004 H CTI WS YALER G NI H CTAL NO NC 11160191 CON3 COM NC CON4 – – NC + + NO RELAY NO COM MAXIMUM RELAY CONTACT RATING = 30VDC <at> 2A TP3 220nF 2.2k LED2 LED1 D2 4004 100 µF COM 1k S1 IC1 PIC16F88-I/P LK3 2 1 LK4 2 10nF 2 470Ω 10k 100nF LK1 IC2 0V 1 4N28 – 1 µF CER 1 µF CER IC3 1 + 10nF IN 1 LK2 2 1k V+ K 10k TP1 470k 0V K 10nF 470Ω 4N28 10nF CON1 (UNDER PCB) VR1 22k 1k D1 4004 10Ω 16V +12V REG1 470Ω Q3 Q4 WIRED FOR DOUBLE COIL LATCHING RELAY Fig.3: this version uses the Jaycar SY-4060 double-coil latching relay which has contacts rated at 30VDC <at> 2A. DO NOT use this version to switch the mains or other high voltages. the RB3 pin, which is normally an input, is set as an output and it goes high to 5V for the time required to read the trimpot settings. When high, the circuit current is increased by 1mA. Yet another power saving tactic involves preventing inputs RA3, RA4 & RB0 from floating if their respective link selections LK2, LK3 & LK4 do not have a link inserted. Any input that 66  Silicon Chip Fig.4: regulator REG1 is a surfacemount device and is mounted on the underside of the PCB as shown here. You will need a fine-tipped soldering iron to install it – see text for details. Q6 Fig.2: this is the version to build if you want to switch the mains (230VAC). It uses a 12V 60A or 80A single-coil latching relay with the contacts on the side (see photo). Refer to Fig.5 for the mains wiring details. ZD1 REG1 ON UNDERSIDE OF BOARD floats between 0V and 5V will cause that input to draw power. This is prevented by periodically driving these ports low for 500µs every 40ms. The 10nF capacitors keep the ports low between each drive period. Relay driving options If you are using a single-coil latching relay, it is driven using transistors Q1-Q6. For a double-coil relay, only transistors Q3 & Q4 are used and the other four transistors are omitted. In this case, the “+” sides of the relay coils are connected to the +11.4V supply and either Q3 or Q4 is switched on to drive the set or reset coil. Diodes D2 and D3 quench the backEMF voltage spike when the driven relay coil is switched off. D2 clamps the voltage when Q3 switches off and D3 clamps the voltage when Q4 switches off. We need all six transistors to drive the single-coil latching relay because we need to change the connection polarity to the coil to provide the set and reset pulses. For one polarity, RB4 switches on transistor Q3 and this connects one side (X) of the coil to 0V while the other (Y) side of the coil is connected to +11.4V via transistor Q2 which is switched on by Q6 when RA6 goes high. For the opposite polarity drive, Q4 is switched on by RB5 and Q1 is switched on via Q5 when RA7 goes high. Diode D2 quenches the stored charge within the relay coil when Q3 is switched off and to ensure this diode fully shunts the current, transistor Q2 is kept conducting for sufficient time after Q3 is switched off. Similarly, when Q4 is switched off, transistor Q1 is kept conducting to allow D3 to fully clamp the voltage as the coil field collapses. Link options Link LK1 selects the set or reset polarity for the relay coil drive circuitry. This is necessary for the battery protection function, so that the relay disconnects the load if the voltage siliconchip.com.au DPDT relay version uses less transistors and resistors compared to the SPST relay version. Figs.2 & 3 shows the parts layout on the PCB for the two versions. Start the assembly by installing regulator REG1 on the underside of the board as shown in Fig.4. This surface-mount part can be easily installed by first using a pair of self-closing tweezers to hold it in place while one of its legs is soldered. That done, check that the component is positioned correctly over the mounting pads before soldering the remaining two pins. Once REG1 is in position, flip the board over and install the single wire link. This goes in just below VR1 and you can either use 0.7mm diameter tinned copper wire or a 0Ω resistor. The resistors are next on the list. Table 1 shows the resistor colour codes but you should also check each one using a digital multimeter before soldering it into position. Follow with diodes D1-D4 and zener diode ZD1, taking care to ensure that they are all correctly orientated. Now for the transistors. Install Q1Q6 for the single-coil relay version but note that only Q3 & Q4 are installed if you are using the double-coil relay. Take care to install the correct transistor type in each position and make sure that they are correctly orientated. IC2 and IC3 can now be installed, along with an 18-pin socket for IC1. These parts must also be correctly orientated – see Figs.2 & 3. Leave This assembled PCB is for the version shown in Fig.3. Take care with parts orientation. drops below the threshold voltage set by trimpot VR1. The adjustment procedure is described later in this article. Links LK2-LK4 can be tied to the RA0 output (which can be high) or tied low to 0V. Alternatively, the associated inputs – RA3, RA4 & RB0 – can be left open circuit (ie, without a link). IC1 checks whether or not a link is installed by first setting its RA0 output high. If a link has been installed between the “A” terminal and an input, that will then cause that input to go high. Conversely, if a link has been installed between an input and 0V, that input will go low. An input without a link connection can be driven both high and low. Reading the input levels after driving the RA3, RA4 and RB0 pins high and low as outputs allows IC1 to determine which links are installed. LEDs 1 & 2 indicate the relay switching. LED1 lights whenever transistor Q3 is switched on and LED2 lights whenever Q4 is switched on. The length of time each LED lights is set by the relay pulse length. Construction The VersaTimer/Switch is built on a PCB coded 19106111 and measuring 103 x 78mm. This fits neatly inside an IP65 polycarbonate case measuring 115 x 90 x 55mm, with the PCB secured to the integral stand-offs using M3 x 6mm screws. Begin be checking that the PCB has the necessary corner cut-outs so that it fits into the box. It can be filed to shape if necessary using the PCB outline shape as a guide. That done, check the PCB for any breaks in the tracks or shorts between tracks and pads. Check also that the hole sizes are correct by test fitting the larger parts (ie, the screw terminal blocks and relay). The corner mounting holes should be 3mm in diameter. Note that two different versions can be built, each using a different relay. Both use 12VDC latching relays but these have different contact configurations and ratings. One relay is a double-coil type with 2A DPDT contacts (Jaycar SY-4060), while the other is a single-coil type with 60A or 80A 250VAC SPST contacts. Follow the correct overlay diagram for your particular relay. The assembly is almost exactly the same for each version. However, the Table 2: Capacitor Codes Value 1µF 220nF 100nF 10nF µF Value IEC Code EIA Code 1µF   1u0 105 0.22µF 220n 224 0.1µF 100n 104 0.01µF   10n 103 Table 1: Resistor Colour Codes o o o o o o o o o siliconchip.com.au No.   1   1 2/6   1 3/5   3   1   1 Value 470kΩ 22kΩ 10kΩ 2.2kΩ 1kΩ 470Ω 100Ω 10Ω 4-Band Code (1%) yellow violet yellow brown red red orange brown brown black orange brown red red red brown brown black red brown yellow violet brown brown brown black brown brown brown black black brown 5-Band Code (1%) yellow violet black orange brown red red black red brown brown black black red brown red red black brown brown brown black black brown brown yellow violet black black brown brown black black black brown brown black black gold brown June 2011  67 4148 4148 PCB M3 x 15mm TAPPED NYLON SPACER AGAINST SIDE OF PRESSPAHN COVER (HELD IN PLACE VIA M3 x 6mm NYLON SCREW) RELAY RELAY CONTACT TERMINALS HEATSHRINK SLEEVING COVERING SOLDER JOINTS & TERMINAL ENDS PRESSPAHN COVER OVER MAINS CONNECTIONS (SEE BELOW) CABLE TIE HOLDS END OF CABLE IN PLACE This view shows how the mains wiring is installed. Insulate the relay terminals with heatshrink and be sure to use Nylon screws to secure the Presspahn cover. Heavy cable will be required to cope with high currents. M3 x 6mm NYLON SCREW & NUT BOX USE M3 x 6mm NYLON SCREW FOR MOUNTING THIS CORNER OF PCB CORD GRIP GROMMET header strip. Install them in the positions shown but leave the jumper links off for the time being. Finally, complete the PCB assembly by installing PC stakes at TP1, TP2, TP3 & TP GND, followed by switches S1 & S2. These miniature switches go in at the bottom left of IC1. SHEATHED MAINS RATED CABLE Fig.5: here’s how to wire the version shown in Fig.2 to switch the mains. Make sure that the 2-wire mains cord is adequately rated for the job and that it is anchored to the case using a cordgrip grommet. You must also insulate the relay terminals with heatshrink and make a Presspahn cover (see below) to isolate the mains connections from the low-voltage circuitry. Mounting it in the case 15 PRESSPAHN COVER CUTTING & FOLDING DETAILS 27 27 FOLD UP FOLD UP FOLD UP FOLD UP 27 27 27 Fig.6: the Presspahn insulating cover is cut from a 108 x 42mm sheet and is folded to form a box, as shown here. You will need to drill holes in the righthand section to accept the Nylon securing screws and a cable tie. microcontroller IC1 out of its socket for the time being. It’s installed later, after the power supply checks have been completed. Follow with the capacitors and trimpots VR1-VR3. Make sure the electrolytic capacitor goes in the right way around and be careful not to get the trimpots mixed up. VR1 is a 20kΩ unit while the other two are 10kΩ types. The 6-way screw terminal blocks are made up by dovetailing either two 3-way or three 2-way blocks together. These can be installed now, with their openings towards the adjacent edge of 68  Silicon Chip the board. Note that the second 6-way screw terminal block is only required for the DPDT relay version (Fig.3). Installing the LEDs The two LEDs are mounted so that the top of each LED is about 8mm above the PCB. This can be achieved by sliding a 3mm cardboard spacer between their leads when soldering them into position. Take care with their orientation – the anode lead of each LED is the longer of the two. The 3-way headers for LK1-LK4 are simply snapped off a single in-line Before fitting the PCB, you will need to drill holes in the case to accept the external leads. For mains switching, you will need to fit a cable gland at one end of the case (for the input trigger and supply leads) and a mains cordgrip grommet (to secure a mains lead) on one side of the case as shown in Fig.5. If you are not switching mains voltages (ie, you are using the arrangement shown in Fig.3), then you will need to install cable glands at both ends of the case, in line with the centres of the screw terminal blocks. Note that only the SPST 60A or 80A relay is suitable for switching mains voltages and this must be installed using the arrangement shown in Fig.2 and Fig.5. The 2A DPDT relay (Jaycar SY-4060) used in Fig.3 is not suitable for mains switching. In addition, the track spacing on the PCB is NOT suitable for mains voltages. Mains switching Fig.5 shows how to wire the unit to switch the mains. However, do NOT attempt to do this unless you are experienced at working with high-voltage siliconchip.com.au wiring and know exactly what you are doing. Make sure also that the mains cable is adequately rated for the load current. Our prototype shows a light-duty 7.5A cable in place but you must use a heavier cable for higher currents. A cord­grip grommet is used to secure the sheathed mains-rated cable to the box (for cables up to 10A). The hole for this grommet must be carefully sized and shaped so that the cord is clamped securely when the grommet is inserted into this hole. That last step is critical – if the hole is too big, the cord will not be clamped securely. As shown, the mains leads are soldered directly to the relay terminals and these must then be insulated using 10mm-diameter heatshrink sleeving. Do not bend the relay terminals as they are liable to break. In addition, it’s necessary to isolate this mains section from the low-voltage circuitry using a Presspahn cover. Fig.6 shows how to make this cover. It’s cut out from a 108 x 42mm piece which is then folded as shown to make a box. Once it’s made, you will need to drill holes in the righthand 27 x 27mm section to match the four 3mm holes (including the mounting hole) in the corner of the PCB. That done, the Presspahn cover can be attached to the PCB using an M3 x 6mm Nylon screw and nut – see Fig.5. The mains lead is then secured to the PCB using a cable tie which loops down through two of the other holes. Before finally installing the board in the case, it will also be necessary to connect the supply and trigger wiring to the 6-way screw terminal block. The PCB assembly can then be dropped into the case and secured using M3 x 6mm screws. Note that you must use a Nylon screw for the corner hole that goes though the Pesspahn (ie, the two screws used to secure the Presspahn material must both by Nylon types). Using Nylon screws ensures that the mains remains isolated from the low-voltage section of the PCB, even if one of the mains wires breaks away from its relay terminal and contacts one of these screws. In addition, a Nylon screw and an M3 x 15mm tapped Nylon spacer is attached to the side of the box, directly above transistors Q4 & Q6. This holds the side of the Presspahn material in place and ensures that it remains siliconchip.com.au The Presspahn insulation folds over to box in the mains connections. Note that one relay terminal protrudes through the side of the cover and this must be insulated using heatshrink sleeving. in position when it’s folded over to form a box and the lid attached. It also stops the Presspahn from bending and damaging the transistors. Complete the assembly by fitting the front panel label. It can be downloaded in PDF format from the SILICON CHIP website. Setting up With IC1 out of circuit, apply power (eg, from a 12V battery) to the +12V and 0V inputs and check the voltage between pin 14 of IC1’s socket and TP GND. This should be very close to 5V, ie, between 4.98V and 5.02V. If this is correct, switch off and insert IC1 into its socket, taking care to orientate it correctly. Now measure the supply voltage applied to the circuit at the +12V input. Using a calculator, divide this voltage by three. Next, use your DMM to monitor the voltage between TP1 and TP GND and press switch S2. Adjust VR1 so that the DMM reads the supply voltage divided by three value, as calculated above (eg, if the supply voltage measures 12.3V, adjust VR1 to give 4.1V between TP1 and TP GND). This adjustment sets the low-battery switch-off value to 11.5V, with the circuit then remaining in standby until the battery voltage rises to 12V. The actual voltages measured by IC1 are 3.83V for the low battery switch-off and 4V for the relay return voltage. This setting can be changed if a different low-battery switch-off voltage is required. The required voltage at TP1 is calculated simply by first dividing the required low-battery switch-off voltage by 3.83V. This value then becomes the divisor for the input supply voltage and the resulting divided value becomes the voltage setting for TP1. For example, let’s say that the required low-battery switch-off voltage is 11V. In this case, 11V divided by 3.83 = 2.87. If the battery voltage is exactly 12V, we simply divide this by 2.87 to get 4.18V. This voltage is then set at TP1 using trimpot VR1. The switch-on (ie, resume) voltage after a low voltage has been detected is now the 4V return voltage multiplied by 2.87. This gives 11.48V. Relay pulse duration Trimpot VR2 sets the pulse duration for the relay. In practice, this can be set anywhere from 0-500ms, with 1V on VR2’s wiper giving 100ms (ie, divide the voltage reading by 10). To carry out this adjustment, connect a DMM between TP2 and TP GND and press S2. It’s then just a matter of adjusting VR2 to set the recommended pulse duration for the relay. For the Jaycar SY-4060, the pulse duration required is about 25ms, so VR2 is set to give 250mV on TP2. For the 60A and 80A relays, the pulse June 2011  69 4148 – TRIGGER IN – – 0V CONTACT SET 1 11160191 + NO + + NC V+ COM 0V H CTI WS YALER G NI H CTAL +12V COM +12V NO 0V NC NO LINK LK1: LK1 sets the relay state when the battery is low. Generally, this is set so that the relay’s NO and COM contacts open when the low-battery cut-out point is reached, to remove battery power from the load. This is done by installing LK1 in position 2. If you use a different relay to the types specified, then LK1 may need 4148 WIRING AN EXTERNAL TRIGGER SWITCH DOUBLE COIL RELAY VERSION CONNECTIONS Setting the links 0V EXTERNAL SWITCH CONTACT SET 2 Fig.7: this diagram shows the external connections to the double-coil relay version. It’s suitable for switching low voltages only (up to 30VDC <at> 2A). needs to be equal to or greater than 60ms which means that VR2 should be set to give at least 600mV. V+ WIRE LINK NC COM MAXIMUM RELAY CONTACT RATING = 30V <at> 2A 4148 4004 4148 16V 4004 16V Fig.8: here’s how to wire an external trigger switch (both versions). to be placed in position 1 to achieve the same result, ie, so that the contacts are open on low battery. You can ensure that LK1 is correct by checking that the relay’s contacts open when the supply is reduced below 11.5V or if VR1 is adjusted fully anticlockwise. You will need to wait about 10s for the low-battery voltage to be detected and the relay switched. Be sure to readjust VR1 to its correct position after checking this operation, as described previously. LED1 lights briefly when the relay contacts close, while LED2 lights briefly when they open. This assumes that you are using one of the specified relays and that LK1 is in position 2. The operation of the LEDs is reversed if LK1 is placed in position 1. LINK LK2: LK2 sets the input trigger edge level. With LK2 in position 2, the relay is triggered when the input signal drops from a high level to 0V (ie, a falling edge trigger). In position 1, the relay triggers on a rising input signal, eg from 0V to 5V (or similar). If LK2 is left out, the relay triggers Table 3: Link Settings & Trimpot Adjustments Link Setting Position 1 Position 2 Open Notes LK1 Low Battery State NO contacts closed on low battery NO contacts open on low battery Not used Relay contact state with low battery LK2 Edge Triggering Triggers on high-going input & when S1 closes Triggers on low-going input & when S1 opens Triggers on both edges and when S1 closes or opens LK3 Operation Momentary with timer Toggle (or alternate) Follow input LK4 with LK3 set for Timer Mode 0-5h 0-50s 0-5m VR2 sets value LK4 with LK3 set for Toggle Mode Powers up with NO contacts closed Powers up with NO contacts open Not used Power up relay state Adjustments Use VR1 Sets low battery switching voltage TP1 monitors divided battery voltage with S2 pressed VR2 Relay pulse duration 0-500ms TP2 monitors VR2 setting with S2 pressed VR3 Timer value TP3 monitors VR3 setting with S2 pressed S1 Test operation S2 Resets timer and sets changed links and adjustments Press whenever links or adjustments are made S2 Press and hold at power up to change timer relay state Selects either NO contact closed with timer or NO contact open with timer 70  Silicon Chip siliconchip.com.au on both rising and falling edges. LINK LK3: LK3 sets the relay operation to either Momentary mode (position 1), Toggle mode (position 2) or Follow mode (no link). The Momentary mode operates with a timer. Once triggered, the relay switches on for the timer duration and then turns off again. By contrast, in Toggle mode, the relay changes state on each trigger signal. Once triggered, it remains in that state until the next trigger signal arrives. The Follow mode allows the unit to be used as a replacement for a standard relay. It duplicates the operation of a standard (non-latching) relay. LINK LK4: LK4 sets the timer range for the Momentary mode. LK4 in position 1 gives a range of 0-5 hours, position 2 gives 0-50 seconds and no link gives 0-5 minutes. The exact time-out value is set by trimpot VR3. For the 0-50s range (position 2), 1V at TP3 (with S2 pressed) gives 10s, 2V gives 20s and so on, up to 5V which gives 50s. Other voltages give corresponding timeout values, eg, 0.5V gives 5s and 2.5V gives 25s. Similarly, for the 0-5 hour range (position 1), 1V at TP3 is equivalent to 1 hour and for the 0-5 minute range (LK4 not installed), 1V at TP3 is equivalent to 1 minute. Switch S2 can be used to cancel (or reset) the time-out during timing. Any retriggering during timing will be ignored. By default, the unit is set so that during timing, the relay’s NO contact is closed. This means that the NO contacts are normally open at power up and after time-out. However, this can be changed so that the relay’s NO contact is closed at power up and open during timing. To do this, press and hold S2 for 5s during power up and the option will be set. Repeat this procedure to revert to the default mode. Link LK4 can also be used when the unit is set to Toggle mode (LK3 in position 2), to select the relay state at power-up. Installing LK4 in position 1 sets the NO contacts closed at power-up, while position 2 sets the NO contacts open at power-up. LK4 has no effect in the Follow mode. trigger the unit, so that you can test the unit without having to feed in an external trigger signal. LEDs1 & 2 indicate the relay operation. As stated, LED1 briefly lights when the relay contacts close, while LED2 briefly lights when they open. Test switch Triggering input Test switch S1 allows you to easily check the results of the above link settings. It simply allows you to manually The IN+ and IN– inputs are used to trigger the VersaTimer/Switch. The maximum trigger voltage is 35V and siliconchip.com.au Parts List 1 PCB, code 19106111, 103 x 78mm 1 115 x 90 x 55mm IP65 polycarbonate enclosure 1 12VDC latching relay (see below) 1 DIP18 IC socket 2 3-6.5mm diameter cable IP65 cable glands 2 3-way PC-mount screw terminal blocks, 5.08mm spacing 1 12-pin SIL pin header with 2.54mm spacings (broken into 4 x 3-way headers) 4 2.54mm pin spacing jumper plugs 2 momentary pushbutton 2-pin PC mount switches (S1,S2) 4 M3 x 6mm screws 4 PC stakes 1 20kΩ miniature horizontal trimpot (VR1) 2 10kΩ miniature horizontal trimpots (VR2,VR3) Semiconductors 1 PIC16F88-I/P microcontroller (IC1) programmed with 1910611A.hex 2 4N28 optocouplers (IC2,IC3) 1 MCP1703T-5002E/CB 250mA 5V low-dropout low-quiescent current regulator (REG1) 2 BC337 NPN transistors (Q3,Q4) 1 3mm green LED (LED1) 1 3mm red LED (LED2) 3 1N4004 1A diodes (D1-D3) 1 1N4148 signal diode (D4) 1 16V 1W zener diode (ZD1) Capacitors 1 100µF 16V PC electrolytic 2 1µF monolithic ceramic 1 220nF MKT polyester 1 100nF MKT polyester 4 10nF MKT polyester Resistors (0.25W 1%) 1 470kΩ 3 1kΩ 1 22kΩ 3 470Ω 2 10kΩ 1 100Ω 1 2.2kΩ 1 10Ω Additional parts for 30V 2A DPDT version 1 12VDC DPDT 2A <at> 30VDC latching relay (Jaycar SY-4060) 2 3-way PC-mount screw terminal blocks, 5.08mm spacing Additional parts for 250VAC 60A or 80A SPST version 1 12V SPST 80A <at> 250VAC latching relay [Oatley Electronics JMX-94F-A-Z (www.oatleyelectronics.com)] Or 1 12V SPST 60A <at> 250VAC latching relay [Virtual-village (www.virtual-village.com.au) or see www.virtualvillage.com.au/4-x-12v-coilpolarized-latching-relays60a-250v-ac-003602-027.html] 2 BC327 PNP transistors (Q1,Q2) 2 BC547 NPN transistors (Q5,Q6) 4 10kΩ 0.25W 1% resistors 2 1kΩ 0.25W 1% resistors Additional parts for for mains control switching 1 108 x 42mm Presspahn sheet 2 M3 x 6mm Nylon screws 1 M3 x 15mm Nylon screw 1 M3 tapped Nylon standoff 15mm long 1 M3 nut 1 cord grip grommet to suit the sheathed mains cable 1 100mm cable tie the minimum is 3.25V if the 10kΩ resistor used for R1. The trigger signal must be capable of delivering about 400µA with a 5V supply. Note that R1 should be changed to 6.2kΩ for a 3V trigger input, 3kΩ for a 2V trigger input and 1.5kΩ for a 1.5V trigger input. Note also that the triggering input is electrically isolated so that a voltage that is not referenced to the Versa­ Timer/Switch circuit can be used as June 2011  71 Latching relay A latching relay differs from a standard (non-latching) relay in that it will remain in either state (or latch) without further power. In some ways, this is analogous to a conventional household light switch – when the switch is flicked to one position, it remains there until the actuator (or switch lever) is switched back to its alternative position. However, instead of the switch lever, a latching relay uses a coil and an armature to activate the switching action. a trigger. The voltage differential between the trigger source and the Versa­ timer/Switch circuit should limited to a maximum of 50V. The triggering sensitivity is quite good. In fact, the unit can be triggered 72  Silicon Chip Fig.10(a) shows the internal construction of a latching relay. It includes two horseshoe-shaped bar magnets which are positioned between the C-shaped core (or pole pieces) of the relay coil. These two bar magnets are physically separated and attached to a pivot which allows the assembly to rotate clockwise and anticlockwise between the C-core. This pivoting assembly is called the “armature”. When the armature is in its anticlockwise position, the top bar magnet’s south pole is attracted to the top section of the currently non-magnetised C-core (or pole piece), while the bottom bar magnet’s north pole is attracted to the lower section. As a result, the armature is held in that position. Note that the bar magnets can be horseshoe shaped as shown in Fig.10(a) or they can be two straight bars with north on one face and south on the other. The latching relay depicted in Fig.10(a) is activated by applying a voltage to the coil, so that the current flows in a direction that causes the top of the C-core to become a south pole and the bottom to become a north pole. When that happens, the like south poles at the top and the like north poles at the bottom are repelled from each other. At the same time, the south pole at the top of the C-core attracts the north pole of the top magnet, while the north pole at the bottom of the C-core attracts the south pole of the bottom armature magnet. As a result, the armature rotates clockwise to the position shown in Fig.10(b). The armature now remains (or latches) in this position, even after coil current is removed. That’s because the north pole at the top of the armature is still attracted to the C-core (which becomes non-magnetised when the coil current ceases). Similarly, the south pole at the bottom of the armature is attracted to bottom pole piece of the now non-magnetised C-core. Flipping back Getting the relay to latch back into its previous position simply involves feeding a by connecting the input across an indicator LED in an external device (ie, it will trigger when the LED lights). Note, however, that R1 should be reduced to either 3kΩ or 1.5kΩ to ensure reliable triggering in this situation. FLEXIBLE CONNECTION POLE (INSIDE COIL) ARMATURE CONTACTS COIL COIL CONNECTIONS NC NO COM NON-LATCHING RELAY CONSTRUCTION A V+ RELAY NC COM NO 2 1 S1 B NON-LATCHING RELAY DRIVE V+ RELAY NC S1 C COM The most common relay is the standard non-latching type. This comprises a relay coil, an armature and switch contacts as shown in Fig.9(a). When no current flows through the coil, the relay contacts are held in their normal position by spring tension, with the NC (normally closed) contact resting against the COM (common) contact and the normally open (NO) contact left open. Conversely, when the relay is powered, the current through the coil causes the armature to be attracted to the coil’s pole piece and this moves the relay contacts to their opposite position. As a result, the COM contact closes against the NO contact and the NC contact opens. Fig.9(b) shows how a standard nonlatching relay can be driven using a switch. The switch (S1) simply connects power to the coil when it is closed. Another arrangement for the non-latch­ ing relay is when the common (COM) and normally open (NO) contacts are used together with a momentary contact switch to form a self-latching operation – see Fig.9(c). Pressing the pushbutton switch (S1) activates the relay and closes the NO and COM contacts. These contacts now form a parallel connection across S1 so that when S1 is opened, the relay coil remains energised. These closed contacts (or other con­ tacts) can also be used to power external circuitry. Note, however, that this selflatching relay circuit is not the same as a latching-type relay, since the relay continues to draw coil current. SPRING PIVOT NO Latching Relays: How They Work SELF-LATCHING RELAY CONNECTION Fig.9: internal details of a non-latch­ ing relay (A) plus non-latching (B) and self-latching (C) drive circuits. Finally, connect the inputs as shown in Fig.8 if you want to trigger the unit using an external pushbutton switch. Note that the switch current adds to the battery drain while it is pressed SC and is 1.1mA at 12V. siliconchip.com.au Latching relay variations Latching relays come in two different types: single coil and double coil. As stated, the single coil latching relay changes state depending on the polarity of the voltage applied to the coil. By contrast, a double-coil type relay uses one coil to set the contacts one way and another coil to reset them back the other way. The advantage of the double-coil relay is that fewer components are required to drive it. Fig.11(a) shows how a single-coil latching relay can be driven using a DP3P switch. In position 1, the top of the coil is at ground and the lower end of the coil is connected to the positive supply. This causes the relay to be in its reset state, with the NO contact open and the NC contact shorted to the COM contact. In position 2, no current flows to the coil while in position 3, the coil current is reversed and the relay switches to the siliconchip.com.au ACTUATOR ARM ACTUATOR ARM POLE PIECE S S RE ARM A TU POLE (INSIDE COIL) COIL PIVOT N S S POLE PIECE 2 1 OPEN COM OPEN COIL CONNECTIONS A POLE PIECE CONTACTS LATCHING RELAY CONSTRUCTION COIL CONNECTIONS CLOSED 2 COIL S N CONTACTS 1 S N PIVOT RE ARM ATU N POLE PIECE POLE (INSIDE COIL) N N CLOSED COM current pulse through the coil in the opposite direction. This forces the top pole piece to become a north pole and the bottom pole piece to become a south pole. As a result, the armature rotates anti-clockwise, back to the position shown in Fig.10(a) Note that the current direction through the coil must be correct in order to get the relay to change state. If it isn’t, the armature remains in its present position. Note also that the north and south markings for the pole pieces in Figs.10(a) & 10(b) are those that would cause the armature to rotate to the position shown. However, as stated, these poles become non-magnetised when coil current ceases. In practice, the coil current is only required for a brief period in order to move the armature to its alternative position. The current pulse can be as short as 5ms for small relays and about 60ms for larger relays. It’s both undesirable and unnecessary to have the coil energised permanently. Prolonged magnetisation of the pole pieces can cause them to become permanently magnetised (called “remanent magnetism”). When this happens, the latching action is less effective in one position (ie, where the remanent magnetism repels the attracted pole after power is removed). This also reduces the current rating of the contacts due to reduced contact pressure. As shown, the armature of the latching relay drives a lever and this in turn opens and closes the contacts. The accompanying photos also show a latching relay with the armature in its alternative positions. LATCHING RELAY IN ALTERNATE STATE B Fig.10: how a latching relay works. It uses magnets at either end of a moving armature which are attracted/repelled by the polepieces, depending on the direction of the current pulse applied to the coil. These inside photos show the two armature positions inside a single-coil latching relay. The armature remains in its last position until the next current pulse is applied to the coil (ie, it self-latches). set position. As a result, the COM contact closes against the NO contact and the NC contact is now open. Fig.11(b) shows the simpler switching arrangement that’s used for a double-coil latching relay. In this case, the relay can be controlled using a SP3P switch, with one coil driven with the switch in position 1 and the other coil driven in position 3. Finally, note that the traditional NO and NC nomenclature does not really apply for latching relays. However, the relay manufacturers still generally indicate NO and NC contacts and qualify these states as valid when a certain current polarity is SC applied to one of the coils. V+ V+ 3 S1a RELAY 2 1 3 R NC S S1b 2 S R RELAY 1 NO COM NC 2 3 COM NO S1 1 A SINGLE COIL LATCHING RELAY DRIVE B DOUBLE COIL LATCHING RELAY DRIVE Fig.11: a single-coil latching relay (A) can be driven using a DP3P switch. The switching for a double-coil latching relay is somewhat simpler since only a SP3P switch is required. No current flows through the coil(s) in position 2. June 2011  73