Professional Documents
Culture Documents
Experiment 2 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and Matlab Graphic User Interface (GUI)
2.1 Objectives
The objective of this experiment is to familiarize the students with the basics of TI C2000 microcontroller, Matlab Real Time Workshop, Code Composer Studio, and Matlab Graphic User Interface (GUI). Students learn how to develop a Simulink program to generate a PWM signal with adjustable duty cycle on one of the I/O pins of the microcontroller.
The ultimate goal of the program we develop in this laboratory is for digital control of a buck and/or boost converter using Matlab/Simulink based on a to-be-developed setup shown in the following diagram. In this lab session, we focus on the generation of a PWM signal with controllable duty cycle on one of the I/O ports of the microcontroller. The duty cycle of the PWM signal will be adjusted online in Matlab/Simulink environment. The PWM signal will be interfaced to the designed buck and/or boost converter in the upcoming lab sessions.
Requirements:
1) Software: Matlab/Simulink and Code Composer Studio 2) Hardware: C2000 Microcontroller(TMS320F28035) and Blackhawk USB2000 emulator
3 2. Initializing the Simulink model by deploying the Target Preference Board block to your Simulink model
If you get this warning window, click YES. 3. Configuration of the Target Preference Board If you double click the Target Preference Board block, you will be able to open the configuration window like below. Click the Get from IDE button. The Target Preference Board will automatically configure your Simulink model by linking to Code Composer Studio.
4 IDE Support will show the information of TI C2000 micro-controller, and confirm the micro controller setting by clicking OK button.
4. Save your Simulink model in a temporary folder in drive C You should save your Simulink in the temporary folder under C drive to link to Code Composer Studio.
Ex) C:\TEMP\exp2\exp2mdl
5 5. Designing a power electronics control module of PWM Add the From RTDX block and "ePWM block in your Simulink model.
6. Setting the From RTDX block Open the configuration window of From RTDX block by double clicking the block, and then configure the RTDX by following the below settings. You must disable the Frame-based option.
Whatever channel name is given here that should be written in the code of the section 2.2.2.6
7. Seting the ePWM block Since the CPU clock of the microcontroller is 60Mhz, we can set the Timer period as 2400 pts to set a period of PWM at 40 s, 2400 pts = 40 s 60 Mhz . Other parameters should be configured as shown in below.
Set the fixed step size at 1e-5 sec and build action as build only.
2.2.2
Designing a control interface by using the Matlab Graphic User Interface(GUI) 1. Starting GUI
Alternatively, you can type GUIDE in the Matlab command window, and GUIDE Quick Start dialog will pop up in your MATLAB.
" 2. Creating a new project Selecting the Blank GUI (default), and then click the ok button, the GUIDE layout editor will appear in your MATLAB like below.
GUIDE layout has the following components in component palette: : Push Button : Slider : Radio Button : Check Box : Edit Text : Static Text : Pop-up Menu : List box : Toggle Button
10
11 4. Configuration settings for each components of above control interface Changing of strings and font sizes of each components.
12
13 5. Save the designed control interface This control interface should be saved in the same folder where the Simulink model is saved, and then the m-file for this GUI will be automatically created in the same folder. Ex) C:\TEMP\exp2\exp2cntrGUI. We need to edit this file and to initialize the Code Composer Studio setting and also to define the functionality of each component we used in the GUI.
Remember how we tagged each component of the GUI program. Those Tags are used in the following sections to edit the GUI program.
6. Editing exp2cntrGUI m-file to initialize the Code Composer Studio settings To initialize the CCS, we need to include the following code in the program as depicted below.
global cc; cc=ticcs; configure(cc.rtdx,1024,4);%setting buffer memories for RTDX% open(cc.rtdx,'duty_ichan','w'); % open RTDX channel for duty_ichan% enable(cc.rtdx,'duty_ichan'); % enable duty_ichan RTDX channel% enable(cc.rtdx); % enable RTDX% cc.rtdx; % link to CCS%
14
7. Editing exp2cntrGUI m-file to define the functionality of Enter Push Button To define the functionality of the Enter push button, we need to write the code in Enter_Callback function as follows:
global cc; dutyin = str2num(get(handles.dutyedit,'string')); %convert strings of the dutyedit to nubmer% writemsg(cc.rtdx,'duty_ichan', int32(dutyin)); % write the value of dutyedit to duty_ichan rtdx channel%
15
8. Editing exp2cntrGUI m-file to define the functionality of Run Halt buttons To define the functionality of the Run and Halt push buttons, we need to write the code in Run_Callback and Halt_Callback functions as follows:
% --- Executes on button press in Run. function Run_Callback(hObject, eventdata, handles) % hObject handle to Run (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global cc; run(cc); % --- Executes on button press in Halt. function Halt_Callback(hObject, eventdata, handles) % hObject handle to Halt (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global cc; halt(cc);
16
2.2.3
Implementation 1. Turn on the TI C2000 micro-controller You must turn on the TI C2000 micro-controller by selecting the USB side of toggle switch.
Type ticcs in the Matlab command window to check the connection between the TI C2000 micro-controller and Matlab. If the connection is established, you will get the following message.
3. Build C code language from simulation model Users can build the simulation model by clicking the build button in the simulation toolbar.
And then, IDE link links to Code Composer Studio to generate C code. If build is completed, Code Composer Studio must be linked like below.
4. Loading C code on the target board Since the build action is selected as build, use must load the C code on the target board manually by selecting load program command in the File option.
1!
5. Run the m-file You can run the control interface by clicking RUN button of toolbar of m-file.
1"
Once you observe the PWM waveform on the oscilloscope, change the duty cycle of the PWM waveform by typing into the value in the Duty cycle box of the GUI, click on Enter button, and confirm the result on the oscilloscope screen. 7. Shut Down Sequence
Once you finish the lab, shut down the set up based on the following sequence: -Halt the GUI program by clicking on Halt button - Close the MATLAB program - Turn off the TI C2000 micro-controller by the toggle switch -Turn off the oscilloscope