Siemens CB1241 Modbus communication

This blog is going to cover how to control a variable frequency drive using Modbus from an S7-1200 controller. The CB 1241 Module will be used to communicate with the VFD through Modbus RTU over RS485. The VFD will be driving a conveyor belt in a vision inspection system which will feature in future posts. For this example, the VFD will control a HVAC fan as a demonstration only.

A live video of this blog can be seen on youtube by selecting the link below:  

https://www.youtube.com/watch?v=kCwF6NiqCBs&list=LL&index=1&t=84s

This blog itself will be divided into 3 distinctive sections:

  • Hardware and wiring.
  • Modbus parameters and conversions
  • Modbus blocks and the TIA configuration

Hardware and Wiring

Before discussing the software, the first step is to place the CB1241 into the slot on the S7 1200 PLC. Then the communication wiring is straight forward. It is important to note:

  • TA/TRA is connected to RS485 B -
  • TB/TRB is connected to RS485 A +

The test rig in this blog is shown below as this has been written during the testing and development stage of an upcoming project

Below is the VFD Termination which highlights all the options for control. The VFD I/O shows the actual I/O on the back of the VFD. Its capable of being controlled by various inputs and outputs but for this application we are only concerned with the with the RS-485 communication port (485+&485-), Vcc, and Ground.

 

Modbus Parameters and Conversions / VFD Manual

For the blog, I have included relevant parameters from the VFD manual as they will be used in the S7 Software blocks. I have taken the liberty of taking an excerpt of the manual so you can see the alternate Range inputs in case you need to change one of the above settings to suit your own set up.

The most important settings are highlighted below as they dictate the device address and serial parameters over modbus RTU.

Hyperlink https://prom-electric.ru/media/GK-3000-Variable-Frequency-Drive-User-Manual.pdf

Function Code

Name

Selected Range Value

P0.01

Freq control channel selection

4: Digital setting 3, serial port given

P0.03

Running command mode selection

2: Serial port control mode

P3.09

Communication configuration

LED hundred's place: communication mode

1: MODBUS, RTU Mode

LED ten's place: data format

6: 1-8-1 Format, without check

LED unit's place: baud rate selection

3: 9600BPS

P3.10

Local address

0~248

0: Broadcast address

248: Host address

001

 

Parameters and Modbus Address for controlling the operational state and the speed

 This VFD will need to receive 3 commands from the PLC for this application: Run, Frequency (speed), and Decelerate to Stop. These commands will differ between manufacturer which are standardized between master and slave by modbus. 

The address and values are shown in HEX format. As an important note, the S7 Blocks for Modbus use the decimal conversion

 

First off, the ID of the device is selected. The VFD is usually a slave [Address] of 1

The function is changed between 03 [Read values] and 06 [Write values]

The content is usually first specifying the parameter [vfd frequency etc] and then the value is attached on.

************* Example ******************

01 06 20 00 00 01 would for example tell the VFD we want to start it

Start - Stop VFD

  • 01 is the slave ID of the VFD
  • 01 (Slave ID) 06 is the register write method (Explain further in Blog)
  • 20 00 is the Address for the RUN command state [Running or stopped]
  • 00 01 is to start the VFD

Note:  01 06 20 00 00 07 would for example tell the VFD we want to STOP it

  • The 00 07 is the value required for STOP

 ************* Example ******************

 

The Address and value is a hex conversion across to an integer. The conversion for starting the VFD is shown below for [01 06 20 00 00 01]:

  • 20 00 = 8192 (Hex to Decimal - Integer)
  • 00 01 = 1 (Hex to Decimal - Integer)

 Very Import Note – Irregular communication issue with this VFD

  • 48192 is communicating as 48193 from the S7 (Operational State)
  • 48193 is communicating as 48194 from the S7 (Frequency Speed)

 

 

TIA configuration and Modbus Blocks

To start, we will create a new TIA project. Open TIA portal > Create new project > click the create button

In the project tree select “Add new device” > Controllers > Simatic S7-1200 > CPU > CPU 1211C DC/DC/DC > 6ES7 211-1AE40-0XB0 then select “OK”.

Now that the PLC has been chosen we are going to select a communication board. Under “Hardware catalog” select Communication boards > Point-to-Point > CB 1241 (RS485) > 6ES7 211-1AE40-0XB0 . Then click and drag the highlighted 6ES7 211-1AE40-0XB0 board onto the highlighted blue slot on the PLC as shown.

You’ll notice the blank space on the PLC populates with your selected communication board.

Once the CB1241 is selected, the module will appear in the center of the Device

Pulse clock settings

We will need to use the system clock to synchronise when the system will read and write data. This application is going to operate in “One S            hot” mode. Meaning we will only be reading / writing one value at a time.

Under the General tab select “System and Clock memory”. Enable both the use of system memory byte and use of clock memory byte check boxes. Change the addresses of “system memory byte” and “clock memory byte” to 1000 and 1001 respectively. This assigns where in memory we can reference different clock based functions.

Configuring the Communications Board

Select the Communications Board by clicking on its graphic representation which is found centrally on the PLC. When selected it will be have a blue boarder. Under the “General tab” select General> IO-link. Observe the baud rate of 9.6kbps this is default rate of transmission in bits per second. All devices need to be on the same baud rate to ensure no data is lost in transmission.

Program Blocks

Now we shall set up the program utilizing the Modbus blocks. Under the Project tree follow the path S71200_ModbusVFD> PLC_1 [CPU 1211C DC/DC/DC] >Program blocks > Main [OB1] . This will be where the main program will be constructed.

The Modbus blocks can be selected under the instructions tab > Communication > Modbus. For this application we will need MB_COMM_LOAD and MB_Master. Drag them to Network 1 and Network 2 respectively.

Right click and “Create Instance” on both blocks to assign them a title and a local data block.

Now we will create variables in a data base block which these Modbus blocks will reference. I’d recommend setting up your variables this way because its easier to scale and can be reviewed at a glance.

Under the Project tree follow the path: S71200_ModbusVFD> PLC_1 [CPU 1211C DC/DC/DC] >Program blocks > Add new block. Select Global DB and name the database MB_COMM_LOAD_DB.

Select the MB_COMM_LOAD block in network 1 and press F1 to bring up the instruction set for the MB_COMM_LOAD block. This will be a reference for what variables and data types are required in the block configuration. The three variables we will create here are the outputs Done, Error, and Status.

Now we will do the same for the MB_MASTER block. Under the Project tree follow the path: S71200_ModbusVFD> PLC_1 [CPU 1211C DC/DC/DC] >Program blocks > Add new block. Select Global DB and name the database MB_MASTER_GDB.

Select the MB_MASTER block in network 2 and press F1 to bring up the instruction set for the MB_MASTER block. This will be a reference for what variables and data types are required in the block configuration. An example of the variables used are shown below.

The final step of creating a database block requires you to uncheck the “Optimized block access”. You can find this by right clicking the database and selecting properties. You have to do this for all global databases because??  I have noticed when you would like to reference a variable from a contact or non modbus block this needs to be deselected to be registered correctly.

Now that the variables have been created you can simply click the relevant tags on the Modbus blocks and browse to their variables within the global data blocks. It will look like the following.

The “REQ” requires a rising edge which tells the block when to execute whatever command the master block calls. For the MB_COMM_LOAD the req needs to execute on the first rising edge. Browse to “FirstScan” this will happen when. Notice the memory address we configured in the CB1241 as a starting address“M1000.0”.

To configure the port on MB_COMM_LOAD simply click port and browse to your CB_1241_(RS485). Notice it will be labelled “Port”. The BAUD rate, as discussed when configuring the Communications Board, is 9600. 

Finally, the MB_DB is to reference the MB_MASTER_DB instance. You select this by copying title of the MB_MASTER block as shown.

Now we compile and download the program to our device. Thank you for reading through this article, and if you have any further questions please feel free to reach out to me at:

contact@appliedprojectsengineering.com

 

Comments are closed