How to import DLL file for Advanced C function

The Advanced C Function is an extension of the C Function, which allows you to include both pre-generated Dynamic Link Libraries (DLLs) and external C language source files. It is important to note that the implementation of functions is hidden, and you will only be able to see the function interface. This feature helps developers to build control applications in third-party software and import their DLL files into the Typhoon HIL toolchain.

This example demonstrates this by showing how a DLL file imported with the Advanced C function can be used as the Controller block of a simple Boost Converter.

Model description

The electrical model of a Boost Convertor consists of a DC Voltage Source, an Inductor with internal Resistance, a Capacitor with internal resistance, two types of loads, and a switch. The initial input voltage is 30 V and the output voltage is 40 V. Carrier frequency is set to 10 kHz, and the modulation signal is generated from the Advanced C function. The control part is tested using two different loads: 320 W and 480 W. The Simulation section describes the transitions and behavior of the model.

Figure 1: Model of boost converter with controller

To include DLL files in the Advanced C function, you need to do the following steps:

  • In order to generate the modulation signal, a DLL file is needed. While you may use many ways to generate the DLL files, in this application we demonstrate the use of Typhoon HIL Control Center's internal C compiler. More details about generating DLL files using the Typhoon HIL compiler is available in the FAQ section.
  • After generating the DLL file, you need to add the location of the file in the “DLL functions” tab in the Advanced C function menu. Also, it is important to add the H file (aka header file) as shown in Figure 2. After configuring, you should find the interface of the function in the “Name” tab.

Figure 2: Advanced C function

After generating DLL file you need to add location of the file in “DLL functions” tab. Also, it is important to add the header file as in Figure 2. After this configuration you should find interface of function in “Name” tab.

To include “Controller” function in Schematic Editor we use simple output_fcn function. The implementation of the “Controller” function it is shown.

output_fnc(){
  Controller(Vo,&duty,Vref);
}

The implementation of the "Controller" function in C language is shown below:

/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <math.h>

#define Dmin	0.
#define Dmax	1

//PI
//double Vref = 40;
double Vsense = 0.;
double err = 0.;
double anti = 0.;
double Rc = 0.;
double Rsat = 0.;
double intg = 0.;
double ka = 166.67;
double kp = 0.006;
double ki = 0.436;
double in0, in1, out = 0;


void Controller(double Vo,double* duty,double Vref)
{
	#define Ts		100e-6   //100kHz
	Vsense = Vo;
	err = Vref - Vsense;
	anti = err - ka*(Rc - Rsat);
	intg += ki*Ts*anti;
	Rc = kp*err + intg;
	
	if ( Rc < Dmin ) Rsat = Dmin;
	else if ( Rc > Dmax ) Rsat = Dmax;
	else Rsat = Rc;
	
	*duty = Rsat; 
	
}
The PI regulator is implemented in the void function “Controller”. The inputs for this function are the reference voltage, which comes from the SCADA Input component, and the output voltage of the Boost Converter. We set the duty cycle for the PWM modulator as outputs for the function. The header file is as follows:
#ifndef _DLL_H_
#define _DLL_H_

void Controller(double Vo,double* duty,double Vref);

#endif

The function interface is implemented in the header file, which is required in this application.

Simulation

In this How-to example, we can see the behaviour of a PI controller implemented by C function. By setting the state of the contactor "On" or "Off", you can easily see the behaviour and validate the PI controller.

The Figure 3 shows how the controller reacts in a step change of load. In the first window, you can see the transition of the voltage of the converter output during the step change. In the second window, you can see how the inductor current decreases during a step change. In the third window, you can see the position of contactor S1.

Figure 3: Step change of load from 480 W to 320 W

In Figure 4, we can see how the controller reacts to a step change of the inverter from 320 W to 480 W. Reference voltage is successfully regulated to the reference value of 40 V for this application. In the first window, you can see a similar transition to the previous scenario. In the second window, you can see how the inductor current increases during a step change. In the third window, you can see the position of contactor S1.

Figure 4: Step change of load from 320 W to 480 W

Note: Importing of DLL files is only supported for Virtual HIL models.
Note: Advanced C function supports only DLL compiled for win64 operative system.
Table 1. Minimum requirements
Files
Typhoon HIL files Available on request
Minimum hardware requirements
No. of HIL devices 1
HIL device HIL402
Device configuration 1

Test Automation

We don’t have a test automation for this example yet. Let us know if you wish to contribute and we will gladly have you signed on the application note!

Authors

[1] Simiša Simić