This example shows EtherCAT communication using the Beckhoff digital I/O terminals EL1004 and EL2004.
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 respectively 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).
% Open the model. mdl = 'xpcEthercatBeckhoffDIO'; mdlOpen = 0; systems = find_system('type', 'block_diagram'); if isempty(strmatch(mdl, systems, 'exact')) mdlOpen = 1; open_system(mdl); end
Figure 1: EtherCAT model using Beckhoff digital I/O terminals EL1004 and EL2004.
Open the mask for the xpcethercatinit 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 getxpcpci('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 slaves' 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 slaves 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 slaves devices.
Select the transmit and receive variables to be accessed as signals from the IO terminals.
Define at least one cyclic task and associate the selected variables to the task.
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 has been created (i.e. the network discovered in step 1 above in the configuration file creation process). Therefore, the configuration file for this example is valid if and only if the EtherCAT slaves' 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 respectively for the four input channels of Terminal EL1004. Only the first two channels of Terminal EL1004 are used in this example. Therefore, make sure the receive variables for channel 1 and channel 2 of Terminal EL1004 are selected respectively in the two xpcethercat_rx_var blocks. These two variables are respectively 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. Therefore, make sure the transmit variables for channel 1 and channel 2 of Terminal EL2004 are selected respectively in the two xpcethercat_tx_var blocks as illustrated on Figure 1. These two variables are respectively 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 xPC Target 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 and Ethercat Rx Frames blocks. See the documentation of these blocks for the meaning of the displayed values.
Scope 2 displays the pulse wave and its inverse generated by the application and transmitted to Terminal EL2004 by the EhterCAT Master.
Scope 3 displays the signals collected at the two inputs ports of Terminal EL1004, i.e. the signals received by Terminal EL2004 from the Master and looped back.
xpctargetspy; %Take a snapshot of the target scopes
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