OttoMeister / Siemens-Tia-Portal-PID-Controller

Siemens SCL Tia Portal Tia-Portal Bibliothek Source Code like in OSCAT PID PI Regler
Do What The F*ck You Want To Public License
68 stars 15 forks source link
1200 1500 controller oscat pi pi-regler pid pid-controller pid-regler plc regler scl siemens sps tia tia-portal
  ____ ___ ____                    _             _ _           
 |  _ \_ _|  _ \    ___ ___  _ __ | |_ _ __ ___ | | | ___ _ __ 
 | |_) | || | | |  / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
 |  __/| || |_| | | (_| (_) | | | | |_| | | (_) | | |  __/ |   
 |_|_ |___|____/   \___\___/|_| |_|\__|_|  \___/|_|_|\___|_|   
  / _| ___  _ __  / ___|(_) ___ _ __ ___   ___ _ __  ___       
 | |_ / _ \| '__| \___ \| |/ _ \ '_ ` _ \ / _ \ '_ \/ __|      
 |  _| (_) | |     ___) | |  __/ | | | | |  __/ | | \__ \      
 |_|__\___/|_|    |____/|_|\___|_| |_|_|_|\___|_| |_|___/      
 |_   _(_) __ _      |  _ \ ___  _ __| |_ __ _| |              
   | | | |/ _` |_____| |_) / _ \| '__| __/ _` | |              
   | | | | (_| |_____|  __/ (_) | |  | || (_| | |              
   |_| |_|\__,_|     |_|   \___/|_|   \__\__,_|_|              

Problem

I have always been deeply involved in control technology within the TIA Portal environment and have consistently found Siemens modules to be unsatisfactory. I require PI controllers for pressure regulation and PID controllers for temperature control. Here are a few issues that have bothered me:

Work

After an extensive search for alternatives, I failed to find a suitable solution. Drawing inspiration from OSCAT, which is straightforward, I have rewritten functions for TIA14 and 15 compatible with 1200 and 1500 series CPUs. I continue to implement these controls in my TIA Portal 18 projects. My intention was not to cater to everyone but to contribute back to the community. Open libraries like OSCAT have provided me with valuable knowledge, and it is only fair that I share my work. Please refrain from debating the functionality; these functions work as intended. Feel free to copy and use them. If you wish, share your experiences with my software with others.

Usage Instructions

The controller produces outputs ranging from 0 to 100. When used with a binary actuator, utilize the clock generator for pulse width modulation. The PI controller is designed to operate independently, suitable for pressure regulation. The PID controller combines PI and D control, suitable for temperature regulation. Always stop the controller with the reset input if the regulation loop is disrupted. This prevents integral windup.

Please note: If you have an extremely large control system, you should call the PI or PID module cyclically every second, as otherwise the internal floating-point numbers become too small and there will be calculation errors.

Installing

Installation is straightforward. Place the two SLC files under "External source files" and execute the menu item "Generate blocks from source."

Porting

Porting code is simple:

// Proportional
#Controller_Response_Proportional := #ir_ProportionalGain * (#ir_Setpoint - #ir_Input);
// Intergal
#Controller_Response_Integral += #ir_IntegrationGain * (#ir_Setpoint - #ir_Input) * #PastTime;
// Derviate
#Intermediate_value += (#ir_SetpointDiverence - #Intermediate_value) * #PastTime / #ir_DerivateActionTime;
#or_Output := (#ir_SetpointDiverence - #Intermediate_value) * #ir_DerivateGain;

Rest of code is mostly to prevent integral windup and ensure the cycle time is valid.

Note on porting to Step-7, Codesys, or similar:

#PastTime := LREAL_TO_REAL(RUNTIME(#StaticCycleTime_Aux));
IF #PastTime > 0 AND #PastTime < 2.0 THEN

The first line returns the time between two calls in seconds with nanosecond accuracy. The second line checks validity. With Step-7, pass time as a parameter; with Codesys, use TIME_TCK. On 300 PLC, it might be possible to work with "SFC64" (TIMETICK).

License

This project is released under the WTFPL LICENSE. WTFPL