This example shows EtherCAT communication using the Beckhoff® digital I/O terminals EL1004 and EL2004.
|On this page…|
For this Example, the EtherCAT network consists of the target computer as EtherCAT Master device and the two analog input/output terminals EL1004 and EL2004 as EtherCAT Slave devices. In order to run this example, a dedicated network card must be installed and available on the target computer to be used for the EtherCAT communication, in addition to the card used for host-target communication. To test this model:
Connect the network port of the dedicated card in the target computer to the network IN port of the Beckoff® EK1100 coupler.
Assemble Terminals EL1004 and EL2004 with Coupler EK1100.
Loop back the first two I/O ports: Connect ports numbered 1 and 5 of Terminal EL2004 to ports numbered 1 and 5 of Terminal EL1004.
Make sure all the terminals are correctly supplied with a 24-volts power supply.
Build and download the model onto the target.
Click here to open the model: xpcEthercatBeckhoffDIOxpcEthercatBeckhoffDIO. This model drives a pulse wave signal and transmits it as well as its inverse as Boolean value to the EL2004 terminal, and receives the input signal transmitted by the EL1004 terminal (see Figure 1).
% The EtherCAT initialization block requires that the configuration ENI % file is present in the current folder. Copy the example configuration % file from the example folder to the current folder. copyfile( [matlabroot,'\toolbox\rtw\targets\xpc\xpcdemos\BeckhoffDIOconfig.xml'], '.', 'f' ); % Open the model. mdl = 'xpcEthercatBeckhoffDIO'; mdlOpen = 0; systems = find_system('type', 'block_diagram'); if isempty( strcmp(systems, mdl ) ) mdlOpen = 1; open_system(mdl); end
Figure 1: EtherCAT model using Beckhoff® digital I/O terminals EL1004 and EL2004.
Open the mask for the EtherCAT Init block and provide appropriate values for the PCI bus and slot numbers for the network card being used for EtherCAT communication. You can obtain these values by using the command tg.getPCIInfo('all') at the Matlab command line on the host computer.
The configuration file BeckhoffDIOconfig.xmlBeckhoffDIOconfig.xml is generated using the Beckoff ET9000 configurator. This file describes the slave network to the master. Below is an overview of the process to create the configuration file in the EtherCAT Configurator (see the user guide for more details):
Connect the network (consisting of Terminals EK1100, EL1004 and EL2004 in this example) to the computer where the EtherCAT Configurator is installed and scan the network to discover the connected devices.
Select the transmit and receive variables to be accessed as signals from the IO terminals.
Define at least one cyclic task, select a task execution rate and associate the selected variables to the task. You only need to select one variable from each PDO to make all variables in that PDO accessible.
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.
Each EtherCAT configuration file is specific to the exact network setup from which it was created (i.e. the network discovered in step 1 above in the configuration file creation process). The configuration file provided for this example is valid if and only if the EtherCAT network consists of Terminals EK1100, EL1004 and EL2004 from Beckhoff®.
The configuration file defines a set of transmit and receive variables. For this example, four receive variables are defined for the four input channels of Terminal EL1004. Only the first two channels of Terminal EL1004 are used in this example. Make sure the receive variables for channel 1 and channel 2 of Terminal EL1004 are selected respectively in the two EtherCAT PDO Receive blocks. These two variables are 'Term 3 (EL1004).Channel 1.Input' and 'Term 3 (EL1004).Channel 2.Input'. In the same way, four transmit variables are defined for the four output channels of Terminal EL2004, but only the first two channels are tested in this example. Make sure the transmit variables for channel 1 and channel 2 of Terminal EL2004 are selected respectively in the two EtherCAT PDO Transmit blocks as illustrated on Figure 1. These two variables are 'Term 2 (EL2004).Channel 1.Output' and 'Term 2 (EL2004).Channel 2.Output'.
% Build the model and download to the target computer. set_param(mdl,'RTWVerbose','off'); % Configure for a non-Verbose build. rtwbuild(mdl); % Build and download application. % Run the model tg.CommunicationTimeOut=20; +tg; pause(10); % Let the model run for 10 seconds
### Starting Simulink Real-Time build procedure for model: xpcEthercatBeckhoffDIO Warning: This model contains blocks that do not handle sample time changes at runtime. To avoid incorrect results, only change the sample time in the original model, then rebuild the model. ### Successful completion of build procedure for model: xpcEthercatBeckhoffDIO ### Looking for target: TargetPC1 ### Download model onto target: TargetPC1
Take a snapshot of the target computer video display. Plotted are the signals transmitted to Terminal EL2004 and received from Terminal 1004. As expected, the transmitted and received signals displayed on the two scopes are identical (see Figure 2).
Scope 1 displays the outputs of the Ethercat Init block. See the documentation of this block for the meaning of the displayed values.
Scope 2 displays the pulse wave and its inverse generated by the application and sent to Terminal EL2004 by the EtherCAT Master.
Scope 3 displays the signals received at the two inputs ports of Terminal EL1004.
tg.viewTargetScreen; %Take a snapshot of the target scopes
Warning: The EraseMode property will be removed in a future release.
Figure 2: Target scopes view for the model of Figure 1.
%Stop the model -tg;
% Close the model if we opened it. if (mdlOpen) save_system(mdl); close_system(mdl); end % EOF xpcethercataiodemo.m