Softwell Automation · SCL Lab Manual
HomeSCL Training
Open TIA Portal · Follow · Paste · Compile · Test

TIA Portal SCL Programming Manual — Basic to Advanced

A complete 20-day Siemens S7-1500 practical guide. Days 1–10 teach SCL instructions and block development. Days 11–20 cover physical I/O mapping, alarms, networks, tower lamps, SINAMICS G120 communication, manual/auto conveyor logic and final commissioning.

20 practicalsFC + FB + DBCopy-ready SCLPLCSIM test tablesPrintable workbook
Recommended softwareTIA Portal V18, V19 or V20 with S7-PLCSIM
Recommended CPUS7-1200 or S7-1500, optimized block access
Before startingKnow PLC tags, OB1 networks and online monitoring
SafetyTest in PLCSIM first; remove forces before real machinery

Manual conventions

FC
Use for calculations and logic that does not require persistent internal memory.
FB + instance DB
Use for timers, counters, sequences and reusable equipment objects.
#LocalVariable
The hash symbol identifies a variable declared in the current block interface.

Phase 1 — Days 1–10: SCL Fundamentals

Learn how SCL blocks are created, called, programmed, compiled and tested before starting machine-level project development.

01
Day 01 · Basic SCL

Create Your First SCL Function

Create an FC in SCL, define an input and output, paste code, compile and test it from OB1.

Create: FC_FirstSCLLanguage: SCLTest: PLCSIM / Watch table

1. Block interface / tag declaration

Create these parameters before pasting the program. The # prefix is used automatically for local block variables.

ParameterData typeSectionStudent address / note
#EnableBoolInput
#ResultBoolOutput

2. TIA Portal step-by-step procedure

3. Copy and paste SCL code

Paste location: Open the block implementation area below the interface declaration. Do not paste program statements inside the declaration table.
Main copy-paste SCL code
#Result := #Enable;

4. Test values and expected result

Test conditionExpected valueExpected behaviorResult
EnableFALSEResult = FALSE
EnableTRUEResult = TRUE

5. More examples

NOT logic
NOT logic
#Result := NOT #Enable;
Two-input AND
Two-input AND
#Result := #Enable AND #SafetyOK;

6. Common mistakes and diagnosis

  • Output not connected in OB1
  • Tag name spelling does not match the FC interface
  • Code pasted in declaration area instead of implementation area
02
Day 02 · Basic SCL

Call an SCL FC from OB1

Create reusable motor-permission logic and correctly map physical or simulation tags in OB1.

Create: FC_MotorPermissionLanguage: SCLTest: PLCSIM / Watch table

1. Block interface / tag declaration

Create these parameters before pasting the program. The # prefix is used automatically for local block variables.

ParameterData typeSectionStudent address / note
#StartPBBoolInput
#StopPBBoolInput
#SafetyOKBoolInput
#MotorPermitBoolOutput

2. TIA Portal step-by-step procedure

3. Copy and paste SCL code

Paste location: Open the block implementation area below the interface declaration. Do not paste program statements inside the declaration table.
Main copy-paste SCL code
#MotorPermit := #StartPB AND NOT #StopPB AND #SafetyOK;

4. Test values and expected result

Test conditionExpected valueExpected behaviorResult
Start=1, Stop=0, Safety=1TRUEMotorPermit = TRUE
Start=1, Stop=1, Safety=1FALSEMotorPermit = FALSE
Start=1, Stop=0, Safety=0FALSEMotorPermit = FALSE

5. More examples

With fault interlock
With fault interlock
#MotorPermit := #StartPB AND NOT #StopPB AND #SafetyOK AND NOT #Fault;
With mode selection
With mode selection
#MotorPermit := #AutoMode AND #StartPB AND #SafetyOK;

6. Common mistakes and diagnosis

  • FC is compiled but never called from OB1
  • Normally-closed stop logic is interpreted incorrectly
  • Physical input addresses are unavailable in PLCSIM without forcing
03
Day 03 · Basic SCL

Boolean Logic: AND, OR, XOR and NOT

Build and test all common Boolean operations in one SCL function.

Create: FC_LogicGatesLanguage: SCLTest: PLCSIM / Watch table

1. Block interface / tag declaration

Create these parameters before pasting the program. The # prefix is used automatically for local block variables.

ParameterData typeSectionStudent address / note
#ABoolInput
#BBoolInput
#AND_OutBoolOutput
#OR_OutBoolOutput
#XOR_OutBoolOutput
#NOT_ABoolOutput

2. TIA Portal step-by-step procedure

3. Copy and paste SCL code

Paste location: Open the block implementation area below the interface declaration. Do not paste program statements inside the declaration table.
Main copy-paste SCL code
#AND_Out := #A AND #B;
#OR_Out  := #A OR #B;
#XOR_Out := #A XOR #B;
#NOT_A   := NOT #A;

4. Test values and expected result

Test conditionExpected valueExpected behaviorResult
A=0, B=00/0/0/1AND=0, OR=0, XOR=0, NOT_A=1
A=1, B=00/1/1/0Outputs match truth table
A=1, B=11/1/0/0Outputs match truth table

5. More examples

NAND
NAND
#NAND_Out := NOT (#A AND #B);
NOR
NOR
#NOR_Out := NOT (#A OR #B);

6. Common mistakes and diagnosis

  • Using = instead of := for assignment
  • Missing brackets in combined expressions
  • Reusing the same output tag for multiple results
04
Day 04 · Basic SCL

IF, ELSIF and ELSE Decision Logic

Use IF, ELSIF and ELSE to classify an analog value into Low, Normal and High states.

Create: FC_TemperatureStateLanguage: SCLTest: PLCSIM / Watch table

1. Block interface / tag declaration

Create these parameters before pasting the program. The # prefix is used automatically for local block variables.

ParameterData typeSectionStudent address / note
#TemperatureRealInput
#LowLimitRealInput
#HighLimitRealInput
#StateIntOutput
#LowAlarmBoolOutput
#HighAlarmBoolOutput

2. TIA Portal step-by-step procedure

3. Copy and paste SCL code

Paste location: Open the block implementation area below the interface declaration. Do not paste program statements inside the declaration table.
Main copy-paste SCL code
#LowAlarm := FALSE;
#HighAlarm := FALSE;

IF #Temperature < #LowLimit THEN
    #State := 1;           // Low
    #LowAlarm := TRUE;
ELSIF #Temperature > #HighLimit THEN
    #State := 3;           // High
    #HighAlarm := TRUE;
ELSE
    #State := 2;           // Normal
END_IF;

4. Test values and expected result

Test conditionExpected valueExpected behaviorResult
Temperature=10.0State=1LowAlarm=TRUE
Temperature=50.0State=2Both alarms=FALSE
Temperature=90.0State=3HighAlarm=TRUE

5. More examples

Simple motor condition
Simple motor condition
IF #Start AND #SafetyOK THEN
    #Motor := TRUE;
ELSE
    #Motor := FALSE;
END_IF;
Three-speed selection
Three-speed selection
IF #SpeedCmd < 500.0 THEN
    #SpeedLevel := 1;
ELSIF #SpeedCmd < 1000.0 THEN
    #SpeedLevel := 2;
ELSE
    #SpeedLevel := 3;
END_IF;

6. Common mistakes and diagnosis

  • Writing ELSE IF instead of ELSIF
  • Not resetting alarm outputs before the decision
  • Using integer constants with unintended data conversion
05
Day 05 · Basic SCL

Set/Reset Motor Memory in SCL

Create retained motor start/stop memory inside an FB using static data and an instance DB.

Create: FB_MotorLatchLanguage: SCLTest: PLCSIM / Watch table

1. Block interface / tag declaration

Create these parameters before pasting the program. The # prefix is used automatically for local block variables.

ParameterData typeSectionStudent address / note
#StartPBBoolInput
#StopPBBoolInput
#SafetyOKBoolInput
#RunningBoolOutput
#RunMemoryBoolStatic

2. TIA Portal step-by-step procedure

3. Copy and paste SCL code

Paste location: Open the block implementation area below the interface declaration. Do not paste program statements inside the declaration table.
Main copy-paste SCL code
IF #StopPB OR NOT #SafetyOK THEN
    #RunMemory := FALSE;
ELSIF #StartPB THEN
    #RunMemory := TRUE;
END_IF;

#Running := #RunMemory;

4. Test values and expected result

Test conditionExpected valueExpected behaviorResult
Start pulse with SafetyOK=1TRUERunning latches
Start returns to 0TRUERunning stays latched
Stop pulseFALSERunning resets

5. More examples

Dominant reset
Dominant reset
IF #Reset THEN
    #Memory := FALSE;
ELSIF #Set THEN
    #Memory := TRUE;
END_IF;
Dominant set
Dominant set
IF #Set THEN
    #Memory := TRUE;
ELSIF #Reset THEN
    #Memory := FALSE;
END_IF;

6. Common mistakes and diagnosis

  • RunMemory created as Temp, so it does not retain state
  • Using FC when internal persistent memory is required
  • No instance DB created or wrong FB instance called
06
Day 06 · Basic SCL

TON Timer in an SCL Function Block

Create an IEC TON timer instance in SCL and use its Q and ET outputs.

Create: FB_OnDelayLanguage: SCLTest: PLCSIM / Watch table

1. Block interface / tag declaration

Create these parameters before pasting the program. The # prefix is used automatically for local block variables.

ParameterData typeSectionStudent address / note
#EnableBoolInput
#DelayTimeTimeInput
#DoneBoolOutput
#ElapsedTimeOutput
#Timer1TONStatic

2. TIA Portal step-by-step procedure

3. Copy and paste SCL code

Paste location: Open the block implementation area below the interface declaration. Do not paste program statements inside the declaration table.
Main copy-paste SCL code
#Timer1(IN := #Enable,
        PT := #DelayTime);

#Done := #Timer1.Q;
#Elapsed := #Timer1.ET;

4. Test values and expected result

Test conditionExpected valueExpected behaviorResult
Enable=0Done=0Elapsed resets
Enable=1 for 3 s, PT=5 sDone=0Elapsed approximately T#3s
Enable=1 for >5 sDone=1Elapsed reaches PT

5. More examples

Fixed five-second delay
Fixed five-second delay
#Timer1(IN := #Enable, PT := T#5s);
#Done := #Timer1.Q;
Delayed motor start
Delayed motor start
#StartDelay(IN := #StartCmd AND #SafetyOK, PT := T#3s);
#MotorRun := #StartDelay.Q;

6. Common mistakes and diagnosis

  • TON instance declared as Temp rather than Static
  • Calling the timer without named parameters
  • Using an invalid TIME literal such as 5s instead of T#5s
07
Day 07 · Basic SCL

CTU Counter with Positive Edge

Count product sensor pulses with CTU and reset the accumulated count.

Create: FB_ProductCounterLanguage: SCLTest: PLCSIM / Watch table

1. Block interface / tag declaration

Create these parameters before pasting the program. The # prefix is used automatically for local block variables.

ParameterData typeSectionStudent address / note
#PulseBoolInput
#ResetBoolInput
#PresetDIntInput
#ReachedBoolOutput
#CountDIntOutput
#Counter1CTU_DIntStatic

2. TIA Portal step-by-step procedure

3. Copy and paste SCL code

Paste location: Open the block implementation area below the interface declaration. Do not paste program statements inside the declaration table.
Main copy-paste SCL code
#Counter1(CU := #Pulse,
          R  := #Reset,
          PV := #Preset);

#Reached := #Counter1.Q;
#Count := #Counter1.CV;

4. Test values and expected result

Test conditionExpected valueExpected behaviorResult
Three rising edges, PV=5Count=3Reached=FALSE
Five rising edges, PV=5Count=5Reached=TRUE
Reset=TRUECount=0Reached=FALSE

5. More examples

Manual edge count without CTU
Manual edge count without CTU
#PulseEdge(CLK := #Pulse);
IF #PulseEdge.Q THEN
    #CountMemory := #CountMemory + 1;
END_IF;
IF #Reset THEN
    #CountMemory := 0;
END_IF;
Batch complete
Batch complete
#BatchDone := (#Count >= #BatchSize);

6. Common mistakes and diagnosis

  • Holding Pulse TRUE and expecting continuous counting
  • Selecting a counter type that does not match DInt values
  • Reset input held TRUE during testing
08
Day 08 · Basic SCL

Analog Scaling: Raw Input to Engineering Units

Convert a Siemens raw analog value to engineering units with clamping and fault indication.

Create: FC_AnalogScaleLanguage: SCLTest: PLCSIM / Watch table

1. Block interface / tag declaration

Create these parameters before pasting the program. The # prefix is used automatically for local block variables.

ParameterData typeSectionStudent address / note
#RawValueIntInput
#RawMinIntInput
#RawMaxIntInput
#EngMinRealInput
#EngMaxRealInput
#EngValueRealOutput
#OutOfRangeBoolOutput

2. TIA Portal step-by-step procedure

3. Copy and paste SCL code

Paste location: Open the block implementation area below the interface declaration. Do not paste program statements inside the declaration table.
Main copy-paste SCL code
#OutOfRange := (#RawValue < #RawMin) OR (#RawValue > #RawMax);

IF #RawValue <= #RawMin THEN
    #EngValue := #EngMin;
ELSIF #RawValue >= #RawMax THEN
    #EngValue := #EngMax;
ELSE
    #EngValue := INT_TO_REAL(#RawValue - #RawMin)
                 * (#EngMax - #EngMin)
                 / INT_TO_REAL(#RawMax - #RawMin)
                 + #EngMin;
END_IF;

4. Test values and expected result

Test conditionExpected valueExpected behaviorResult
Raw=0EngValue=0.0OutOfRange=FALSE
Raw=13824EngValue≈50.0OutOfRange=FALSE
Raw=27648EngValue=100.0OutOfRange=FALSE
Raw=30000EngValue=100.0OutOfRange=TRUE

5. More examples

0–27648 to 0–100%
0–27648 to 0–100%
#Percent := INT_TO_REAL(#Raw) * 100.0 / 27648.0;
4–20 mA represented by 5530–27648
4–20 mA represented by 5530–27648
#Value := INT_TO_REAL(#Raw - 5530) * 10.0 / REAL#22118.0;

6. Common mistakes and diagnosis

  • Integer division used before conversion to Real
  • RawMax equals RawMin, causing division by zero
  • Using 27648 for a module/channel configured with a different normalized range
09
Day 09 · Basic SCL

CASE Statement for Operating Modes

Select Manual, Auto, Maintenance or Safe behavior using a CASE statement.

Create: FC_ModeSelectorLanguage: SCLTest: PLCSIM / Watch table

1. Block interface / tag declaration

Create these parameters before pasting the program. The # prefix is used automatically for local block variables.

ParameterData typeSectionStudent address / note
#ModeUSIntInput
#ManualEnableBoolOutput
#AutoEnableBoolOutput
#MaintenanceEnableBoolOutput
#InvalidModeBoolOutput

2. TIA Portal step-by-step procedure

3. Copy and paste SCL code

Paste location: Open the block implementation area below the interface declaration. Do not paste program statements inside the declaration table.
Main copy-paste SCL code
#ManualEnable := FALSE;
#AutoEnable := FALSE;
#MaintenanceEnable := FALSE;
#InvalidMode := FALSE;

CASE #Mode OF
    0: ; // Safe / stopped
    1: #ManualEnable := TRUE;
    2: #AutoEnable := TRUE;
    3: #MaintenanceEnable := TRUE;
ELSE
    #InvalidMode := TRUE;
END_CASE;

4. Test values and expected result

Test conditionExpected valueExpected behaviorResult
Mode=1ManualEnable=TRUEOther enables FALSE
Mode=2AutoEnable=TRUEOther enables FALSE
Mode=9InvalidMode=TRUEAll enables FALSE

5. More examples

Fault message selection
Fault message selection
CASE #FaultCode OF
    0: #Message := 'No fault';
    1: #Message := 'Emergency stop';
    2: #Message := 'Motor overload';
ELSE
    #Message := 'Unknown fault';
END_CASE;
Step actions
Step actions
CASE #Step OF
    0: #Valve := FALSE;
    10: #Valve := TRUE;
    20: #Motor := TRUE;
END_CASE;

6. Common mistakes and diagnosis

  • Outputs not reset before CASE, causing old state to remain
  • Missing ELSE branch for invalid values
  • Mode data type too small or inconsistent with HMI tag
10
Day 10 · Basic SCL

FOR Loop for Array Total and Average

Process an array with a FOR loop and calculate total, average, minimum and maximum.

Create: FC_ArrayStatisticsLanguage: SCLTest: PLCSIM / Watch table

1. Block interface / tag declaration

Create these parameters before pasting the program. The # prefix is used automatically for local block variables.

ParameterData typeSectionStudent address / note
#ValuesArray[0..9] of RealInput
#TotalRealOutput
#AverageRealOutput
#MinimumRealOutput
#MaximumRealOutput
#iIntTemp

2. TIA Portal step-by-step procedure

3. Copy and paste SCL code

Paste location: Open the block implementation area below the interface declaration. Do not paste program statements inside the declaration table.
Main copy-paste SCL code
#Total := 0.0;
#Minimum := #Values[0];
#Maximum := #Values[0];

FOR #i := 0 TO 9 DO
    #Total := #Total + #Values[#i];

    IF #Values[#i] < #Minimum THEN
        #Minimum := #Values[#i];
    END_IF;

    IF #Values[#i] > #Maximum THEN
        #Maximum := #Values[#i];
    END_IF;
END_FOR;

#Average := #Total / 10.0;

4. Test values and expected result

Test conditionExpected valueExpected behaviorResult
Values 1..10Total=55Average=5.5, Min=1, Max=10
All values=5Total=50Average=5, Min=5, Max=5

5. More examples

Reset array
Reset array
FOR #i := 0 TO 9 DO
    #Values[#i] := 0.0;
END_FOR;
Count alarms
Count alarms
#AlarmCount := 0;
FOR #i := 0 TO 15 DO
    IF #Alarms[#i] THEN
        #AlarmCount := #AlarmCount + 1;
    END_IF;
END_FOR;

6. Common mistakes and diagnosis

  • Loop runs 0 TO 10 for an array ending at 9
  • Total is not reset before every scan
  • Minimum initialized to 0.0, giving wrong results for all-positive arrays

Phase 2 — Days 11–20: Mapping, Drives and Project Development

Use the fixed S7-1500 address standard, global mapping DBs and SCL project blocks to develop a complete conveyor application.

11
Day 11 · Advanced Project

Digital Input Mapping

Map %I10.0 to %I11.7 into readable S7-1500 global DB members using SCL IF–ELSE.

PLC: S7-1500Language: SCLTest: PLCSIM / Watch table

Topic: Digital Input Mapping with IF–ELSE

1. TIA Portal procedure

  1. Create FC_Input_Mapping in SCL.
  2. Create Boolean members in DB_Input_Map using the names shown in the conveyor workbook.
  3. Paste the code below into the implementation area.
  4. Compile the FC and call it before all logic-development blocks in OB1.
  5. Use a watch table to monitor both the physical address and mapped DB member.
  6. Force only during PLCSIM testing; remove all forces before real-machine operation.

2. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 11 SCL source
IF %I10.0 THEN
    "DB_Input_Map".Emergency_Stop := TRUE;
ELSE
    "DB_Input_Map".Emergency_Stop := FALSE;
END_IF;

IF %I10.1 THEN
    "DB_Input_Map".Auto_Manual_Selector_Switch := TRUE;
ELSE
    "DB_Input_Map".Auto_Manual_Selector_Switch := FALSE;
END_IF;

IF %I10.2 THEN
    "DB_Input_Map".System_Auto_Start_Push_Button := TRUE;
ELSE
    "DB_Input_Map".System_Auto_Start_Push_Button := FALSE;
END_IF;

IF %I10.3 THEN
    "DB_Input_Map".System_Auto_Stop_Push_Button := TRUE;
ELSE
    "DB_Input_Map".System_Auto_Stop_Push_Button := FALSE;
END_IF;

IF %I10.4 THEN
    "DB_Input_Map".System_Fault_Reset_Push_Button := TRUE;
ELSE
    "DB_Input_Map".System_Fault_Reset_Push_Button := FALSE;
END_IF;

IF %I10.5 THEN
    "DB_Input_Map".System_Fault_Acknowledge_Push_Button := TRUE;
ELSE
    "DB_Input_Map".System_Fault_Acknowledge_Push_Button := FALSE;
END_IF;

IF %I10.6 THEN
    "DB_Input_Map".Entry_Sensor := TRUE;
ELSE
    "DB_Input_Map".Entry_Sensor := FALSE;
END_IF;

IF %I10.7 THEN
    "DB_Input_Map".Exit_Sensor := TRUE;
ELSE
    "DB_Input_Map".Exit_Sensor := FALSE;
END_IF;

3. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed

Topic: Extended Input Mapping: Conveyor, Safety and Feedback

4. TIA Portal procedure

  1. Continue in FC_Input_Mapping below the first-byte mappings.
  2. Create the required members in DB_Input_Map before compiling.
  3. Keep normally-closed field-device meaning clearly documented.
  4. For Emergency Healthy signals, invert only when the electrical drawing confirms NC logic.
  5. Test every input individually in PLCSIM or with the disconnected machine.

5. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 11 SCL source
IF %I11.0 THEN
    "DB_Input_Map".Conveyor_Forward_Push_Button := TRUE;
ELSE
    "DB_Input_Map".Conveyor_Forward_Push_Button := FALSE;
END_IF;

IF %I11.1 THEN
    "DB_Input_Map".Conveyor_Reverse_Push_Button := TRUE;
ELSE
    "DB_Input_Map".Conveyor_Reverse_Push_Button := FALSE;
END_IF;

IF %I11.2 THEN
    "DB_Input_Map".Forward_Position_Sensor := TRUE;
ELSE
    "DB_Input_Map".Forward_Position_Sensor := FALSE;
END_IF;

IF %I11.3 THEN
    "DB_Input_Map".Reverse_Position_Sensor := TRUE;
ELSE
    "DB_Input_Map".Reverse_Position_Sensor := FALSE;
END_IF;

IF %I11.4 THEN
    "DB_Input_Map".VFD_Healthy := TRUE;
ELSE
    "DB_Input_Map".VFD_Healthy := FALSE;
END_IF;

IF %I11.5 THEN
    "DB_Input_Map".VFD_Fault := TRUE;
ELSE
    "DB_Input_Map".VFD_Fault := FALSE;
END_IF;

IF %I11.6 THEN
    "DB_Input_Map".Safety_Relay_Healthy := TRUE;
ELSE
    "DB_Input_Map".Safety_Relay_Healthy := FALSE;
END_IF;

IF %I11.7 THEN
    "DB_Input_Map".Main_Contactor_On_Feedback := TRUE;
ELSE
    "DB_Input_Map".Main_Contactor_On_Feedback := FALSE;
END_IF;

6. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed
12
Day 12 · Advanced Project

Digital Output and Analog Mapping

Map %Q6.0 to %Q7.7, %IW0 to %IW8 and %QW0 to %QW2 with clear global tags.

PLC: S7-1500Language: SCLTest: PLCSIM / Watch table

Topic: Digital Output Mapping with IF–ELSE

1. TIA Portal procedure

  1. Create FC_Output_Mapping in SCL.
  2. Create Boolean members in DB_Output_Map.
  3. Place output mapping after all command and alarm logic in OB1.
  4. Never write the same physical output from another FC, FB or OB.
  5. Test each output with the power circuit safely isolated.

2. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 12 SCL source
IF "DB_Output_Map".Conveyor_Forward_Command THEN
    %Q6.0 := TRUE;
ELSE
    %Q6.0 := FALSE;
END_IF;

IF "DB_Output_Map".Conveyor_Reverse_Command THEN
    %Q6.1 := TRUE;
ELSE
    %Q6.1 := FALSE;
END_IF;

IF "DB_Output_Map".Brake_Contactor_Command THEN
    %Q6.2 := TRUE;
ELSE
    %Q6.2 := FALSE;
END_IF;

IF "DB_Output_Map".Green_Lamp_Command THEN
    %Q6.3 := TRUE;
ELSE
    %Q6.3 := FALSE;
END_IF;

IF "DB_Output_Map".Yellow_Lamp_Command THEN
    %Q6.4 := TRUE;
ELSE
    %Q6.4 := FALSE;
END_IF;

IF "DB_Output_Map".Red_Lamp_Command THEN
    %Q6.5 := TRUE;
ELSE
    %Q6.5 := FALSE;
END_IF;

IF "DB_Output_Map".Blue_Lamp_Command THEN
    %Q6.6 := TRUE;
ELSE
    %Q6.6 := FALSE;
END_IF;

IF "DB_Output_Map".Hooter_Command THEN
    %Q6.7 := TRUE;
ELSE
    %Q6.7 := FALSE;
END_IF;

3. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed

Topic: Analog Input and Output Mapping

4. TIA Portal procedure

  1. Create FC_Analog_Mapping in SCL.
  2. Create INT members AI_0_Raw through AI_8_Raw in DB_Analog_Map.
  3. Create INT members AO_0_Raw and AO_2_Raw in DB_Analog_Map.
  4. Paste the direct mappings.
  5. Add scaling only after confirming each module measurement range and raw-value format.

5. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 12 SCL source
"DB_Analog_Map".AI_0_Raw := %IW0;
"DB_Analog_Map".AI_2_Raw := %IW2;
"DB_Analog_Map".AI_4_Raw := %IW4;
"DB_Analog_Map".AI_6_Raw := %IW6;
"DB_Analog_Map".AI_8_Raw := %IW8;

%QW0 := "DB_Analog_Map".AO_0_Raw;
%QW2 := "DB_Analog_Map".AO_2_Raw;

// Example 0–10 V scaling for a 0–27648 module
"DB_Analog_Map".Speed_Feedback_Percent :=
    INT_TO_REAL("DB_Analog_Map".AI_0_Raw) * 100.0 / 27648.0;

"DB_Analog_Map".AO_0_Raw :=
    REAL_TO_INT(LIMIT(MN := 0.0,
                      IN := "DB_Project".Speed_Setpoint_Percent,
                      MX := 100.0) * 27648.0 / 100.0);

6. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed
13
Day 13 · Advanced Project

Alarm Mapping and First-Fault Logic

Develop machine alarms, alarm priority and first-fault indication from mapped feedbacks.

PLC: S7-1500Language: SCLTest: PLCSIM / Watch table

1. TIA Portal procedure

  1. Create FC_Alarm_Mapping.
  2. Create alarm Boolean members and Alarm_Code in DB_Alarm_Map.
  3. Create Reset_Alarms and Fault_Acknowledge commands in DB_Project.
  4. Place alarm logic before tower-lamp logic.
  5. Test one alarm at a time and verify common alarm and first-fault code.

2. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 13 SCL source
IF NOT "DB_Input_Map".Emergency_Stop THEN
    "DB_Alarm_Map".Emergency_Stop_Alarm := TRUE;
ELSE
    "DB_Alarm_Map".Emergency_Stop_Alarm := FALSE;
END_IF;

IF NOT "DB_Input_Map".Safety_Relay_Healthy THEN
    "DB_Alarm_Map".Safety_Relay_Alarm := TRUE;
ELSE
    "DB_Alarm_Map".Safety_Relay_Alarm := FALSE;
END_IF;

IF "DB_Input_Map".VFD_Fault THEN
    "DB_Alarm_Map".VFD_Fault_Alarm := TRUE;
ELSE
    "DB_Alarm_Map".VFD_Fault_Alarm := FALSE;
END_IF;

IF NOT "DB_Network_Map".VFD_Communication_OK THEN
    "DB_Alarm_Map".VFD_Communication_Alarm := TRUE;
ELSE
    "DB_Alarm_Map".VFD_Communication_Alarm := FALSE;
END_IF;

"DB_Alarm_Map".Alarm_Present :=
    "DB_Alarm_Map".Emergency_Stop_Alarm OR
    "DB_Alarm_Map".Safety_Relay_Alarm OR
    "DB_Alarm_Map".VFD_Fault_Alarm OR
    "DB_Alarm_Map".VFD_Communication_Alarm;

IF "DB_Alarm_Map".Emergency_Stop_Alarm THEN
    "DB_Alarm_Map".Alarm_Code := 1;
ELSIF "DB_Alarm_Map".Safety_Relay_Alarm THEN
    "DB_Alarm_Map".Alarm_Code := 2;
ELSIF "DB_Alarm_Map".VFD_Fault_Alarm THEN
    "DB_Alarm_Map".Alarm_Code := 3;
ELSIF "DB_Alarm_Map".VFD_Communication_Alarm THEN
    "DB_Alarm_Map".Alarm_Code := 4;
ELSE
    "DB_Alarm_Map".Alarm_Code := 0;
END_IF;

3. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed
14
Day 14 · Advanced Project

Network and Tower-Lamp Mapping

Map PLC, HMI, RIO and VFD communication status and drive the tower lamp and hooter.

PLC: S7-1500Language: SCLTest: PLCSIM / Watch table

Topic: Network Mapping for PLC, HMI, RIO and VFD

1. TIA Portal procedure

  1. Create FC_Network_Mapping.
  2. Create Boolean members in DB_Network_Map for HMI, RIO and VFD status.
  3. Map device status from the actual hardware/system tags generated by TIA Portal.
  4. Use the simulation switches shown below only for offline training.
  5. Replace simulation members with real diagnostic tags before commissioning.

2. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 14 SCL source
// Training simulation mapping
IF "DB_Project".Sim_HMI_Online THEN
    "DB_Network_Map".HMI_Communication_OK := TRUE;
ELSE
    "DB_Network_Map".HMI_Communication_OK := FALSE;
END_IF;

IF "DB_Project".Sim_RIO_01_Online THEN
    "DB_Network_Map".RIO_01_Communication_OK := TRUE;
ELSE
    "DB_Network_Map".RIO_01_Communication_OK := FALSE;
END_IF;

IF "DB_Project".Sim_RIO_02_Online THEN
    "DB_Network_Map".RIO_02_Communication_OK := TRUE;
ELSE
    "DB_Network_Map".RIO_02_Communication_OK := FALSE;
END_IF;

IF "DB_Project".Sim_VFD_Online THEN
    "DB_Network_Map".VFD_Communication_OK := TRUE;
ELSE
    "DB_Network_Map".VFD_Communication_OK := FALSE;
END_IF;

"DB_Network_Map".All_Networks_OK :=
    "DB_Network_Map".HMI_Communication_OK AND
    "DB_Network_Map".RIO_01_Communication_OK AND
    "DB_Network_Map".RIO_02_Communication_OK AND
    "DB_Network_Map".VFD_Communication_OK;

3. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed

Topic: Tower Lamp and Hooter Mapping

4. TIA Portal procedure

  1. Create FC_Tower_Mapping.
  2. Create status members in DB_Tower_Map.
  3. Use alarm priority: red overrides yellow and green.
  4. Use the system clock memory or a cyclic clock tag for flashing.
  5. Pass the final tower commands to DB_Output_Map.

5. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 14 SCL source
IF "DB_Alarm_Map".Alarm_Present THEN
    "DB_Tower_Map".Red_Lamp_On := TRUE;
    "DB_Tower_Map".Yellow_Lamp_On := FALSE;
    "DB_Tower_Map".Green_Lamp_On := FALSE;
    "DB_Tower_Map".Hooter_On := NOT "DB_Project".Fault_Acknowledged;
ELSIF "DB_Project".Auto_Cycle_On THEN
    "DB_Tower_Map".Red_Lamp_On := FALSE;
    "DB_Tower_Map".Yellow_Lamp_On := FALSE;
    "DB_Tower_Map".Green_Lamp_On := TRUE;
    "DB_Tower_Map".Hooter_On := FALSE;
ELSIF "DB_Project".Manual_Mode_Selected THEN
    "DB_Tower_Map".Red_Lamp_On := FALSE;
    "DB_Tower_Map".Yellow_Lamp_On := TRUE;
    "DB_Tower_Map".Green_Lamp_On := FALSE;
    "DB_Tower_Map".Hooter_On := FALSE;
ELSE
    "DB_Tower_Map".Red_Lamp_On := FALSE;
    "DB_Tower_Map".Yellow_Lamp_On := FALSE;
    "DB_Tower_Map".Green_Lamp_On := FALSE;
    "DB_Tower_Map".Hooter_On := FALSE;
END_IF;

"DB_Output_Map".Green_Lamp_Command := "DB_Tower_Map".Green_Lamp_On;
"DB_Output_Map".Yellow_Lamp_Command := "DB_Tower_Map".Yellow_Lamp_On;
"DB_Output_Map".Red_Lamp_Command := "DB_Tower_Map".Red_Lamp_On;
"DB_Output_Map".Hooter_Command := "DB_Tower_Map".Hooter_On;

6. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed
15
Day 15 · Advanced Project

Manual/Auto Selection and Conveyor Interlocks

Create basic permission, mode selection, forward/reverse interlocks and safe manual operation.

PLC: S7-1500Language: SCLTest: PLCSIM / Watch table

Topic: Manual Mode Selection and Basic Permission

1. TIA Portal procedure

  1. Create FC_Mode_and_Permission.
  2. Use the mapped selector-switch state to determine Manual and Auto mode.
  3. Combine emergency, safety, VFD health and network health into Basic_Permission.
  4. Use Basic_Permission in every motor command.
  5. Display each permission individually on the HMI for troubleshooting.

2. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 15 SCL source
IF "DB_Input_Map".Auto_Manual_Selector_Switch THEN
    "DB_Project".Auto_Mode_Selected := TRUE;
    "DB_Project".Manual_Mode_Selected := FALSE;
ELSE
    "DB_Project".Auto_Mode_Selected := FALSE;
    "DB_Project".Manual_Mode_Selected := TRUE;
END_IF;

IF "DB_Input_Map".Emergency_Stop AND
   "DB_Input_Map".Safety_Relay_Healthy AND
   "DB_Input_Map".VFD_Healthy AND
   NOT "DB_Input_Map".VFD_Fault AND
   "DB_Network_Map".VFD_Communication_OK THEN
    "DB_Project".Basic_Permission := TRUE;
ELSE
    "DB_Project".Basic_Permission := FALSE;
END_IF;

IF "DB_Project".Manual_Mode_Selected AND
   "DB_Project".Basic_Permission THEN
    "DB_Project".Manual_Permission := TRUE;
ELSE
    "DB_Project".Manual_Permission := FALSE;
END_IF;

3. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed

Topic: Manual Conveyor Forward and Reverse Logic

4. TIA Portal procedure

  1. Create FC_Manual_Mode.
  2. Use the mapped forward and reverse push buttons.
  3. Prevent simultaneous forward and reverse commands.
  4. Stop at the corresponding position/over-travel sensor.
  5. Drop both commands immediately when Basic_Permission becomes false.

5. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 15 SCL source
IF "DB_Project".Manual_Permission AND
   "DB_Input_Map".Conveyor_Forward_Push_Button AND
   NOT "DB_Input_Map".Conveyor_Reverse_Push_Button AND
   NOT "DB_Input_Map".Forward_Position_Sensor THEN
    "DB_Project".Manual_Forward_Command := TRUE;
ELSE
    "DB_Project".Manual_Forward_Command := FALSE;
END_IF;

IF "DB_Project".Manual_Permission AND
   "DB_Input_Map".Conveyor_Reverse_Push_Button AND
   NOT "DB_Input_Map".Conveyor_Forward_Push_Button AND
   NOT "DB_Input_Map".Reverse_Position_Sensor THEN
    "DB_Project".Manual_Reverse_Command := TRUE;
ELSE
    "DB_Project".Manual_Reverse_Command := FALSE;
END_IF;

"DB_Output_Map".Conveyor_Forward_Command :=
    "DB_Project".Manual_Forward_Command AND
    NOT "DB_Project".Manual_Reverse_Command;

"DB_Output_Map".Conveyor_Reverse_Command :=
    "DB_Project".Manual_Reverse_Command AND
    NOT "DB_Project".Manual_Forward_Command;

6. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed
16
Day 16 · Advanced Project

SINAMICS G120 PROFINET Setup, Control and Status

Configure the G120 telegram, write control word/speed setpoint and read status/fault feedback.

PLC: S7-1500Language: SCLTest: PLCSIM / Watch table

Topic: SINAMICS G120 PROFINET Hardware and Telegram Setup

1. TIA Portal procedure

  1. Add the SINAMICS G120 device or GSDML device in Network view.
  2. Connect the PLC and drive to the same PROFINET network.
  3. Assign unique device name and IP address to the drive.
  4. Select the required standard telegram; this manual uses a 2-word command and 6-word status concept.
  5. Record the PLC input and output start addresses assigned to the telegram.
  6. Create DB_G120_PN with Control_Word_1, Speed_Setpoint, Status_Word_1, Actual_Speed, Current, Torque, Power and Spare_Status.
  7. Do not run the motor until motor data identification and safety checks are complete.

2. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 16 SCL source
// Example cyclic telegram mapping.
// Replace %QW20/%QW22 and %IW20... with actual assigned addresses.
%QW20 := "DB_G120_PN".Control_Word_1;
%QW22 := "DB_G120_PN".Speed_Setpoint_Word;

"DB_G120_PN".Status_Word_1 := %IW20;
"DB_G120_PN".Actual_Speed_Word := %IW22;
"DB_G120_PN".Current_Word := %IW24;
"DB_G120_PN".Torque_Word := %IW26;
"DB_G120_PN".Power_Word := %IW28;
"DB_G120_PN".Spare_Status_Word := %IW30;

3. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed

Topic: G120 PROFINET Control Word and Speed Setpoint

4. TIA Portal procedure

  1. Create FC_G120_PN_Command.
  2. Confirm the exact bit definition from the selected SINAMICS telegram manual.
  3. Initialize the control word before setting individual bits.
  4. Use DB_Project commands and permissions, not direct HMI-to-drive control.
  5. Limit the speed setpoint to the permitted engineering range.

5. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 16 SCL source
"DB_G120_PN".Control_Word_1 := WORD#16#0000;

IF "DB_Project".Basic_Permission THEN
    "DB_G120_PN".Control_Word_1.%X0 := TRUE;   // ON/OFF1
    "DB_G120_PN".Control_Word_1.%X1 := TRUE;   // OFF2 released
    "DB_G120_PN".Control_Word_1.%X2 := TRUE;   // OFF3 released
    "DB_G120_PN".Control_Word_1.%X3 := TRUE;   // Operation enabled
ELSE
    "DB_G120_PN".Control_Word_1.%X0 := FALSE;
END_IF;

IF "DB_Project".Manual_Forward_Command OR "DB_Project".Auto_Forward_Command THEN
    "DB_G120_PN".Control_Word_1.%X11 := FALSE; // Forward
ELSIF "DB_Project".Manual_Reverse_Command OR "DB_Project".Auto_Reverse_Command THEN
    "DB_G120_PN".Control_Word_1.%X11 := TRUE;  // Reverse
END_IF;

IF "DB_Input_Map".System_Fault_Reset_Push_Button THEN
    "DB_G120_PN".Control_Word_1.%X7 := TRUE;   // Fault acknowledge pulse
ELSE
    "DB_G120_PN".Control_Word_1.%X7 := FALSE;
END_IF;

"DB_G120_PN".Speed_Setpoint_Word :=
    REAL_TO_INT(LIMIT(MN := 0.0,
                      IN := "DB_Project".Speed_Setpoint_Percent,
                      MX := 100.0) * 16384.0 / 100.0);

6. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed

Topic: G120 PROFINET Status, Feedback and Fault Mapping

7. TIA Portal procedure

  1. Create FC_G120_PN_Status.
  2. Use the selected telegram documentation to verify each status bit.
  3. Map ready, operation enabled, fault and warning states.
  4. Convert the actual-speed word into percent or engineering units.
  5. Use the decoded status in DB_Network_Map and DB_Alarm_Map.

8. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 16 SCL source
IF "DB_G120_PN".Status_Word_1.%X0 THEN
    "DB_G120_PN".Ready_To_Switch_On := TRUE;
ELSE
    "DB_G120_PN".Ready_To_Switch_On := FALSE;
END_IF;

IF "DB_G120_PN".Status_Word_1.%X2 THEN
    "DB_G120_PN".Operation_Enabled := TRUE;
ELSE
    "DB_G120_PN".Operation_Enabled := FALSE;
END_IF;

IF "DB_G120_PN".Status_Word_1.%X3 THEN
    "DB_G120_PN".Fault_Active := TRUE;
ELSE
    "DB_G120_PN".Fault_Active := FALSE;
END_IF;

IF "DB_G120_PN".Status_Word_1.%X7 THEN
    "DB_G120_PN".Warning_Active := TRUE;
ELSE
    "DB_G120_PN".Warning_Active := FALSE;
END_IF;

"DB_G120_PN".Actual_Speed_Percent :=
    INT_TO_REAL("DB_G120_PN".Actual_Speed_Word) * 100.0 / 16384.0;

"DB_Network_Map".VFD_Communication_OK :=
    "DB_G120_PN".Ready_To_Switch_On OR
    "DB_G120_PN".Operation_Enabled;

"DB_Input_Map".VFD_Fault := "DB_G120_PN".Fault_Active;

9. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed
17
Day 17 · Advanced Project

Reusable PLC–G120 PROFINET Function Block

Build and call a reusable G120 PROFINET control block for project logic.

PLC: S7-1500Language: SCLTest: PLCSIM / Watch table

1. TIA Portal procedure

  1. Create FB_G120_PROFINET and an instance DB.
  2. Use global DB members shown below for this training version.
  3. Call the FB once per drive from OB1.
  4. Keep all physical telegram addresses in one mapping region.
  5. Commission at zero or low speed with the machine mechanically safe.

2. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 17 SCL source
REGION Telegram_Read
    "DB_G120_PN".Status_Word_1 := %IW20;
    "DB_G120_PN".Actual_Speed_Word := %IW22;
    "DB_G120_PN".Current_Word := %IW24;
END_REGION

REGION Permission_and_Command
    IF "DB_Project".Basic_Permission AND
       NOT "DB_G120_PN".Fault_Active THEN
        "DB_G120_PN".Control_Word_1 := WORD#16#047F;
    ELSE
        "DB_G120_PN".Control_Word_1 := WORD#16#0000;
    END_IF;

    IF "DB_Output_Map".Conveyor_Reverse_Command THEN
        "DB_G120_PN".Control_Word_1.%X11 := TRUE;
    ELSE
        "DB_G120_PN".Control_Word_1.%X11 := FALSE;
    END_IF;
END_REGION

REGION Telegram_Write
    %QW20 := "DB_G120_PN".Control_Word_1;
    %QW22 := "DB_G120_PN".Speed_Setpoint_Word;
END_REGION

3. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed
18
Day 18 · Advanced Project

SINAMICS G120 Modbus RTU Communication

Configure Modbus RTU and develop the cyclic read/write sequence in SCL.

PLC: S7-1500Language: SCLTest: PLCSIM / Watch table

Topic: SINAMICS G120 Modbus RTU Hardware and Parameters

1. TIA Portal procedure

  1. Install and configure the S7-1500 communication module supported by the project.
  2. Use RS-485 wiring with correct polarity, shield and termination.
  3. Configure identical baud rate, parity, stop bits and slave address in PLC and G120.
  4. Set the drive command source and setpoint source to fieldbus/Modbus as required.
  5. Create DB_G120_MB for request, response, control word, status word, speed and diagnostics.
  6. Use Siemens MB_COMM_LOAD and MB_MASTER instructions according to the installed module version.
  7. Perform one request at a time and wait for DONE or ERROR before the next request.

2. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 18 SCL source
// Call once at startup or when communication parameters change
"MB_COMM_LOAD_DB"(
    REQ := "DB_G120_MB".Load_Request,
    PORT := "Local~CM_PtP_1",
    BAUD := 19200,
    PARITY := 2,
    MB_DB := "MB_MASTER_DB",
    DONE => "DB_G120_MB".Load_Done,
    ERROR => "DB_G120_MB".Load_Error,
    STATUS => "DB_G120_MB".Load_Status);

// Replace PORT and parameter values with the actual hardware configuration.

3. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed

Topic: G120 Modbus RTU Read/Write Sequence in SCL

4. TIA Portal procedure

  1. Create FC_G120_Modbus_Sequence.
  2. Use one sequence step for write control word/speed and another for read status/actual speed.
  3. Trigger MB_MASTER only with a one-scan request pulse.
  4. Advance the step only after DONE; record ERROR and STATUS on failure.
  5. Confirm Modbus register numbers and zero/one-based addressing from the G120 manual.

5. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 18 SCL source
CASE "DB_G120_MB".Comm_Step OF
    0:
        "DB_G120_MB".Request := FALSE;
        "DB_G120_MB".Comm_Step := 10;

    10: // Write control word and speed setpoint
        "DB_G120_MB".Mode := 1;
        "DB_G120_MB".Start_Address := 40100; // Example only
        "DB_G120_MB".Data_Length := 2;
        "DB_G120_MB".Request := TRUE;
        "DB_G120_MB".Comm_Step := 11;

    11:
        "DB_G120_MB".Request := FALSE;
        IF "DB_G120_MB".Done THEN
            "DB_G120_MB".Comm_Step := 20;
        ELSIF "DB_G120_MB".Error THEN
            "DB_G120_MB".Comm_Step := 900;
        END_IF;

    20: // Read status word and actual speed
        "DB_G120_MB".Mode := 0;
        "DB_G120_MB".Start_Address := 40110; // Example only
        "DB_G120_MB".Data_Length := 2;
        "DB_G120_MB".Request := TRUE;
        "DB_G120_MB".Comm_Step := 21;

    21:
        "DB_G120_MB".Request := FALSE;
        IF "DB_G120_MB".Done THEN
            "DB_G120_MB".Comm_Step := 10;
        ELSIF "DB_G120_MB".Error THEN
            "DB_G120_MB".Comm_Step := 900;
        END_IF;

    900:
        "DB_G120_MB".Communication_Fault := TRUE;
        IF "DB_Input_Map".System_Fault_Reset_Push_Button THEN
            "DB_G120_MB".Communication_Fault := FALSE;
            "DB_G120_MB".Comm_Step := 0;
        END_IF;
END_CASE;

6. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed
19
Day 19 · Advanced Project

Conveyor Project: Manual and Auto Modes

Develop manual movement, auto sequence, permissions, sensors and step transitions from the tag workbook.

PLC: S7-1500Language: SCLTest: PLCSIM / Watch table

Topic: Conveyor Project Manual Mode from the Tag Workbook

1. TIA Portal procedure

  1. Create FC_Conveyor_Manual_Project.
  2. Use the workbook concepts Manual_Forward_Push_Button, Manual_Reverse_Push_Button, Forward_Position, Reverse_Position and VFD_Healthy.
  3. Generate Brake_Contactor_Command before motor run.
  4. Prevent a direction change until both drive commands are off.
  5. Create feedback timeout alarms as the next extension.

2. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 19 SCL source
IF "DB_Project".Manual_Mode_Selected AND
   "DB_Project".Basic_Permission THEN
    "DB_Project".Manual_Mode_Healthy := TRUE;
ELSE
    "DB_Project".Manual_Mode_Healthy := FALSE;
END_IF;

IF "DB_Project".Manual_Mode_Healthy AND
   ("DB_Input_Map".Conveyor_Forward_Push_Button OR
    "DB_Project".HMI_Manual_Forward_Push_Button) AND
   NOT "DB_Input_Map".Forward_Position_Sensor AND
   NOT "DB_Output_Map".Conveyor_Reverse_Command THEN
    "DB_Output_Map".Brake_Contactor_Command := TRUE;
    "DB_Output_Map".Conveyor_Forward_Command := TRUE;
ELSE
    "DB_Output_Map".Conveyor_Forward_Command := FALSE;
END_IF;

IF "DB_Project".Manual_Mode_Healthy AND
   ("DB_Input_Map".Conveyor_Reverse_Push_Button OR
    "DB_Project".HMI_Manual_Reverse_Push_Button) AND
   NOT "DB_Input_Map".Reverse_Position_Sensor AND
   NOT "DB_Output_Map".Conveyor_Forward_Command THEN
    "DB_Output_Map".Brake_Contactor_Command := TRUE;
    "DB_Output_Map".Conveyor_Reverse_Command := TRUE;
ELSE
    "DB_Output_Map".Conveyor_Reverse_Command := FALSE;
END_IF;

IF NOT "DB_Output_Map".Conveyor_Forward_Command AND
   NOT "DB_Output_Map".Conveyor_Reverse_Command THEN
    "DB_Output_Map".Brake_Contactor_Command := FALSE;
END_IF;

3. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed

Topic: Conveyor Project Auto Mode and Step Sequence

4. TIA Portal procedure

  1. Create FC_Conveyor_Auto_Project.
  2. Latch Auto_Cycle_On from Start and Stop commands.
  3. Use an integer Auto_Step in DB_Project.
  4. Keep command outputs assigned in one CASE statement.
  5. Reset the sequence immediately on loss of permission, stop command or alarm.
  6. Adapt the sensor order to the actual conveyor sequence in the attached workbook and machine drawings.

5. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 19 SCL source
IF "DB_Input_Map".System_Auto_Start_Push_Button AND
   "DB_Project".Auto_Mode_Selected AND
   "DB_Project".Basic_Permission AND
   NOT "DB_Alarm_Map".Alarm_Present THEN
    "DB_Project".Auto_Cycle_On := TRUE;
END_IF;

IF "DB_Input_Map".System_Auto_Stop_Push_Button OR
   NOT "DB_Project".Basic_Permission OR
   "DB_Alarm_Map".Alarm_Present THEN
    "DB_Project".Auto_Cycle_On := FALSE;
    "DB_Project".Auto_Step := 0;
END_IF;

"DB_Project".Auto_Forward_Command := FALSE;
"DB_Project".Auto_Reverse_Command := FALSE;

CASE "DB_Project".Auto_Step OF
    0:
        IF "DB_Project".Auto_Cycle_On AND
           "DB_Input_Map".Entry_Sensor THEN
            "DB_Project".Auto_Step := 10;
        END_IF;

    10: // Move conveyor forward
        "DB_Project".Auto_Forward_Command := TRUE;
        IF "DB_Input_Map".Forward_Position_Sensor OR
           "DB_Input_Map".Exit_Sensor THEN
            "DB_Project".Auto_Step := 20;
        END_IF;

    20: // Wait for delivery permission
        IF "DB_Project".Delivery_Permission THEN
            "DB_Project".Auto_Step := 30;
        END_IF;

    30: // Return conveyor
        "DB_Project".Auto_Reverse_Command := TRUE;
        IF "DB_Input_Map".Reverse_Position_Sensor THEN
            "DB_Project".Auto_Step := 0;
        END_IF;

    ELSE
        "DB_Project".Auto_Step := 0;
END_CASE;

IF "DB_Project".Auto_Cycle_On THEN
    "DB_Output_Map".Conveyor_Forward_Command := "DB_Project".Auto_Forward_Command;
    "DB_Output_Map".Conveyor_Reverse_Command := "DB_Project".Auto_Reverse_Command;
END_IF;

6. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed
20
Day 20 · Advanced Project

Final Integration, Faults and Commissioning

Integrate mapping, alarms, network, tower, VFD and conveyor logic; test with PLCSIM and commission safely.

PLC: S7-1500Language: SCLTest: PLCSIM / Watch table

Topic: Integrated Faults, Timeouts, Network and Tower Logic

1. TIA Portal procedure

  1. Create FB_Project_Diagnostics with an instance DB for timers.
  2. Use TON timers for forward and reverse travel timeout.
  3. Generate first-out fault codes and common alarm.
  4. Stop all motion on any active critical fault.
  5. Use the tower and hooter mapping from Day 20.
  6. Display fault code, fault text, network states and current sequence step on the HMI.

2. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 20 SCL source
"DB_Diagnostics".Forward_Timeout_Timer(
    IN := "DB_Output_Map".Conveyor_Forward_Command AND
          NOT "DB_Input_Map".Forward_Position_Sensor,
    PT := T#10s);

"DB_Diagnostics".Reverse_Timeout_Timer(
    IN := "DB_Output_Map".Conveyor_Reverse_Command AND
          NOT "DB_Input_Map".Reverse_Position_Sensor,
    PT := T#10s);

IF "DB_Diagnostics".Forward_Timeout_Timer.Q THEN
    "DB_Alarm_Map".Forward_Travel_Timeout_Alarm := TRUE;
END_IF;

IF "DB_Diagnostics".Reverse_Timeout_Timer.Q THEN
    "DB_Alarm_Map".Reverse_Travel_Timeout_Alarm := TRUE;
END_IF;

IF "DB_Input_Map".System_Fault_Reset_Push_Button AND
   NOT "DB_Output_Map".Conveyor_Forward_Command AND
   NOT "DB_Output_Map".Conveyor_Reverse_Command THEN
    "DB_Alarm_Map".Forward_Travel_Timeout_Alarm := FALSE;
    "DB_Alarm_Map".Reverse_Travel_Timeout_Alarm := FALSE;
END_IF;

IF "DB_Alarm_Map".Alarm_Present OR
   "DB_Alarm_Map".Forward_Travel_Timeout_Alarm OR
   "DB_Alarm_Map".Reverse_Travel_Timeout_Alarm THEN
    "DB_Output_Map".Conveyor_Forward_Command := FALSE;
    "DB_Output_Map".Conveyor_Reverse_Command := FALSE;
END_IF;

3. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed

Topic: Complete Project Integration, PLCSIM and Commissioning

4. TIA Portal procedure

  1. Use the exact OB1 execution order shown below.
  2. Compile software and hardware completely.
  3. Run PLCSIM tests for every physical input, output command, alarm and sequence transition.
  4. Test manual forward and reverse at a low speed.
  5. Test Auto mode one transition at a time using a watch table.
  6. Confirm loss of emergency, safety, VFD health and communication stops the conveyor.
  7. Confirm fault reset works only after the fault cause is removed.
  8. Back up the commissioned project and export PLC tag tables and block sources.

5. Copy-paste SCL code

Important: This manual intentionally avoids local # tags. Create the quoted global DB members exactly as shown, then paste the code into the SCL implementation area. Addresses shown for drive telegrams and Modbus registers are examples and must be replaced by the actual configured values.
Day 20 SCL source
// Recommended OB1 call order
"FC_Input_Mapping"();
"FC_Analog_Mapping"();
"FC_Network_Mapping"();
"FC_Mode_and_Permission"();

// Choose one drive communication method for the machine
"FB_G120_PROFINET_DB"();
// OR call Modbus communication blocks and FC_G120_Modbus_Sequence

"FC_Conveyor_Manual_Project"();
"FC_Conveyor_Auto_Project"();
"FB_Project_Diagnostics_DB"();
"FC_Alarm_Mapping"();
"FC_Tower_Mapping"();
"FC_Output_Mapping"();

// Final safety rule:
// No physical output is written anywhere except FC_Output_Mapping.

6. Verification checklist

□ Block created and compiled
□ Required DB members created
□ OB1 call added
□ PLCSIM/watch-table test completed
20-Day CourseSelect a day