



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Purpose. These notes explain how a PLC uses subroutines to divide control logic into smaller functional blocks. The examples are generic and focus on program organization rather than a specific assignment, trainer, or manufacturer-provided worksheet. Topics covered
1. Why PLC Programs Use Subroutines
1.1 Benefits of a modular program
1.2 Main routine versus subroutine Program section Primary responsibility Good design practice Main routine Controls overall program flow and decides which functions are allowed to run. Keep it concise enough that the operating sequence can be understood quickly. Subroutine Handles one machine function, output group, mode, or sequence step. Use one clear purpose and avoid hidden dependencies on unrelated routines. Fault or alarm routine Checks abnormal conditions and records or responds to faults. Prioritize safe states and make reset conditions explicit. 1.3 Typical execution pattern
Rung 0 [System_Enable] -------------------- (Call STARTUP routine) Rung 1 [Auto_Mode] [No_Fault] ------------ (Call AUTO routine) Rung 2 [Manual_Mode] ---------------------- (Call MANUAL routine) Rung 3 [Fault_Present] -------------------- (Call ALARM routine) Rung 4 ------------------------------------ (End main routine)
2.4 Example routine logic MAIN Rung 0 [System_Enable] -------------------- (Call INDICATION routine) INDICATION SUBROUTINE Rung 0 [Green_Command] [/Red_Command] ------ (Green_Light) Rung 1 [Red_Command] [/Green_Command] ------ (Red_Light) Rung 2 ------------------------------------ (Return)
2.5 Output ownership rules
2.6 Quick scan-order check
3. Planning a Subroutine-Based Program 3.1 Define functions before addresses
3.2 Suggested planning worksheet Function Routine Inputs needed Outputs affected Safe-state rule System permission MAIN Enable, stop, fault status Routine calls Disable calls when permission is false Status indication STATUS Mode and command bits Pilot lights Clear non-latched outputs when disabled Automatic sequence AUTO Start, sensors, timers Motors and valves Stop motion on fault or mode change Alarm handling ALARM Fault bits and acknowledgments Alarm lamp or message Keep active until the reset rule is satisfied 3.3 Naming and documentation
3.4 Common design mistakes Mistake Why it causes trouble Writing to the same output from several routines The final state may depend on scan order, making the behavior difficult to predict and troubleshoot. Calling a routine in several unrelated places The program flow becomes hard to follow and the routine may execute more often than intended. Skipping reset logic Latched states or retained values may remain active after a mode change. Using unclear addresses without tags Wiring mistakes and wrong-terminal troubleshooting become more likely. Testing every function at once A failure becomes harder to isolate because several conditions change together.
5. Review Questions
Answer key
6. Summary