0% found this document useful (0 votes)
12 views

Integration_of_C2000_Microcontrollers_with_MATLAB_Simulink_Embedded_Coder_A_Real-Time_Control_Application

This paper discusses the integration of Texas Instruments' C2000 microcontrollers with MATLAB Simulink for real-time control applications, highlighting the efficiency of using Embedded Coder and Code Composer Studio. It provides a comprehensive guide on programming the TMS320F28379D DSP, including the setup of essential functions like PWM, ADC, and PI controllers, while emphasizing the advantages of a coding-free approach. The document aims to fill the gap in existing resources by offering clear instructions and examples for effective control model development in power systems.

Uploaded by

Peter pan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Integration_of_C2000_Microcontrollers_with_MATLAB_Simulink_Embedded_Coder_A_Real-Time_Control_Application

This paper discusses the integration of Texas Instruments' C2000 microcontrollers with MATLAB Simulink for real-time control applications, highlighting the efficiency of using Embedded Coder and Code Composer Studio. It provides a comprehensive guide on programming the TMS320F28379D DSP, including the setup of essential functions like PWM, ADC, and PI controllers, while emphasizing the advantages of a coding-free approach. The document aims to fill the gap in existing resources by offering clear instructions and examples for effective control model development in power systems.

Uploaded by

Peter pan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

2024 7th International Conference on Electrical Engineering and Green Energy

Integration of C2000 Microcontrollers with


MATLAB Simulink Embedded Coder: A Real-Time
2024 7th International Conference on Electrical Engineering and Green Energy (CEEGE) | 979-8-3503-5062-3/24/$31.00 ©2024 IEEE | DOI: 10.1109/CEEGE62093.2024.10744177

Control Application
Mohammad Abidur Rahman Ali A. Abushaiba Akrem M. Elrajoubi
Student Faculty advisor IEEE IEEE member
School of Engineering & School of Engineering & Engineering College of Engineering
Engineering Technology Technology University of Misurata
University of Arkansas University of Arkansas Misurata, Libya
Little Rock, AR, USA Little Rock, AR, USA [email protected].
[email protected] [email protected]

Abstract— C2000™ 32-bit microcontrollers excel in real- applications, such as regenerative braking for electric machines
time control, optimizing closed-loop performance for and active filtering [2]. These processors of the C2000
various applications such as industrial motor drives, solar microcontroller family can be used to develop a control model
inverters, digital power systems, and sensing. The lineup of micro-inverter topology with the help of MATLAB Simulink
offers Premium and Entry-performance microcontroller Embedded Coder and Code Composer Studio [3]. It does not
units (MCUs). This paper explores the integration process require hard programming, which saves time, is more efficient,
of Texas Instruments™ (TI) C2000 microcontroller units and can be executed faster. TMS320F28379D Digital Signal
with MATLAB and Simulink using Code Composer Studio Processor (DSP), a member of the C2000 microcontroller
(CCS) and Embedded Coder (EC) support package for family, is a faster and cheaper controller, proving its efficiency
C2000 microcontrollers. It shows how to set up Simulink to in designing effective PI-type controllers and Model Predictive
program the Digital Signal Processor (DSP) microcontroller Controllers (MPC) for PV systems and power electronic
unit and the communication between the host computer and converters [4], [5]. It has been proven efficient for Artificial
the C2000 target hardware using the LAUNCHXL- Neural Network-based control of five-level inverters to ensure
F28379D launchpad. Basic functions such as Pulse Width selective harmonic elimination [6]. The Embedded Coder
Modulation, Analog Digital Conversion, and Proportional- generates the code automatically, so less time is needed for
Integral controllers are explained. Finally, a closed-loop programming and control implementation. TI C2000 DSPs
control model for a C2000 Digital Power Buck Converter offer a practical and simple control design for DC motors [7].
BoosterPack is implemented, showcasing the effective MATLAB Simulink and Embedded Coder for DSP controller
integration of TI C2000 microcontroller units with help to develop automated control algorithm development
MATLAB, Simulink, and related tools for real-time control methods, solving the problems of long development cycles and
in the power system context. complicated programming for traditional embedded system
Keywords— TMS320F28379D DSP, Code Composer design [8]. MATLAB Simulink environment can also be used
Studio, Embedded Coder, MATLAB Simulink. for real-time simulation of power electronic systems [9].
Despite the widespread usage of C2000 MCUs, limited
I. INTRODUCTION documentation and scholarly articles address the integration of
C2000 microcontrollers, developed by Texas Instruments, it with MATLAB Simulink, with even fewer detailing
represent a family of 32-bit devices engineered explicitly for operational configurations. Moreover, existing resources lack a
real-time control applications. Known for their exceptional comprehensive illustration of the process. This paper endeavors
performance in processing, sensing, and actuation, C2000 to fill this gap by presenting a straightforward, thorough, and
microcontrollers find widespread use in diverse fields, such as accessible guide for programming Texas Instruments™ (TI)
industrial motor drives, solar inverters, digital power systems, C2000 microcontroller units using MATLAB Simulink
electric vehicles, transportation, and sensing and signal Embedded Coder. The paper demonstrates the communication
processing [1]. With a focus on optimizing closed-loop protocol between the host computer and the target model.
performance, the C2000 microcontroller family offers a range Additionally, it furnishes clear instructions for implementing
of models, each tailored to meet the demands of advanced fundamental functions such as Pulse Width Modulation
control applications. They can be used to control bidirectional (PWM), Analog Digital Conversion (ADC), and Proportional-
Buck-Boost DC-DC controllers to ensure improved dynamic Integral (PI) controllers using the MCUs along with
characteristics of the converter at different electrical mathematical calculations. Furthermore, the paper showcases

979-8-3503-5062-3/24/$31.00 ©2024 IEEE 131


Authorized licensed use limited to: National Chung Hsing Univ.. Downloaded on March 11,2025 at 15:56:20 UTC from IEEE Xplore. Restrictions apply.
the implementation of DC-DC control for a buck converter
using TMS320F28379D DSP, one of the MCUs, offering a
coding-free solution that saves time, reduces costs, and is easy
to execute. It also shows an example of parallel processing of
the MCU to ensure faster system response.
First, make sure that the toolboxes for MATLAB Coder,
Simulink Coder, and Embedded Coder are installed on your PC.
Embedded Coder can generate optimized C and C++ codes
from MATLAB and Simulink models, enabling rapid Fig. 1. F28379D launchpad with a running program.
prototyping and deployment of embedded systems. To confirm
the toolboxes installed in your MATLAB version, execute the sequence on the target hardware using Code Composer Studio.
"ver" command in the command window. Choosing Simulink When the execution is completed, you can see the index.html
for code generation simplifies DSP programming by producing file in MATLAB, which will show you the code generation
readable, compact, and efficient C code, ensuring compatibility report for the project. A F28379D launchpad is shown in Fig. 1
across processors [10]. with the blinking GPIO34 LED after running the program.
Since the DSP's flash memory was used for programming, you
II. CCS V11 TARGET CONFIGURATION can toggle the USB switch on and off to verify that the program
First, ensure Code Composer Studio (CCS) version 11 is is still operational and hasn't been removed from RAM.
installed. You should update to CCS version 11 if you currently
use an older version. The Embedded Coder Support Package for III. PWM, ADC, GPIO, AND PI BLOCKS
TI C2000 Processors, which is now supported in MATLAB TMS320F28379D DSP has up to 24 PWM outputs with
2022b, has to be installed. For MATLAB 2023b, you need the enhanced channels, which is adequate to control many three-
C2000 Microcontroller Blockset. While installing the support phase power converters. Sixteen of these ePWM modules are
package, you have to choose the F28379D processor from the High-Resolution capable, as shown in Table 1. SYSCLK is set
microcontroller package list. Then, it will require downloading to 200 MHz, which is the maximum clock speed of the
and installing C2000 ware, TI control suite, TI C2000 Code TMS320F28379D as specified in the CPU clock. Fig. 2 shows
Generation Tools, and TI C2000 ARM Code Generation Tools. two synchronized enhanced Pulse Width Modulator (ePWM)
This process can be done both manually and automatically. blocks; the frequency and duty cycle are the inputs. The pulses
Then, you have to validate the path of these tools. Now, you can for the two ePWM outputs in Fig. 2 are displayed in Fig. 3,
program the microcontroller using Simulink. where they are synchronized with the TBPHS = 1500 (number
of cycles for the time period) phase shift. Observe that each
A. FLASH memory Programming (stand-alone mode) ePWM contains two complementary signals, the switching
You will have to set the configuration parameters to make frequency is 50 KHz, and these two ePWM outputs are 180
the system target file as either "ert.tlc" or "idelink_ert.tlc" on degrees displaced. The duty cycles are 0.33 (=1000/(2*1500))
the code generation page if you plan to operate in RAM and 0.23 (=700/(2*1500)), respectively for channel 1
programming mode. When using stand-alone mode, the (ePWM1A) and channel 3 (ePWM2A).
program is stored in the DSP's flash memory, meaning it won't
be lost if the DSP control card is disconnected from the
computer. Check the “Boot from the flash option” in the
configuration parameters window. These settings in the Model
Configuration Parameters box indicate to EC the type of DSP
being programmed, allowing it to determine the memory
capacity, configure the appropriate peripherals, and operate at
the proper frequency. Make sure the solver is set to fixed-step
and discrete by opening the configuration options; the fixed-
step size should stay auto. Texas Instruments and C2000 should
be selected on the hardware implementation page [11]. For this
tutorial, we will use the LAUNCHXL-F28379D launchpad as Fig. 2. Two synchronized ePWM blocks.
hardware, which is powered by TMS320F28379D DSP.
B. Debug Configurations and Code Running Fig. 4 displays the ePWM Block Parameters to generate two
complementary PWM signals at a duty cycle of 0.5 and a
We can generate the code by clicking the Build, Deploy & frequency of 20 KHz . For a frequency of 40 KHz, the Timer
Start icon. It will connect with CCS V11 automatically and period would be 9999 for up-count mode and down-count
create a .out file for the project. If you click on the ‘View mode. But for up-down count mode, it would be 5000. The duty
Diagnostics’ tab, you will find a link for the project in Code cycle depends on the CMPA value, and the counting mode
Composer Studio. Once you open it in Code Composer Studio, specified in the General tab of ePWM block. Since it is in up-
you will find the C programming files for all the project counting mode, set the CMPA value to 4999.5 to get the duty
subsystems. MATLAB will initialize the executable load

132
Authorized licensed use limited to: National Chung Hsing Univ.. Downloaded on March 11,2025 at 15:56:20 UTC from IEEE Xplore. Restrictions apply.
cycle, D= 0.5, since 4999.5/9999 = 0.5. As observed, input ports
or dialogs can be used to specify the frequency and duty cycle.
Under the General tab, the Timer period can be specified and
calculated using equations (1) and (2). Each action can be
selected from the list of options (Do nothing, Clear, Set,
and Toggle). For this operation, Action when counter=ZERO is
Set, and Action when counter=CMPA on up-count (CAU) is
Clear. Also, the counting mode can be chosen (Up, Down, or
Up-Down).

For up-count and down-count mode:

𝐶𝑙𝑜𝑐𝑘 𝐹𝑟𝑒𝑞𝑢𝑒𝑛𝑐𝑦
Timer period = −1 ()
𝑒𝑃𝑊𝑀 𝐹𝑟𝑒𝑞𝑢𝑒𝑛𝑐𝑦

For up and down count mode:


Fig. 4. ePWM block parameters.
𝐶𝑙𝑜𝑐𝑘 𝐹𝑟𝑒𝑞𝑢𝑒𝑛𝑐𝑦
Timer period = (2)
2 ∗ 𝑒𝑃𝑊𝑀 𝐹𝑟𝑒𝑞𝑢𝑒𝑛𝑐𝑦
Fig. 5 shows an example of converting analog-to-digital
signals connected to the chosen ADC input pins using the
Analog Digital Converter (ADC) block. The ADC produces a
vector of uint16 values as its output. Each ADC has the feature
of a selectable resolution of 16 bits or 12 bits. Since 12 bits are
selected for this case, the range of the output values is 0 to 4095,
and the input channel is ADCINA0. The sample duration is
equal to the period of the output pulse of ePWM (f=20 KHz),
shown in Fig. 6. The “Post interrupt at the end of conversion”
option has to be unchecked. You have to connect the negative

Fig. 3. Synchronized ePWM pulses.


Fig. 5. ADC example.

TABLE I. EPWM OUTPUT SIGNALS

ePWM Module Module Outputs GPIO Pin


ePWM1 ePWM1A GPIO00
ePWM1B GPIO01
ePWM2 ePWM2A GPIO02
ePWM2B GPIO03
ePWM3 ePWM3A GPIO04
ePWM3B GPIO05
ePWM4 ePWM4A GPIO06
ePWM4B GPIO07
ePWM5 ePWM5A GPIO08
ePWM5B GPIO09
ePWM6 ePWM6A GPIO10
ePWM6B GPIO11
ePWM7 ePWM7A GPIO12
ePWM7B GPIO13
ePWM8 ePWM8A GPIO14
ePWM8B GPIO15 Fig. 6. ADC block parameters.

133
Authorized licensed use limited to: National Chung Hsing Univ.. Downloaded on March 11,2025 at 15:56:20 UTC from IEEE Xplore. Restrictions apply.
Fig. 7. PI controller for the duty cycle of ePWM output.

to the ground point and the power supply DC voltage to pin have been provided to handle data transfer between blocks
ADCINA0 when you design, download, and execute this basic running at different speeds and to convert an input signal to a
model on the DSP board. So, by adjusting the voltage from 0 to specific data type.
3V, you can regulate the duty cycle of this PWM signal. Check
the option labeled "Enable ADC start of conversion for module The TMS320F28379D DSP can be programmed using these
A" on the ePWM block. Similarly, you may use the ADC input fundamental settings; however, a few more things may be done
to adjust the PWM output pulse's frequency when you make it to enhance the efficiency of code output. For example, under
an input port. the code generating advisor's Configuration Parameters box,
Fig. 7 shows an example model of using the PI controller to you can select objectives for the code output, like execution,
change the duty cycle of the ePWM output signal. Here, the ROM, and RAM efficiency. You will get a pop-up window
frequency was set to 40 kHz by making the time period 9999 when you click the "Set Objectives" button, allowing you to
and up counting mode. Convenience of design is crucial for the rank the alternatives. When a model is built, it may be analyzed
system controller to ensure the intended operation. It is evident using the verify model option, and
that the rate transition block and data type conversion block

Fig. 8. SCI Transmit block parameters.

Simulink will also offer suggestions for enhancing the


efficiency of the generated code. It is now appropriate to begin
developing your model. Any blocks from discrete block sets,
logic, and math are acceptable. Using the trial-and-error
method, you can check if a block is in the continuous state or Fig. 9. SCI Receive block parameters.
not. You have to add the block to your model and then build the
program. If there are incompatibilities, Simulink will notify
you. To get to the DSP-specific blocks (ADC, GPIO, CAN,
PWM, etc.), you have to drill down to Embedded Coder Support
Package for Texas Instruments C2000 Microcontrollers>
F2837xD. There are also several IQ math, memory operations,
and sensors such as BME280, BMI 160, etc.
IV. SERIAL COMMUNICATION
Fig. 8 shows the Serial Communication Interface (SCI)
transmit block. Fig. 9 shows how the SCI receive block
establishes the serial communication between the C2000 target Fig. 10. BOOSTXL-BUCKCONV and its key components.
hardware and the host computer. USB docking station is

134
Authorized licensed use limited to: National Chung Hsing Univ.. Downloaded on March 11,2025 at 15:56:20 UTC from IEEE Xplore. Restrictions apply.
directly linked to the pins of the SCI_A module in the F28379D voltage of the converter. Fig. 13 shows the output voltage and
launchpad. You can use Serial Transmit and Receive block, inductor current for different voltage requests. It was seen that
MATLAB script, or frame size for this launchpad to build serial the output voltage follows the reference voltage.
communication. Frame size is used to transmit data when the Alongside Voltage Mode Control (VMC), Average
transmit rate is faster than the receive rate [12]. Current Mode Control is also possible for the DC-DC Buck
converter module using the launchpad. For the Average Current
V. CLOSED LOOP CONTROL EXAMPLE Mode control of the Buck converter, the Control Law
The C2000 Digital Power BoosterPack, BOOSTXL- Accelerator (CLA), a 32-bit FPU processor, of the
BUCKCONV, features a non-isolated, digitally controlled DC- TMS320F28379D DSP can be used. It operates in parallel with
DC buck converter. It offers a quick and easy way to learn about the main CPU and is particularly useful for real-time control
digital power supply control using C2000 MCUs. It has Voltage applications where fast and deterministic execution of control
Mode Control (VMC) and Peak Current Mode Control algorithms is critical. Fig. 14 shows output voltage and inductor
(PCMC). A compatible C2000 launchpad can be used to control current of the Buck converter with Average Current Mode
the board. In this case, LAUNCHXL-28379D has been used to control using Control Law Accelerator (CLA) of TMS320
control the BOOSTXL-BUCKCONV. The DC-DC F28379D microcontroller. The spike in inductor current
synchronous buck power stage regulates the power terminal occurred due to rapid change of voltage request.
block at 2 VDC. The BoosterPack has a permanently connected
7.5-Ω resistive load and a 2-Ω software-controlled active load,
which is useful for testing transient performance and loop
tuning [13]. Fig. 11 shows BOOSTXL-BUCKCONV and its
key components. Fig. 12 shows the BOOSTXL-BUCKCONV
BoosterPack connected to the LAUNCHXL-28379D
launchpad. We used this setup to control the Buck converter
using the launchpad.
A model has been developed for the Voltage Mode Control
(VMC) of the Buck converter [14]. It employs a discrete
proportional-integral (PI) controller to minimize the reference
and output voltage error. The ePWM can be used to generate
gate signals for the voltage control of the converter. Fig. 12
shows the ePWM signals generated by the launchpad to control
the high side and low side of the converter to control the output

Fig. 13. Output voltage and inductor current of the Buck converter with Voltage
Mode Control (VMC).

Fig. 11. BOOSTXL-BUCKCONV connected to LAUNCHXL-28379D


launchpad.

Fig. 14. Output voltage and inductor current with Average Current Control.

Fig. 12. Switching signal for the Buck converter.

135
Authorized licensed use limited to: National Chung Hsing Univ.. Downloaded on March 11,2025 at 15:56:20 UTC from IEEE Xplore. Restrictions apply.
VI. CONCLUSION [4] S. Lopez-Blandon, S. Pulgarin-Correa, and E. Giraldo, “Adaptive State
Space Embedded Control of a Synchronous Buck Converter,” in 2023
This paper demonstrates the successful integration of the IEEE 6th Colombian Conference on Automatic Control (CCAC), IEEE,
C2000 microcontroller units with MATLAB and Simulink, 2023, pp. 1–6.
facilitated by the Embedded Coder support package for C2000 [5] M. Metry and R. S. Balog, “An Adaptive Model Predictive Controller for
Current Sensorless MPPT in PV Systems,” IEEE Open J. Power
microcontrollers. It provides clear instructions on programming Electron., vol. 1, pp. 445–455, 2020, doi: 10.1109/OJPEL.2020.3026775.
the microcontrollers using MATLAB Simulink Embedded [6] A. E. Toubal Maamar, M. Helaimi, R. Taleb, M. Kermadi, and S. Mekhilef,
Coder and shows fundamental functions like ADC, PI “A neural network‐based selective harmonic elimination scheme for five‐
controller, PWM, etc. The closed-loop control application on level inverter,” Circuit Theory & Apps, vol. 50, no. 1, pp. 298–316, Jan.
2022, doi: 10.1002/cta.3130.
the buck converter shows how the switching signal can be [7] V. K. Awaar, N. Anjali, M. S. Rani, S. Bannuru, S. Tangallapally, and A.
generated easily using the MCU without manual coding and Siri, “Parameter Estimation and Speed Control of FOC Based PMSM
how its parallel processing power can be used to ensure faster Drive Using F28379D,” in 2022 IEEE 2nd International Conference on
system response. This seamless integration proves highly Sustainable Energy and Future Electric Transportation (SeFeT), IEEE,
2022, pp. 1–6.
effective for real-time control applications, such as artificial [8] J. Qiu, C. Zhu, and Y. Wang, “Automatic Fast Experiment System Design
intelligence-based control, PI control of power converters, Based on Matlab Embedded Code,” in 2021 China Automation Congress
renewable energy systems, electric vehicle systems, etc. The (CAC), IEEE, 2021, pp. 7360–7363.
Embedded Coder support package makes generating code [9] J. Aruni, J. Titus, and K. Hatua, “Design of a DSP-based Control Platform
for Real-Time Simulation of Power Electronic Systems,” in 2021 IEEE
easier and faster than writing it manually. This paper 2nd International Conference on Smart Technologies for Power, Energy
highlighted how this integration can speed up work processes and Control (STPEC), IEEE, 2021, pp. 1–6.
in DSP-based solutions, making them more efficient. [10] J. C. Molina Fraticelli, “Simulink Code Generation: Tutorial for
Generating C Code from Simulink Models using Simulink Coder,” 2012.
REFERENCES [11] “Getting Started with Texas Instruments C2000 Microcontroller Blockset
- MATLAB & Simulink.” Accessed: Feb. 28, 2024. [Online]. Available:
[1] Texas Instruments Inc., “The Essential Guide for Developing with C2000 https://www.mathworks.com/help/ti-c2000/ug/getting-started-with-
Real-Time Microcontrollers (Rev. F)”. C2000-example.html
[2] N. Rigogiannis, D. Voglitsis, and N. Papanikolaou, “Microcontroller Based [12] “Serial Communication Using SCI Blocks - MATLAB & Simulink.”
Implementation of Peak Current Control Method in a Bidirectional Buck- Accessed: Jan. 29, 2024. [Online]. Available:
Boost DC-DC Converter,” in 2018 20th International Symposium on https://www.mathworks.com/help/ti-c2000/ug/serial-communication-
Electrical Apparatus and Technologies (SIELA), Bourgas: IEEE, Jun. example.html
2018, pp. 1–4. doi: 10.1109/SIELA.2018.8447148. [13] Texas Instruments Inc., “C2000 Digital Power Buck Converter
[3] A. Elrajoubi, S. S. Ang, and A. Abushaiba, “TMS320F28335 DSP BoosterPack Design Guide (Rev. A)”.
programming using MATLAB Simulink embedded coder: Techniques [14] “Closed Loop Control of a DC-DC Buck Converter - MATLAB &
and advancements,” in 2017 IEEE 18th Workshop on Control and Simulink.”https://www.mathworks.com/help/ti-c2000/ug/dc-dc-buck-
Modeling for Power Electronics (COMPEL), IEEE, 2017, pp. 1–7. converter.html

136
Authorized licensed use limited to: National Chung Hsing Univ.. Downloaded on March 11,2025 at 15:56:20 UTC from IEEE Xplore. Restrictions apply.

You might also like