21
Experiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and Matlab Graphic User Interface (GUI) 3.1 Objective This experiment is in continuation of Experiment 2. In Experiment 2, the students learned how to generate and send a PWM signal to one of the I/O ports of the target board (microcontroller) by using Matlab/Simulink. In this experiment, the students learn how to read and import a PWM signal from one of the I/O ports of the microcontroller and plot it in Matlab/Simulink. 3.2 Building a Simulink Model 1. Create a new Simulink model

Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

Embed Size (px)

Citation preview

Page 1: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

Experiment 3 Introduction to TI C2000 Microcontroller, Code Composer

Studio (CCS) and Matlab Graphic User Interface (GUI)

3.1 Objective

This experiment is in continuation of Experiment 2. In Experiment 2, the students learned how to generate and send a PWM signal to one of the I/O ports of the target board (microcontroller) by using Matlab/Simulink. In this experiment, the students learn how to read and import a PWM signal from one of the I/O ports of the microcontroller and plot it in Matlab/Simulink.

3.2 Building a Simulink Model

1. Create a new Simulink model

Page 2: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

2. Initialize the Simulink model by deploying the Target Preference Board block to your Simulink model

3. Configure 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.

Page 3: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

Click the Get from IDE button. The Target Preference Board will automatically configure your Simulink model by linking to Code Composer Studio. IDE Support will show the information of TI C2000 micro-controller. Click ok to close the window.

4. Save your Simulink model in a temporary folder in C drive You should save your Simulink in the temporary folder under C drive.

Ex) C:\TEMP\exp2\exp2mdl

Page 4: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

5. Design a power electronics control Simulink model Add the ADC, Rate Transition, Constant, IQN x int32, Data Type Conversion, and To RTDX in your Simulink model.

Page 5: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and
Page 6: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and
Page 7: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

6. Configure the ADC block Open the configuration window of ADC block by double clicking on the block and follow the below settings.

Page 8: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

7. Configure the Rate Transition block The Rate Transition block transfers data from the output of a block operating at one rate to

the input of a block operating at a different rate. Configuration parameters are shown in the below figures.

8. Configure the scaling factor of the ADC Piccolo F 28035 has a built-in 12-bit ADC (Analog to Digital Converter) with an input range of 0 to 3.3 V. To compensate an offset, a division of 0.86 is added to the lower side. The ADC converts the analog signals to a 12 bit digital signal. When a 3.3 V input signal is applied to the ADC, it will convert to the maximum digital value, 4095(2^12). When the 0 V is applied to the ADC, it will convert to the minimum digital value, 0. Therefore, converted analog signal should be re-scaled by the scaling factor, 3.3/4096/0.86 = 0.000971.

Since the microcontroller performs the mathematical calculation based on fixed-data format, the constant source block should be configured as the fixed 32 bit integer value. The configuration of the constant block is depicted in the below figure.

Page 9: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

9. Configure the Data Type Conversion block The Data Type Conversion block converts the data type of its input to the required one at its output. Since the RTDX requires the int32 data type, input must be converted to the data type of int32.

Page 10: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

10. Configure the To RTDX block

11. Configure the simulation parameters

Set the fixed step size at 1e-5 sec and the build action as build only.

3.3 Design a control interface by the Matlab Graphic User Interface(GUI)

1. Start the GUI

Whatever channel name is given here that should be written in the code of the section 3.3.6

Page 11: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

Alternatively, you can type GUIDE in the Matlab command window, and GUIDE Quick Start dialog will pop up in your MATLAB.

Page 12: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

2. Create a new project

Select the “Blank GUI (default)” and then click the ‘ok’ button, the GUIDE layout editor will appear in your MATLAB like below.

GUIDE layout has below components in component palette:

: Push Button

: Slider

: Radio Button

: Check Box

: Edit Text

: Static Text

: Pop-up Menu

: List box

: Toggle Button

Page 13: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

: Table

: Axes

: Panel

: Button Group

: ActiveX control

3. Design the control interface to plot the data read from the target board

This control interface consists of one Axes, one Edit box, two Push Buttons, and two Static Text components. The Axes box will plot the obtained data from the DSP as well as showing its numerical value in the Edit box. Two Push Buttons will be used as Run and Halt, respectively. Two Static Texts will be used to label each component. The sample control interface is shown in the below figure. Specify the Tag names for the components and change/edit the m-code associated with the GUI accordingly.

Page 14: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

4. Save the designed control interface model in C:\TEMP

5. Edit exp3cntrGUI m-file to initialize the output pl ot settings % Initializing output plot settings % set(handles.figure1, 'visible' , 'off' ) axes(handles.axes1); set(handles.axes1, 'xlim' ,[0 100]); set(handles.axes1, 'ylim' ,[-1 5]); set(handles.axes1, 'xlimmode' , 'manual' ); set(handles.axes1, 'ylimmode' , 'manual' ); set(handles.axes1, 'layer' , 'bottom' ); set(handles.axes1, 'nextplot' , 'add' ); xlabel( 'Fixed steps' ); ylabel( 'Analog output(V)' ); % Plot some dummny data first to get axis handles % allNaN = NaN*ones(1,100); plot(allNaN); handles.h1 = line( 'parent' ,handles.axes1);

Page 15: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

6. Edit exp3cntrGUI m-file to initialize the Code Composer Studio settings % Initializing CCS settings % global cc; cc=ticcs; configure(cc.rtdx,1024,4); open(cc.rtdx, 'ochan1' , 'r' ); enable(cc.rtdx, 'ochan1' ); enable(cc.rtdx); cc.rtdx

Edit exp3cntrGUI m-file to plot data on the Axes of GUI and to show numerical Ydata values on the Edit box % Read data from Target Board, and plot them on the axes1 % frameSize = 1; xlimit = 100; NumOfFrames = xlimit/frameSize; yLines = handles.h1; set(handles.figure1, 'visible' , 'on' ); r = cc.rtdx; while (isenabled(cc.rtdx)) set(yLines, 'ydata' , allNaN, 'xdata' , [1:xlimit]); pause(1e-5); for k = 1:NumOfFrames if ~ishandle(yLines) return ; end

Page 16: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

yAll = get(yLines, 'ydata' ); x = (k-1)*frameSize+1; y = (k-1)*frameSize+frameSize; % Read Data from the Target through RTDX % numMsgs = r.msgcount( 'ochan1' ); if (numMsgs > 0), if (numMsgs > 1), r.flush( 'ochan1' ,numMsgs-1); end yAll(x:y) = readmsg(cc.rtdx, 'ochan1' , 'int32' ); set(handles.dataedit, 'String' ,num2str(yAll(y))); end set(yLines, 'ydata' ,yAll, 'xdata' ,[1:xlimit]); pause(1e-5); end end

7. Edit exp3cntrGUI m-file to define the functionality of “Run” and “Halt” buttons % --- 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 v ersion of MATLAB % handles structure with handles and user data ( see GUIDATA)

Page 17: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

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 v ersion of MATLAB % handles structure with handles and user data ( see GUIDATA) global cc; halt(cc);

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.

2. Check the connection between the Matlab and TI C2000 micro-controller

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.

Page 18: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

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.

Page 19: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

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.

Page 20: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

5. Run the m-file You can run the control interface by clicking RUN button of toolbar of m-file.

6. Plot the PWM waveform in GUI

Note : Analog signal is connected to ADC A0 port for this lab manual

Page 21: Experiment 3 Introduction to TI C2000 Microcontroller ...ece495/Power_Electronics_Lab/exp3.pdfExperiment 3 Introduction to TI C2000 Microcontroller, Code Composer Studio (CCS) and

Once you observe the PWM waveforms, 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