⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ccsfirdemo_script.m

📁 matlab连接ccs的例子
💻 M
字号:
%CCSFIRDEMO Link to Code Composer Studio(tm) IDE demo - Script
%  A script version of the GUI demo.  This is available in the
%  GUI by pressing the button called 'View Script'.  This script
%  is provided to remove the details of the gui.  It illustrates
%  many of the commands available for 'The Link for Code Composer
%  Studio(tm)' product
%
% $Revision: 1.7 $  $Date: 2002/06/12 15:30:56 $
% Copyright 2001-2002 The MathWorks, Inc.

% Opens a link to the board number 0, Processor Number 0
% Use the Matlab command 'CCSBOARDINFO' or the gui
% selection tool 'BOARDPROCSEL' to determine your
% boardnum and procnum in multiple processor configurations.
cc = ccsdsp('boardnum',0,'procnum',0);
% Note - For some configuration it is necessary to load a 
% GEL file to configure the EMIF registers at this point.  
% This demo is designed to use internal memory, so in many
% case this is unnecessary.  However, if the target configuration
% requires a GEL file, This can be achieved by creating
% workspace file that can be loaded by Matlab with the 'open' 
% command or manually loading the GEL file from Code Composer.
% cc.open('ccsfir.wks')  %Optional workspace/GEL load

% Loads the necessary project file.  If necessary, uncomment the
% project file that is appropriate for your DSP processor
demodir = fullfile(matlabroot,'toolbox','tiddk','tidemos','ccsfir');
cc.cd(demodir);
cc.open('ccsfir_6x0x.pjt');  % use for 6201/6702/6202 processors
%cc.open('ccsfir_6x11.mak');  % use for 6211/6711 processors
%cc.open('ccsfir_54xx.mak');  % use for 5401 processors
cc.visible(1);

% After building the necessary program file: 'ccsfir.out', the
% next command will load it into the DSP processor.
pause;
cc.reset
pause(0.5)
cc.load('a6x0x.out');  % use for 6201/6702/6202 processors
%cc.load('a6x11.out');  % use for 6211/6711 processors
%cc.load('a54xx.out');  % use for 5401 processors

% Use Matlab's FIR1 command to create filter coefficients.  Refer
% to the Matlab Fir filter design tools such as FIR1 to specify
% the desired filter type and response.  In this case, the filter
% is a Low-pass design with a cutoff at at pi/2 radians
ncoeff = 15;
coeff = fir1(ncoeff-1,0.5);

% Query the symbol table of the target to deterine memory location
% of relavant parameters.  The names are taken directly from the
% target source code: ccsfir.c
s = struct('coeff',[]);
s.coeff = cc.address('coeff');
s.din = cc.address('din');
s.dout = cc.address('dout');
s.ncoeff = cc.address('ncoeff');
s.nbuf = cc.address('nbuf');

% Scale the coefficients to allow the FIR1 coefficent values (-1 to 1)
% to work properly with the int16 data types (-1*(2^15 - 1) to 2^15). 
cscaling = 2^15;
%
icoeff = int16(cscaling.*coeff);
cc.write(s.coeff,icoeff);
incoeff = int32(ncoeff);
cc.write(s.ncoeff,incoeff);

% Create a block of data values with normal distribution
% Data is scaled for proper operation with int16 data types.
% This scaling is optimized for the input data block
nfrm = 1024;
din = randn(nfrm,1);
glim = max([abs(max(din)) abs(min(din))]);
dscale = 2^15/(glim*0.99);  
idin = int16(dscale*din);
cc.write(s.din,idin);
inbuf = int32(nfrm);
cc.write(s.nbuf,inbuf);

% The supplied target code has been strucutued to halt after running the
% filter.  Thus, execute the target until a halt is detected.
% In some configuration, it may be necessary to insert a breakpoint
% in the code to halt the processor (for example, when using a RTOS
% that runs to idle, but never halts)
cc.restart;
cc.run('runtohalt');

% Read the filtered data block from the memory of the target
idout = cc.read(s.dout,'int16',nfrm);

% Compute spectra of the filtered data block and compare to
% Matlab computed estimate of ideal response (using FREQZ)
[sout wsd]= pwelch(double(idout));
sin = pwelch(double(idin));
runningsum = sout./sin;
wplotdb = 10*log10(runningsum);
sco = freqz(coeff,1,wsd);
scodb = 20*log10(abs(sco));
wsdb = wsd/pi;
plot(wsdb,wplotdb,'r',wsdb,scodb,'b');
xlabel('Frequency (Normalized)');
ylabel('Magnitude (dB)');

% The following loop will will iteratively filter new blocks of 
% pseudo-random data and average the results.  This will produce 
% an improved estimate of actual filter response.  (statistically)

ntimes = input('Repeat the filter characterization N times to improve the estimate (0=exit): ');
for j=1:ntimes

    din = randn(nfrm,1);
    glim = max([abs(max(din)) abs(min(din))]);
    dscale = 2^15/(glim*0.99);  
    idin = int16(dscale*din);
    cc.write(s.din,idin);
    
    cc.restart;
    cc.run('runtohalt');
    
    idout = cc.read(s.dout,'int16',nfrm);
    sout= pwelch(double(idout));
    sin =pwelch(double(idin));
    if j == 1,
        runningsum = (sout./sin);
    else
        runningsum = runningsum + (sout./sin);
    end
    wplotdb = 10*log10(runningsum./(j));
    plot(wsdb,wplotdb,'r',wsdb,scodb,'b');
    xlabel('Frequency (Normalized)');
    ylabel('Magnitude (dB)');
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -