engineer

tim   .

                                                      


newpad.gif (50 bytes)

.   hunkin

                                                         


cartoonist

 

A PLC PRIMER


If you need to control a washing machine or any mass produced machine, you’d use a microcontroller, mainly because it’s the cheapest solution. The low cost is what also makes microcontrollers so attractive for hobby projects. However, if you’re an engineer working on a large scale machine– like a roller coaster ride or an automated factory production line, you’d be more likely to use a device called a Programmable Logic Controller.   

PLCs are industrial computers, about the size of a brick, which repeatedly scan through a list of instructions like a microcontroller, but they have much slower cycle times. They don’t usually switch outputs more than 10 times a second unless they have special extra modules plugged in. They’ve been around since the 1970s and cost anything from $200 to many thousands. They have an arcane programming language called ladder logic, which has its roots in designing relay logic. Given their disadvantages, you would think PLCs would have become extinct long ago, but they are still widely used today. 

I use PLCs for all the coin operated machines I make and though I often think I’ll change to PIC chips, PLCs keep improving and are now affordable second-hand on e-bay. One of their advantages over computer or micro-controller control is that they are so quick and easy to install. A PLC ‘brick’ has a row of connections for switches and sensors on one side and a row of relay or transistor outputs on the other. It even has a small power supply built in for the sensors.  No circuit boards or soldering, just a screwdriver. Engineers working on large-scale machines are more used to working with a screwdriver than a soldering iron. They don’t usually design or build their own circuits. This maybe just tradition, but it also minimises risk simply connecting tried and tested components instead of starting from scratch. 

The main advantage of PLCs though is that their behaviour is so totally predictable – I make lots of mistakes getting a PLC program to run well, but once it works it will usually stay working reliably for ever. They are designed to work in extremely hot, cold or humid conditions, and are unaffected by electromagnetic interference. They can also be switched on and off at will without worrying about crashing hard disks or corrupting data. Even if one does fail after 10 years, a replacement will still be available off the shelf. This stability is the main reason they continue to be used for factory automation. An hour’s downtime in a factory is very expensive so reliability is worth a lot. Reliability is important for me because people get cross if they put money in one of my coin operated machines and it doesn’t work. 

I recently bought a PLC on ebay from a carwash company and it arrived with water dripping out of it. I nearly sent it back, but tried plugging it in out of curiosity and it worked perfectly, and has been ever since. An engineer from Rockwell automation told me he’d found a PLC in a tea factory completely full of tea leaf dust. It had been working fine for over ten years. 

The first PLC was designed in 1968 by a company called Modicon (MOdular Digital CONtroller). At the time all industrial process control and machine tool control was still done with relays. Machines often had rows of cabinets full of relays wired together. (On an even larger scale, telephone exchanges were literally whole buildings full of relays.) Alongside the relays there were other ingenious electromechanical devices like time delay relays, cam timers and uniselectors. Time delay relays often simply had piston dashpots to slow the movement of the contact arm.  Cam timers had a geared motor that turned a cam shaft alongside a row of microswitches. As the cams rotate, they operate the switches. Uniselectors use a series of pulses (particularly the old telephone dialling pulses) to move contact wiper arms to many different positions. Entire computers have been made with relay logic, most famously the one made by Konrad Zuse’s in 1941.   

Relay logic needed a lot of wires. This is the circuit for a single flip flop.

The equivalent representation in ladder logic, though it isn’t obvious, looks like this.


This sort of relay electromechanical control was surprisingly reliable, though it did have its limitations. ‘The Doctor’, who writes and dispenses an illegible prescription form, is one of my older coin operated machines, made in 1987 with relay logic. It depended on a number of micro-switches triggering everything in the right order. Last year I replaced the relays with a PLC and was amazed how much simpler it became. The accurate timers within the PLC made half the micro-switches redundant. The machine is now much more reliable and even has a xenon beacon that flashes when the prescription forms run out. 

Digital control is so useful and so universal today that it’s not obvious why it took so long to take over. However, replacing cabinets full of relays with a digital equivalent was not straightforward. Although relay logic is relatively simple, a digital version required a surprisingly fast processor. The ladder logic used to design relay circuits is sometimes described as an ‘IF….THEN’ high level programming language.  Each step of the ladder consists of a series of virtual inputs or relay contacts with an output relay coil on the end. IF the conditions of the contacts are met, THEN the coil will be energised. The program executes each step of the ladder, and then jumps back to beginning again.  Relays can switch at about 60 cycles a second so to get 60 complete scans of the ladder running its high level programming language needed a lot of processing power. Desktop PCs only became fast enough to run PLC programs about 10 years ago. 

When Modicon introduced the PLC, not only did they have to invent a new architecture to get the processors to run fast enough, they also had to make the electronics a lot more reliable. Computers of the time were certainly not reliable. To overcome this, their basic idea for the PLC was to make everything bigger. Larger ferrite cores for memory and wider tracks on the circuit board were included to create more ‘energy per bit’. This increased the signal to noise ratio and hence the reliability. Fans were also avoided, as any outside air entering the PLC could be dirty and cause corrosion. 

The finished PLCs were still not reliable enough at first, so Modicon engineers built a test chamber called ‘the blue box’. Each PLC had to run for a minimum of 24 hours in arctic and tropical conditions. It was then vibration tested, run next to a Tesla coil to test for electromagnetic interference, and finally hit repeatedly with a rubber hammer.  When one of the first Modicon PLCs was being taken to show a customer, the engineers tripped and dropped it as they entered the factory. What made the sale was not that the PLC still worked after being dropped but the engineers’ casual assumption that dropping wouldn’t affect it. By the standards of the time these PLCs were astonishingly reliable. Some have run for 50,000 hours without any problems. I have had trouble with some really old Mitsubishi ones I found in a scrapyard, but apart from that I’ve only ever had one completely fail, and that was replaced free of charge. I have also fried quite a few outputs, but that has always been my fault for overloading them. 

Although the first PLCs simply imitated relays they quickly became more sophisticated. Mathematical functions were added, followed by a form of flow chart programming. This enabled just a small section of the ladder to be active at any time and quickly became essential as programs became longer and more complex. Real time clocks were added, though these were perhaps too simple as there were only 2 digits for the year. Some of the panic about the millennium bug was based on the PLCs embedded in essential equipment. I suspect the reason why there were no problems was that the real time clocks were never widely used. They were awkward to program and irrelevant to most industrial control.  

Today, all computers are a lot more reliable than they were in the 1970s, so PLCs now use a lot of the same chips (ARM risk processors are often used). However today’s PLCs are still built to run in really tough environments. They still have no cooling fans, and work at temperatures up to 60 degrees centigrade, far hotter than any PC. They also still work next to a tesla coil, I’ve tried it.  (The input filtering that allows them to work in a strong electromagnetic field restricts the speed of today’s PLCs to about 100 cycles a second.) 

5-10 years ago, there was a vogue for ‘soft PLCs’. These were software programs that ran on Windows PCs, with ladder programming identical to traditional PLCs. When they first appeared, it was predicted that they would finally make traditional PLCs redundant but this never happened. A limited custom operating system is obviously capable of being much more reliable than any complete PC operating system.     

Making use of the computing power available today,  PLCs now have plug-in modules for motion control of servo motors, industrial modems for operating them remotely, and SCADA computer interfaces which allows a diagram of the machine or process to be displayed on a touch screen. PLCs can be connected to distant motors or sensors via a network, which saves a lot of wiring. Some factories even link all their PLCs together on a network, but there are many different incompatible network systems and if the network fails, a whole factory can grind to a halt. Some companies, including Ford, prefer to keep their machines separate for this reason. 

At the other end of the spectrum, there are now simple PLCs called intelligent relays designed to replace just one or two relays or timers. These are programmed graphically in logic blocks, quite similar to programming a Lego Mindstorm controller. Its easy to get a simple program to run, but I find them very frustrating. If a program has more than a few logic blocks it becomes difficult arranging them on the screen so the connections remain visible. Every edit tends to cover some of the connections up again. Last year, while helping a friend put together a giant sculpture clock, I spent three days inside a cramped steel sphere cursing his ‘intelligent’ relay.  

Generally though I’m a huge fan of PLCs. I’m not a typical factory automation engineer who can just buy all the modules they want to make their PLCs do anything. But for me their basic limitations have advantages. Being restricted to a limited number of slow switching on/off digital outputs forces me to keep my entire machines cheap and simple. For a simulator ride my PLC will just trigger a compact flash card video player to start playing. The PLC then controls the motion by timed on/off outputs to the actuators. There is no communication with the video but they stay quite adequately in synch and the jerky unrealistic movements are amazingly effective. Commercial simulators have software which runs a timeline with the video and analogue outputs to the actuators. Much more sophisticated, but the final effect isn’t that different from mine.    

I wish computers could be a bit more like PLCs. They certainly don’t need their enormous complexity for most tasks and they certainly could be more robust. If only every computer was built to be dropped, run next to a tesla coil and hit with a rubber hammer.

Also see Electricity

 

 

home

search

about the site

site
map

links to
other sites

where to see stuff

contact me