What's new
What's new

PLC Programming for beginners

rbmgf7

Aluminum
Joined
Oct 18, 2017
I've been trained on PLC programming from my last employer but it was more troubleshooting and familiarization based training. I did often make some programming changes and integration.

I have a simple project where I would like to tackle programming one from scratch.

Wondering what sources are out there to help teach me the ins and outs? I know everything is different but I want to make sure I'm getting the basics.

Thanks.
 
I went to the local community college and took every continuing education course they offered on PLC, HMI, and VFD programming. The classes were enjoyable and I felt I learned quite a bit. However, without programming on a regular basis, it's unlikely I could write a solid program in a reasonable amount of time.
Sounds like you're well ahead of me as far as familiarity goes, so maybe classes like that would get the ball rolling for you.
 
Take a one semester class in C or Fortran programing. At the end of the class you will have a understanding of how a program is structured. The key concept is that the rules of programing apply to all languages. The topics will include the main program, subroutines, the data base, program entry points, fixed point arithmetic, looping, conditional branching, debugging, and reusable code.

The company sponsored classes on PLC programing concentrate on explaining the trivia associated with the specialized PLC functions. The classes do not teach one how to program. The training is sufficient if you are modifying or debugging existing code.

Once you understand the basics of programing you will find that a quick look in the PLC documentation will provide all the details you need to use the specialized functions. This includes the bit manipulation commands, the timers, the triggers, the counters, memory management and the specialized forms of looping and branching.

One of the major mistakes that non programers make when programing the PLC is not understanding the importance of initialization of the PLC data base at startup.

The machine that you want to control is described in terms of states. That could be valve or carriage positions, parts count, process duration, weights ,temperatures, speeds, and interlock status. When the PLC is turned on the program initialization step needs to determine what all of these states are before it can start running the machine. There is a similar problem when shutting the machine off. The PLC needs to park the machine in a specified configuration before shutting off the power.

The PLC programing work runs as follows:

On the first day you write an essay to yourself describing what the block of code is supposed to do. This includes the machine startup, run, and shutdown operations
It includes a list of all machine states altered by the code, It includes a list of all input and output variables, It includes requirements for data storage in the PLC memory.
If you are working at a company you then talk to the mechanical designer and make sure that all the motors, valves, limit switches, and sensors that you need are included in his design and are installed where they need to be according to the essay you wrote. You then go to the electrical engineer and make sure his wire lists match the inputs and outputs that are listed in your essay.

On the second day you will write the comments for your PLC program using the PLC code editor. Just the comments-not the code. This will include your original essay at the top of the program and then detailed descriptions for what each line of code is supposed to do. This is a iterative process. As you write the comments you may discover that you need more parts or I/O added to the machine to make it work, There may be major problems with timing or sequencing of the machine process. The motors, actuators, and valves may need to be resized to meet the timing requirements,

This will also be were you can get a idea of how fast the PLC processing speed needs to be for machine operation and how much PLC memory is required.

On the third day you will write the PLC code to match the comment lines. This is a book keeping operation and not a programing job. You completed the programing job when you wrote the comments.

The programing process repeats for each PLC subroutine. If the work becomes too complicated you need to break the job up into smaller pieces and more subroutines.
The general rule for programing is that only 30 percent of the project time is spent writing code. The other 2/3 of the time is spent thinking.

I have worked at some places were the expectation is that the code writing will start on the first day of the project. This is a very good way to turn a two week project into a failed six month project.

.
Your simple PLC project may not need this level of discipline. The process will be needed if you intend to become proficient at programing more complicated machines in the future.
 
What he said...

Look at visual basic. As it is common for things like access.

You need to define local and global variables and many other "processes".

The write comments first is a good one. We will borrow it.

We do same in our head for database programming and just get going, writing the comments sure is easier to build the framework of what you are trying to do.

I will add to this. As you build your comments add questions and guesses as you go.

In a routine you may need to do something like go to point x.

But how do you get there?

Where are you now?

How do you know this?

As you continue with your first steps the answers to such questions come up so note it.

Good luck, we learned something today and was not looking to, bonus.

Sent from my SM-G781V using Tapatalk
 
Is listed in more detail but I roll with the thought that....You have to think in English (or any language) "What do you want it to do?"

For example: conveyor stop in accumulation.....if part present, and space available, then transfer the part.

Armed with that "job instruction" you can go write the logical code to match.
 
There are on line PLC interest forums where questions can be asked.

I've got a couple of GE devices (old) and the internet forums have been very helpful.
 
Some other tips - I look first at the Estop circuit if there's going to be powered motion. I'm not smart enough to understand safety project/safety logic so I just use good old hardwired circuits for my own uses. Basically you want to have a relay or contactor which does something like remove AC power to a motor or drop the output power to a valve bank.

Being a career maintenance guy, I also like to have an AUTO and MAN selector with various pushbuttons so you can recover from conditions where you get stuck between steps so to speak. Might want to have a jog or creep-speed mode, etc. The MANual mode PBs can be full independence or can have various "check clear" conditions so you don't crash things out-of-sequence. Entirely up to you.
 
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.
 
I have a Unitronics Vision 350 PLC with a integrated operator panel sitting here that's ready to go into the trash. I've hesitated because I though it would be nice to try to find an experimenter type to give it to. Works as far as I know, still in the box, all there I think. Seems like it might be good for learning on.

I know it ain't an Allen Bradley but still seems like the concepts would transfer.

Free to you if you want to pay shipping, probably medium flat rate box.

PM me if interested.
 
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.

Wow, this is an amazing overview for a noob like me to PLC. Thanks for taking the time to spell it out in such detail!

Are there any relevant books you would recommend to learn PLC concepts?

I foresee needing at least a cursory knowledge of this topic in the future.
 
Are there any relevant books you would recommend to learn PLC concepts?

.



I have not worked with PLCs in over 20 years. That work was with the Siemens S7 system.

At a new job I was asked to complete a PLC program that had been abandoned by a former employee. Up to that point I had only worked in Fortran. I spent two weeks looking at the PLC code trying to determine a way to repair all the existing errors and complete all the required logic. It was a mess. It was ladder logic. I spent another two weeks thinking about why the coding style produced all those errors and had so many logical dead ends. I ended up discarding the code and starting over. The new program was based on how I had worked in my Fortran days.

Over the years I have discovered that many of the scoundrels in engineering like to hide in the software group. It only takes a few weeks to discover a fraud in mechanical or electrical engineering. Software is different. You can fool management for at least a year. A skilled scoundrel will jump to a new job just before he is discovered and repeat the fraud. If the scoundrel jumps ship often enough he can make his way into management and coast through into retirement.

And now back to your book question.

I do not have any recommendations. At least one of the PLC suppliers will have a introduction to PLC programing PDF. It will be ladder logic based.

The Siemens automation website does have a interesting over view of the latest developments in PLCs. The tutorials are no longer on their website.

SIMATIC Controllers | Industrial Automation Systems SIMATIC | Siemens Global

I see they now offer a CPU architecture that works with 64 bit words.

They have developed a modern graphics style programing tool and offer PC based software that converts your desktop computer into a PLC with a add on C or visual basic .compiler.

Their original attempt to integrate motion control with the S7 PLC system was a failure. Since that time they claim to have developed a successful product.


My goal in responding to the original post was to point out to potential PLC users the disadvantages of using ladder logic style programing methods.
For a system with a few digital I/O it still makes sense. Modern PLCs have much more capability and it is worthwhile to become familiar with what they can do.
 
Last edited:
I have seen some pretty good Youtube videos out there. When the concept of a "seal circuit" makes sense to you with both a hardwired relay system and a PLC then the rest is downhill, that's really the central concept in how ladder logic works.

A really good way to learn it is to work in a maintenance department with a factory that uses them or a machine builder that integrates them.

An interesting project is a shop security system...collect data from sensors, decide when to arm, disarm, alarm, silence alarm, etc. Can be simple or radically complex. Communicate the status with signal lamps. Use hardwired I/O or learn a networked I/O protocol.

Another project is control of an air compressor - use it to enable/disable, have a runtime counter in case a hose/tank/pipe blows and its running 24x7. Accumulate/retain runtime hours for filter/belt maintenance intervals based on actual useage.

Have seen some interesting small-sized automatic bandsaw (air operated shuttle feed) projects with a PLC. If you get confident you could buy something like a trashed out DoAll horizontal (hydraulic shuttle feed) with heavy duty mechanicals and rebuild the control project.

With an expandable I/O and enough inputs and outputs, both of the above projects could run from the same PLC....
 
I guess I should give up programming PLCs in ladder logic because it would be so much better to program in a language that no maintenance guy will ever understand. It is no coincidence that ladder logic looks like a wiring schematic.

Like a schematic you have contacts typically indicated as X for inputs. You have coils typically indicated as C. They you have outputs typically indicated as Y.

A PLC program is boolean logic. Every line can be understood as: if this is true and this is true then this coil is on. You could similarly have a line that says if this is true or that is true then this coil is on.
You can also have nots. If this isn’t on then turn the coil on.

All ladder logic gets read the same way scanned from top to bottom over and over. First all the inputs are read, and nothing happens. Then every line is read top to bottom evaluated and nothing happens. Finally the results are used to turn on or off all the outputs.

The previous is all bit logic just on or off. There are also words of various sizes that can represent integers, decimal numbers or text. These let you do math, comparisons etc. Say if V1 an integer equals 5 a constant then turn on coil C1.

Sub programs and such make things easier to read or allow parts of the program to be used over and over.

Thats the basics and they all work that way. It runs factories, waste treatment plants and automation all over the world.
 
Wondering what sources are out there to help teach me the ins and outs? I know everything is different but I want to make sure I'm getting the basics.
Also wonder the best way to learn this now?

I learned ladder logic by designing stuff with actual relays. Over a 100 or them in a panel.
At the same time learned Fortran, Cobal, and digital logic design. One of these closer to relay level logic.
When the Modicon 084 came out it was so great a deal.
No more zillion wires or failed contacts and a deterministic cycle which C, Fortran or others do not do nicely.
PLCs are inheriting different from most all conventional computer programming languages.
If your past started with one you may tend to think it the right road. I could argue either as best all day long.

Maybe the best way to learn is to build something, explore and play with it.
Bob
 
Automation Direct has some very low cost PLCs like the Click platform and the P1000. The P1000 even has one with stackable Arduino boards! My goto is the BRX series for the heavy lifting that most of what I do involves. Get one and automate something, dog treat dispenser, cat feeder, squirrel trap.
 
I'll second the automation direct. PLC's you can actually afford. Free software. Free video tutorial series. Free 1-800 tech support based in Georgia.
The BRX line is a good place to start. full featured and can even get cards that can run high speed I/o at 2MHz. great for high encoder count servos
i have deployed quite a few machines at work with BRX brains. They pair really well with Teknic step/dir servos as well as VFD's
 








 
Back
Top