MOULDLKnowledge BaseElectrical Knowledge Base3D Model DownloadsMembership
中文版Model Store »
Knowledge Base › Electrical Knowledge Base › How do you separate manual and automatic modes using subroutines?
HomeModels
Table of contents

On this page

PLC & Programming (100 articles)

Quick Reference

  • PLC & Programming
  • Electrical & Electronic Basics (monthly)(每月更新中)
  • Electrical Control & Drawings (monthly)(每月更新中)
  • Drives & Actuators (monthly)(每月更新中)
  • Sensors & Detection (monthly)(每月更新中)
  • Industrial Communication & Networks (monthly)(每月更新中)
  • HMI & Host Systems (monthly)(每月更新中)
  • Industrial Robots & Motion Control (monthly)(每月更新中)
  • Mechatronic System Integration (monthly)(每月更新中)
  • Fault Diagnosis & Standards (monthly)(每月更新中)

How do you separate manual and automatic modes using subroutines?

Mixing manual and automatic logic in one flow is the first step toward an unmaintainable program. The right structure: the main program only decides the mode and handles common concerns, while manual and automatic logics live in their own subroutines, selected by the mode bits. The two never cross, never share output drives — and mode switching becomes predictable. The sections below cover the architecture, interfaces, switching and pitfalls.

1. The recommended architecture: a four-stage main program

StageContentKey point
Common processingInput debounce, E-stop/safety collection, alarm handlingMode-independent, runs always
Mode decisionRead the mode switch, derive the active modeThe only place the mode state is written
Call branchManual → CALL manual subroutine; Auto → CALL auto subroutineExactly one call per scan
Output summarySubroutine intermediates + interlocks → final outputsOne shared exit for both modes

Two core rules: ① exactly one mode's subroutine executes per scan (CALL one of two); ② both subroutines drive only their own intermediates — the outputs Y are driven once, in the summary stage. That is the root of "mode switching never fights".

2. The manual subroutine: jog thinking

Manual logic = button-driven + simple interlocks, no self-holding sequences: hold to move, release to stop (jog), or SET with basic conditions RST. Points: ① every action carries "manual mode AND its button", broken when either fails; ② mechanism interlocks still apply (two cylinders that would collide never extend together); ③ home/position conditions join the permissions (no fast motion before homing). The manual program should answer every press with exactly one predictable response.

3. The automatic subroutine: step thinking

Automatic logic = a stepping flow: step flags + transition conditions, or SFC. Points: ① the auto subroutine's entrance checks "auto allowed" (E-stop clear, no alarms, home conditions); if not allowed, clear the step number and hold at step 0; ② each step's outputs write to auto-specific intermediates; ③ the flow ends back at step 0. The auto subroutine never reads manual buttons — mode isolation means the two sides do not look at each other's signals.

4. Three tasks at mode switching

ActionWhy
Clear the auto flow (step number to 0, auto intermediates cleared)Residual steps would fire the mechanism mid-way at the next auto start
Manual outputs to safe positions, or wait for the operatorNothing may move by itself at the switch instant
Trigger on the mode switch's edge, not the levelA level trigger re-clears every scan; an edge clears once, cleanly

Put the switching logic in its own small "mode-switch handling" stage, triggered by the mode switch's rising/falling edge, performing "clear auto + confirm manual initial state". The first response after any mode change must be stillness — never spontaneous motion.

5. Rules for shared data

The two subroutines share only three classes: safety state (E-stop, alarms), mechanism feedback (in position, home), and output intermediates (each writes its own, merged in the summary). Rules: ① dedicated intermediate zones per mode (a manual M block / an auto M block), never reused; ② shared read-only data lives in a common area neither writes; ③ the output summary states every Y's source: manual intermediate OR auto intermediate, ANDed with the global interlocks.

6. Common errors

SymptomCauseFix
Auto flow keeps running after switching to manualAuto subroutine lacks the mode gateAND the auto mode bit at the auto entrance
Mechanism lurches when switching back to autoStep number not cleared, resumes mid-flowClear the step number to 0 on the switch edge
Manual-held motion persists after switchingManual intermediates not clearedClear the manual zone at the switch
Two mode switches fightBoth switches write the mode bit directlyThe mode bit follows one combining logic, commented
Double coilsManual/auto each drive Y directlyAll outputs unified in the summary

7. Notes

Mode separation means "one will commands the mechanism at a time". Subroutines give it a physical boundary (CALL one of two), intermediate zones give it a data boundary (each writes its own), and the output summary is the last line of defence (unified interlocks). With the three boundaries up, switching is always clean.

8. References

Operating modes (manual/automatic), stop and reset design follow GB 5226.1 / IEC 60204-1 (control functions and operating modes); subroutine organisation follows IEC 61131-3 convention; CALL instruction details follow the PLC's programming manual.

9. Cautions

⚠️ Three traps to avoid:
① Jog logic secretly self-holding — the action sticks across a mode switch;
② Level-triggered mode switching clearing zones every scan — buttons "go deaf" for a scan at the switch;
③ One or two Ys still driven inside the subroutines — double-coil landmines left behind.

Delivery check: search the program for every Y coil — all of them live in the output summary; and run the "zero motion at switch instant" test with the mode selector.

Related reading

Related 3D models: Ready to build it? Download free 3D models & CAD drawings at MOULDL »
MOULDL · Electrical Knowledge Base · free self-study reference for electrical & automation engineers, 3D CAD models at MOULDL