Integration into TwinCAT (BC9191)

This example explains how to write a simple PLC program for SMI in TwinCAT and how to link it with the hardware. The task is to control an SMI motor and to change the direction of rotation with a button.

Unpacking the example files

Hardware

Setting up the components

The following hardware is required:

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

This example assumes that an Up button was connected to the first KL1002 input and a Down button to the second, and that an SMI motor is connected to Address 1.

Software

Creation of the PLC program

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

Integration into TwinCAT (BC9191) 1:
Sample-BC-Options

Next, generate the following global variables:

VAR_GLOBAL
    bUp          AT %I* : BOOL;
    bDown        AT %I* : BOOL;
    stInData     AT %I* : ST_KL6831KL6841InData;
    stOutData    AT %Q* : ST_KL6831KL6841OutData;
    stCommandBuffer     : ST_SMICommandBuffer;
END_VAR

bUp : Input variable for the Up button.

bDown : Input variable for the Down button.

stInData : Input variable for the SMI terminal.

stOutData : Output variable for the SMI terminal.

stCommandBuffer : required for communication with SMI.

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

Therefore create a MAIN program (CFC) in which the blocks FB_KL6831KL6841Communication, FB_SMIUpStep and FB_SMIDownStep can be called up. Make sure to link the communication block with stInData, stOutData and stCommandBuffer.

Integration into TwinCAT (BC9191) 2:

Connect the input bStart of the StepUp block with the global variable bUp and stCommandBuffer with the global variable stCommandBuffer. Proceed accordingly for the StepDown block.

Integration into TwinCAT (BC9191) 3:

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

Integration into TwinCAT (BC9191) 4:

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

Configuration in the System Manager

Create a new 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.

Integration into TwinCAT (BC9191) 5:

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.

By pressing one of the directions buttons the SMI motor selects the direction for the angle specified under uiAngle.