EtherCAT® Communication - Motor Position Control with an Accelnet™ Drive and Beckhoff® Analog IO Devices

This example shows how to control the position of a motor using EtherCAT communication.


To run this example, you need an EtherCAT network that consists of the target computer as EtherCAT Master device and an Accelnet™ AEP 180-18 drive from Copley Controls as EtherCAT Slave device. Connect a supported brushless or brush motor to the drive. An example motor that works with this example is the SM231BE-NFLN from PARKER.

This example requires a dedicated network card that is installed and available on the target computer. Use the dedicated card for the EtherCAT communication. The dedicated card is in addition to the card used for the Ethernet link between the development and target computers.

To test this model:

  1. Connect the network port of the dedicated card in the target computer to the EtherCAT IN port of the Accelnet™ drive.

  2. Connect the EtherCAT OUT port of the Accelnet™ drive to the EtherCAT IN port of the Beckhoff® EK1100 coupler.

  3. Assemble the Beckhoff® EK1100 coupler and the Beckoff® IO terminals EL3062 and EL4002.

  4. Connect a motor to the Accelnet™ Drive.

  5. Connect a variable power supply to the Input port 1 of the EL3062 terminal.

  6. Make sure the Accelnet™ drive and the Beckhoff® terminals are supplied with a 24-volt power source.

  7. Build and download the model onto the target.

For a complete example that configures the EtherCAT network, configures the EtherCAT master node model, and builds then runs the real-time application, see the Simulink Real-Time EtherCAT documentation.

Open the Model

To open the model, in the Command Window, type:


This model creates a sine wave, and modulates it by multiplying by the value of the signal present at the first input port of Terminal EL3062. The modulated signal is sent as motor position command to the drive.

The EtherCAT initialization block requires that the configuration ENI file is present in the current folder. Open the model.

mdl = 'slrtex_ethercat_position_control';
mdlOpen = 0;
systems = find_system('type', 'block_diagram');
if isempty( strcmp(systems, mdl ) )
  mdlOpen = 1;

Figure 1: EtherCAT model for controlling the position of a motor through an analog input terminal.

Configure the Model

Open the mask for the EtherCAT Init block and provide the required values for the PCI bus and slot numbers for the network card being used for EtherCAT communication. To get these values, in the Command Window, type tg.getPCIInfo('all'). An example command to set configuration parameters for the EtherCAT Init block is:

set_param('slrtex_ethercat_position_control/EtherCAT Init ','pci_bus','5','pci_slot','0','pci_function','0')

Describe Network with Configurator

Using a third-party EtherCAT configurator that you install on a development computer, generate an EtherCAT configuration file CopleyMotorPositionConfig.xml.

This file describes the network to the master. For more information, see the Simulink Real-Time EtherCAT documentation.

An overview of the process for creating the configuration file in the EtherCAT configurator is:

  1. Connect the EtherCAT network (consisting of the Accelnet drive, terminal EK1100, EL3062, and EL4002 in this example) to the computer where the EtherCAT configurator is installed and scan the network to discover the connected slave devices.

  2. Select the transmit and receive variables to be accessed as signals from the Beckhoff® IO terminals and the Process Data Objects (PDOs) variables to be accessed from the Accelnet™ drive.

  3. Define at least one cyclic task, select a task execution rate, and associate the selected IO and PDO variables to the task. You only must select one variable from each PDO to make every variable in that PDO accessible.

  4. Export the configuration file into an XML file. Make sure the name of the XML file is different from the name of your Simulink® model.

  5. Close or disconnect configurator from the EtherCAT network or you could get interference between Simulink Real-Time and configurator.

Each EtherCAT configuration file is specific to the exact network setup for which it was created. (For example, the network discovered in step 1 of the configuration file creation process.) The configuration file provided for this example is valid if and only if the EtherCAT network consists of an Accelnet™ drive from Copley Controls and terminals EK1100, EL3062, and EL4002 from Beckhoff®.

For this example, five receive PDO variables are defined in the configuration file and three are used in the three EtherCAT PDO Transmit blocks: Control Word, Modes of Operation, and Profile Target Position.

  • The Control Word PDO variable serves to control the state of the drive. The constant value 15 is given as input to the block to set the first 4 bits to 1 to enable the drive. Refer to the CANOpen manual from Copley Controls for details on the bits mapping of this variable.

  • The Modes of Operation PDO variable serves to set the operating mode of the drive. The constant value 8 is given as input to the block to set the mode of the drive to 'Cyclic Synchronous Position mode'. Refer to the CANOpen manual from Copley Controls for details on supported modes of operation.

  • The Profile Target Position PDO variable serves to set the desired position. In this example, the position command given as input to the block is a sine wave modulated by the signal read at the first input channel of terminal EL3062.

Transmit PDO variables are also defined in the configuration file and two are used in the two EtherCAT PDO Receive blocks: 'Actual Motor Position' for the drive and 'Channel 1.Value' for the EL3062 terminal. The Actual Motor Position PDO variable indicates the current value of the motor position as read in the drive. Make sure the required transmit and receive PDO variables are selected in the blocks before running the example (you could need to refresh these variables).

Build, Download, and Run the Model

Build the model and download to the target computer. Then, run the model. Let the model run for 20 seconds.

tg = slrt('TargetPC1');
### Starting Simulink Real-Time build procedure for model: slrtex_ethercat_position_control
### Generated code for 'slrtex_ethercat_position_control' is up to date because no structural, parameter or code replacement library changes were found.
### Successful completion of build procedure for model: slrtex_ethercat_position_control
### Created MLDATX ..\slrtex_ethercat_position_control.mldatx

Display the signals in the Simulation Data Inspector

The position command for the motor is varied following the modulated sine wave. The motor turns alternatively in one direction and its opposite. By varying the amplitude of the voltage at Input port 1 of terminal EL3062 between 0 and 10 volts, the amplitude by which the position of the motor changes increases or decreases in same proportion.

  • The Initialization trace displays the outputs of the Ethercat Init block. See the documentation of this block for the meaning of the displayed values.

  • Position Control trace displays the PDOs received from and sent to the Drive. Those PDOs are the position command (sent to the Drive by the Master) and the actual motor position (sent to the Master by the Drive). As expected, these two signals coincide, after the small offset introduced by the transmission delay.

To view the plotted signal data, open the Simulation Data Inspector.


This image shows an example view on the Simulink Scope.

This image shows an example view on the Simulation Data Inspector.

Stop and Close the Model

When the example completes its run, stop and close the model.

if (mdlOpen)