PLC and motion control with CODESYS: EtherCAT, SoftMotion and tasks
CODESYS is a PLC programming environment for the IEC 61131-3 languages, and it brings the EtherCAT master, SoftMotion axes and visualisation together in one project. The MAT-LC CPU family and the HMI-R9 panels are CODESYS-based.
6 questions answered
Basics
Commissioning
Troubleshooting
Basics
01
Which SMB products are programmed with CODESYS?
The MAT-LC CPU family consists of CODESYS-based PLC controllers, ranging from single-axis motion to multi-axis robotics and CNC. The HMI-R9 operator panels are CODESYS-compatible, and the Panel PC CNC controller bundles a CODESYS-based multi-axis CNC controller with a panel PC and EtherCAT I/O.
How do I add an EtherCAT servo axis in CODESYS, step by step?
The order is: install the drive's ESI file into the Device Repository, add an EtherCAT Master to the device tree and select the right network interface, scan the network and take the drives it finds into the project, create a SoftMotion axis for each drive and enter the scaling (encoder counts per unit) and limits. Then configure the EtherCAT task with a fixed cycle time and download.
Test each axis on its own with MC_Power and MC_Jog first
Enable DC for synchronised motion
Scaling error: the axis goes the right way but the wrong distance
MC_Power, MC_Home, MC_MoveAbsolute: which motion blocks should I start with?
PLCopen motion blocks are hardware-independent and follow an axis's life cycle. A typical order: power the axis with MC_Power, reference it with MC_Home, then move it with MC_MoveAbsolute or MC_MoveRelative; stop it with MC_Stop and clear faults with MC_Reset. Each block is accepted only while the axis is in a suitable state.
If a block does nothing, check the axis state first (MC_ReadStatus)
In the CODESYS task configuration, which task should run at which cycle?
Motion and EtherCAT communication must run in the highest-priority task with a fixed cycle, and that task must be selected as the bus cycle task. Machine logic, alarm handling and HMI communication move to lower-priority tasks with longer cycles, so slow code never delays the motion task.
Enable the task watchdog so an overrun does not pass silently
CODESYS cannot find or connect to the controller. What should I do?
First confirm that the PC and the controller are on the same IP subnet and that no firewall in between blocks CODESYS gateway traffic. Check the gateway is running and scan the network again. If the device is found but the project will not download, check that the device description version in the project is compatible with the runtime version on the controller.
Try once over a direct cable, with no switch in between
Read the controller's IP address and subnet mask the way the manual describes
My variables reset when power is lost. RETAIN or PERSISTENT?
RETAIN variables keep their value across a power loss but can be reset when a new project is downloaded. PERSISTENT variables also survive program downloads, which makes them the right choice for machine settings, recipes and counters. Confirm in the controller manual that the hardware supports retained memory.
The MAT-LC platform includes a battery system module