- Reorganized project: codesys/, docs/codesys|redesign|integration|reference/, scripts/ - CODESYS project and exports in codesys/ - Documentation index in docs/README.md - Redesign and light naming configuration - Water boiler control and safety design Co-authored-by: Cursor <cursoragent@cursor.com>
7.2 KiB
CODESYS PLCopen XML Analysis
Overview
This document contains detailed information extracted from the PLCopen XML export (Home_Automation.xml), which provides a more structured view of the project compared to the CODESYS export format.
Project Information
- Format: PLCopen XML (TC6 0200)
- CODESYS Version: V3.5 SP21
- Export Date: 2026-01-27T14:48:52
- Project Name: Home_Automation.project
Task Configuration
MainTask
- Type: Cyclic
- Interval: t#4ms (4 milliseconds)
- Priority: 1
- Watchdog: Disabled
- Program: PLC_PRG
EtherCAT_Task
- Type: Cyclic
- Interval: t#4ms (4 milliseconds)
- Priority: 1
- Watchdog: Disabled
- Purpose: EtherCAT communication and network variable updates
Data Structures
struct_switches
TYPE struct_switches :
STRUCT
all_off: BOOL; // Command to turn all lights off
all_on: BOOL; // Command to turn all lights on
sw_1: BOOL; // Switch 1 state
sw_2: BOOL; // Switch 2 state
sw_3: BOOL; // Switch 3 state
sw_4: BOOL; // Switch 4 state
sw_5: BOOL; // Switch 5 state
sw_6: BOOL; // Switch 6 state
END_STRUCT
END_TYPE
struct_lights
TYPE struct_lights:
STRUCT
l_1: BOOL; // Light 1 control output
l_2: BOOL; // Light 2 control output
l_3: BOOL; // Light 3 control output
l_4: BOOL; // Light 4 control output
l_5: BOOL; // Light 5 control output
l_6: BOOL; // Light 6 control output
END_STRUCT
END_TYPE
Function Block: fb_toogleButton
Interface
Inputs:
Input: BOOL- Input signal (switch state from network)
Outputs:
Output: BOOL- Output signal (light control)
Internal Variables:
Switch: BOOL- Internal switch stateLight: BOOL- Internal light stateFlag1: BOOL- Internal flag 1Flag2: BOOL- Internal flag 2RT: R_TRIG- Rising edge triggerPulse: TP- Pulse timerCTU_0: CTU- Counter up 0CTD_0: CTD- Counter down 0CTU_1: CTU- Counter up 1CTU_2: CTU- Counter up 2TOF_0: TOF- Timer off delay 0
Implementation (Ladder Diagram)
Network 1: Input Debouncing
- Input signal → TP (Pulse Timer) with PT = t#100ms
- TP output → TOF (Timer Off Delay) with PT = t#100ms
- TOF output → Switch (internal state)
- Purpose: Debounces input signal with 100ms pulse and 100ms off delay
Network 2: Flag1 Logic
- Switch AND (NOT Light) AND (NOT Flag2) → Flag1
- Purpose: Sets Flag1 when switch is on, light is off, and Flag2 is off
Network 3: Flag2 Logic
- Switch AND Light AND (NOT Flag1) → Flag2
- Purpose: Sets Flag2 when switch is on, light is on, and Flag1 is off
Network 4: Light Toggle Logic
- Flag1 AND (NOT Flag2) → Light (toggle)
- Purpose: Toggles light state based on flag conditions
Network 5: Output Assignment
- Light → Output
- Purpose: Direct output assignment
Timing Characteristics
- Input Debounce: 100ms pulse timer (TP)
- Output Delay: 100ms off delay (TOF)
- Total Response Time: ~200ms (debounce + delay)
Function Block: fb_switch
Interface
Inputs:
switches: struct_switches- Switch states from Node-RED
Outputs:
lights: struct_lights- Light control outputs to Node-RED
Internal Variables:
all_off: fb_toogleButton- Toggle button for "all off"all_on: fb_toogleButton- Toggle button for "all on"sw_1: fb_toogleButton- Toggle button for switch 1sw_2: fb_toogleButton- Toggle button for switch 2sw_3: fb_toogleButton- Toggle button for switch 3sw_4: fb_toogleButton- Toggle button for switch 4sw_5: fb_toogleButton- Toggle button for switch 5sw_6: fb_toogleButton- Toggle button for switch 6
Implementation (Continuous Function Chart - CFC)
Logic Flow for Each Light (l_1 through l_6):
-
All Off Logic:
all_off.Output AND lights.l_X → AND gate → (forces light off) -
All On Logic:
all_on.Output AND (NOT lights.l_X) → AND gate → (forces light on) -
Individual Switch Logic:
switches.sw_X → sw_X.Input → sw_X.Output → lights.l_X -
Combined Logic (OR):
(all_on logic) OR (sw_X.Output) OR (other sources) → lights.l_X
Execution Order (example for l_1):
- Execution Order 1: AND gate for all_on logic
- Execution Order 2: sw_2 toggle button
- Execution Order 3: OR gate combining sources
- Execution Order 4: AND gate for all_off logic
- Execution Order 5: Output assignment to lights.l_1
- Execution Order 30: sw_1 toggle button (individual control)
Key Logic Patterns:
- All Off: Uses AND gate with
all_off.Outputand current light state - All On: Uses AND gate with
all_on.Outputand inverted light state - Individual Control: Each switch has its own toggle button instance
- Priority: All_off can override individual controls, all_on combines with individual
Program: Lights
The "Lights" program contains instances of fb_switch for all 15 rooms:
masterBedroom: fb_switchmasterBathroom: fb_switchbedroom_1: fb_switchbedroom_2: fb_switchbathroom: fb_switchguest_wc: fb_switchkitchen: fb_switchpantry: fb_switchlivingRoom: fb_switchdiningRoom: fb_switchveranda: fb_switchentrance: fb_switchfront: fb_switchback: fb_switchside: fb_switchhallway: fb_switch
Network Variables
NVL_Sender (Sent to Node-RED)
All 15 room light structures:
l_masterBedroomthroughl_outBack(struct_lights)
NVL_Receiver (Received from Node-RED)
All 15 room switch structures:
masterBedroomthroughoutBack(struct_switches)
Control Logic Summary
Individual Light Control
- Switch Input →
switches.sw_X(from Node-RED) - Toggle Processing →
fb_toogleButtoninstance- 100ms debounce (TP)
- 100ms delay (TOF)
- Toggle logic with flags
- Output →
lights.l_X(to Node-RED)
Global Commands
All Off:
switches.all_off→all_offtoggle button- Output ANDed with current light state
- Forces all lights off
All On:
switches.all_on→all_ontoggle button- Output ANDed with inverted light state
- Forces all lights on
- Combined with individual switches via OR logic
Timing Characteristics
- Task Cycle: 4ms (MainTask and EtherCAT_Task)
- Input Debounce: 100ms
- Output Delay: 100ms
- Network Variable Update: 50ms (from .export analysis)
- Total Response: ~200ms (debounce + delay)
Implementation Language
- fb_toogleButton: Ladder Diagram (LD)
- fb_switch: Continuous Function Chart (CFC)
- Lights Program: Continuous Function Chart (CFC)
Key Insights
- Debouncing: All switch inputs are debounced with 100ms pulse timer
- Toggle Logic: Uses flag-based state machine for reliable toggling
- Priority System: All_off has priority over individual controls
- Combined Control: All_on works in conjunction with individual switches
- Fast Response: 4ms task cycle ensures responsive control
- Structured Design: Each room is independent with its own fb_switch instance
Analysis Date: January 27, 2026
Source File: Home_Automation.xml
Format: PLCopen XML (TC6 0200)