EL6821 with CX5120

This sample explains how to write a simple PLC program for DALI in TwinCAT and how to link it with the hardware.

A single lamp is to be controlled and switched to the maximum output value or switched off with a push button.

Sample: DALI_Sample_EL6821_CX5120.zip

EL6821 with CX5120 1:

The TwinCAT project is available for download as *.zip file. This must first be unpacked locally so that the archive (*.tnzip file) is available for import into the TwinCAT project.

Hardware

Setting up the components

1x CX5120 Embedded PC

1x EL1008 digital 8-channel input terminal (for the switch-on/switch-off function)

1 x power supply terminal EL9562

1x DALI terminal EL6821

1 x end terminal EL9011

Set up the hardware and the DALI components as described in the documentation.

This sample assumes that an On button was connected to the first EL1008 input and an Off button to the second. There is a lamp at DALI address 0.

Software

Creation of the PLC program

Create a new TwinCAT XAE Project and a Standard PLC Project. Add the Tc3_DALI library in the PLC project under References. Generate a global variable list with the name GVL_DALI and create the following variables:

VAR_GLOBAL
  bSwitchOn           AT %I* : BOOL;
  bSwitchOff          AT %I* : BOOL;
  stEL6821InData      AT %I* : ST_EL6821InData;
  stEL6821OutData     AT %Q* : ST_EL6821OutData;
END_VAR

bSwitchOn: Input variable for the On button.

bSwitchOff: Input variable for the Off button.

stEL6821InData Input variable for the DALI terminal (see ST_EL6821InData).

stEL6821OutData: Output variable for the DALI terminal (see ST_EL6821OutData).

Create a program (CFC) for the background communication with the DALI terminal. The function block FB_EL6821Communication is called in the program. In the communication block ensure that the structures stInData and stOutData are linked.

EL6821 with CX5120 2:

Create a MAIN program (CFC) in which the function blocks FB_DALI102RecallMaxLevel and FB_DALI102Off are declared as follows.

PROGRAM MAIN
VAR
  fb102RecallMaxLevel  : FB_DALI102RecallMaxLevel(Communication.fbEL6821Communication);
  fb102Off             : FB_DALI102Off(Communication.fbEL6821Communication);
END_VAR

The communication block is specified in the round brackets after the declaration. The reference to the desired DALI terminal is defined via this specification.

For more information, see Transfer of the reference to the communication block.

Call the two instances of the function blocks FB_DALI102RecallMaxLevel and FB_DALI102Off with the following variables.

The input bStart of the function block for switching on a lamp with the maximum output value is linked to the global variable bSwitchOn.

The input bStart of the function block for switching off a lamp is linked to the global variable bSwitchOff.

EL6821 with CX5120 3:

Navigate to the task configuration section and configure the PlcTask. By way of example, the task is assigned priority 16 and a cycle time of 6 ms.

EL6821 with CX5120 4:

Create another task for background communication. Give this task a higher priority (lower number) and a lower interval time than the Plc task.

EL6821 with CX5120 5:

Add the program for the communication to this task. Further information on task configuration can be found in the description of the function block FB_EL6821Communication.

EL6821 with CX5120 6:

I/O configuration

Select the CX as target system and initiate a search for its hardware.

In the instance (DALI_Sample_EL6821_CX5120 Instance) of the PLC project, you can see that the input and output variables of the PLC program are assigned to the corresponding tasks (PlcCommunication and PlcTask).

EL6821 with CX5120 7:

Now link the global variables of PLC program with the inputs and outputs of the bus terminals. Create the Solution and enable the configuration.

The lamp with the maximum brightness value is switched on by pressing the first push button. The second push button can be used to switch it off again.