Silicon ChipFlexible Digital Lighting Controller, part 1 - October 2020 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: The balance between historical and forward-looking articles
  4. Feature: Satellite Navigation in Space by Dr David Maddison
  5. Project: D1 Mini LCD BackPack with WiFi by Tim Blythman
  6. Feature: Improved ADS-B Reception on a Computer by Jim Rowe
  7. Project: Flexible Digital Lighting Controller, part 1 by Tim Blythman
  8. PartShop
  9. Serviceman's Log: Decisions, decisions, decisions... by Dave Thompson
  10. Review: The CAE SoundCam by Allan Linton-Smith
  11. Project: USB SuperCodec – part three by Phil Prosser
  12. Vintage Radio: AWA model 501 console radio by Associate Professor Graham Parslow
  13. Project: High Power Ultrasonic Cleaner – part two by John Clarke
  14. Product Showcase
  15. Feature: The Matrox ALT-256 Graphics Card by Hugo Holden
  16. Market Centre
  17. Notes & Errata: Four USB power supplies for laptop charger, Circuit Notebook, August 2020; Velco 1937 radio chassis restoration, August 2020; Infrared Remote Control Assistant, July 2020
  18. Advertising Index
  19. Outer Back Cover

This is only a preview of the October 2020 issue of Silicon Chip.

You can view 40 of the 112 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 "D1 Mini LCD BackPack with WiFi":
  • Mini WiFi LCD BackPack PCB [24106201] (AUD $5.00)
  • 3.5-inch TFT Touchscreen LCD module with SD card socket (Component, AUD $35.00)
  • Mini WiFi LCD BackPack kit (Component, AUD $70.00)
  • Matte/Gloss Black UB3 Lid for Micromite LCD BackPack V3 or Pico BackPack using 3.5in screen (PCB, AUD $5.00)
  • Arduino sketch for the Mini WiFi LCD BackPack (Software, Free)
  • Mini WiFi LCD BackPack PCB pattern (PDF download) [24106201] (Free)
Items relevant to "Flexible Digital Lighting Controller, part 1":
  • Flexible Digital Lighting Controller main PCB [16110202] (AUD $20.00)
  • Flexible Digital Lighting Controller Micromite Master PCB [16110201] (AUD $5.00)
  • Flexible Digital Lighting Controller CP2102 Adaptor PCB [16110204] (AUD $2.50)
  • Flexible Digital Lighting Controller LED slave PCB [16110205] (AUD $5.00)
  • PIC16F1705-I/P programmed for the Flexible Digital Lighting Controller [1611020A.HEX] (Programmed Microcontroller, AUD $10.00)
  • PIC32MX170F256B-50I/SP programmed for the Flexible Digital Lighting Controller Micromite master [1611020B.hex] (Programmed Microcontroller, AUD $15.00)
  • PIC16F1455-I/P programmed for the Flexible Digital Lighting Controller WS2812 Slave [16110205.HEX] (Programmed Microcontroller, AUD $10.00)
  • Si8751AB 2.5kV isolated Mosfet driver with integral power supply (Component, AUD $10.00)
  • Micromite LCD BackPack V3 complete kit (Component, AUD $75.00)
  • Hard-to-get parts for the Flexible Digital Lighting Controller (Component, AUD $100.00)
  • Flexible Digital Lighting Controller front panel PCB [16110203] (AUD $20.00)
  • Firmware and software for the Fiexible Digital Lighting Controller (Free)
  • Firmware and PC software for the Digital Lighting Controller [1611010A.HEX] (Free)
  • Flexible Digital Lighting Controller mains slave PCB patterns (PDF download) [16110202-3] (Free)
  • Flexible Digital Lighting Controller Master PCB patterns (PDF download) [16110201, 16110204] (Free)
  • Flexible Digital Lighting Controller LED slave PCB pattern (PDF download) [16110205] (Free)
  • Drilling and cutting diagrams for the Flexible Digital Lighting Controller Micromite master (PDF download) (Panel Artwork, Free)
  • Cutting diagram for the Flexible Digital Lighting Controller mains slave rear panel (PDF download) (Panel Artwork, Free)
  • Cutting diagrams and front panel artwork for the Flexible Digital Lighting Controller LED slave (PDF download) (Free)
Articles in this series:
  • Flexible Digital Lighting Controller, part 1 (October 2020)
  • Flexible Digital Lighting Controller, part 1 (October 2020)
  • Flexible Digital Lighting Controller, part 2 (November 2020)
  • Flexible Digital Lighting Controller, part 2 (November 2020)
  • Flexible Digital Lighting Controller, part 3 (December 2020)
  • Flexible Digital Lighting Controller, part 3 (December 2020)
  • Digital Lighting Controller Translator (December 2021)
  • Digital Lighting Controller Translator (December 2021)
Items relevant to "USB SuperCodec – part three":
  • USB SuperCodec PCB [01106201] (AUD $12.50)
  • USB SuperCodec Balanced Input Attenuator add-on PCB [01106202] (AUD $7.50)
  • Parts source grid for the USB SuperCodec (Software, Free)
  • USB SuperCodec PCB pattern (PDF download) [01106201] (Free)
  • USB SuperCodec Balanced Input Attenuator add-on PCB pattern (PDF download) [01106202] (Free)
  • USB SuperCodec front panel artwork (PDF download) (Free)
  • Drilling and cutting diagrams for the USB SuperCodec Balanced Input Attenuator (PDF download) (Panel Artwork, Free)
Articles in this series:
  • USB SuperCodec (August 2020)
  • USB SuperCodec (August 2020)
  • USB SuperCodec – part two (September 2020)
  • USB SuperCodec – part two (September 2020)
  • USB SuperCodec – part three (October 2020)
  • USB SuperCodec – part three (October 2020)
  • Balanced Input Attenuator for the USB SuperCodec (November 2020)
  • Balanced Input Attenuator for the USB SuperCodec (November 2020)
  • Balanced Input Attenuator for the USB SuperCodec, Part 2 (December 2020)
  • Balanced Input Attenuator for the USB SuperCodec, Part 2 (December 2020)
Items relevant to "High Power Ultrasonic Cleaner – part two":
  • High Power Ultrasonic Cleaner main PCB [04105201] (AUD $7.50)
  • High Power Ultrasonic Cleaner front panel PCB [04105202] (AUD $5.00)
  • PIC16F1459-I/P programmed for the High Power Ultrasonic Cleaner [0410520A.HEX] (Programmed Microcontroller, AUD $10.00)
  • One 40kHz 50W ultrasonic transducer (Component, AUD $55.00)
  • ETD29 transformer components (AUD $15.00)
  • Hard-to-get parts for the High Power Ultrasonic Cleaner (Component, AUD $35.00)
  • High Power Ultrasonic Cleaner main PCB patterns (PDF download) [04105201-2] (Free)
  • High Power Ultrasonic Cleaner lid panel artwork & drilling diagram (PDF download) (Free)
Articles in this series:
  • High Power Ultrasonic Cleaner (September 2020)
  • High Power Ultrasonic Cleaner (September 2020)
  • High Power Ultrasonic Cleaner – part two (October 2020)
  • High Power Ultrasonic Cleaner – part two (October 2020)
Articles in this series:
  • The Matrox ALT-256 Graphics Card (October 2020)
  • The Matrox ALT-256 Graphics Card (October 2020)
  • The Vintage Matrox ALT-512 Graphics Card (November 2020)
  • The Vintage Matrox ALT-512 Graphics Card (November 2020)

Purchase a printed copy of this issue for $10.00.

You won’t believe what you can do with this one! Flexible Digital Lighting Controller Create a truly spectacular lighting display – large or small – with this very flexible, very expandable Digital Lighting Controller. It’s sensational for Christmas lights but it could be used for other things like amateur theatre lighting control or even controlling lamps around your home. Incidentally, we aren’t pretending that the incredible display on this page either came from this controller or, indeed, was put together by us. (It’s actually from England). The point is, if you wanted to produce something like this . . . you could! By Tim Blythman 36 Silicon Chip Australia’s electronics magazine siliconchip.com.au I t’s been exactly ten years since we published a Digital Lighting Controller – the last one was in October 2010 (siliconchip.com.au/Series/14). It used one control unit that could control up to four slave units with eight lights each, so it could manage up to 32 mains-powered lights. It was a popular project, with Altronics producing kits. Some of these were used to create amazing Christmas displays. You can see one of these at https://youtu.be/mBgLltJ5br8 Unfortunately, those kits have now been discontinued, and the question arose: should we design a new Digital Lighting Controller, and could we make it easier to build with more capabilities? The answers are yes, yes and yes! Ten years later A lot has happened in the last ten years. In particular, the Arduino ‘ecosystem’ has flourished, making it much easier for the average person to program a microcontroller. Stunning LED light displays are now possible using chainable LED strips such as those using the WS2812 type ‘smart’ LEDs. But there are still times when you might want to control mains-powered lights, or indeed, a mixture of mainspowered lights and DC-powered LEDs or LED strips. Controlling mains-powered lights with an Arduino (or any microcontroller) can be hard. One simple way is to use our Opto-isolated Mains Relay project from October 2018 (siliconchip. com.au/Article/11267). That makes it possible to switch mains devices off and on easily and safely. But it can only control one device at Features & specifications • • • • • • • Modern solid-state lighting controller with trailing-edge dimming Four channels per slave unit 16 slave addresses available for up to 64 channels total Up to 250W of lights per channel (limited by fuse & PCB tracks) 256 brightness steps (0-100%) per light Serial control interface works with just about any microcontroller Informative front panel a time, and only switches it on or off. For a great lighting display, you need to be able to control lots of lights and vary their brightness, not just switch them on or off. Hence, our new Digital Lighting Controller which can do all of this. New and improved The new Digital Lighting Controller uses a very similar overall philosophy to the previous design. A single ‘master’ unit can interface to and control many ‘slave’ units, each of which drives multiple mains outlets. The old design used an eight-wire shift register interface to trigger a Triac every mains half-cycle via an optocoupler. That meant that the master unit had to drive the bus continuously for the outlets to be activated on time. The nature of the shift-register interface also means that there were only 20 Triac trigger points in each half-cycle and thus 20 distinct dimming levels. Our new design does not have this limitation and can produce 256 different levels, giving seamless ‘fades’ in and out. Using Triacs also meant that only leading-edge dimming was possible, as the Triacs latch on until the end of the half-cycle at the next mains zerocrossing (see Fig.1 overleaf). That limits its usage pretty much just to incan- descent or halogen lamps. In February 2019, we introduced the Versatile Trailing Edge Dimmer (siliconchip.com.au/Series/332). It uses a pair of back-to-back Mosfets to switch the connected lamps on and off at the correct times. Rather than applying power midcycle and shutting it off at the end of the cycle like a traditional dimmer, a trailing-edge dimmer applies power from the zero-crossing and shuts it off at some later point in the mains cycle (Fig.2). This makes little difference to incandescent lamps, as the brightness of the light depends on what fraction of the cycle it is being powered and not much else. But for more modern lamps, mainly LEDs (which often have a capacitor at their input), the difference is critical. Because the leading edge design switches on at mid-cycle, there can be a huge inrush current as the capacitor(s) charge up. Since the trailing edge design only switches on at the zero-crossing, when the voltage is at a minimum, the inrush current is no different to what it would be if there was no dimming occurring. And this is how most dimmable LEDs are designed to operate. For more details on leading vs trailing edge dimming, see page 25 of our This is the Slave Unit – the bit that takes the signal from the master controller and drives the lights. We’ll describe the master controller next month. siliconchip.com.au Australia’s electronics magazine October 2020  37 A EARLY TRIGGERING: HIGHER OUTPUT B LATER TRIGGERING: LOWER OUTPUT A LATER TRIGGERING: HIGHER OUTPUT SC Ó SC B EARLIER TRIGGERING: LOWER OUTPUT Ó Fig.1: a leading-edge dimmer varies the switch-on point during the mains cycle, but always switches off at the zero crossings. So the earlier it switches on, the more power is applied to the load and the brighter the light. But this does not work well with LEDs or with other lamps that have electronic drivers. Fig.2: a trailing-edge dimmer achieves a similar result, but it instead switches the lamp on at the zero crossings and then switches it off at some point later in the mains cycle. The later the switch-off, the brighter the lamp. This scheme is compatible with lights that have electronic drivers, including most dimmable LEDs. February 2019 issue. As you might have seen in the Versatile Trailing Edge Dimmer article, the circuitry for controlling the Mosfets is more involved than that needed for Triacs (and that is why leadingedge dimmers were the standard until recently). In the Trailing Edge Dimmer, a small transformer is used to provide an isolated, ‘floating’ supply to drive the Mosfets, which is switched by an optoisolator under the supervision of a microcontroller. To simplify things for our Digital Lighting Controller, we are using a clever little chip that bundles all of the features of isolation and power transfer into a tiny SOIC-8 package. It is the Si8751AB isolated Mosfet driver IC, previously used in our Smart Battery Charge Controller from December 2019 (siliconchip.com.au/Article/12159). (bipolar) RS-485 signalling. To keep our circuit simple, we’re using singleended serial at a lower rate of 38,400 baud. This still allows us to transmit enough data to update the brightness of 64 lights once per mains cycle. The lower rate means that the circuit will be less sensitive to outside noise and interference, despite lacking the bipolar signalling. Using a single-ended serial signal means that just about anything which can produce a serial waveform can control our lighting ‘slaves’. Rather than a microcontroller, you could use a USB-serial converter to connect the To make the Digital Lighting Controller more flexible, we’ve adopted a simple two-wire serial interface between the master and slave units. This is inspired heavily by the DMX-512 protocol, which is used in professional studio and stage lighting applications. As the name suggests, DMX-512 can address up to 512 individual devices. This is many more than we need, even for a big display. The DMX-512 protocol runs at 250,000 baud using Silicon Chip Fig.3: the measured current drawn by a lamp as a function of the requested brightness level set (0-255). The straight line shows an ideal linear response. In practice, the varying filament resistance is responsible for some slight deviation from the ideal. There are also minor deviations at the extremes due to the turn-on time of the Mosfets. Slave circuit The full circuit diagram for each four-channel lighting slave unit is shown opposite. This is separated into three sections (red-shaded, greenshaded and the rest) which correspond to separate, isolated areas on the PCB. Mains voltages are restricted to the redshaded part, while the isolated input stage is shaded in green. The remaining section operates at 5V DC, but is not necessarily ‘safe’. The main reason for this is that Digital Lighting Controller current vs brightness value 160 140 Measured current Ideal linear response 120 Lamp current (mA) Communications for light control 38 Digital Lighting Controller to a computer. We’ll show you how to connect the slaves up to various controllers in our follow-up article next month, as well as how to build a Micromite-based controller to provide similar functions to the previous design. This article will concentrate on describing the slave side of the design. As touched on above, it’s also easy to use an Arduino board to drive the Digital Lighting Controller slave unit, and this means you can also mix our mains lighting control slaves with other lighting elements such as addressable RGB strips. One thing to note is that you will need to add a simple transistor buffer to most serial sources if you intend to drive multiple slaves, especially if you plan to approach the maximum number of 16. That’s because a microcontroller pin can’t supply enough current to drive many slaves, especially with longish wires between them. Luckily, a transistor buffer is elementary to add. 100 80 60 40 20 0 0 32 64 96 128 160 192 224 256 Brightness value (0-256) Australia’s electronics magazine siliconchip.com.au                 SC  Fig.4: the slave circuit is quite simple thanks to the SI8751AB isolated Mosfet drivers. Adding a microcontroller allows a much simpler communications protocol compared to our earlier designs, eliminating the need for the master to send signals continually. DIGITAL LIGHTING CONTROLLER siliconchip.com.au Australia’s electronics magazine October 2020  39 the devices that we’ve used to separate the mains from the 5V sections are only available in a SOIC package. While rated for 630V of isolation, the SOIC package dimensions mean that necessary safety clearance requirements cannot be met; there is only 4.7mm between pins on opposite sides. Even with a slot down the middle of the device, this is not quite good enough. 4.7mm is sufficient separation in most cases, but it may not be adequate in conditions of high humidity or low air pressure (eg, at high altitudes). So we cannot rely on IC2-IC5 to provide safety isolation. Thus, there are two degrees of isolation between the mains voltages and the input control signals. The 5V section is completely closed off from the outside during operation. Opto-isolator OPTO1 comes in a DIL package which easily meets the safety clearance requirements. Slots are cut in the PCB down the middle of each isolation device, to improve creepage separation. Serial reception CON1/CON1a, CON9 and CON10 are used to receive the serial signal or pass it along to another slave unit. CON9 and CON10 are RJ45 sockets, allowing cheap CAT5 cables to be used. The two sockets allow the signal to be daisy-chained between slave units. CON1 and CON1a are provided for testing purposes, or if you wish to provide some other means of routing the control signal. We’ll discuss some options for this later. The incoming signal passes through a current-limiting 220Ω resistor into the LED of the 6N137 high-speed optoisolator, OPTO1. A 1N4148 diode (D1) is wired in reverse across OPTO1’s LED to protect it in case reverse voltage is applied. When the LED inside OPTO1 is driven, OPTO1’s pin 6 is pulled to ground (pin 5). At other times, it is pulled up to 5V by a 1kΩ resistor connected to pin 8. This signal goes to pin 5 on microcontroller IC1, which is configured to work as a UART receiver. IC1’s pins 3, 11, 12 and 13 are connected to each of the switches in four-way DIP switch S1, with the other terminals connected to ground. During operation, the microcontroller applies a weak pull-up to each of these pins, allowing it to detect the switch state. The four switches allow sixteen address combinations to be set, so that sixteen unique slave units can control up to 64 lamps. The switches are switched off during ICSP programming, as having pins 12 and 13 pulled to ground will interfere with the programming process. IC1 is a PIC16F1705 microcontroller which receives signals from the serial bus and controls the Mosfets to provide the required brightness for each controlled light. The PIC16F1705 is a close ‘cousin’ of the PIC16F1455 that we’ve used in a fair number of projects to date (eg, the Microbridge and Micromite LCD BackPack V2/V3). The main difference is that the PIC16F1705 lacks a USB controller, as we do not need it for this circuit. The 16F1705 is thus also slightly cheaper than the 16F1455. IC1’s pin 4 MCLR input is pulled up to 5V by a 10kΩ resistor. This pin, along with pins 12 and 13 connect to CON2, the ICSP (in-circuit serial programming) header. CON2 must never be used while the slave unit is connected to mains power; it is only for initial programming, Fig.5: the overlay diagram for the front panel board. The underside is externally visible and has cut-outs for the RJ45 connectors plus labels, including for the LEDs. Note that all the components are fitted to the underside in an unusual manner. The SMD LEDs are soldered in place upside-down, so that they shine through (and are diffused by) the fibreglass, while the header is surface-mounted so that the fibreglass forms an insulation barrier between the internal circuitry and the outside world. 40 Silicon Chip Australia’s electronics magazine siliconchip.com.au and is not needed if you build the unit using a pre-programmed chip. Mains-powered light control Pins 6, 7, 8 and 9 of IC1 drive the input pins (pin 3) of IC2-IC5. These are SI8751 isolated Mosfet gate drivers which contain RF circuitry capable of transmitting enough power across their internal silicon isolation gap to drive a Mosfet gate directly. IC2-IC5 also have a TT pin (pin 2) which sets the internal drive strength and thus the Mosfet gate turn-on time. In this case, it is connected to ground for the fastest turn-on. On the output side, IC2-IC5 generate a positive voltage on their pin 8 relative to pin 5. These are connected to the gate and source of the output transistors, respectively. The Mosfets are connected back-to-back, with gates and sources commoned. Their drains form the external connections between the Active and load. Using this arrangement means that the intrinsic diodes are connected back-to-back to prevent conduction when the Mosfets are off. In practice, the gate turn-on is actually quite slow, taking hundreds of microseconds. This is due to the fairly weak drive of the SI8751 ICs, combined with the doubled Mosfet gatesource capacitance. Fortunately, as we turn on the Mosfets at the zero crossings, when the instantaneous mains voltage is very low and minimal current is flowing, Mosfet dissipation during switching is low. The turn-off is much quicker, which is crucial as it can occur at any point in the mains cycle. The Mosfet drains are also connected via high-voltage 10pF capacitors to the Miller clamp pins (pins 6 and 7) on IC2-IC5. The SI8751 devices have circuitry to clamp the source to the gate (thus forcing the Mosfet off) if conditions are detected which might inadvertently turn the Mosfet on. This would mainly be due to parasitic internal capacitance between each Mosfet drain and gate. The pairs of back-to-back Mosfets connect between the incoming Active and the respective output Active connection on CON4-CON7. The Neutral and Earth connections on CON4CON7 connect straight back to the input, CON3. So when a Mosfet pair is off, no current flows to its load, but when the Mosfet pair is on, current can flow so the attached lamp can light. Zero-crossing detection To detect the phase and zero crossings of the mains sinewave, two 4.7MΩ seriesconnected high-voltage safety resistors connect the incoming Neutral to the 5V circuit’s ground, with an identical arrangement connecting Active to IC1’s pin 10. This high-impedance circuit is sufficient to safely sense the polarity and thus (when the polarity changes The “business end” of the front panel showing how the SMD LEDs are soldered in position. All the bottomemitting SMD LEDs we found were designed to shine through a hole, which would breach the fibreglass isolation barrier. Hence, our use of standard SMD LEDs soldered upside-down. siliconchip.com.au Australia’s electronics magazine at the zero crossing), the phase of the mains waveform. Status indication Several front-panel LEDs, mounted on a separate front panel PCB, indicate the state of the slave. Each LED has a 1kΩ current-limiting resistor on the main board. LED1 lights up when OPTO1’s output is low. Since the idle state of the serial data is high, LED1 is off until serial activity occurs. The remaining LEDs are lit when their associated signal level is high. LED2-LED5 are driven by the same signals that are fed to the Mosfet drivers, and thus show the output states. Due to persistence of vision, even a very low lamp output level shows clearly on the LEDs. LED6 is connected to IC1’s pin 2 (which is not used for anything else) and is used to flash error codes. LED7 is driven by the 5V rail, and so indicates when 5V power is available. The front panel PCB connects to the main PCB by a short 10-way ribbon cable. The LEDs are fitted upsidedown to shine through the PCB and illuminate the letters made from the PCB solder mask. As well as providing clear lettering, the use of a PCB as front panel also means that a better level of isolation is provided than if, say, the LEDs were mounted through holes in the front panel. Power supply Mains power is applied via barrier terminals CON3. The Active current passes through 5A fuse F1, which protects against any faults on the PCB and further downstream, including connected lamps. As well as going to the lamps (via Mosfets in the case of Active), the Active and Neutral lines also both feed into MOD1, an integrated 230V AC to 5V DC converter. It’s capable of delivering 2W (ie, 400mA) which is easily sufficient for this circuit. MOD1 has an isolation voltage rating of over 3kV AC and has more than 25mm between its input and output pins. Its 5V output powers all the ICs on the board (IC1-IC5) and OPTO1. Each of these has a local 100nF supply bypass capacitor. Serial protocol For the correct signal polarity, the incoming DATA- line (which connects October 2020  41               Fig.6: assembly of the main PCB is relatively straightforward. It uses a mix of SMD and through-hole parts; it’s generally easiest to fit the SMDs first, then the low-profile through-hole parts, then the taller parts like the connectors. Be careful with the orientations of the ICs, polarised headers, DIP switches and the diode; all other parts either only go in one way around, or it doesn’t matter. Clean off any flux residue around the isolators, slots or safety resistors to ensure sufficient creepage distances. Note that this diagram and the photo opposite are reproduced slightly smaller than life size to fit on the page (about 85%). to pin 2 of the RJ45 sockets CON9 and CON10) is the serial data source, while the DATA+ line should connect to the signal source’s supply rail (eg, 3.3V or 5V). This way, current will flow through OPTO1’s LED when a logic low is transmitted, meaning that OPTO1’s output will be in-phase with the incoming signal. You could run the slave unit from an RS-232 level signal, which usually has a swing of something like ±12V. In this case, DATA+ connects to the TX signal, with DATA- goes to the RS232 bus’ ground. As RS-232 signals are inverted compared to TTL signals, the resulting inversion due to OPTO1 means that the signal going to IC1 has the correct phase. In any case, D1 prevents damage if the signal is misconnected. Much of our serial protocol has been borrowed from DMX-512, which should make it possible to use existing software libraries to generate the necessary data, even though the electrical signal levels are different. How42 Silicon Chip ever, you will need to adjust the baud rate to 38,400. A DMX-512 ‘frame’ contains enough data to set the state of all addressed devices; the slave unit state (brightness levels) doesn’t change until it receives a frame telling it to update this state. The DMX-512 protocol documentation refers to ‘mark’ and ‘space’ states. Like most serial protocols, the mark state is the same as the idle (no data being sent) state, which is a logical ‘1’. A space is the same as a logical ‘0’. For the most part, it is similar to other serial formats. A single ‘0’ (space) starts each byte, followed by the eight data bits and a single ‘1’ (mark). To synchronise the transmitter and receiver, a ‘break’ condition is sent down the serial line. This is a space state of at least 20 bit times. This is recognised by the receiver as normal data must not spend more than nine bit times in the space state. In our case, IC1’s serial peripheral can detect a break of 13 bit times or longer, so we simply use this condiAustralia’s electronics magazine tion. It manifests as a data framing error with a data byte of 0x00 (all spaces). The first byte after the ‘break’ is called a start code, which identifies the type of data which is in the frame being sent. A start code of 0x00 is used to indicate that the following data should be used to set the channel levels; in our case, the dimmer duty cycle and thus the lamp brightness. After this, the bytes are sent in order of the devices they are addressed to. The second byte after the break is for device 0, the next for device 1, and so forth. At 38400 baud, it takes around 17ms to transmit data for 64 channels, so updates can occur 60 times per second, if necessary. Software operation When power is applied, IC1 checks its address by querying the states of the switches in S1. Thus, the address cannot be changed during operation (you shouldn’t have the enclosure open anyway!) As each slave unit can control siliconchip.com.au While none of the SMD parts on this board are hard to solder, you do need to use the right technique to avoid frustration or bad joints. We strongly suggest spreading flux paste on the large pads for Mosfets Q1-Q8 before placing the part. This way, when you apply solder to the tabs, it will readily flow under the devices and form a good connection with the PCB. You need a hot iron to solder those tabs due to the thermal mass of those parts. The installation of ICs IC2-IC5 is straightforward, but make sure that if you bridge any pins, you clean up those bridges with solder wick and some extra flux. four outlets, the address switches are marked +4, +8, +16 and +32. Setting all switches off will mean that this slave unit responds to addresses 0, 1, 2 and 3. To set the next addresses, 4, 5, 6 and 7, set switch +4 to on. With all the switches set, the total base address is +60, so that the slave responds to addresses 60, 61, 62 and 63. When the UART receives a break signal, an internal counter is reset. The first byte is checked to ensure that channel data is being sent (start code 0x00) and the counter continues to increment for each byte received. Any other start codes are ignored. If the incoming data is addressed to one of the outputs controlled by the slave unit, an internal variable is updated with the new intensity setting. There is no synchronising latch, as the output can only be turned on at the start of each cycle, but the software continually checks if it needs to be turned off. Due to the relatively slow turn-on time of the Mosfet gate drive ICs, we siliconchip.com.au need to set the outputs high slightly in advance, and this is possible because the threshold of the zero crossing is not quite at zero. This means that the zero detection pin changes state slightly before the zero crossing in one direction and slightly after in the other. So we use the early pin state change to trigger the start of the Mosfet cycle, with an internal counter keeping track of when the Mosfets should be switched off. We also use the internal counter to time when the Mosfet turn-on should occur at the other zero-crossing. The software logic also avoids triggering for a period early in each cycle, which makes it more resistant to noise on the mains line. With this in mind, IC1 turns on each output around the zero crossing (if the brightness setting is not zero). It then turns it off at the appropriate time during each mains half-cycle, unless a 100% duty cycle is requested, in which case the output remains on continuously. Australia’s electronics magazine An array loaded with scaling factors is used to give a more linear relationship between the input value and output brightness. This is necessary because of the way the voltage varies across each half-cycle. For example, to achieve one quarter lamp intensity, the output is set for the first third of the cycle, as the area under an ideal (sinusoidal) mains waveform is the same for the central (peak) third as for the other two-thirds combined (because the integral of a sinewave between 0° and 60° has the same value as the integral of a sine wave between 60° and 90°). Of course, the actual response will depend a lot on the nature of the connected lamp; incandescents and LEDs will all differ, but this result will be closer to linear than without this compensation (see Fig.3). Finally, pin 2 is brought high if a fault occurs, for example, if no zero crossing is detected for a longer period than expected. The way the outputs are controlled means that they October 2020  43 will default to off if no zero crossing is detected. An interesting feature of the software is that it does not need to use interrupt routines to respond to events, because there usually is nothing happening. Thus the main body of the program consists of nothing more than checking the interrupt status flags and reacting as needed. The software is designed to work with 50Hz mains, but will work with 60Hz. As the mains cycles are shorter, any brightness values above 238 will result in full intensity. Also, the linearity compensation will not be as wellmatched as with a 50Hz supply, but otherwise, it will be fully functional. The power supply module we are using is capable of working down to 100V. Thus, the slave unit is fully capable of working with practically all common mains voltage and frequency standards. Construction Start construction with the front panel PCB, which is coded 16110203 and measures 251mm x 75mm. It hosts a few surface-mounted parts, but they are not difficult to solder and space is plentiful. Refer to its PCB overlay diagram, Fig.5, to see which parts go where. The usual surface mount gear is helpful. This includes tweezers, magnifiers, flux paste and solder braid. In a pinch, a fine-tipped soldering iron may be sufficient. Fume extraction is a very good idea too, especially when using flux as it will generate some smoke. The seven LEDs are mounted unusually, with their lenses towards the PCB. This allows the light to be diffused by the PCB material and be masked by the front copper layer. While reversemount SMD LEDs exist, they are usually designed to slot into a hole in the PCB, and having such a hole would defeat the purpose of using the panel for isolation. You could use through-hole LEDs, but we found that they did not shine as well as the surface-mounted types. It isn’t difficult to solder the LEDs in place upside-down; you just need to be generous with the solder. Work with each colour in turn to avoid mixing them up. Apply a blob of solder to one pad for each LED. Then hold the LEDs in place with tweezers, observing the orientation of the cathode as marked on the PCB (usually indicated by a green dot or ‘T’). Carefully manipulate the LED as you 44 Silicon Chip apply heat, aiming to get the LED in the correct location. Once this is done, solder the other lead, using plenty of solder. If necessary, apply flux to the first lead and reapply the iron to dress the joint. When moving from one lead to the other, wait for a few seconds to ensure that the solder has hardened. The LED may slip off if both leads are heated at the same time. While CON11 is a regular throughhole header, it is surface-mounted to maintain isolation. You might like to fit a header socket onto the pins to align them while soldering. This will keep the pins located correctly in case the plastic holder melts slightly. Check the orientation of the locking tab against the silkscreen and rest the locking header in place. The usual philosophy for surface mount parts applies, just with much larger clearances. Tack one pin in place, check that the other pins are centred and flat on their pads, then apply solder to the remaining pins. If necessary, go back and refresh the first pin. You might wish to apply solder to the other end of the pins to add extra strength. The downside of this mounting method is that the mechanical strength of the header is not as good as if it were mounted normally. So take care when plugging and unplugging the cable later. Once you have confirmed that everything is working, you might like to secure the header with neutral-cure silicone sealant. Don’t use acetic cure sealant as it may cause corrosion. Main PCB assembly Continue assembly now with the main PCB, which is coded 16110202 and measures 216 x 133mm. Fig.6 is its overlay diagram, which you should refer to as you read the following instructions. Fit the SMD parts (IC2-IC5) by applying flux paste to the pads and tacking the SOIC ICs by one pin. Observe the orientation dot and bevel, which should be on the side closest to IC1. Adjust the ICs if necessary and then solder the remaining pins. If a bridge occurs between pins, solder the remaining pins and carefully use the solder braid to draw the excess solder from the pins, using extra flux if needed. The eight output Mosfets (Q1-Q8) are also SMDs, but are not small, which makes them easier to manage. Fit these next. Australia’s electronics magazine Rest each Mosfet within its footprint. Ensure the large drain pad is visible under the edge of the Mosfet to allow better access with your soldering iron. As with other surface-mounted parts, apply flux paste (especially important on the large pad) and tack one of the smaller (source or gate) leads in place. Using tweezers, adjust the positioning if necessary, ensuring it is flat against the PCB. With this done, solder the other small lead to its pad. There should be enough room to gently push down on the lead with the iron while introducing the solder into the side, where the lead touches the pad. For the larger drain lead, add some solder to the iron tip and press it gently against where the large tab meets its pad. Feed the solder in nearby, using the heat of the component tab to melt the solder. Once the tab is hot enough, the solder will melt and spread freely. You may need to increase your iron temperature to achieve this. Feed in enough solder to form a fillet that goes the full width of the part, then remove the solder and then the iron. Leave the board stationary for a few seconds until the solder solidifies. Once IC2-IC5 and Q1-Q8 are fitted, clean any excess flux from the PCB using a recommended cleaner, especially as some of these parts sit astride an isolation slot. Once clean, allow the PCB to dry thoroughly. Through-hole parts For all the remaining parts on this board, it’s essential to ensure that they have reliable solder joints without excess solder and to trim the leads properly, to avoid affecting the safety isolation. Start by fitting the four 4.7MΩ safety resistors next; these are slightly larger than the others. Ensure that the joints are solid and clean without excess solder. Then mount the remaining resistors, followed by the capacitors. None of these are polarised; refer to Fig.6 to see which types go where. Install the single diode (D1), being sure to orientate its cathode band as shown. Then fit the fuse into the fuse clips to align them and ensure that they are orientated correctly, before soldering them in place. Remove the fuse for now. Fit OPTO1 next. Gently bend its leads inwards and slot it into the PCB, with pin 1 on the ‘safe’ side of the isolation barrier. Solder one pin on siliconchip.com.au each side, checking that the part is flat against the PCB before soldering the remainder. You might like to fit a socket for IC1, but this is probably not necessary if it is programmed already. It should be fitted with its pin 1 adjacent to the 100nF capacitor. Now mount pin header CON2 but only if you still need to program IC1. Then fit CON8, but being a locking type header, you also need to orientate it correctly. You can also fit a two-way header to either CON1 or CON1a now (they are connected in parallel). These are not needed for regular operation, but can be useful for testing. CON9 and CON10 are the RJ45 sockets that pass through the front panel. Thus they must both be fitted, regardless of whether you plan to use them, or else there will be a hole in the panel (and that would be unsafe). Working with one socket at a time, slot it into the PCB and tack in place with one pin. Double-check that it is straight, as it may not fit the front panel otherwise. It’s a good idea to test-fit the front panel before soldering the remaining pins. S1 can be fitted either way, but it makes sense to fit it so that the switches are on when towards the addresses near the board edge. Use a multimeter to check this if necessary before soldering in place. If you need to program IC1, ensure that all the switches are off initially. MOD1 should only fit one way, but double-check the markings first. The side marked AC must be closest to the mains input connector. Then solder and trim its leads. The final parts on the PCB are the five barrier terminals for connecting the mains cables. Solder them in place, keeping them flat against the PCB. Front panel cable The front panel connection cable is a 10-way ribbon cable with polarised line sockets at either end, wired straight through (ie, pin 1 to pin 1 etc). Both ends will look the same, and it doesn’t matter which way it is fitted. Refer to Fig.7 for details. Separate the wires at each end of the ribbon cable, strip off a little insulating, then crimp and/or solder them into the pins. When pushing the pins into the plastic blocks, ensure that they click into place (use a tiny screwdriver to push them in further if necessary), siliconchip.com.au Parts list (for one slave unit) 1 double-sided main PCB coded 16110202, 216mm x 133mm 1 double-sided front panel PCB coded 16110203, 251mm x 75mm 1 ABS instrument case (260mm x 190mm x 80mm) [Altronics H0482, Jaycar HB5910] 3 M3 x 6mm panhead machine screws 2 M3 x 20mm machine screws 2 12mm Nylon untapped spacers 1 sheet Presspahn or similar insulation, cut to 215 x 100mm [eg Jaycar HG9985] 1 2-pin header (CON1; optional) 1 5-pin header (CON2; optional, for ICSP) 5 3-way barrier terminals, 8.25mm pitch (CON3-CON7) [Altronics P2102] 1 10-pin 2.54mm locking header (CON8) [Jaycar HM3420, Altronics P5500] 2 PCB-mount RJ45 sockets (CON9,CON10) [Altronics P1448] 1 10-pin 2.54mm right-angle locking header (CON11) [Jaycar HM3430, Altronics P5520] 2 10-pin 2.54mm locking line sockets [Jaycar HM3410, Altronics P5480 + 10 x P5470A] 1 10cm length of 10-way ribbon cable or similar 1 covered M205 fuseholder (for F1) [Altronics S5985] 1 5A M205 fast-blow fuse (F1) 1 Meanwell IRM-02-5 230V AC to 5V DC 2W switchmode converter # (MOD1) [Digi-key 1866-3009-ND] 1 4-way DIP switch (S1) 1 14-pin DIL IC socket (optional; for IC1) Semiconductors 1 PIC16F1705-I/SP microcontroller programmed with 1611020A.HEX (IC1) 4 Si8751AB isolated Mosfet drivers, SOIC-8 (IC2-IC5) # 1 6N137 high-speed opto-isolator, DIP-8 (OPTO1) # 8 SiHB15N60E 600V SMD Mosfets*, TO-263 (Q1-Q8) # 1 green SMD LED, 3216/1206-size (LED1) # 5 yellow SMD LEDs, 3216/1206-size (LED2-LED6) # 1 red SMD LED, 3216/1206-size (LED7) # 1 1N4148 small signal diode (D1) Capacitors 6 100nF 63V MKT 8 10pF 3kV SL0 ceramic # Resistors (all 1/2W 1% metal film axial, except where noted) 1 10kW (brown black orange brown or brown black black red brown) 8 1kW (brown black red brown or brown black black brown brown) 1 220W (red red brown brown or red red black black brown) 4 4.7MW 3.5kV safety-rated resistors # (eg, VR37000004704JA100) Mains connectors (see text for alternatives) 4 mains flush-mount panel sockets [Jaycar PS4094, Altronics P8243] 1 mains lead with fitted 3-pin plug [Jaycar PS4110], or extension lead with socket end cut off 1 cable gland to suit mains lead 1m 10A-rated 3-core mains cable (could be cut from an extension lead) 10 small cable ties # These components are available as part of a pack of hard-to-get parts from the SILICON CHIP ONLINE SHOP (cat SC5636). The programmed micro and PCBs are sold separately and also check that the pins are in the right order at each end. Once it’s finished, plug it in at both ends to connect the two boards. Programming the PIC If you need to program the PIC, now Australia’s electronics magazine is a good time. We recommend using a PICkit 3 or PICkit 4 with the MPLAB X IPE software. MPLAB X can be downloaded from www.microchip.com/ mplab/mplab-x-ide The latest version only supports computers with 64-bit processors, October 2020  45 Fig.7: the front panel cable is made from a pair of 10-way polarised crimp headers. Each end is wired the same, so the cable is reversible. The pins will also line up directly between the front panel and the main PCB when both are correctly mounted in the enclosure. but you can download older versions from https://www.microchip. com/development-tools/pic-anddspic-downloads-archive Connect the programmer to CON2 and open the IPE. Select PIC16F1705 from the “Device” dropdown menu. You will also need to enable “Power target from tool” on the Power tab. Click “Apply”, then “Connect”, and ensure that communication is working. If not, you should check that the PCB is assembled correctly. Next to HEX file, click “Browse” and find “1611020A.HEX” (available for download from our website), then click “Program”. If you watch the front panel LEDs, you should see the PWR LED light up as the PICkit applies power to the circuit. Final assembly The two PCBs can now be fitted into the case. The main PCB sits towards the front of the case, to allow room at the rear for the mains sockets. It attaches to five moulded plastic posts using M3 machine screws, with the longer screws and spacers used for the two holes closest to the mains terminals. Once that’s in, you can slot the front panel PCB in place. To keep the slave unit as compact as possible, we are using flush-mount style mains sockets. These require a specific cut-out to be held securely; we recommend tracing our template (available as a PDF download from our website) and drilling them as accurately (a drill press will make this much easier) before finishing with a file or hobby knife. It’s essential to cut these accurately, if too much material is removed, there may not be sufficient left to retain the socket properly. Also, drill the hole as shown for the incoming mains lead. 46 Silicon Chip Fig.8: a simple test lead can be made from a cable with an RJ45 plug at one end (eg, an Ethernet cable cut in half) with header plugs or male jumper wires attached to two of the bare wires. The cables we used had the colours shown, although others could be wired differently. Pin 1 goes to the Uno 5V, with the adjacent wire to pin D1 (TX). This lets you use a Micromite or Arduino board to test the Slave unit. This is sized to suit the cable gland. Pre-wire each socket before fitting into the panel, as access will be more difficult once they are on the panel. Cut four 15cm pieces of three-core mains cable and strip the outer insulation from about 5cm at each end. Cut 2cm off the end of the Active and Neutral wires at one end. As the Earth lead is longer, it will be disconnected from the barrier terminals last if the cable is yanked out. Then strip 6mm from both ends of each inner core. Screw the un-shortened ends into the panel sockets; brown for Active (A or L), blue for Neutral (N) and green/ yellow for Earth (E). Separate the panel sockets and attach them to the rear panel via the mounting holes. Then secure the free ends of the mains leads into the terminals of CON4-CON7. Insulation To ensure that you can’t accidentally come in contact with any of the exposed metal at mains potential, cut a 215x100mm sheet of Presspahn or similar and drill or cut two 3.5mm holes in it, centred 6.5mm from the short ends of the sheet (ie, 202mm apart). If you aren’t sure what it should look like, refer to our photos. Place this over the high-voltage section and attach it using the two longer PCB mounting screws with spacers. Mains input Since the rear panel space is already quite cramped, the incoming mains lead is captive and secured by a cable gland. To reduce the possibility of tampering and the chance of the lead being pulled through, the nut of the cable gland is installed inside the case. While working, plug the mains plug lead into one of the sockets. This will eliminate the possibility of it being Australia’s electronics magazine inadvertently powered up while you are working on it. Thread the body of the cable gland in place as shown in the photos, then thread the free end in from the outside. As with the other leads, cut the Active and Neutral leads around 2cm shorter, then trim 6mm from the bare ends. Screw these into the Mains In barrier terminal (CON3), observing the correct colour coding, then slot the rear panel in place. Before closing the case, use the cable ties to secure the groups of mains leads together as shown and tighten up the cable gland firmly. You can add a drop of cyano-acrylate (eg superglue) to the threads to secure it, although as it’s on the inside, as long as you do it up tight, it should be fine. The final step before closing the case is to fit the fuse. It should be a 5A fastblow type. Fit the top of the case and fasten with the included screws. Alternative mains connections We’ll describe two alternative connector arrangements, but like all mains wiring, they should be approached with caution. These have the advantage of requiring less work on the rear panel. Both require running three-core mains lead through the rear panel. If the lamps you are using do not need to be disconnected from the slave unit, they can be permanently wired into the barrier terminals. You should use the same procedure as described above for the incoming mains lead, securing the cords with cable glands fitted inside the enclosure and also secure the leads with cable ties. Another option is to use pre-wired mains sockets cut from extension cables. These can be found for just a few siliconchip.com.au dollars each. They must also be secured to the rear panel using a cable gland and with cable ties fitted. Testing If you have lamps that you wish to plug in for testing, do that before connecting the slave unit to the mains. It’s a good idea to have good access to a switched socket, so you can quickly shut off the power in the event of a problem. Make sure the enclosure lid is secure, then plug in the mains lead and switch on the power. You should see the PWR LED light up, possibly followed by the AUX LED. Your attached test lamps should not light, nor should any of the CH0-CH3 LEDs or the COM LED. If all is well, you can continue testing with a control signal. Test controls The COM LED is active whenever the OPTO1 input is being driven, so this part of the circuit can be tested by merely applying 3V-5V between the DATA+ (positive) and DATA- (negative) connections. When mains power is disconnected, the AUX light should light up briefly as the 50Hz waveform disappears but IC1 continues to receive power from the capacitors in MOD1 for a few seconds. As we noted near the start, the slave unit uses a straightforward serial protocol. If you have an Arduino board (we used the Uno, but boards such as the Mega should work too), then we’ll show a simple test rig you can make to inject control signals into the slave unit. You could use this as the basis of your controller, depending on what you have in mind. Upload our test sketch file (available for download from our website) to the Uno, and wire up a CAT5 lead as shown in Fig.8. The Uno simply produces patterns to cycle through each lamp in turn (using addresses 0-3), ramping each up and down in brightness. Even with no mains lamps connected, you should see the CH0-CH3 LEDs on the front panel cycling on and off in turn. If all these things are working, then the slave unit is fully functional. You might like to experiment with your own Master controller, or wait until next month when we will describe our design. SC siliconchip.com.au (Above): the wired slave unit from the rear, which also shows the four flush-mounted mains outlets. To complete the unit, we drilled a sheet of Presspahn insulation (as shown at right) which fits over the exposed mains circuitry on the PCB, (as shown below). m 50m You may need to trim some of the mounting posts m 202m inside the bottom of the enclosure so that they don’t foul the component 225 x 100mm leads on the Presspahn or similar underside. Australia’s electronics magazine October 2020  47