PID Control using FB41 for Siemens S7-300 PLC


Thread Starter

Donald Tan

I am currently trying to program a Siemens S7-300 PLC (CPU 313) for PID control using FB 41. Where can I find more examples and more details on how to use FB41.

I have tried to run the controller_update.pdf which I have downloaded from the PLCArchive section on my PLC. I have no problems compiling the source code. However, when the program was downloaded and run on the PLC, the PLC SF Software Error LED was turned on.

I tried to read through the manual on PID control but find it hard to understand the explanation.

Essentially, what are the important inputs and outputs parameters that I should take note. I am only interested to design a single input and single output PID controller.

I am trying to control the input voltage to a valve using the controller in order to control the temperature of a reaction vessel.

Any advice on the above would be greatly appreciated. Please feel free to email me at pwdt2002(AT) if you could offer me any help.

Thanks and wishing all of you at Control.Com Merry Christmas and a Happy New Year.

Gary Wrotnowski

1. Create an OB35 100 millisecond time interrupt routine. program a call... such as...


The result is the Instance Data Block, DB41 will be created automatically. Symbolic names are automatically created for you for all the Block parameters of FB41. However you would want to assign a Global Variable name to DB41 such as "Tank"

Then you can work with Symbolics. Referring to the PDF files that install on your computer with STEP7 you can find documentation on the SFB41 System function. For example P,I,D parameters would be

"Tank".Gain REAL Number such a 5.00 P
"Tank".TI T#2s TIME format 2 seconds reset I
"Tank".TD T#1s TIME format 1 second ,derivative D

Good Luck ... let me know if you have further questions.

gary wrotnowski
770 740 3096
PLC instructor

Jan Steen Nielsen, Denmark

Forget all about FB41 - It does't work properly!.
I have through many years developed a PID-Controller myself, starting with S5 and now also for S7-300 & S7-400 and it have been used in many applications in real life.
My controller is both types in the same FB(121):
An analog + Step-controller and is very easy to program and understand. Furthermore you call this FB121 where ever you want in your program, because it have its own time-share inside for calculations and have also a built-in correction for the actual scantime, in fact it MUST be called every scan to work properly.
E-Mail to me ([email protected] and you get this work together with many other blocks in a little (packed) program in OB1, where all blocks are listed. Hereafter you "Retrieve" the program directly in S7-Software and copy-paste which block you need.
Note: I will send this work for FREE, because I feel sorry for you to use much more time on FB41.

Kevin E. Moore

If you are using Step7 V5.1 or later, it is better to use FB58 from the PID Control folder in the Standard Library. It is greatly improved over FB41 and there is a built-in operator interface tool you access by double-clicking on the data block you create when you call FB58 from OB1 or OB35.

michele Bellini

Hi , i'm an Italian beginner with the PLC PID control.
I must control a speed across voltage regulator; but i read the real speed 2 second later that the reality.
I analize at the moment the FB 41 and the FB 58.

The FB 58 is not only for temperature or?

Thanks for you answere
dear colleaques,
i am looking for some teaching examples of PID controller ...i have experience in S7-300 but never work with PID..any one can assist me by sending some documents for self training...
Hey Jan,

thanks alot. I would like to get this. Can u plese mail it to me on:
rishabh.mishra [at]

Thanks Buddy....Keep Booming
i have a large plc program comprises on many FB , DB, FCs ..n now i wana change PID values i will find that PID settings are in which block. cause whole program is without comments? plz guide me

Jan Steen Nielsen

Hello Amir Ovcina (and others)

I have made an all-in-one PID-Controller (FB121) and many other useful functions for Simatic S7-300/400 series for free downloading under PLC Archive+"PID-Control" in

You (and others) are wellcome to get the latest issue of this work of mine. Many of those functions are now open for free.

My old e-mail (L-N@mbox301...) is not active anymore, but you may use my new mail: [email protected]

Kindly regards
Jan Steen Nielsen