KL6771 with CX5120

This sample describes how a simple PLC program for MP-Bus can be written in TwinCAT and how it is linked with the hardware. The task is to control an individual damper drive and change it with a button.

Sample: MPBus_Sample_KL6771_CX5120.zip

Hardware

Setting up the components

The following hardware is required:

Set up the hardware and the MP-Bus components as described in the associated documentation.

This sample assumes that the address of the damper drive is known.

Software

Creation of the PLC program

Create a new "TwinCAT XAE project" and a "Standard PLC project".

Add the library Tc2_MPBus under "References" in the PLC project.

Generate a Global Variable List with the name GVL_MPBus and create the following variables:

VAR_GLOBAL
    bOpen          AT %I* : BOOL;
    bClose         AT %I* : BOOL;
    arrKL6771_IN   AT %I* : ARRAY [0..11] OF BYTE;
    arrKL6771_OUT  AT %Q* : ARRAY [0..11] OF BYTE;
    stDataKL6771          : DataKL6771;
END_VAR

bOpen: Input variable for the Open button.

bClose: Input variable for the Close button.

arrKL6771_IN: Input variable for the MP-Bus terminal.

arrKL6771_OUT: Output variable for the MP-Bus terminal.

stDataKl6771: Required for communication with MP-Bus (see DataKL6771).

All MP-Bus function blocks must be called in the same task.

Therefore, create a MAIN program (CFC) in which the KL6771 and MP_DamperLinearActuator function blocks are called. Make sure to link arrKL6771_IN, arrKL6771_OUT and stDataKL6771 in the communication block.

KL6771 with CX5120 1:

The input SetPoint is set depending on the selected function. Link the global variables bOpen and bClose with an auxiliary variable.

KL6771 with CX5120 2:

Go to the task configuration and give the task a lower interval time.

Further conditions can be found in the description of the function block KL6771.

KL6771 with CX5120 3:

I/O configuration

Select the CX as target system and initiate a search for its hardware. In the project instance within the PLC section, you can see that the input and output variables are assigned to the task.

Now link the global variables with the inputs and outputs of the Bus Terminals.

The linking of MP-Bus variables is described in detail below.

Right-click the array arrKL6771_IN and select "Change Link".

KL6771 with CX5120 4:

Under "I/O Configuration" select the terminal, select "All Types" and "Continuous", then select "ParameterStatus", "InputData1" to "InputData10" with the left mouse button and the >SHIFT< key. Then click "OK".

KL6771 with CX5120 5:

You can now check the connection. To do this, go to the KL6771 and open it. All terminal data should now show a small arrow. If that is the case, then proceed in exactly the same way with the outputs.

KL6771 with CX5120 6: