DC/DC Buck Converter

This example shows how to develop DC-DC power conversion applications for Texas Instruments™ C2000™ processors. The incremental model refinements in this example suggest a workflow for designing and implementing DC-to-DC Buck Converter applications on embedded platforms. This example highlights advanced processor-specific capabilities of code generation software.

Required Spectrum Digital Boards:

Recommended tutorials:

Contents

Introduction

This example suggests a development workflow for a power conversion application. You should complete the IDE Link component workflow examples before continuing with this example.

NOTE: Before continuing, verify that you have configured your F2808 based board in the Code Composer Studio™ (CCS) Setup using the JTAG configuration file provided by the JTAG emulator vendor. If not, please go to CCS Setup and select the correct board.

Task 1 - Simulate the Controller-Converter Interaction

This step requires Simscape™.

In this task, you will create a plant model of a buck converter using blocks from the Simscape™ library. Later, you will use this plant model in simulation to test the application algorithm control loop.

1. Open the Simulation of the Controller Using a Plant Model of the Buck Converter.

2. Click on the "Buck Converter Plant" subsystem and then open the buck converter model as well as each of the load models.

3. Start the simulation. Use the "Voltage_out" scope to observe the perturbations caused by the active load. Double click on the "Pgain", "Igain" and "Dgain" constant blocks and change their values to tune the gains in real time. Change the gains to obtain the best response to control the system.

Task 2 - Profile the Controller Algorithm Execution Time

In this task, you will profile the real-time execution of the buck controller algorithm created in Task 1. This helps to estimate the time needed to execute the control loop. Based upon the profiling results, you will be able to determine the maximum frequency of the control loop on the hardware.

1. Open the Control Loop Timing Model.

2. Note that device driver blocks have been added in addition to the Control subsystem. Open one of the "ePWM" blocks. On the General tab of the block parameters, notice that the period is 256. The F2808 device runs at 100 MHz. Therefore, 256 clock cycles represents a period of 2.5 microseconds (400 kHz). On the same tab, notice that the HRPWM mode is enabled. This will allow the ePWM module to use its micro step technology and have a duty cycle resolution smaller than the system clock of the F2808.

3. Open the Model Configuration Parameters dialog and select "Coder Target" under "Code Generation". Next, click "Target Hardware Resources". On the "Peripherals" tab, under "ADC", notice that the ADC acquisition window settings are set to small values. This increases the speed of the ADC conversion. The operation can be done because of the low impedance of the voltage sensing device connected to the ADC. For more information, right-click the ADC block and select help.

4. Open the Simulink® Model Explorer by selecting View > Model Explorer (or by entering Ctrl+H). In Model Explorer, go to Configuration > Solver and set "Fixed step size" to 10 microseconds.

5. While in Model Explorer, open the Simulation Configuration > Code Generation. Under the "Coder Target" tab, enable "Profile real-time execution".

6. Generate code by clicking "Build Model" button on the toolbar of your model (Ctrl+B). Once code has been generated, let it run for a few seconds and then halt the execution in CCS. At the MATLAB® command prompt invoke the profiler by entering:

     profile(CCS_Obj, 'execution', 'report').

7. Inspect the profiling report to see the execution time for the control algorithm.

8. You can automate the profiling operation with a MATLAB script. This script can be run on the current active model.

Task 3 - Integrate the Algorithm with the Asynchronous Scheduler

This task shows you how to use a hardware interrupt to trigger the control loop. Specifically, it shows how to:

This strategy minimizes the impact of PWM switching on ADC conversion results by performing conversions while PWM transitions are less likely.

In motor control application the ADC interrupt usually triggers the control loop when the ADC conversion completes. However, in this power conversion application, the output impedance of the voltage sensor device is low enough that the ADC acquisition window can be set to a small value. Therefore, we can use a single PWM event to both trigger the start of ADC conversion and to launch the control algorithm. By the time the PWM Interrupt Service Routine executes, the ADC has completed converting the two channels of interest.

1. Open the Control Loop Timing Model constructed in Task 2 .

2. Put all the blocks except the "Model Source" block in a "Function-Call Subsystem" that you can find in the Simulink browser under "Simulink" > "Ports & Subsystems".

3. The control loop is going to be triggered using a PWM interrupt. Drag the "C280x/C28x3x Hardware Interrupt" block from the library. Open the block and set the parameters to access EPWM1_INT ISR:

4. Connect the "Hardware Interrupt" output to the trigger input on the "Function-call Subsystem".

5. Open the "Function-call Subsystem"

Open the first PWM block's mask and go to the "Event Trigger" tab. Select "Enable ADC start module A". The default settings for the other parameters trigger the ADC conversion every time the PWM counter reaches 0. On the same Tab, select "Enable ePWM Interrupt". Select "Number of event for interrupt to be generated" to "Second event". This setting will raise a PWM interrupt on every other counter period match. The period is set to 256 clock cycles or 400 kHz. Generating an interrupt every other counter period match will allow us to refresh the PWM duty cycle every 5 microseconds or 200 kHz. The default settings for the other parameters allow the ePWM interrupt to be serviced when the PWM counter reaches 0.

Open the ADC block's mask and set "Start of conversion" to "ePWMxA".

6. A pre-configured model DC/DC Buck Converter Asynchronous Scheduling Model is available and saved with all the steps described in Task 3 completed.

Task 4 - Integrate and Run Legacy Code in an Open Loop Fashion

This task shows you how to integrate legacy code into your design. As an example, we will integrate hooks to a GUI developed by TI®. We will use the GUI provided in the C2000 Digital Power Experimenter Kit software package. This will allow the code generated for your model to interact with the GUI running on the host PC and exchange data in real-time through a serial interface connection.

This task relies on the installation of third party software from TI®. You need to have this software package installed on your system to complete this task. Follow the instructions enclosed with the C2000 Digital Power Experimenter Kit.

1. Open the open-loop version of the Two-Channel DC/DC Buck Converter Model.

2. Open the Model Configuration Parameters dialog and select "Coder Target" under "Code Generation". Next, click "Target Hardware Resources". Under "Source files", modify the reference to TI_F28xxx_SysSW\~SupportFiles\source\SciCommsGui.c to match your installation folder.

Under "Include Paths", modify the reference to TI_F28xxx_SysSW\~SupportFiles\DSP280x_headers to match your installation folder.

3. Open the "Serial_GUI" subsystem. You will see the hooks placed to interact with a third party GUI created by TI.

4. Note that the inputs to the GUI are placed on the left side of the "Serial_GUI" subsystem. Variable names are assigned by right-clicking the signal lines inside the "Properties". Inside the signal properties, note that the signals are set to ImportedExtern to tell Simulink that the signals will be declared by an external C file in the generated code.

5. Note the outputs of the GUI are placed on the right side of the "Serial_GUI" subsystem. "Memory Copy" blocks have been used to access source code symbols that match signals from the third party source file: SciCommsGui.c

6. Observe that there are three "Custom Code" blocks in the top right corner of the "Serial_GUI" subsystem. These blocks perform variable declarations and initializations, and call the serial routine during the execution of the program. Right-click the "System Outputs" block and go to "Block Parameters (Subsystem)". Observe that the subsystem is set to "Treat as atomic unit" in order to place the call to the serial routine "SerialHostComms" at the right location in the execution of the generated code.

7. Observe that the model is set to run in an open loop fashion. The function called subsystem "Open-Loop Control" has been slightly modified from the previous task in order to bypass the control actions.

Note that there are three subsystems labeled "A_Tasks", "B_Tasks", and "C_Tasks" that perform background operations. These tasks match what has been created in the laboratory exercises of the TI software package coming with the C2000 Digital Power Experimenter Kit.

8. Generate code by clicking "Build Model" button on the toolbar of your model (Ctrl+B).

9. While the code is running on the target, open the TI® GUI by running the executable TwoChannelBuck.exe inside your installation folder under: TI_F28xxx_SysSW\TwoChannelBuck\~GUI. Enable channel 1 and/or 2 and set the desired voltage. Use SW2 hardware switch to provide input voltage to the control algorithm.

Use the GUI to tune other parameters and use the "Graph Display" to watch the results. Turn the SW2 switch in the "off" position before finishing this step.

Note that the measured voltage is slightly different than the desired voltage. This behavior is the consequence of the open loop action. While running in "Open-Loop" the "Transient Response Tuning" parameters on the GUI are inactive.

Task 5 - Run the Model in Closed Loop.

After you have confirmed the correctness of the generated code on the embedded processor in open-loop, run the code in a closed-loop fashion.

1. Open the closed-loop version of the Two-Channel DC/DC Buck Converter Model.

2. Open the "Closed-Loop Control" subsystem and observe that the "Controller" output is connected to the "Demux" leading to the "ePWM" pair. This connection creates the closed control loop.

3. Generate code by clicking "Build Model" button on the toolbar of your model (Ctrl+B).

4. While the code is running on the target, open the TI® GUI by running the executable TwoChannelBuck.exe inside your installation folder under: TI_F28xxx_SysSW\TwoChannelBuck\~GUI. Enable channel 1 and/or 2 and set the desired voltage. Use SW2 hardware switch to provide input voltage to the control algorithm.

You can now access the "Transient Response Tuning" parameters and change the PID gains in real-time using the GUI. Click on the "Show Graph" button to display the voltage output of the buck converter. Turn the SW2 switch in the "off" position before finishing this step.

Summary

This example provides a workflow to generate and verify code for power conversion applications. It shows how to simulate the controller with a plant model, profile the generated code, integrate the algorithm using the asynchronous scheduler, tune and monitor target signals using legacy code and a third party interface.