chat gtp TIA Portal V18
chat gtp TIA Portal V18

Chat GTP is a powerful AI which become very popular recently. We are going to ask it to write program for PLC and see if that really works in TIA Portal V18.

  1. Write program to start motor in ladder logic

ChatGTP understands how program should look like but is not capable to create ladder logic diagram. Lets try FBD

2.Write code in FBD to control motor

Again, FBD code doesn’t look great. Time for SCL

3. Write program in SCL to control motor

This time we have quite a long SCL code generated, code is pasted below

CHATGTP: Here is an example SCL program to control a motor using Siemens S7-300 PLC:

PROGRAM Motor_Control
VAR
MotorSpeed : REAL; (* Motor speed in RPM ) MotorDirection : BOOL; ( Motor direction: 0 for reverse, 1 for forward ) MotorRun : BOOL; ( Motor run command *)

(* Motor control parameters *)
MotorMaxSpeed : REAL := 1000.0;   (* Maximum speed in RPM *)
MotorMinSpeed : REAL := 0.0;      (* Minimum speed in RPM *)
MotorAcceleration : REAL := 100.0;(* Acceleration rate in RPM/sec *)
MotorDeceleration : REAL := 100.0;(* Deceleration rate in RPM/sec *)

(* Motor feedback signals *)
MotorCurrentSpeed : REAL; (* Motor speed feedback signal *)
MotorRunning : BOOL;      (* Motor running feedback signal *)

END_VAR

(* Main program ) BEGIN ( Initialize motor control parameters *)
MotorSpeed := MotorMinSpeed;
MotorDirection := 1;
MotorRun := 0;

(* Set motor feedback signals to initial values *)
MotorCurrentSpeed := 0.0;
MotorRunning := 0;

(* Control loop *)
WHILE TRUE DO
    (* Read motor feedback signals *)
    MotorCurrentSpeed := MotorCurrentSpeed + MotorAcceleration * T#1S;
    MotorRunning := MotorRun AND (MotorSpeed > MotorMinSpeed) AND (MotorSpeed <= MotorMaxSpeed);

    (* Check motor direction *)
    IF NOT MotorDirection THEN
        MotorSpeed := MotorSpeed - MotorDeceleration * T#1S;
    ELSE
        MotorSpeed := MotorSpeed + MotorAcceleration * T#1S;
    END_IF

    (* Limit motor speed *)
    IF MotorSpeed > MotorMaxSpeed THEN
        MotorSpeed := MotorMaxSpeed;
    END_IF

    IF MotorSpeed < MotorMinSpeed THEN
        MotorSpeed := MotorMinSpeed;
    END_IF

    (* Control motor *)
    IF MotorRunning THEN
        (* Set motor speed *)
        // Depending on the type of motor control used, you might need to convert the MotorSpeed value to the appropriate format, e.g. analog output, frequency, PWM duty cycle, etc.
        // Here we assume that MotorSpeed is directly proportional to the motor control signal, e.g. a 4-20 mA signal or a 0-10 V signal.
        Motor_Control_Signal := MotorSpeed;

        (* Set motor direction *)
        // Depending on the motor control scheme, you might need to use different methods to set the motor direction, e.g. a relay, a H-bridge, a VFD, etc.
        // Here we assume that the MotorDirection signal directly controls the motor direction, e.g. a relay or a solid-state switch.
        Motor_Direction_Signal := MotorDirection;
    ELSE
        (* Stop motor *)
        Motor_Control_Signal := 0.0;
        Motor_Direction_Signal := 0;
    END_IF

    (* Wait for one cycle *)
    TON1(IN:=TRUE, PT:=T#1S);
END_WHILE

END_PROGRAM

It cannot be copied in TIA Portal and run because SCL declaration of variables is different. There are some fundamental mistakes and basically this code will put PLC in stop because of infinite While DO Loop 🙂 See Video… https://www.youtube.com/watch?v=lk_ciWIgy08

By admin

Related Post

One thought on “Can Chat GTP write program for Siemens TIA Portal?”

Leave a Reply