Comprehensive Guide to PLC Function Blocks: Master in One Week

As a veteran in industrial control with over ten years of experience, I often see many beginners struggling to understand function blocks in PLC programming. Today, I will systematically walk you through the most commonly used function blocks in PLCs. Mastering these basic function blocks will enable you to handle about 80% of industrial control scenarios.

Timer Function Blocks TON/TOF/TP

The timer can be considered the “big brother” among PLC function blocks. Simply put, a timer is like an alarm clock in our lives; you can set a time, and it will trigger or turn off an action when the time is up.

Basic Concepts

  • TON: On-Delay Timer (most commonly used)

  • TOF: Off-Delay Timer

  • TP: Pulse Timer

Key Parameter Descriptions:

  • IN: Timer Enable Input

  • PT: Preset Time

  • Q: Timer Output

  • ET: Elapsed Time

Practical Application Cases

For example, in a factory conveyor belt:

  1. TON Application: The conveyor belt can only be loaded 3 seconds after starting

  2. TOF Application: After pressing the stop button, the conveyor belt continues to run for 5 seconds before stopping

  3. TP Application: Spray cleaner every 10 seconds

//TON Timer Example - Delay Start Conveyor Belt

TON_0.IN := Start_Button;  // Start button input

TON_0.PT := T#3S;         // Set delay to 3 seconds

TON_0(IN := TON_0.IN, PT := TON_0.PT); // Timer execution


Belt_Start := TON_0.Q;    // Start conveyor belt after timer expires

Counter Function Blocks CTU/CTD/CTUD

The counter is like the counter in a supermarket cashier’s hand, used to record the number of times an action occurs.

Basic Concepts

  • CTU: Up Counter

  • CTD: Down Counter

  • CTUD: Up/Down Counter

Important Parameters:

  • CU: Up Count Input

  • CD: Down Count Input

  • R: Reset Input

  • PV: Preset Value

  • CV: Current Value

  • Q: Count Completed Output

Practical Application

For example, in a packaging line:

// Packing Counting Program

CTU_0.CU := Product_Sensor; // Product sensor

CTU_0.R := Box_Full;        // Box full signal

CTU_0.PV := 12;             // 12 products per box

CTU_0(CU := CTU_0.CU, R := CTU_0.R, PV := CTU_0.PV);


Box_Change := CTU_0.Q;      // Change box when quantity is reached

SR Latch Function Block

This function block is like a dual-control switch for a light; one sets it, and the other resets it.

Key Features

  • Set (S) has a higher priority than Reset (R)

  • The output state remains until a new input changes it

Application Scenarios

Commonly used for:

  1. Motor Start/Stop Control

  2. Fault Alarm Memory

  3. Working Mode Switching

Common Problems and Solutions

  1. Timer Jitter Issue

Solution: Increase debounce delay, generally 5-10ms will suffice

  1. Counter Miscounting

Solution:

  • Check the sensor installation position

  • Increase filtering time

  • Use rising edge triggering

  1. Function Block Output Instability

Solution: Check the scan cycle settings to ensure the signal duration is greater than the scan cycle

Debugging Tips

  1. Use Online Monitoring Function
  • Observe changes in internal variables of function blocks

  • Modify parameters in real-time for testing

  1. Create Standard Program Templates

Package commonly used function blocks into subprograms to improve development efficiency

  1. Software Simulation Verification

Test program logic using simulation software before implementation

Safety Precautions

  1. Never debug function block parameters with power on

  2. Key devices must have hardware limit protection

  3. It is recommended to use fail-safe function blocks

  4. Important parameters should be maintained without power

Practical Suggestions

  1. Start with simple timers to grasp the basic principles

  2. Make a small test board for function block combination experiments

  3. Collect typical application cases to build a personal code library

  4. Record problems and solutions encountered during debugging

To improve your programming skills, it is not enough to just read; practical experience is essential. Here are some devices you should prepare for hands-on practice:

  • A small PLC (recommended Siemens S7-200SMART)

  • Several push buttons

  • Indicator lights

  • Simple loads (such as small motors)

Advanced Suggestions:

  • Become proficient in online debugging tools

  • Learn modular programming concepts

  • Accumulate industry application experience

  • Study the differences in function blocks among brands

Through systematic learning and practice, I believe you will quickly master the use of these function blocks and lay a solid foundation for future automation projects.

Leave a Comment