Allen Bradley PLC programming course.
Enroll Today!
Siemens PLC programming course
Register for FREE!
Check out our FANUC Robotics course
Register Today!
Back to tutorials

Programming a SEW VFD using Modbus TCP in Unity Pro

By
Redouane Ait Ali Yahia
Learning Path
No items found.
Table of Contents

Introduction

In modern industrial environments, the most common way to remotely control VFDs (Variable Frequency Drives or Inverters) is by using a Fieldbus communication with a PLC. This offers a higher level of control as it enables access to the VFD’s parameters and data, allowing us to precisely adjust the motor’s behavior in our PLC programs and to monitor the status of the drive.

SEW-EURODRIVE is one of the main players among the VFD manufacturers. They offer a user-friendly and accessible configuration environment, making it one of the easiest to use when it comes to establishing Fieldbus communication with PLCs from various manufacturers such as Siemens, AB, Omron..etc.

In this tutorial, we will learn how to exchange process data (Setpoint Speed, Ramp, Actual Speed, and Output Current) between any SEW Movitrac B inverter equipped with a DFE33B Modbus TCP interface and a Schneider Electric Modicon M340 PLC using Unity Pro. The goal is to demonstrate the general way to set a VFD/PLC Fieldbus communication.

Prerequisites

To follow along with this tutorial, you will need 

  1. An Installation of SE’s Unity Pro. Click here
  2. Basic knowledge of the ST language 
  3. Basic knowledge of VFDs parameters and configuring.
  4. Basic knowledge of Modbus TCP.

No PLC or VFD hardware is required for this tutorial. 

Understanding the Configuration of a SEW Movitrac

The Movitrac B series comes as a compact device with a modular Fieldbus interface card equipped with RJ45 ports (Figure 1.1). For this tutorial, we are considering any Movitrac B model equipped with a DFE33B Modbus TCP interface directly wired to the PLC via an RJ45 cable.

NB: The instructions shown in this tutorial apply to any SEW VFD model.

Figure 1.1 : SEW VFD model MC07B0022-5A3-4-S0/DFE32B/FSC11B.

In the SEW configuration environment, parameters are addressed as follows.

Figure 1.2: Breaking down of the SEW parameter address.

For example, to define the inverter’s maximum speed (P 302), you need to enter the main group 3 (Motor Parameters), Subgroup 0 (Limits 1),  Desired subgroup 2 (Maximum speed) and set an integer value (from 0 to 5500 rpm). 

The default settings of the inverter allow you to do quick setups and tests, but to exchange data via Fieldbus, we need to modify some parameters. You can access the inverter’s parameters by using a DBG60B keypad or by using the SEW software Movitools.

In this example, we want to retrieve the actual speed (rpm) and the output current (%In, In being the rated current of the chosen VFD model) from the inverter and send the setpoint speed (rpm) and the ramp time (ms). In the SEW environment, these kinds of data inputs are called process data, and their parameters are located at P 87x (Process data parameter settings). 

On a typical Movitrac B inverter, process data are sets of 3 integers (16-bit words) that can either be read (PI) or written (PO). In our case, that means that we have two 16-bit words to read (PI1 and PI2) and write (PO1 and PO2).

We will not learn how to set parameters during this tutorial, but we are assuming that the target inverter has the following parameters set as follows

  • P 100 (Setpoint source) value : 8 (MASTER Sbus).
  • P 870 (Setpoint description PO1) value : 1 (Setpoint speed).
  • P 871 (Setpoint description PO2)  value : 8 (Ramp time).
  • P 873 (Setpoint description PI1)  value : 1 (Actual speed).
  • P 874 (Setpoint description PI2)  value : 2 (Output current).

All other parameters are kept at their default value including the IP address of the inverter {192.168.10.4/255.255.255.0}.

You can refer to the Movitrac B manual for more details  

Creating a new project in Unity Pro

Now that we have prepared the inverter, it is time to do some programming in Unity Pro. Let’s start by launching Unity Pro and creating a new project by clicking on File -> New.

Figure 2.1: Creating a new project in Unity Pro.

A project creation window opens asking you to choose a CPU and a rack. Since we are working with Modbus TCP, we select the BMX P34 2020 CPU which inherently supports Modbus TCP to avoid adding a communication module. Besides, you are free to choose the rack you want. In this case, we will select a 4 slot rack. Once your selections are done, click on OK.

Figure 2.2: CPU and rack selection.

When your project is created, save your project to fully create your project file. Click on the save icon, select a save folder (we kept the default one), and click on OK. Remember to save your project after each step! 

Figure 2.3: Saving the project.

Step 3 - Configuring the Modbus TCP Network in Unity Pro

On the left side of your screen, you can find the project browser (See Figure 3.1 below) that shows the different components of your project such as the hardware configuration, networks, variables, tasks..etc. 

To establish a Modbus TCP communication, we have to create a network in our project. To do this, open the “Communication” folder, right-click on the “Networks'' folder and select “New Network”.

Figure 3.1: Creating a new network in Unity Pro.

The “Add Network” window opens, select “Ethernet” as network, and type “sew_modbus” in the network name section. Once done, click on OK.

Figure 3.2:  Add network window.

The network is created and you can see it appearing in the project browser under the “Networks” folder. Double click on it to edit its properties and select the “CPU 2020, CPU 2030 (>= V02.00), PRA 0100” model family.

Figure 3.3: Network properties in Unity Pro.

Upon selecting the model family, a warning window will appear asking you to confirm the network family change. This is a normal warning, simply click on yes and wait for the operation to be completed.

Figure 3.4: Network family change warning.

Once the network family is changed, click on the “IP configuration” tab. This is where you can define the IP address and sub-mask of your network. Since the default IP address of the inverter is {192.168.10.4/255.255.255.0}, we need to set an IP address located on the same network. In my case, I chose the address {192.168.10.2/255.255.255.0}. Keep the gateway address untouched.

Figure 3.5: IP Configuration of a network in Unity Pro.

The last thing we have to do is to tell the CPU that we will use its RJ45 Modbus port for our network. To do so, open the “Configuration” folder and all its subsequent folders. Double-click the “Ethernet” port of your CPU to open its configuration.

Set the Function as “ETH TCP IP” and select “sew_modbus” in Net Link.

Figure 3.6: Ethernet port configuration in Unity Pro.

Programming in ST in Unity Pro

To read or write process data, we have to create a MAST task in our project that will contain our ST code.

Open the “Program” folder in the Project Browser followed by the “Tasks” folder. Right-click on the “MAST” folder and select  “New Section”.

Figure 4.1: Creating a new section in Unity Pro.

A task creation window opens. Type “Main” in the name section and select the ST language. Then click on OK.

Figure 4.2: New section window.

Now we have a task window where we can start building our code. In this program, we will be using the FFB functions “READ_VAR” and “WRITE_VAR” to read or write consequent data from the network we created. 

To add a function, right-click in the “Main” window add select “FFB Input Assistant”.

Figure 4.3: Opening the FFB Input Assistant in Unity Pro.

In the FFB Input search bar, type “READ_VAR”. Then, click on OK.

Figure 4.4: FFB Input Assistant in Unity Pro.

In the prototype section (Figure 4.4), you may notice that all the READ_VAR function parameters data types are displayed and explained. This will be helpful during the creation of the variables.

Figure 4.5: READ_VAR function in Unity Pro.

As you can see, the function’s parameters are left empty with a comment telling the data type of each parameter.

Use the FFB Input Assistant again, this time to add the WRITE_VAR function.

Figure 4.6: READ_VAR and WRITE_VAR functions in Unity Pro.

We need one last more FFB function, the ADDM function which converts a set character string into a topologic address that the READ_VAR and WRITE_VAR functions can take as an input in the “ADR” parameter.

Use the FFB Input Assistant to add the ADDM function. Be sure to add it before the other functions. We need it to be executed before them.

Figure 4.7: READ_VAR, WRITE_VAR, and ADDM functions in Unity Pro.

You can fill in the function parameters right away with the proper values but for more clarity in our program, we will create some variables.

Open the “Data Editor” by double-clicking in the “Elementary variables” section of the “Variables”  folder of the Project Browser.

Figure 4.8: Data Editor in Unity Pro.

Create the following variables by defining a name and a type for each variable like shown in Figure 4.9.

Figure 4.9: All variables we need.

Then add the variables to the code like shown in Figure 4.10.

Figure 4.10: Using the variables we created in the FFB functions.

According to the SEW documentation, speed and current values in the inverter are scaled. 

  • For speed values, 1 digit equals 0.2 rpm. 
  • For current values, 1 digit equals 0.1 %In.

For the last step, we have to make the values we are reading or writing practical to use in the program by assigning them to more explicit variables and adding the proper divisions to respect the scales as explained in the comments of Figure 4.11.

NB: To use the READ_VAR and WRITE_VAR functions, you also need to initialize the 3rd word of their GEST parameter to a non-null value in milliseconds. This parameter defines the function’s timeout. I usually set it at 100ms but feel free to use the value you need for your future programs. 

Figure 4.11: Adding the assignments Initializations.

Conclusion

In this tutorial, you learned how to easily interact with a SEW VFD using Unity Pro and Modbus TCP. 

As an automation engineer, having to establish different Fieldbus communications between the different devices of your project is a key skill to acquire. VFDs are the best example to demonstrate how they can be done since they are one of the most common parts of an industrial machine.

SEW VFDs offer almost ready-to-use systems with a user-friendly and intuitive configuration environment. Making it easy to work with. Especially when working with a Fieldbus inherently supported by the PLC environment as it is for Modbus TCP in Schneider’s electric PLCs and software.

Back to tutorials

Ready To Learn More?

Level-up your career with unlimited access to practical, in-depth technical courses taught by industry experts. Explore our courses