Showing posts with label Siemens. Show all posts
Showing posts with label Siemens. Show all posts

Useful resources for PLC programming: PLC-DEV website


I want to make a review on plc-dev website that contains some posts that i think they are really helpful and complete for PLC programmers.
The website has 3 main sections for the 2 most used marks of PLC, Siemens and Allen Bradley, and a talk about Modbus protocol, one of the most used protocols and a protocol that is supported from all PLCs:

Allen Bradley
Even if I think that the best blog to learn Allen Bradley programming (and ladder in general) is Nearly In Control with his RsLogix 5000 tutorial, PLC DEV contains a mass of documentation about Allen Bradley and their products.
Some useful post for starters are:
and a big collection of manuals that must be read (depending on the hardware you are using) is here:

Siemens
The section of Siemens programming is really helpful.
The pain of Siemens PLC is AWL / STL language of programming, both for programmers than for "readers" of programs.
Also this section contains some useful article that resume how to connect, upload and download programs with Step7 (not the best User Interface in the world as you already know), a quick reference for Siemens Libraries (OB, FC, FB, SFC, SFB), and it contains also some useful information about AWL/STL language and addressing.
The parts that i found more useful are:

Modbus
Modbus protocol is a very common protocol that every device support.
This section explain what is a Modbus (RTU, TCP, Modbus +), the electrical wiring (RS 232, 422, 485, Ethernet) and it solves many doubts about the difference between Protocol and Networks.
Modbus FAQ

Example on how to write sequences with Siemens Step 7 (S7-300)

The last post with RsLogix 5000 showed how to write sequence in an understandable way with Allen Bradley PLCs. Here it is a sample for Siemens Step 7.

I will analyze the exercise #3 of learning pit, you can find the full text here:
This is the system with I/Os:

And the state machine that we have to realize is this one:
With green arrows there's the sequence that we should respect, and with black arrows the start/stop conditions.
Notice that when the cycle gets interrupted, it must restart from the last state (this means that you can't drain if you didn't heat before, and so on...); at the end of the cycle you can choose if restart the cycle to do more batches, or to stop it if the batch count is done or if the selector was in single batch position.
The sequence can be realized in this way:
You can write each step of the sequence in a word (DB4.DBW0) and pass every step with a SHL_W (equally as BSL for Allen Bradley) instruction.
If you notice, you can read every rung of the sequence as you could read a green arrow in the diagram above, like "When Step1 and High Level Sensor GO TO Step 2" and so on.
With those steps we know how to enable outputs, because in STEP 1: Fill Mixer i should enable the filling pumps, checking if the product count respects the % of product 1 and 2:
 Step 2: Heat and Mix
T1 is meant to keep the mixer running for 4 seconds after the step change, so you can mix for 4 seconds then start the drain pump.
Step 3: Drain Pump
Step 4: Increment batch count and reset product counter (because the mixer is empty)
Step 5: check product count and restart the cycle or stop it.
How to read this: in the last step of a cycle the 1st thing to do is to reset the steps of the cycle.
Then, if the selector is in Multiple batch, i check batch-count to see if i have to restart the cycle (2nd coil) or to stop the process (Reset automatic mode.)
Of course if the selector is not in multiple batch mode i should reset the automatic mode wihtout checking for anything.

To start the cycle use a segment like this:
The important part of this post is anyway the one with SHL_W, the rest is just about turning ON and OFF some outputs. I post the AWL code for the change steps sequence, just translating it from ladder, to show you how it's made.
As you can see you can write a sequence using a SLW obtaining the same (almost...) readbility as with KOP.

You can download the full exercise with simulation (to be used with PLC-SIM) here: http://www.megaupload.com/?d=83C551Y6

Using PLC Simulators: Testing plants without plants

One thing that i usually do when i program is to write test routines for the program.
Test routines are useful because:
1 - you can check how the code is running and if he has some bugs, debugging it without doing some physical damage to the plant.
2 - you can check if the model of the machine in your mind is similar to the real machine, seeing how the code is going and what is still needed to complete the machine.
3 - other people that read the program checks how "it should work" through the test utility, for example what input you should expect if the motor starts running, or how you control an analogic output coming from a PID, or simulate movements whit motors and encoders, and so on.


On PLC there are simulators (i often use RSEmulate of Allen Bradley, because we often use their plcs) that can execute programs and "force" input and output, so let's see how to use them.
I do an example with a ladder program:
I have a motor (O:0/0)  that  starts when i press a button (I:0/0).
The motor is connected toan encoder (I:0.1) and when encoder is arrived at 14 the motor must stop his run.
There is an alarm sensor (I:0/1) that must block the motor if the encoder fail.
This is a way to do the program:

And this is how i test the inputs and encoders.
It's actually easy not only to test the entire application in this way, but also to see what should happen when the motor starts, and when it should stop.

If you upload a program with a Test Routine (that of course is disabled), you can also understand in a easier way how the program works and save a lot of time, and there is not necessity of calling the constructor's assistance (that fired is main programmer 10 days ago and that is still searching for a cheap one, as usually).

I add a solution for RsLogix 500, that can be emulated and tested with RsEmulate 500.
For Siemens users, try to do this with the simulator of Step 7, and if you can't force Inputs automatically, just use  a DB and put in parallel test bits / words and merkers.

Hope this post can be useful for someone, the program for RsLogix 500 can be found here:
http://www.mesta-automation.com/Downloads/ProcessSimulation.rar

C# and Siemens PLC: LIBNODAVE

Usually i work with Allen Bradley PLCs, but most of PLC's programmers use Siemens PLC.
One thing that i really appreciate of Siemens is the possibility to connect a PC to PLC in a total FREE way, using LIBNODAVE.

Libnodave is a free library compiled in some programming languages (C, C++, C# etc...) that permit to exchange data with Siemens PLC for free and to embed the driver in  the program.
You just have to add as reference the libnodave.Net.dll and start to read and write data using the simple samples inside the docs.
The main page of libnodave is here:
http://libnodave.sourceforge.net/
and the download page of the full package is here:
http://sourceforge.net/projects/libnodave/

At the moment they have developed the version 0.8.4.5, but the project is still alive and healty.
There is also an help forum here:
http://sourceforge.net/projects/libnodave/forums/forum/205657
that can help who is having troubles while writing is first driver.

As usual, once you wrote how to communicate with the PLC, you can fire an event of "DataChanged" and use it to update your WPF UI with databinding, as seen in the previous posts.

UPDATE: You can find a project contaning some communication samples on http://siemensplctoolboxlib.codeplex.com/ . It's one layer above  libnodave and it's possible to download the the source code.