TI+Lab+2 Intro To Model Based Design With Simulink Manual
TI+Lab+2 Intro To Model Based Design With Simulink Manual
Introduction to Model-based Design Using MATLAB/Simulink, Code Composer Studio, and the TI 6713 DSK
This lab is mostly based on the Mathworks webinar, Implementation and Verification on TI DSPs with Link for Code Composer Studio++ 3.0" located at: http://www.mathworks.com/cmspro/webconf15055.html The webinar takes approximately 1 hr to watch uninterrupted. Watch this prior to performing this lab if possible. Not all parts of the webinar can be performed in the lab, such as the Processor in the Loop function, without Real Time Workshop Embedder Coder. Additional procedures are described not included in the webinar. Hardware Requirements: TI 6713 DSK PC Software Requirements: Mathworks Products - MATLAB R2007a - Simulink - Signal Processing Toolbox - Signal Processing Blockset for Simulink - Real Time Workshop (w/o Embedder Coder) - Link for Code Composer Studio - Embedded Target for TI C6000 DSP Texas Instruments Products - Code Composer Studio 3.1 (available with the TI 6713 DSK) NOTE: MATLAB 2007b products are not compatible with Code Composer Studio (CCS) 3.1 which is what we have available. You must instead use version 2007a. Installation: 1. Ensure that all of the software products are installed. They should be. Hardware Setup 1. Connect the TI 6713 eval board to the PC using the USB cable. 2. Connect power to the board. 3. Dont press any buttons on the board. PART 1: CREATE A CCS PROJECT FROM A SIMULINK MODEL 1. Make sure that the 6713 Simulator is setup in CCS a. Close CCS if open b. Clear MATLAB workspace variables c. Go to Start Programs Texas Instruments Code Composer Studio 3.1 Setup Code Composer Studio v3.1 d. Ensure that C6713 Device Cycle Accurate Simulator is included in your System Configuration tree on the left. If not, find it in the center window on the Factory
Boards tab and select Add at the bottom. Then select Save and Quit. When you asked if you would like to open CCS, select Yes. 2. When the parallel Debug Manager appears, double click on the TMS3206713 and this will open up the CCS main window for this device. 3. Go back to the MATLAB command window, and type dspafxr to open up the example reverb model in Simulink. A Simulink model similar to Figure 1 below should appear.
Figure 1 4. You should adjust the model to look Figure 1 above. You may have to delete some of the other junk in the model, add the Chirp source and Time Scope sink. If you click on the colorful button shown in the top right of Figure 1, or type simulink in the Matlab command window, this will open the Simulink Library Browser. You can find the Chirp block under the Signal Processing Blockset within the DSP Sources group, and the Time Scope is located in the DSP Sinks group. Click, drag, and drop these into the model if they dont already exist, and connect them as shown above. 5. Click the play button and then double click on the Time Scope to ensure that the model runs in Simulink and that an output signal is generated. 6. Open up the Simulink Library Browser a. Go to the Link for Code Composer blockset b. Go to Target Preferences c. Drag the Custom Board block into the model. The Custom Board will automatically set many of the Real Time Workshop settings. 7. Double-click on the Custom Board block a. Under Board Properties, select the C6713 in the Processor field. b. Check the Simulator check box. c. Under Link to IDE, select C6713 Device Cycle Accurate Simulator i. Notes: The Memory Tab settings will determine the content of the .cmd file (Memory map settings) which is generated by Link for CSS when the project is built. ii. The Sections tab allows you to specify which sections of code get placed in which sections of memory. 8. Click OK to accept the changes, and go back to the example reverb model.
9. Go to Simulation Configuration Parameters, or just type Ctrl+E. 10. In the Select tree on the left, go to Real Time Workshop Link for CCS a. Under Runtime , set Build Action to Create Project 11. Accept the settings, close Configuration Parameters, and go back to your model. 12. Press Ctrl+B to create the project in CCS. 13. Go back to the CCS window and look at the generated code. a. Under the Source folder, find the <model name>.c file. i. This should include the Model Step function which is the main function for the primary algorithm. It also defines local I/O variables. b. Find the <model name> data.c file i. This contains all of the parameters set in the Simulink model. c. Find the MW_c6XXX_csl.c file i. This is the Mathworks version of Chip Support Library ii. It contains all interrupt service routines (if any) and time code/config d. Find the <model name>_Project Generator.cmd i. This contains the memory map settings generated by Link for CCS 14. Press F7 to build the code. Summary of Generated Files in the CCS Project Created by Real Time Workshop - .c and .h files to implement the algorithms described by the Simulink model Created by Link for Code Composer Studio - The processor specific files (i.e. those required to implement the algorithm specifically on the TI 6713 processor) that the designer would normally have to write manually. o Memory Map - .CMD files o Real Time scheduler and timer code o Interrupt handling code PART 2: BUILD AND EXECUTE A SIMULINK MODEL ON THE TARGET PROCESSOR In this part of the lab, you will use the Embedded Target for C6000 DSP blockset to implement an audio processing algorithm on the target processor using the audio inputs and output on the board. 1. Clear your MATLAB workspace variables a. Note: In general, every time want to rebuild a project from Simulink to CCS, always clear your MATLAB workspace variables. 2. Close CCS. 3. Go back again to Start Programs Texas Instruments Code Composer Studio 3.1 Setup Code Composer Studio v3.1 4. Click on the C6713 Device Cycle Accurate Simulator and click Remove to remove it from your System Configuration on the left. Press Save and Quit and choose to open up CCS. 5. In the Parallel Debug Manager window, double-click on the CPU_1 processor and the CCS window for that device will open. 6. Go back to your reverb example model. 7. Delete the Chirp source and Time Scope sink from the model. 8. Open the Simulink Library Browser and go the Embedded Target for C6000 DSP blockset. a. Within the C6713 DSK Board Support group, you will find several blocks including the ADC , DAC ,LED ,Reset, and DIP Switch. The ADC and DAC blocks can be used in your Simulink model for your inputs and outputs and will provide generated code to configure the codec and 6713 peripherals. 9. Drag an ADC block into your reverb model and place it as the Source where the Chirp was previously.
10. Drag a DAC block into the model and connect it at the reverb output where the Time Scope was located. 11. Double-click on the ADC block. a. Notice that a drop down allows you to select between the Line In or Mic In. Set it to Line in for this example. b. Set the input sampling rate to any option for this example, keeping in mind that this affects the reverb time constant. c. The other options are pretty much self explanatory, and the default settings should be fine. 12. Double-click on the DAC block. a. Note the other possible settings, although nothing should need to be changed for this example. 13. Click on the Custom Board block and delete it. 14. Go to Simulink Library Browser Target for TI C6000 C6000 Target Preferences 15. Find the C6713DSK block and drag it into the model. This target preferences block is already configured for the TI 6713 DSK. No additional changes to this block are needed for this example. 16. Press Ctrl+E to access the Configuration Parameters. 17. In the Select tree under Real Time Workshop Link for CCS, ensure that under Runtime the Build Action: is set to Build and Execute. 18. Prior to building the model, go back to Code Composer Studio and make sure that the target is connected. An indicator is in the bottom left corner of the window. One can repeatedly Connect and Disconnect the target by pressing Alt + C . 19. After the target it connected, go back to your model. 20. Press Ctrl+B . In this case, because the Build Action was set to Build and Execute in your Configuration Parameters settings, this action will sequentially create the CCS project, build the project code, and the begin running the algorithm on the target board. 21. Test the algorithm by sending line level audio into the Line In port, and listen through speakers connected to the Line Out port. Brief Intro to Profiling 1. Double click on the Target Preferences block. a. Make Simulator unchecked b. Make High Speed RTDX checked c. Set Operating System to none d. Click OK to save changes and close out target preferences window 2. Press Ctrl E to access Configuration Parameters. a. In the Select tree on the left, click on :Real Time Workshop Link for CCS b. Under Code Generation, check the box for Profile real-time task execution c. Under Runtime, ensure that the Build and Execute is selected. d. Click OK to save changes and close the window. 3. At your Simulink model, press Ctrl + B to build and execute. It will generate a project in CCS and begin running. Go to CCS. Let it run for a few seconds and then press Shift + F5 to halt the program. 4. Go back to MATLAB to the command window. a. Notice in the workspace , CCS_Obj b. At the command prompt, type: profile_execution(CCS_Obj) 5. An HTML report will be generated that describes some of the performance stats. 6. The Figure generated will also illustrate the used/remaining time for the clock rate.
PART III: CREATE YOUR OWN AUDIO SIGNAL PROCESSING ALGORITHM In this part of the lab you will create your own signal processing algorithm and use the DIP Switch and LED blocks located with the Target for TI C6000 Library to enable use of the DIP Switches and LEDs on the 6713 board to control your algorithm in real time. 1. So far youve created a simple reverb model. Use the Subsystem block under the Common blockset and place the reverb model into its own system. You can do this by cutting the reverb model and pasting it into a new Subsystem block. A signal sent into the input port should be reverberated at the output port. 2. Create a new subsystem performing an audio signal processing algorithm of your choice. Examples might include a simple tremolo, a filter, delay, distortion, etc. Contain this within an additional Subsystem block as you did with the reverb. This can all be done with the same Simulink model. 3. Test your new algorithm by feeding it will a source (i.e. a .wav file or chirp, etc) and monitoring it with a sink (i.e. a Time Scope, or .wav out, etc) 4. Once your new algorithm is performing properly, setup the model so that you can switch between the reverb subsystem and your new algorithm in real time using one of the DIP Switchs. Youll need to use a Multi-port Switch located in the Signal Routing library. This is shown in Figure 2 below.
Figure 2 5. The top port is an indexing port, while the bottom two are the selectable input ports. While the top port is given a 1 it will select the 1st input port and when given a 2 it will select the 2nd. You can change the number of inputs and use the same scheme for any desired number of input ports. The goal is to push a momentary DIP Switch on the eval board and switch between your algorithm and the reverb. Both may be running simultaneously, but only the output of one is sent to the DAC. In order to do this, you will have to use a combination of other simulink blocks such that when the DIP Switch is toggled; either a constant 1 or a constant 2 is provided to the index port of the Multi-port switch. One possible method is use a counter. To figure out how to use the DIP Switch, read the description of the DIP Switch block located in the Target for TI C6000 library and also see the help for C6713 DSK DIP Switch. 6. Furthermore, you want to use the LEDs on the eval board to indicate which algorithm is running. Use the LED block from the same library in your model to accomplish this task. You might want to have one LED lit for one algorithm and a different LED for the other. 7. Furthermore, your reverb model in Figure 1 contains a few different parameters that you might want to change in real-time such as the feedback gain, the delay time, or the wet/dry mix. Use another DIP Switch to adjust one or more of these other parameters. The trick here is use the switch to increment through a range of values. One possible method is use a counter.