PLC Programming Best Practices for Maintenance-Friendly Code
The worst programs I've troubleshot were written by people who never had to maintain them. Here's how to write code that your future self (or the night shift tech) won't curse at 2 AM.
Naming Conventions
- Use descriptive tag names:
Conveyor_1_Motor_RunnotM001 - Include location:
Line3_Packer_Jam_Sensor - Consistent format: Pick a style and stick to it
Documentation
- Rung comments: Explain WHY, not just what
- Routine descriptions: What does this routine do?
- Version history: Who changed what, when, and why
Structure
- Modular routines: One function per routine
- Consistent order: Inputs → Logic → Outputs
- Error handling: Add fault routines (OB121 in Siemens, fault routine in A-B)
Maintenance Features
- Diagnostic messages: Push meaningful alarms to HMI
- Mode indicators: Show Auto/Manual/Fault status clearly
- Override capabilities: Allow safe manual control for testing