Matlab and Ccs Interface Manual With Filter Program
Matlab and Ccs Interface Manual With Filter Program
Matlab and Ccs Interface Manual With Filter Program
V1.0
EdGate Technologies #68,15th Cross, 1st Block, R.T.Nagar, Bangalore: 560 032 PH: 080 23535125 /8. www.edgate.in
Page 1
EdGate Technologies
V1.0
Contents
Requirement verification System requirements Mathworks software requirements Texas instruments software requirements Hardware set up Procedure to run demo program Procedure for creating new model FIR Filter IIR Filter Aaudio loopback with sw,LED,reset peripheral Modulation and Demodulation
Page 2
EdGate Technologies
V1.0
implementation of your Simulink model TheEmbedded Target for TI C6000 DSP supports TI C67x loating-point DSPs and C64x and C62x fixed-point DSPs, including onboard and onchip DSP peripherals. It automates the creation of Code Composer Studio projects and supports several evaluation boards, including the DM642EVM, C64 I 6DSK, C671 3DSK, C6711DSK, and C670IEVM.
Page 3
EdGate Technologies
V1.0
KEY FEATURES
Generates documented, readable C code in Code Composer Studio project
format using Real time Workshop (RTW). This generated code can be edited for further changes. The Embedded Target for C6000 DSP Platform integrates Simulink and MATLAB with TI's eXpressDSP tools and C6000 DSP processors. It consists of Simulink libraries for designing and simulating DSP applications. These libraries include key operations such as Multirate, and adaptiveiltering transforms matrix manipulation and linear algebra statistics spectral analysis Using these libraries you can develop digital signal processing applications that have any of the following characteristics:
Single rate
Page 4
EdGate Technologies
V1.0
Matlab used must be compatible with ccstudi oversion (for example matlab2007A compatible with ccs3.1 and ccs3.3, matlab2008A and B are also compatible with ccs3.1,for more information on compatibility check matworks website)
Page 5
EdGate Technologies
V1.0
Page 6
EdGate Technologies
V1.0
Hardware setup
We will make use of function generator and an oscilloscope. Both will be connected to the TI C6713 on line-in and line-out connectors. Frequency of Carrier Signal is fixed at 15 kHz while the message signal is varried from the function generator. Since DSK C6713 ensures realtime simulation, once the message signal is varied we will see on oscilloscope that modulated signal is also varying. Lets discuss different steps involved.
EdGate Technologies
V1.0
embedded application using the full computational power of MATLAB. This can be used to assist DSP debugging and development.Another possible use is for creation of MATLAB scripts forverification and testing of algorithms that exist in their final implementation on an actual DSP target.Before discussing the methods available with the link object,it's necessary to select a DSP target. When the link is created, it is specific to a particular CPU, (i.e. a DSP processor) so selection is required before proceeding. In general, the selection process is only necessary for multiprocessor configurations of Code Composer Studio
Page 8
EdGate Technologies
V1.0
echo off; Another selection option is a GUI tool called 'boardprocsel'. Please Note - the CPU that is selected in the GUI will be used for the rest of this tutorial. For single processor installations, of Code Composer Studio, simply select 'OK' from the message box to continue.
4. Press any key to continue, then select aDSP from the GUI (or click OK): boardprocsel
[boardNum,procNum] = boardprocsel boardNum = procNum =0 drawnow; 0
echo off The goal of this selection process is a board numberand processor number that uniquely identify a particulartarget DSP. These values are then applied during the link creation.You selected board number = 0, and processor number = 0Next, the actual connection between the MATLAB command line and Code Composer will be established. This link is represented by a MATLAB
Page 9
EdGate Technologies
V1.0
object, which for this session will be saved in variable 'cc'. The link object is created with the 'ccsdsp' command, which accepts the board number and processor number as input parameters. Other properties can also be defined during the object creation; refer to the 'ccsdsp' documentation for more information on these properties.The generated 'cc' object will be used to direct actions to the designated DSP chip. Therefore, it will appear in all commands that follow the object creation. Naturally, in multiprocessor implementations it is possible to have more than one link object. NOTE: Before proceeding, your DSP hardware should be reset and configured as needed for operation by Code Code Composer.
timeoutValue = 10; % time-out value in seconds set(cc,'timeout',timeoutValue); % Set CCSDSP default time-out value echo off You may have noticed Code Composer appear briefly when 'ccsdsp' was called. If Code
Composer was not running before the link is established, it is started and then placed in the background.In most cases, you will need to interact with Code Composer, so the first method that will be introduced (called 'visible')controls the state of Code Composer on the desktop. This accepts a Boolean input that makes Code Composer visible (1) or invisible (0) on the desktop. For the rest of this tutorial, we will need to interact with Code Composer, so we'll use 'visible' to bring it up to the desktop.
Page 10
EdGate Technologies
V1.0
ERROR1:
Solution: make sure that your dsp board is correctly connect. remove power supply and reconnect it and try the above comments ie ccsdsp ERROR2:
Page 11
EdGate Technologies
V1.0
Could not connect to CCS. Please ensure your CCS installation is set up properly. Exiting CCSTUTORIAL demo... Solution: Make sure that your usb cable is connect properly,remove and reconnect and try Make sure that your matlab version support your ccs version(2007A is compatible with ccs3.1 and ccs3.3) IF stil giving ths same error then uninstall all ccstudio files and TI drivers from your PC also uninstall matlab and its related files.then again install ccstudio and matlab
'isrtdxcapable' - reports CPUs ability to perform RTDX(tm) transfers. The next segment will demonstrate these methods.
Page 12
EdGate Technologies
V1.0
Board number
:0
Page 13
EdGate Technologies
V1.0
is to create executable code for the target DSP with Code Composer. For this tutorial, a Code Composer project file and a board specific executable were created and included with MATLAB. We will first attempt to load the included executable directly, and if the load fails (could be because it is a different board or processor), we will build the included project. The following set of commands will locate the tutorial project and load it into Code Composer. This will use the 'open' method, which can direct Code Composer to load a project file or a program file.
Page 14
EdGate Technologies
V1.0
BuildOpts: [1x1 struct] ProjectAction: 'upToDateProj-upToDateProg' RebuildDemo: 0 demoPjt.ProjectFile ans = C:\ProgramFiles\MATLAB\R2007a\work\LinkForCCSDemos_v3.0\ccstutorial\c6x\c67x\ccstut. pjt demoPjt.DemoDir ans = C:\Program Files\MATLAB\R2007a\work\LinkForCCSDemos_v3.0\ccstutorial\c6x\c67x
You should notice the tutorial's project loaded in Code Composer.Examine the files in Code Composer that comprise this project the main source file used by this tutorial is 'ccstut.c', a linker command file (*.cmd) and vector table source file (*.asm), which will be different, depending on the DSP family you are using. Before building this project, we will attempt to load the included executable. This will use the 'load' method, which should only be used for program files.The 'Link for Code Composer Studio' includes methods for reading the target's symbol table to give direct access to data in the DSP memory. NOTE: The symbol table is only available after the program file is built and then loaded into the DSP. Notice the results of checking the symbol table for the variable 'ddat' before and after the load.
Page 15
EdGate Technologies
V1.0
Page 16
EdGate Technologies
V1.0
be specified by either a source file location or a physical memory address.For this tutorial, we need to insert a breakpoint at line 64 of the 'ccstut.c' source file.To assist your visibility of this action, the method 'open' is used to display the source file in Code Composer. Furthermore, the 'activate' method will force this file to the front.(Although it is not demonstrated here, 'delete' can be used to remove a breakpoint.)
activate(cc,srcfile,'text') % Bring the source file forward insert(cc,srcfile,brkpt) echo off Examine the source file 'ccstut.c' in the Code Composer Studio source editor area. There should be a breakpoint on line 64 (indicated by a red dot). Next, locate the two global data arrays: 'ddat' and 'idat', which are located at lines 44 and 45 in this file. These DSP memory arrays can be accessed directly from MATLAB command line using the 'read' and 'write' methods.To control target execution, use the 'run','halt' and 'reload' methods. The following section will demonstrate these methods. Note: This approach to access DSP memory is powerful but rudimentary. Later in the tutorial, we'll introduce an easier method based on C variables (supports C6x, C54x, C55x, R2x, R1x, OMAP % Insert breakpoint at line 64
Page 17
EdGate Technologies
V1.0
Page 18
EdGate Technologies
V1.0
idatV = -1 508 647 7000 Compare Data: idat, ddat with Code Composer, then press return write(cc,address(cc,'ddat'),ddat_value) % Modify memory values write(cc,address(cc,'idat'),idat_value) run(cc,'runtohalt',20); % Resume execution from breakpoint, then modify % Read memory values
ddatV = read(cc,address(cc,'ddat'),ddat_type,4) ddatV =3.1416 12.3000 0.3679 0.7071 idatV = read(cc,address(cc,'idat'),idat_type,4) idatV = 1 restart(cc); 2 3 4
For Assembly language programmers, there are also methods to access CPU registers: 'regread' and 'regwrite'.Press any key to continue: regread,regwrite tReg = regread(cc,'A0','2scomp') tReg = 0 regread(cc,'B2','binary') ans = 0 regwrite(cc,'A2',tReg,'2scomp') regread(cc,'A2','2scomp') ans =0 % verify the value previously written % unsigned version of B2 % 2's complement version of A0
Page 19
EdGate Technologies
V1.0
echo off Direct access to DSP memory is powerful, but for C programmers it is more convenient to manipulate memory in ways consistent with the defined C variables. This type of access is implemented using MATLAB objects as representations of embedded entities. First, let's take a look at the same data values that we explored above but now we'll manipulate them using objects. First, we'll restart the program and apply the 'list' method, which queries Code Composerfor information, on 'idat', i.e. the global C variable of intere
goto(cc,'main') % Open file where 'main' is found and set the CCS cursor to the start of 'main' run(cc,'main') % Run to start of 'main' - ensured Embedded C variables get initialized listI = list(cc,'variable','idat') % Returns structure of information about global variable: 'idat'listI = idat: [1x1 struct] listI.ida ans = name: 'idat' isglobal: 0 address: [38836 0] size: 4 bitsize: 16 type: 'short'
Page 20
EdGate Technologies
V1.0
'createobj',you can directly read the entire variable or access individual elements of an array. Note: Up to this point all methods were applied to the original 'cc' object that was created with 'ccsdsp'. The 'cc' object represents communication with a particular embedded processor in Code Composer Studio.However, for the remainder of this tutorial, methods are applied to many different objects. In typical object-oriented fashion, the action performed by a method will depend on it's object. The relevant object is always the first parameter passed to the method. For example, in thefollowing section, 'cvar' is an object representing the embedded 'idat' variable.
Address units per value : 2 au Representation Size : signed :[4] : 8 au : row-major : little
Page 21
EdGate Technologies
V1.0
read(cvar) % Reads the entire embedded array into the MATLAB workspace ans = -1 508 647 7000
read(cvar,2) % Reads only the second element ans = 508 write(cvar,4,7001) % Modifies the fourth element to 7001 read(cvar) % See changes ans = -1 508 647 7001
read(cvar,[1 cvar.size]) % Read only first and last elements ans = -1 echo off The previous 'read' takes the raw memory values and converts theminto equivalent MATLAB numeric values. The conversion that gets applied is controlled by the properties of the object, which were initially configured in 'createobj' to settings appropriate for your DSP architecture and C representation. In some cases, it is useful to alter these default conversion properties. Several properties such as 'endianness', 'arrayorder' and 'size' canbe directly modified using 'set'. More complex changes are possible using methods such as 'convert' and 'cast', which adjust multiple properties simultaneously. 7001
Page 22
EdGate Technologies
V1.0
NUMERIC Object stored in memory: Symbol name Address Data type Word size : idat : [ 38836 0] : unsigned short : 16 bits
Address units per value : 2 au Representation Size : unsigned :[2] : 4 au : row-major : little
read(uicvar) % Note - first value is no longer -1, but unsigned equivalent ans = 65535 508
convert(cvar,'unsigned short') % Same as Cast, but alters properties of existing class NUMERIC Object stored in memory: Symbol name Address Data type Word size : idat : [ 38836 0] : unsigned short : 16 bits
Page 23
EdGate Technologies
V1.0
DSP variables such as strings, structures, bitfields, enumerated typesand pointers can be manipulated just as easily. The following demonstrates some common manipulations on
structures, strings and enumerated types. In particular, note the 'getmember' method,which extracts a single field from a structure as a new MATLAB object.
Total Address Units Array ordering Members read(cvar) ans = iy: [2x3 double] iz: 'MatlabLink'
Page 24
EdGate Technologies
V1.0
cfield = getmember(cvar,'iz') % Extract object from structure ENUM Object stored in memory: Symbol name Address Word size : iz : [ 38832 0] : 32 bits
Address units per value : 4 au Representation Size : signed :[1] : 4 au : row-major : little
: MATLAB=0, Simulink=1, SignalToolbox=2, MatlabLink=3, EmbeddedTargetC6x=4 write(cfield,4) % Write to same enumerated variable by value read(cvar) ans = iy: [2x3 double] iz: 'EmbeddedTargetC6x'
Page 25
EdGate Technologies
V1.0
Address units per value : 1 au Representation Size : signed : [ 29 ] : 29 au : row-major : little : ASCII
ans =Treat me like an ANSI String write(cstring,7,'ME') read(cstring) ans =Treat ME like an ANSI String write(cstring,1,127) % Set first location to numeric value 127 (a non-printable ASCII character) readnumeric(cstring) % Read equivalent numeric values ans =Columns 1 through 18
Page 26
EdGate Technologies
V1.0
127 114 101 97 116 32 77 69 32 108 105 107 101 Columns 19 through 29 78 83 73 32 83 116 114 105 110 103 echo off To learn more about data manipulation and 0
32 97 110 32 65
function
calls,please
run
'FUNCTIONCALLTUTORIAL'.
MATLAB data use 'clear' on the objects derived from 'ccsdsp' (including all objects returnedby 'createobj'). In addition, 'close' is performed on the tutorial project to remove it from Code Composer.
MATLAB data use 'clear' on the objects derived from 'ccsdsp' (including all objects returned by 'createobj'). In addition, 'close' is performed on the tutorial project to remove it from Code Composer. % Clean-up Code Composer close(cc,demoPjt.ProjectFile,'project') % close the project file
Page 27
EdGate Technologies
V1.0
delete(cc,srcfile,brkpt) % Remove breakpoint at line 64 close(cc,srcfile,'text') % Close source file % Clear data objects clear cc cvar cfield uicvar cstring
Page 28
EdGate Technologies
V1.0
3) configure ccstudio according to your external target board 4) close down the ccstudio window 5) open up the matlab window 6) Type the following comments to make sure that correct board is selected and link is made with ccstudio and matlab a)ccsboardinfo
Page 29
EdGate Technologies
V1.0
Page 30
EdGate Technologies
V1.0
timeoutValue = 10; % time-out value in seconds set(cc,'timeout',timeoutValue); % Set CCSDSP default time-out value
7) library verification
type c6000lib on comments window of matlab
Page 31
EdGate Technologies
V1.0
Fig1
a)c6000 dsp core support lib To get below window click on c6000dsp core support block shown above
Page 32
EdGate Technologies
V1.0
a)hostcommunication library
To get below window click on hostcommunication library block shown Fig1
c)RTDX instrumentation To get below window click on RTDX instrumentation block shown Fig1
Page 33
EdGate Technologies
V1.0
Page 34
EdGate Technologies
V1.0
Page 35
EdGate Technologies
V1.0
Page 36
EdGate Technologies
V1.0
11) Select c6713dsk drag and place in the new model window(untitled)
Click on yes
Page 37
EdGate Technologies
V1.0
12) Similarly drag and place all the required block on new model window As shown bellow
13)
Page 38
EdGate Technologies
V1.0
14) Save the model:file save (give any name with .mdl extension)click on save
15) Check and change the property of your simulink block placed on model window by double clicking on particular block
a)Target reference property setting
Page 39
EdGate Technologies
V1.0
Make sure that cpu clock speed (MHZ) is same as target cpu clock speed(for c6713 its 225Mhz)
Page 40
EdGate Technologies
V1.0
Memory /section
Page 41
EdGate Technologies
V1.0
Chage ADC source to line in or mic in as you want If line in is selected input must be given to the line in port (line in of aic23 codec) of dsk board If mic inis selected input must be given to the mic in port(mic in of aic23 codec) of dsk board
Page 42
EdGate Technologies
V1.0
Select sampling rate between 8khz to 96khz(in case of audio select 44.1khz)
Then click on ok
Page 43
EdGate Technologies
V1.0
DAC property
Word length=16-bit Sampling rate=44.1kHz(same as ADC sampling rate) Over flow mode=wrap
Page 44
EdGate Technologies
V1.0
Simulationconfiguration parameters(ctrl+E)
Solver
Type= fixed step solver=discrete(no continue state) All others field are used as default
Page 45
EdGate Technologies
V1.0
Project option=custom Built action=built_and_execute Interrupt over notification method=no Click on applyok
Page 46
EdGate Technologies
V1.0
19) Now observe the flowing changes on matlab and ccs window
Page 47
EdGate Technologies
V1.0
Page 48
EdGate Technologies
V1.0
20)
Hardware connection
Page 49
EdGate Technologies
V1.0
FIR FILTER
Place the digital filter design block in between ADC and DAC Digital filter design block are found under signal processing filter design toolbox Drag and place in the model window as shown in fig2
Page 50
EdGate Technologies
V1.0
Double click on digital filter design block in fig2 and set the property of the filter
Response type
Select any one of the response type according to your requirement 1)low pass 2)high pass 3)band pass 4)differenciator,multiband,Hilbert transformer etc
Page 51
EdGate Technologies
V1.0
Design method
IIR
butterworth Chebyshev typei Chebyshev typeii Elliptic Maximally flat etc
Page 52
EdGate Technologies
V1.0
Order of filter
Select appropriate order of the filter base on your requirement(here we have taken order as 10)
Unit:
Select unit of the frequency as Hz or kHz
Sampling frequency
Type appropriate sampling frequency base on nyquist criteria(for audio we have atken fs=48000hz)
Page 53
EdGate Technologies
V1.0
IIR FILTER
Double click on digital filter design block in fig3 and set the property of the filter as shown bellow
Page 54
EdGate Technologies
V1.0
Order of filter
Select appropriate order of the filter base on your requirement(here we have taken order as 10)
Unit:
Select unit of the frequency as Hz or kHz(Hz)
Sampling frequency
Type appropriate sampling frequency base on nyquist criteria(for audio we have atken fs=4800hz)
Fig4
Page 55
EdGate Technologies
V1.0
2) DAC
Page 56
EdGate Technologies
V1.0
Double click on switch block and change the following property Tick on sw0-sw3 Data tpes =integer Click ok
Double click on LED block Click on ok No change in reset block use as default
Page 57
EdGate Technologies
V1.0
4) C6713DSK
Double click on c6713dsk block and change the property as shown above diagram Operating system=none Applyok
Page 58
EdGate Technologies
V1.0
Page 59
EdGate Technologies
V1.0
Page 60
EdGate Technologies
V1.0
ADC:Message signal Line in parameters and carrier signal parameters can be set as
following. This is very important. Set ADC Source as Line In, Sample Rate 32kHz, Word Length 16-bit.
Carrier:Amplitude of the message signal can be change through function generator (up to 5KHz), whereas, frequency of the carrier signal is 15KHz.
Page 61
EdGate Technologies
V1.0
Constant
Page 62
EdGate Technologies
V1.0
Page 63
EdGate Technologies
V1.0
Page 64
EdGate Technologies
V1.0
Page 65