The first day ? My lathes had 23 pages of e-sized logic diagrams ... I'd be damn lucky to get that far in the first month !
E. G. you are describing what a PLC program looks like when it is written without a Main program - Subroutine program structure, and worse, written in ladder logic. I have seen such programs exceed over one hundred pages. It is a very poor way to do machine control.
When done with some careful planing it is possible to divide a complex operation into small easily written and debugged blocks of code. Three pages of code, with some exceptions, is the practical limit. This is code written in the statement list format with every line of code having a corresponding comment card explaining what the code does.The Siemens PLC text editor is set up to make this a easy to read format. I suspect the other vendors have the same feature.
I will illustrate this with a simple example.
You have been given the job of automating a rotary transfer machining center with 12 stations. The machine is designed to produce wheel flanges. The machining operations require drilling, reaming, and tapping of the bolt pattern and boring of the bearing seat. The machine will be reconfigured each work shift to produce a different size flange. There will be different bolt patterns and bearing bore sizes
The machine is fed flange blanks from a 20 slot cassette on the incoming conveyor and discharges the finished flanges into a empty cassette downstream on the same conveyor.
The machine consists of a load station, 8 machining stations, a optical inspection station, a serial number etch station and a exit station.The cycle time to produce one flange is equal to the cycle time of the slowest station plus one index of the rotary transfer mechanism.
Each machining station will have a cutting tool spindle plus a clamping mechanism to hold the part.
If your were to attempt to program this with only a main program in ladder logic you could have 50 pages of code that would take months to write.
Fortunately, we have taken that introductory programing class and know better.
The PLC program is set up as follows:
There is a Main program that reads the start, shutdown, and emergency stop operator commands. This program also controls the rotary index operation when it receives the process complete signal from all 12 stations. It halts the indexer when it receives a bad part signal from the optical inspection station or when it receives a dull/broken tool signal from a machining station, It sends a unique serial number to the etch station after each index.
The Main program will call a subroutine that updates the PLC data base at each index using the digital, analog, and serial port input/output signals from the PLC I/O rack. It ,calls each of the 12 station subroutines with the start, run, and shutdown program entry points.
There is a load station subroutine that handles the part swap from the cassette to station one. It also increments the cassette conveyor by one cassette slot. When the cassette is empty it signals the conveyor to transfer the cassette to the unload station.
There is a one machining subroutine which will be called eight times. Each time it is called it will access a different start address in the PLC memory. Each station's reserved block of memory will be used to enable the spindle, specify speed, feed , and depth of cut,record maximum motor current, record status signals from the motor controller, record interlock signals, and monitor the station's watchdog timer.
At the start of the work shift, the data blocks for each of the eight machining stations will be updated by the operator to configure the stations for the selected wheel flange .For example, if this is a 8 bolt flange the 8 hole flange machining stations will be enabled, If it is a 6 bolt flange the 6 hole flange stations are enabled.
If a different size bearing bore is selected it will revise the boring station boring head travel stop.
The machining station configuration data can be updated by either editing the PLC data base directly (not a good idea), or by using a PC based graphical interface (much safer but more expensive).
The optical inspection station subroutine is a communication interface to the image capture board installed in a PC. It instructs the capture board when to take a picture and enters a part pass/fail signal into the inspection station data block.
The serial number etch station is the communication interface to the marking laser. Its data block stores the current serial number, the laser status, safety interlocks, process completion bit, and the watchdog timer.
The unload station is similar to the load station. It does have one complication. It uses the same cassette conveyor as the load station. It will need to coordinate with the load station so that the empty cassette transfer is sequenced correctly. It is also apparent that the cassette conveyor will need 3 independently controlled sections. One to index the load station, one to transfer the cassette to the unload station, and one to index at the unload station. This is where you have to go back to the mechanical designer and tell him to rework his conveyor design and tell the electrical designer that two more motors will be needed.
The PLC data base will consist of, for example, 500 32 bit words. The first 100 words are reserved for the PLC special function timers, counters, triggers, and the PLC operating system data base.
The next 100 words are reserved for the PLC I/O rack. For the machine described above, station one will use words 301 to 320, station two will use words 321 to 340, station three will use words 341 to 360 and so on.
Each station subroutine is called with its memory start address passed as a parameter. By doing this you only need to write one machining station program even though there are nine machining stations.
The PLC data base update subroutine is needed because the machine wire lists are prepared independently of the PLC software book keeping. When the electrical work is completed, you will have the addresses of each of the digital I/O signals and the addresses of the 16 bit analog signals. This subroutine copies the bits and words to the 12 station data blocks and the main program data block.
At first glance there should be one subroutine that copies the inputs to the station data blocks at the start of the PLC cycle and a second subroutine that copies the station outputs back to the I/O rack at the end of the PLC computation cycle. In practice these are all done at the same time. The PLC only updates the I/O once per computation cycle.
If a ethernet communication module is installed in the I/O rack it is possible to program the swap of the I/O addresses before the data makes it way back to the PLC cpu.This is something that is done on more elaborate PLC installations. The problem with this is that it is not hard coded. There is nothing preventing someone from tampering with the ethernet data swap program entries and causing a machine crash.
None of the subroutines described above will require more than three pages of code to implement.
The most time consuming part of this work is in debugging the communication between the PLC and the external controllers. For this machine you need to talk with spindle motor controllers, conveyor stepper motor indexers, load arm servo motor controllers, the etch laser controller and the image capture board. The documentation that you receive with these devices sometimes has major errors and is frequently hard to decipher.