How to Troubleshoot Obscure Errors in Custom PLC Code
Introduction
Programmable logic controllers (PLCs) are digital computers used for automation of industrial processes. They run custom code to control machines and processes. As with any complex software system, obscure errors can occur that are difficult to troubleshoot. This article provides an in-depth guide on techniques and strategies to diagnose and fix obscure errors in custom PLC code.
Understanding the PLC System
To effectively troubleshoot PLC code errors, you need to understand how the PLC system is designed and operates.
PLC Hardware Components
The main hardware components of a PLC include:
- CPU - This is the brain of the PLC. It executes the ladder logic program and processes I/O.
- Power supply - Provides power to the CPU, I/O modules, and field devices.
- I/O modules - Interface between field devices and the CPU. Analog I/O modules handle continuous signals while discrete I/O modules handle on/off signals.
- Communication modules - Allow the PLC to communicate with HMIs, SCADA systems, and other PLCs. Common protocols are Ethernet, Serial, and Fieldbus.
PLC Operating System
The operating system manages tasks like:
- Program scan - Cyclically executes the ladder logic program from start to finish.
- I/O scan - Updates inputs and outputs.
- Communication - Handles network communication protocols.
- Program execution - Executes logic, sequencing, math, and other instructions.
Ladder Logic Programming
Ladder logic is the main programming language used with PLCs. It uses graphic symbols to emulate electromechanical control circuits. The main elements are:
- Contacts - Represent input conditions
- Coils - Represent outputs
- Instructions - Logic, math, data handling, communications, etc.
Understanding general ladder logic programming techniques is key for troubleshooting errors.
Check PLC System Health
Before diving into application code, check the overall health of the PLC system.
- Scan network communications - Use network analysis tools to check for errors. Make sure PLC is communicating properly with HMIs, drives, and I/O.
- Check power supplies - Verify voltages. Power fluctuations can cause issues.
- Confirm I/O wiring - Make sure inputs and outputs are wired to correct terminals and functioning.
- Scan system logs - PLC logs events like faults, warnings, and exceptions. Review for clues.
- Monitor CPU resources - High memory and CPU usage can indicate problems.
Fix any underlying system issues before troubleshooting application code.
Understand Ladder Logic Execution
It's critical to understand how ladder logic executes to effectively troubleshoot errors.
- Scan cycle - The PLC executes the ladder diagram from left to right and top to bottom, over and over.
- Parallel branches - Parallel contacts are logical ANDs. All must be true to energize output.
- Series branches - Series contacts are logical ORs. One true energizes output.
- Function blocks - Encapsulate complex code into reusable modules.
Know how code executes across branches and scan cycles. Visualize program flow.
Check Ladder Logic Structure
Look for structural issues in the ladder logic that could cause obscure problems:
- Unintentional infinite loops - This can lock up the PLC. Make sure loop counters increment properly.
- Race conditions - Outputs toggling when not intended due to poor code structure.
- Unused code - Old code that was never removed can cause conflicts.
- Poor sequence - Code executing in the wrong order. Use step sequences.
- Too complex - Overly complex code sections make troubleshooting difficult. Simplify.
Cleaner and simplified code logic will reduce obscure bugs.
Verify I/O Addresses
One of the most common sources of issues is incorrect I/O addressing in code.
- Check I/O modules - Confirm that I/O modules match the code configuration.
- Cross-reference tags - Line-by-line, verify every tag address matches documentation.
- Watch live data - Observe if input data matches real-time signals during operation.
- Force outputs - Force ON or OFF in software to test wiring.
Meticulously confirming I/O addresses will reveal many obscure errors.
Review Data Storage Areas
Data storage areas like registers, counters, and timers are used across code sections and can be sources of problems.
- Undefined registers - Make sure all registers are defined before use to avoid random values.
- Counter/timer values - Verify timer and counter preset and accumulated values are as expected.
- Retentive registers - Registers retaining values across power cycles can cause issues. Confirm status.
- Database corruption - Various code activities can corrupt PLC database. Scan integrity.
Data storage is complex so carefully inspect these areas of code.
Check Error Logs
The PLC logs various errors and warnings that can provide clues on obscure bugs.
- I/O faults - Inputs or outputs reporting faults indicate wiring issues.
- Scan overruns - The scan time exceeded the allotted window, indicating performance problems.
- Network errors - Communications issues with external devices.
- Program faults - Specific faults with logic, I/O addressing, or configuration.
Detailed error logs often point directly to root causes.
Use Debug Tools
Debug software tools are invaluable for solving obscure errors through visibility.
- Force values - Force I/O or internal registers to test logic.
- Real-time monitoring - Watch program scan and I/O update in real-time.
- Breakpoints - Halt program scan at specific rungs to inspect.
- Step ladder - Step through program rung-by-rung to diagnose issues.
- Trending - Graph data over time to visualize erratic behavior.
Use all available debug features to gain visibility.
Leverage Ladder Logic Best Practices
Many obscure bugs can be avoided by using ladder logic best practices:
- Add comments - Provide context for program sections and explain key rungs.
- Standardize structure - Develop reusable templates for commonly used code.
- Segregate code - Separate sections into functional blocks.
- Reduce complexity - Break code into simpler logical chunks.
- Validate data - Check data ranges and validity before use.
- Track versions - Use version control for code changes.
Clean and well-structured ladder logic avoids obscure logic issues.
Seek Additional Expertise
For extremely obscure errors, leverage additional expertise:
- PLCs vendor support - Many vendors provide tech support contracts for troubleshooting.
- Automation consultants - Independent experts with deep knowledge across PLC platforms.
- Integrators - Many have staff with specialized skills at debugging code.
- Online forums - Fellow programmers discussing similar exotic errors.
Obscure bugs often require tapping specialized knowledge.
Conclusion
Troubleshooting obscure PLC errors requires methodically checking system health, understanding program execution, verifying logic structure and I/O addressing, inspecting data areas, checking logs, utilizing debug tools, following best practices, and seeking help from experts. Meticulously following these troubleshooting techniques will systematically isolate and correct even the most obscure PLC errors.