Application example

Application example 1:

EtherCAT XML Device Description

The display matches that of the CoE objects from the EtherCAT XML Device Description. We recommend downloading the latest XML file from the download area of the Beckhoff website and installing it according to installation instructions.

Motor control with visualization

Application example 2: Sample program (download)

Used Master: TwinCAT 2.11 (for older versions the control loop has to be programmed manually; in this case it is already implemented in the NC).
This application example demonstrates movement of a motor to any position or in continuous mode with the aid of visualization. The velocity, the starting acceleration and the deceleration can be specified.

The sample program consists of two files (PLC file and System Manager file).

First open the PLC file and compile it so that you have the *.tpy file available that is required for the System Manager.

Please note that you may have to adjust the target platform in the PLC program (default: PC or CX 8x86). If required, you can select the right target platform in the Resources -> Controller configuration tab.

Application example 3:
Selection of the target platform

Please note the following for the System Manager file:

The PLC program is configured as follows. The libraries TcMC.lib and TcNC.lib must be integrated (see Fig. Required libraries).

Application example 6:
Required libraries

Once this is done, certain global variables are declared (see Fig. Global variables). The data types PLCTONC_AXLESTRUCT and NCTOPLC_AXLESTRUCT deal with the communication between the PLC and the NC.

Application example 7:
Global variables

Once the global variables have been declared, programming can commence. Start with declaring local variables (see Fig. Local variables).
MC_Direction is an enumeration type that specifies the direction of movement for the MC_MoveVelocity function block, which in turn initiates continuous travel of the motor.
An axis reset is carried out with the MC_Reset function block. Absolute positioning is carried out with the MC_MoveAbsolute function block. The current axis position can be read with the MC_ActualPosition function block.
MC_Power enables the axis; MC_Stop is required for stopping the axis.

Application example 8:
Local variables

The program code is as follows (see Fig. Program code):

Application example 9:
Program code

The motor can then be operated with the aid of the following visualization (see Fig. Visualization).

Press Enable to enable the axis. In "Free run mode" you can now use the Left or Right buttons, and the motor will run with a speed defined under fbMoveVelocity_Axis_1 in the selected direction. In "Absolute mode" you can specify a Velocity, Acceleration, Deceleration and the Setpoint Position and initiate the motion with Start Job. If no values are entered for acceleration and deceleration the default value of the NC is used.

Application example 10:
Visualization
Application example 11:

Information on function blocks and data types

Further information on the function blocks and data types used can be found in the Beckhoff Information System.