wiring.txt
1 [[cha:wiring]] 2 3 = Best Wiring Practices 4 5 == Electrical Noise 6 7 Electrical noise in a system is caused by Electromagnetic Interference (EMI), where signals appearing in one 8 electrical circuit interfere with an adjacent circuit, either through electromagnetic induction, electrostatic 9 coupling or conduction. EMI can cause problems with the daily operation of a CNC machine, and can manifest itself in 10 various ways such as false triggering of limit switches, prematurely interrupted tool probing operations, corruption 11 of a serial data link to a VFD or erratic behaviour of the CNC control systems and software. 12 13 When current passes through a conductor a magnetic field is created. As the current increases the magnetic field gets 14 stronger, and then collapses again when current ceases to flow. If this alternating magnetic field happens to cross 15 another conductor it can induce an unwanted voltage into it, which presents itself as noise. 16 17 There are several methods that can be employed to minimise the effects of EMI in any electrical system. The most 18 effective of these is obviously to prevent the noise from occurring in the first place. In reality the method of 19 controlling the effects of EMI is usually by applying measures to prevent noise from contaminating wanted signals in 20 the CNC system. 21 22 == Ground, Earth and Common 23 24 Confusion can arise when using terms such as earth, ground and common. In some cases they may be used to describe the 25 same thing; that being the point in an electrical system to which all voltages are referenced to. For the purpose of 26 this article, the terms 'earth' and 'ground' refer to the point at which the incoming mains supply is earthed to, 27 whereas 'common' is the return or negative terminal on a DC supply. In some cases it is permissible to ground the 28 common on a DC supply, thereby making the negative terminal on that supply the same potential as the incoming AC 29 earth, but for the purposes of this discussion the terms 'earth' and 'common' must be made distinct from each other 30 to avoid confusion. 31 32 == Wire Selection and Use 33 34 Wire comes in many types, sizes and configurations. Wading through all the wire available is a monumental task of its 35 own, but for the purposes of this article it is only necessary to consider the types of wires typically used when 36 wiring a CNC controller. Additionally, how the wire is to be used can have some effect on the overall system. What 37 follows are some tips that may prove helpful. 38 39 === Single Conductor Wire 40 41 Wire comes in two forms: solid conductor and stranded. Solid core wire is generally cheaper than stranded, but more 42 likely to break if used in applications where repeated bending is expected. Fortunately, the prevalence of stranded 43 wire on the market means that its use should be encouraged wherever possible. 44 45 Wires should be terminated such that all strands in the conductor are neatly and securely located into the mating 46 receptacle. This may be accomplished by either twisting the strands together before inserting in the termination, 47 or using a compression crimp such as a spade or bootlace terminal. Care should be made to ensure that no strands of 48 wire end up outside the termination to prevent accidental shorting with adjacent terminations. 49 50 If using a compression crimp on the bare wire, avoid soldering the strands together before crimping. Crimping the 51 lug onto a soldered wire can result in the lug working loose over time as the soldered strands lose their 52 compressibility once the crimp has been applied. For this same reason, soldered wire should not be installed in a 53 terminal block where the screw stud bites directly onto the wire when tightened. 54 55 When stripping the wire ready for a termination, only remove the minimum amount required to keep the termination 56 covered when complete. Stripping too much insulation off will expose some of the wire that something can short 57 against. 58 59 The circuit that the wire is intended for should also be considered; the voltage the circuit operates at and the 60 amount of current it carries have a bearing on the choice of wire to be used. The thin insulation on a piece of 61 recycled CAT5 ethernet cable is insufficient to withstand the voltages that can appear at the output terminals of a 62 Variable Frequency Drive, nor is the cross sectional area of the conductor sufficient to carry several amps of 63 current without overheating and potentially causing a fire. Conversely, while it is perfectly permissible to wire a 64 limit switch circuit using 2.5 sqmm cable, it creates needless bulk in the wiring loom. Consult any manufacturer’s 65 documentation and your local country’s electrical wiring codes for minimum suggested wire gauges for power and 66 control requirements. 67 68 === Shielded Wire 69 70 There are two types of shielded wire. One has a bare wire braid that surrounds the wire inside, and the other has 71 metal foil that surrounds the wire inside. The type of shielded wire selected will depend on the amount of noise you 72 are trying to combat. 73 74 .Foil Shielded Wire 75 76 Foil shielded wire has a thin aluminium or copper foil that is usually bonded to a film of plastic that surrounds 77 the wire. The enclosed wire is usually 100% covered. Attaching the foil to earth can be difficult, especially if 78 the foil is constructed from aluminium or laminated to a plastic backing material. For this reason, it is 79 usual to find a bare metal stranded wire enclosed inside the cable which is in contact with the foil for the 80 full length of the cable. This is called the drain wire and is used to make the connection to earth with. 81 82 .Braided Shielded Wire 83 84 Braided shielded wire has a woven copper braid that surrounds the wire. It is more bulky than foil and does not 85 provide 100% coverage, but is more flexible than foil shielded types. Coverage is typically 70% to 95% depending on 86 how tight the braid has been constructed. Despite the lower coverage of braided shield, the effectiveness is 87 greater than foil shielding due to the increased bulk of the braid, and copper being a better conductor than 88 aluminium. 89 90 For very noisy environments, a further subset of the above two shielding methodologies may be employed, whereby both 91 braid and foil shielding is used simultaneously. Individual wires in a multi-conductor cable may also be shielded 92 along with an overall shield being applied to the entire cable jacket. 93 94 == AC Line Voltage 95 96 The incoming mains AC that powers the CNC system can pick up and carry noise into the power supplies and other 97 equipment. For example, if the incoming supply is also used to feed large motors, electrical noise may be 98 generated on the line feeding the CNC components. Although most modern electronic devices feature built-in mains 99 filtering to help minimise the susceptibility to mains-borne interference, the custom and modularised nature of a 100 CNC system can mean that components used come from a wide variety of sources with differing degrees of inherent 101 noise immunity. 102 103 Inline filters may be installed on the incoming mains supply feeding the CNC control system to help reduce any 104 induced noise. Running the CNC system from a different mains circuit to any large electrical sources of noise may 105 also help minimise any potential sources of mains-borne interference. 106 107 [NOTE] 108 Be aware that in many countries, the installation and alteration of mains circuits can only be carried out by 109 licenced electricians. 110 111 == Power Supply Units 112 113 === AC Ground 114 115 A typical CNC machine may have several different Power Supply Units (PSUs) installed in the system. Any device 116 powered from the incoming mains designed to be earthed must be properly and permanently terminated to mains earth. 117 Ideally this should be made to the same point in the system, which may be a threaded post or bolt, a copper/brass 118 termination strip or a large metallic mounting plate within the control enclosure. 119 120 The prevalence of high-frequency switchmode PSUs used in CNC systems increase the likelihood of RF noise 121 being coupled from them to adjacent circuitry. Many of these PSUs have a metal case which, if connected 122 to mains earth, will help screen the coupling of high frequency EMI into other electrical components. 123 124 From a safety standpoint, it is important that these mains earth connections also be mechanically strong and 125 unlikely to break free, and the wire used has a cross-sectional area sufficient to carry the anticipated fault 126 current should a short to earth occur. It is also imperative that mains earth is never used as a current-carrying 127 conductor for other components in the system. Earth shall be used for one purpose only: safety earthing. 128 129 Note also that the colour of the jacket used to make a termination to earth may be prescribed by the wiring code 130 for your country, and the conduction of other unrelated signals in that same wire colour may be prohibited. 131 132 === DC Common 133 134 Commoning of a DC PSU is somewhat dependent on the electrical operating requirements of the CNC system. For example, 135 a stepper motor driver operating with a 24VDC motor supply and a 5V logic supply may have optically-isolated signal 136 input lines which provide complete electrical separation of the driver’s input and output circuitry for safety and 137 noise immunity purposes. Tying the stepper motor and logic control supply commons together in this case may have a 138 detrimental impact on the operation of the system. 139 140 In general it makes most sense to keep the commons of the various DC PSUs used in the CNC system separate from each 141 other, and separate from the AC mains earth unless there is a specific requirement to tie them together. In most 142 cases the common points of the heavy-duty power sections of the CNC system (eg, stepper motor or servo motor 143 drivers, spindle motors etc) will be segregated from common points of the electrically-sensitive sections of the 144 CNC (control interface boards, limit switches, tool probe circuitry etc) to prevent cross-contamination of the two 145 systems. 146 147 Should it be necessary to connect several common points of different PSUs together, or to connect a common of a 148 PSU to AC main earth, it should be done at a single point only and as close to the common terminal of the PSUs as 149 possible. 150 151 In CNC machines where the hardware drivers and interfacing circuitry are pre-assembled, the decision as to which 152 DC commons are tied where is usually taken out of the hands of the end user. 153 154 == DC Supply Feeds 155 156 In situations where a DC circuit is run with the common point disconnected from the mains earth (ie, the supply is 157 ‘floating’), it can be helpful to run DC supplies using twisted pairs of wires, whereby each pair of wires in the 158 circuit (eg, the positive and negative leads) is physically twisted together in a helix pattern. The twist in the 159 wire allows both conductors to share the same ‘real estate’ as closely as possible. Any EMI that passes across 160 them will therefore be largely cancelled as both conductors will receive the same degree of EMI. For additional 161 protection use twisted wire that is housed in a shielded jacket with the shield terminated to mains earth. 162 163 Note however that twisted pairs of wires are less effective at combatting the effects of EMI if one of the two 164 wires is referenced to mains earth, as the conductor at earth potential is less able to be influenced by EMI than 165 the un-earthed conductor. In these instances the twisting of the wires has less of an impact on the overall noise 166 immunity, and shielded cable will be intrinsically more effective at reducing noise pickup. 167 168 == Signal Wires and Control Lines 169 170 The wires that are used to transmit logic signals to and from various peripherals in the CNC (eg, stepper motor 171 controller inputs, axis limit switches etc) are the most susceptible to noise interference. The reason for this is 172 the low level voltages that are used to convey the information. When a limit or home switch is engaged, or a tool 173 probe has made or broken contact, this signal is used to signify the event has taken place. Typically this is done 174 by using input pins on the computer interface card or parallel port which, dependent on the application, may be 175 signalled using as little as 3.3V. Evidently a 2V noise spike has the potential to corrupt the validity of a 176 signal if the useful range is only 0-3.3V. 177 178 If possible, isolate the common point of the PSU supplying the logic peripherals from the rest of the system. 179 For example, keeping the common of the low voltage power supply isolated from the common of the stepper motor 180 supply will reduce the chances of large currents flowing in the stepper motor return line contaminating the common 181 of the low voltage supply. 182 183 If the controller uses differential signalling, use twisted pairs to carry the signal. Shielded cable is preferred 184 when the control lines are single-ended, or if the distances traversed are long or through electrically hostile 185 environments. When grounding the shield in the cable, terminate to the mains earth. 186 187 If the controller and interfacing devices can withstand higher control signals, consider altering the wiring and 188 power supply requirements to use a bigger voltage for signalling (eg, 12V or 24V). The same 2V EMI noise spike 189 that could corrupt a 3.3V limit switch signal will be far less likely to cause issues with a limit switch 190 operating with a 24V signal. 191 192 == Stepper or Servo Motor Drivers 193 194 The metal housing of the driver should be connected to the local mains earth in the CNC system. Some driver 195 enclosures will indicate a specific terminal as being the earthing point, in which case this point must be 196 connected to earth via a dedicated wire. 197 198 Control and power wiring should be segregated as much as possible. Route signal input wires well away from power 199 supply and motor drive output lines. 200 201 It is recommended to run both driver input and motor output wiring in shielded cable with the shield terminated to 202 mains earth. The shield on the input lines helps reduce the amount of interference they can receive, while the 203 shield on the output lines reduces the amount of noise they can radiate. 204 205 == Variable Frequency Drives 206 207 If at all possible the Variable Frequency Drive (VFD) should be mounted in a separate enclosure or cabinet to reduce 208 the risk of it radiating noise into adjacent wiring. If the VFD enclosure is metallic it must be earthed as per any 209 recommendations in the manufacturer’s documentation. 210 211 Because the VFD is a high power, high frequency electronic switching device, the output is notoriously prone to 212 EMI radiation, and it is advisable to run the VFD output to the connected motor in a shielded cable, with the 213 shield terminated to mains earth. 214 215 == Routing Conductors 216 217 === Routing Movable Wires 218 219 Any wire that will be moved about during normal operation of the CNC falls into this category. For example, wires 220 running from stepper drivers through a cable management system (drag chains) and then to the stepper motors 221 mounted on a moveable gantry. Cables and wires operating in these circumstances should be rated for extra 222 flexibility. This precludes the use of solid-core wires and cables, as the constant flexing will lead to fatigue 223 and eventual failure of the conductors. 224 225 If running cables in a cable track/carrier, tie them down at both ends of the cable track. If not, ratcheting can 226 occur and fatigue the cable prematurely. Care should also be taken to ensure that mechanical rubbing of conductors 227 against other parts of the machine is prevented. 228 229 In a cable track/carrier observe the neutral axis idea. Have the wire run as close to the neutral axis as 230 possible. Make sure the wire is not in tension in the longest neutral axis situation. 231 232 === Routing Stationary Wires 233 234 As discussed earlier, running different signal classes (high voltage and low voltage) in proximity to each other 235 has the tendency to exacerbate EMI interference. Separate conductors by as much distance as possible. If two 236 conductors must cross over each other make the crossing as close to a 90 degree angle as possible. 237 238 Avoid long loops of excess wire at any peripheral devices - they are great antennas for receiving or transmitting 239 noise. Where possible, run wires in close proximity to large earthed structures. If the controller enclosure 240 features a large metallic back plate that is earthed, secure all control wiring against this surface as much as 241 possible while wiring between two points. 242 243 == Mechanical Noise 244 245 Very few mechanical switches (eg, an axis limit switch or tool probe input) will close or open perfectly when 246 operated. More often than not the switch contacts will physically bounce against each other several times within a 247 very short space of time when operated. This may be interpreted by the machine controller as multiple operations 248 of the same signal when in reality only one clean state change was expected. Sometimes it doesn’t matter, but in 249 many circumstances it is desirable to ensure that any state change is as ‘clean’ as possible and does not 250 interfere with the operation of the machine. This is accomplished by debouncing. 251 252 Debouncing is achieved by permitting a state change on a mechanical switch to only register with the controller 253 after a fixed period of time to allow any bouncing in the switch contacts to settle. Time delays of 5-15 254 milliseconds are usually sufficient. This can be done with the addition of some hardware to the signal circuit or 255 in software within LinuxCNC. 256 257 === Hardware Debouncing 258 259 Several schemes exist to implement debouncing of switches and relay contacts with hardware, ranging from the 260 addition of a single capacitor across the signal and common lines, to dedicated debouncing integrated circuits 261 such as the MC14490 or MAX6818. Several hardware debouncing schemes can be found via the link below: 262 263 https://electrosome.com/switch-debouncing/ 264 265 === Software Debouncing 266 267 The Hardware Abstraction Layer (HAL) of LinuxCNC includes a debounce component. This component has a single input 268 pin and a single output pin. Its job is to monitor the input and to send an output after the input has activated 269 for a programmed delay period. More information can be found for the debounce component by visiting the following 270 page: 271 272 http://linuxcnc.org/docs/html/man/man9/debounce.9.html 273 274 == Documentation 275 276 The importance of documenting the installed wiring and components cannot be over-emphasised. Should the user want 277 to modify the CNC system further down the track, or if trouble should arise that needs correcting, then complete 278 and concise documentation of the wiring and equipment can save many hours of head scratching and frustration. 279 280 === Hardware Documentation 281 282 At a minimum, make sure to save any documentation associated with the installed hardware in a safe place. Stepper 283 controllers, break out boards, power supplies, VFDs, interfaces and controllers, servo and stepper drivers and any 284 associated device settings are all critical components of the system and their documentation should be kept at 285 hand for easy reference. 286 287 === Wiring Schematics 288 289 As the CNC machine is wired, make sure to draw up a schematic that can be referenced to later. The schematic does 290 not have to be all that neat, but it should be understandable in such a way that it could be easily interpreted at 291 a later date, ideally by anyone who may need to service the equipment. Include details such as wire colours used, 292 pin numbers, part numbers and any other notes that will help explain particular details not immediately apparent 293 from first glance at the schematic. 294 295 === Wiring Identification 296 297 Take the time to identify each wire in the system. When a bundle of wires has been cable-tied in place it can be 298 very difficult to look at them and know for sure which wire goes where. Label the motor wires with the joint or 299 axis they are associated with, or identify each signal wire so that it is easy to identify what that signal does. 300 It will also help if this information is transferred to the wiring schematics.