Many PLC programmers can make a machine work, but far fewer can write code that is easy to understand, maintain, and modify. Professional PLC programme structure is what separates a competent engineer from an excellent one. Well-structured code reduces commissioning time, simplifies troubleshooting, and makes future modifications safer.
The Modular Approach
Modern PLC programming follows a modular design philosophy where the programme is divided into self-contained functional blocks:
Organisation Blocks (OBs):
- OB1 (Main cycle): Calls function blocks and functions in a logical sequence
- OB100 (Startup): Initialises variables and performs startup checks
- OB35 (Cyclic interrupt): Time-critical tasks such as PID control at fixed intervals
- OB82 (Diagnostic interrupt): Handles hardware diagnostic events
Function Blocks (FBs): Reusable programme modules with their own instance data. Each FB encapsulates the logic for a specific piece of equipment (motor, valve, conveyor section).
Functions (FCs): Stateless programme modules for calculations, data conversion, and utility operations.
Data Blocks (DBs): Structured data storage for equipment parameters, recipe data, and process variables.
Naming Conventions
Consistent naming conventions are essential for team collaboration:
- Use descriptive names that clearly identify the purpose (e.g., FB_MotorControl, FC_CalculateFlowRate)
- Prefix tags with their area or equipment identifier (e.g., Area1_Conveyor1_Speed)
- Follow a company standard that all team members understand
- Avoid abbreviations that may be ambiguous to other engineers
Programme Structure Example
A typical machine control programme might be structured as:
- Mode management: Manual, automatic, step, and maintenance modes
- Sequence control: Step sequencer using GRAPH or structured text state machines
- Equipment control: Individual FBs for each motor, valve, and cylinder
- Alarm management: Centralised alarm generation and logging
- Communication: HMI data exchange, recipe management, and MES integration
- Diagnostics: System health monitoring and performance data collection
Reusable Function Blocks
Creating reusable FBs for common equipment types saves development time and improves consistency:
A motor control FB should include:
- Start/stop commands with interlock inputs
- Running feedback monitoring with timeout detection
- Overload and fault handling
- Operating hours counter
- HMI faceplate interface data
A valve control FB should include:
- Open/close commands with position feedback
- Travel time monitoring for stuck valve detection
- Manual override capability
- Maintenance mode for testing
Documentation Within the Programme
Good PLC code is self-documenting:
- Comment every network explaining its purpose, not just what it does
- Use structured comments at the top of each FB describing inputs, outputs, and behaviour
- Maintain a revision log within the programme header
- Include references to the relevant P&ID, electrical schematic, and functional design specification
Version Control
Professional automation projects require version control:
- Use TIA Portal's built-in project versioning
- Create project archives at key milestones (FAT, SAT, handover)
- Document all changes in a change log with dates and reasons
At EDWartens UK, our advanced PLC programming courses emphasise programme structure, modular design, and professional coding practices that meet industry expectations.