KL6811 Integration into TwinCAT (BC9191)

This example explains how to write a simple PLC program for DALI in TwinCAT and how to link it with the hardware. The task is to control an individual dimmable lamp via a button.

Unpacking the example files

Hardware

Setting up the components

The following hardware is required:

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

This example assumes that a Dim button was connected to the first KL1002 input and a Reset button to the second, and that a dimmable lamp is connected to DALI address 0. Set the initial fade rate of the ballast to 7 to achieve suitable dimming.

Software

Creation of the PLC program

Create a new PLC project for BC-based systems (BCxx50 via AMS) and add the libraries TcDALIV2.lbx and TcSystemBCxx50.lbx. Then navigate to Project→Options... →Build and select TreatLREAL as REAL.

KL6811 Integration into TwinCAT (BC9191) 1:

Under Controller Settings, select BC9191 and set the Maximal Number of POUs to 1000.

KL6811 Integration into TwinCAT (BC9191) 2:

Next, generate the following global variables:

VAR_GLOBAL
    bSwitch      AT %I*     : BOOL;
    bReset       AT %I*     : BOOL;
    stDALIInData     AT %I* : ST_DALIV2InData;
    stDALIOutData    AT %Q* : ST_DALIV2OutData;
    stCommandBuffer         : ST_DALIV2CommandBuffer;
END_VAR

bSwitch: Input variable for the Dim button.

bReset: Input variable for the Reset button.

stDALIInData: Input variable for the DALI terminal.

stDALIOutData: Output variable for the DALI terminal.

stCommandBuffer : Required for the communication with DALI.

Since BC devices can only process one task, communication with DALI cannot run separately.

Therefore, create a MAIN program (CFC) in which the FB_DALIV2Communication() and FB_DALIV2Dimmer1Switch() function blocks are called. Make sure to link the communication block with stDALIInData, stDALIOutData and stCommandBuffer.

KL6811 Integration into TwinCAT (BC9191) 3:

Connect the input bSwitchDimm of the dimmer block with the global variable bSwitch and stCommandBuffer with the global variable stCommandBuffer.

KL6811 Integration into TwinCAT (BC9191) 4:
KL6811 Integration into TwinCAT (BC9191) 5:

Parameter

Make sure that the specified parameters nMinlevelMasterDevice and nMaxLevelMasterDevice match the minimum and maximum values of the device, in order to avoid malfunction.

Go to the task configuration and give the task a lower interval time. More detailed information can be found in the FB_DALIV2Communication() block description.

KL6811 Integration into TwinCAT (BC9191) 6:

Now load the project as a boot project to the BC and save it.

Configuration in the System Manager

Create a new TwinCAT System Manager project, select the BC as the target system, and search for the associated hardware.

Add the PLC program created above under PLC configuration.

KL6811 Integration into TwinCAT (BC9191) 7:

Now link the global variables of the PLC program with the Bus Terminal inputs and outputs, create the allocations, and activate the configuration. Then start the device in run mode.
Your BC is now ready for use.

The lamp can now be controlled by pressing or holding the dimmer button. Use the Reset button to reset the entries in arrBufferMaximumDemandMeter and arrBufferOverflowCounter.