ELEKTOR DCIPLC
a computer-simulated PLC
Published in issue 300, June 2001
Elektor project page.
PLCs are micro controller circuits boards that are frequently used in a wide variety of industrial control and automation applications.
The PLC described here is implemented in software. A complete PLC is simulated in a standard Windows PC. Using an external connection box, the PC can also sense and control many kinds of real items.
The abbreviation 'PLC ' stands for 'Porgrammable Logic Controller'. These devices are also sometimes referred to as 'freely programmable controllers' in the trade. This term refers to an electronic circuit that can be used to automate machinery and processes. A PLC thus can replace a conventional relay logic circuit.
A PLC always consist of a CPU module and several digital input and output modules. The number of input and output modules depends on the size of the process to be controlled.
One the major adventages of a PLC is that it makes it very easy to extend or modify the process. Consequently, PLCs have for years been an indispensable element in the automation of industrial systems.
Recently, PLCs have also like to have certain things automated in their house. Automatic garden sprinkler systems, awning controllers security systems and many other types of systems can easily be controlled using a PLC. Extensions or modifications can be made relatively easily after the system has been installed.
Figure 1 shows an example of a simple motor circuit, one case built using push buttons and relays and in the other case using a PLC. If you want to modify the operation of the circuit, you will have to modify the hardware if you use the relay circuit, but with the PLC all you have to do is make a few changes to the program.
The objective of the DCIPLC design is to implement a PLC in a relatively simple an inexpensive manner using a minimum of hardware, a serial interface and PC software. This saves trouble and expense of building a real PLC. In addition programming this controller is very intuitive and user-friendly.
DCIPLC is actually a program that replaces the CPU module of a PLC, and within which control programs can be developed and modified.With the aid of a serial interface cable and some hardware, the states of 32 inputs can be monitored and 32 outputs can be driven. The program runs under the Windows.
The minimum system requirement is a 100-MHz Pentium processor. The installed software takes up approximately 3 MB, including the examples.
The hardware of this design consist of nothing more than an assembly that converts PC serial port information into a number inputs and outputs. The actual input and output interface must be developed by the user. It can be connected to the DCIPLC interface circuit board using flat cables. It is not possible to design a universial interface that satisfies all possible needs.
If you look at the schematic diagram for the hardware (figure 2), you will see that it actually consist of little more than a handful of CD4094 and CD4021 shift registers. The 4094 shift register is an integrated circuit containing eight flipflops connected in series. With each clock signal, the logic level on the input ('0' or '1') is shifted by one position, so that after eight clock pulses and one strobe pulse we have an 8-bit output signal available. In our circuit, four of these shift registers are connected in series(IC5-IC8). This gives us a total of 32 outputs.
The 4021 shift register has the (relative to the 4094) that can also be used 'the other way around'. It can thus be used to read in the levels on its eight inputs. The output levels of the eight internal plipflops appear on after the other on the serial output when clock pulses are applied to the clock input of the IC.
Layout PCB.
Serial Cable.
I have chosen to use the PC serial port for the connection to the because it offers several advantages, namely:
In the interface hardware, the RS232 signal levels are limited by Zener diodes D1-D3 to +4,7 V and -0,6 V. The resistors R1-R3 provide current limiting.
Immportant: Place the 9-way sub-D connector female on the bottom (connectors) side!
In addition to the shift registers, the circuit board includes a voltage regulator to provide a 5-V supply voltage. The input voltage may range from 10V to 20V. Thera are also 32 LEDs (D5-D36) with associated series resistors, whitch make the levels on the 32 ouputs visible. Finally, we can note that all 32inputs are fitted with pull-up resistors, so that a High level is present on any unused input.
Elektor electronics magazine have made a printed circuit board that has been designed for this hardware.
It is a double-sided board, in order to avoid the use of wire bridges.
Assembling the circuit board is certainly not difficult. Since the ICs draw only a small amount of current, the 7805 doas not need a heat sink. We have chosen to use rectangular LEDs, so that they can be placed close together in groups of eight located exactly opposite the associated header pins.
Standard 2x10 pin headers or box headers are used for connections to the outside world. A length of flath cable can easily be connected to each header using a press-on (IDC) connector. Each connector has +5 V and ground connection on the two extra pins, and a ground connection is present opposite each connection (see the schematic diagram). When assembling the circuit board, keep in mind that the connectors must be fitted on the solder side. This will make the numbering of the inputs and outputs match the numbering on the front-panel foil (see figure 4).
If you want to finish the assembly a tidy manner, you can mount the circuit board in a small enclosure fitted with a front panel foil, such as the one shown in figure 4.
The DCIPLC program is designed to allow you easily prepare a PLC program by simply placing place blocks.
The length of the ladder logic diagram that is constructed in this manner is limited to 99 lines. Ladder Logic Diagrams, which are in many ways similar to relay logic diagrams, are frequently used to graphically generate programs. When putting together a ladder logic diagram, you should always bear in mind that the symbols in the diagram represent instructions rather than physical contacts.
When the instructions in the program are executed, the states of the inputs are monitored. Depending on the states, various ouputs are set either High or Low.
Note: A 'flag' is a sort of internal output that is used to store an intermediate result. A flag can be 'set' and 'reset' just like an output, so it is effectively an invisible output.
When generating a program, it is good idea to work from left to right and to only start a new row after the current has been completed. The second point is also necessary because the program checks for empty rows.
You should also make a habit of always assigning a particular output only once when generating a PLC program.
Every PLC works in the following manner:
If the same output is used more than once in a program, this output will be assigned the state that it receives in the last row in which it is located. The DCIPLC program processes a complete user program 20 to 100 times per second. The actual rate depends on the speed of the PC and the length of the program.
The following example is a simple sprinkler controller for a garden.
We assume that two locations in the garden must be watered. We want to be able to choose from three options, depending on how dry the ground is: a short sprinkling time, a long sprinkling time and a very long sprinkling time.
This what we need:
Now let's see how to enter the program.
First, in the DCIPLC program op a new file and save it as 'sprinkler.plc'. Select the button Test for ON in the toolbar(number 1 in figure 5) and click on cell 0 in row 1.
The chosen instruction will now be located in this cell, and a dialogue window will appear to allow you to assign the input and add a comment. In this dialogue, select 'input' and enter '0' as the assignment. This will cause input 0 of the PLC to be assigned to this instruction. If you wish, you can enter a comment, which can later by viewed by clicking on the cell with the right-hand mouse button. If you now click on 'OK' input will be assigned. This is shown by the fact that 'IY0' appears at the top of the cell.
Next, place a Test for OUT instruction (2) in each of the following cells, and assign these instructions to F11 and F12.
F11 and F12 are flags that will be set and reset later on the program. They are used to prevent another timer from being chosen after one of the pushbuttons has been pressed.
Now select the Line instruction (12) and click once in cells 3 trough 8. The lines have now been placed.
Select the Set output instruction (7) and click in cell 9. The output instruction will be placed and a dialogue window appear. Select 'Flag' and enter '10'. You can also add a comment if you wish. Now you can see that the first row is already finished. Generate the remaining rows on a similar manner, as shown in Figure 6.
Once you have finished, you can save the program, and it is then ready to tested.
To test the program, or to run it without the hardware, you can use the simulation mode. To do so, click on 'Simulation mode' in the 'Status' menu. A window will appear, in which you can enter the states of the outputs.
Set input 1 High and then Low. This starts timer 2, and outputs 1 and 2 will then remain high for 20 minutes.
The program gives a visual representation of the states of the inputs and outputs and also display the current values of the timers.
Once sprinkling has started, setting one of the inputs High no longer has any effect. This is because rows 1,2 and 3 have been blocked (F11 and F12).
After the hardware has been connected, you can make the proper port settings using the 'Ports' menu.
You can choose from COM1 - COM4, and you can also set the speed. It is a good idea to initially set a low speed and then check in RUN mode whether the inputs generate the proper responses and the outputs are correctly driven. Click on 'Run mode' in the 'Status' menu, or click on the toolbar button with the green arrow.
You can return to the edit mode at any time by clicking on 'Edit mode' in the 'Status' menu or click on the button with the red circle. This causes all hardware outputs to be reset to zero.
The following tips will help you obtain the best results from the program in the run mode:
These measures allow Windows to reserve the maximum possible amount of time for the DCIPLC program, which has beneficial effect on its performance. If a CD-ROM is inserted in the tray of the CD player, for example, the DCIPLC program will stop responding for a few seconds, since Windows gives priority to the CD-ROM drive. During this interval, the timers are no longer updated and inputs are not checked. If youobserve the above recommendations, the program will check the inputs at least ten times per second and the timer error wil not exceed two seconds in 24 hours.
On a 400-MHz Pentium machine, the sprinkler program achieves a speed of 90 cycles per second.
For coupling the controller to various types of devices, relays and sensors, readers of Elektor electronics magazine can draw on a vast store of circuits that have been published in earlier issues. Still, we would like to provide a pair of simple examples.
Figure 8a shows an 8-channel output interface consisting of a buffer IC and eight relays. This can be used to supply power to eight devices or circuits (with proper choice of relay, it is even possible to switch the mains voltage, but you must make sure a safe construction).
For coupling the controller to various types of devices, relays and sensors, readers of Elektor electronics magazine can draw on a vast store of circuits that have been published in earlier issues. Still, we would like to provide a pair of simple examples.
Figure 8a shows an 8-channel output interface consisting of a buffer IC and eight relays. This can be used to supply power to eight devices or circuits (with proper choice of relay, it is even possible to switch the mains voltage, but you must make sure a safe construction).
Figure 8b shows an 8-channel input interface. This consists of eight optocouplers with associated current limiting resistors. If the two terminals are connected together, a High level appears in the corresponding PLC input.
Add new comment