PLC Program for 100 Motors Using IEC 61131-3 Structured Text (ST)

Rexroth Super Heavy Motors


 When working with Siemens PLCs and utilizing SCL (Structured Control Language) to program for multiple motors, such as 100 motors, it's essential to define an appropriate data structure to manage the states of these motors and develop functions to handle initialization, control, and alarm logic. Below is a simplified example demonstrating how to accomplish these tasks using SCL.

First, you need to create a new SCL source file within the TIA Portal (Totally Integrated Automation Portal) and define a structure to represent each motor.


   


  1. Defining the Motor Data Structure
    In SCL, you can define a TYPE to serve as the data structure for a motor. 

   


TYPE Motor :
STRUCT
   id : INT;               
   speed : REAL;          
   isRunning : BOOL;        
   isAlarm : BOOL;         
END_STRUCT
END_TYPE

//define an array that contains 100 motors
VAR
   motors : ARRAY[1..100] OF Motor;
END_VAR


   


  1. Initializing Motors
    Next, you can write an initialization function to set the initial states of all the motors.

   


FUNCTION FC_InitMotors : VOID

VAR
   i : INT;

END_VAR
BEGIN
   FOR i := 1 TO 100 DO
       motors[i].id := i;
       motors[i].speed := 0.0;
       motors[i].isRunning := FALSE;
       motors[i].isAlarm := FALSE;
   END_FOR;
END_FUNCTION


   


  1. Controlling Motors
    Write a function to set the speed of a motor and update its running status based on the speed value.


   


FUNCTION FC_SetMotorSpeed : VOID
VAR_INPUT
   motorId : INT;
   newSpeed : REAL;
END_VAR
VAR
   motor : POINTER TO Motor;

END_VAR
BEGIN
   IF motorId >= 1 AND motorId <= 100 THEN
       motor := ADR(motors[motorId]);
       motor^.speed := newSpeed;
       IF newSpeed > 0.0 THEN
           motor^.isRunning := TRUE;
       ELSE
           motor^.isRunning := FALSE;
       END_IF;
   END_IF;
END_FUNCTION


   


  1. Alarm Handling
    Write a function to check the status of all motors and set alarm flags as needed.


   


FUNCTION FC_CheckMotorAlarms : VOID
VAR
   i : INT;

END_VAR
BEGIN
   FOR i := 1 TO 100 DO
       // Assuming an alarm is triggered when the speed exceeds a certain threshold.
       IF motors[i].speed > 1000.0 THEN
           motors[i].isAlarm := TRUE;
       ELSE
           motors[i].isAlarm := FALSE;
       END_IF;
   END_FOR;
END_FUNCTION


   


  1. Function Invocation
    In the main program (OB1 or other organization block) of the PLC, you need to invoke these functions to initialize motors, set speeds, and handle alarms.


   



   FC_InitMotors();
   FC_SetMotorSpeed(1, 500.0);
   FC_SetMotorSpeed(2, 1200.0);
   FC_CheckMotorAlarms();


   

These code examples are simplified and assume that you already have a basic understanding of TIA Portal and PLC programming. In practical applications, you may need to handle additional details such as interfacing with hardware, more sophisticated error handling, and logging. Furthermore, the SCL programming environment for PLCs may offer additional features and libraries that you can leverage to simplify your programming efforts.