📄 ccsfirdemo.m
字号:
function varargout = ccsfirdemo(varargin)
% CCSFIRDEMO Demo of the 'Link for Code Composer Studio(tm)'.
% CCSFIRDEMO launchs a GUI demonstration of the 'Link for Code
% Composer Studio(tm)' product. It uses the power of MATLAB
% to design a FIR filter that will be tested directly and
% interactively on the Target DSP processor. The resulting
% filter performance is plotted and compared to a Theoritical
% response generated by MATLAB. To run this demo, a small
% target project must be modified to match the user's
% specific configuration. The necessary target source code
% is provided in the subdirectory CCSFIR, along with some
% sample project files.
%
% See also RTDXLMSDEMO, CCSTUTORIAL, RTDXTUTORIAL
% CCSFIRDEMO('callback_name', ...) invoke the named callback.
% Last Modified by GUIDE v2.0 02-Nov-2001 09:46:58
% $Revision: 1.16 $ $Date: 2002/06/12 15:30:57 $
% Copyright 2001-2002 The MathWorks, Inc.
if nargin == 0 % LAUNCH GUI
fig = openfig(mfilename,'reuse');
% Generate a structure of handles to pass to callbacks, and store it.
% include spaces for some later additions
handles = guihandles(fig);
handles.cc = [];
handles.symbols = [];
handles.bcoef = [];
handles.halt = [];
handles.swdb = [] ;
handles.scodb = [];
guidata(fig, handles);
if nargout > 0
varargout{1} = fig;
end
blockdiagram(handles.axes);
drawnow;
set(handles.exit,'UserData',1); % Halt a loop
elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK
try
[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
catch
disp(lasterr);
end
end
%----------------------------------------------------------------
% Local routine will modify theoritical filter plot
function plotfilter(h, eventdata, handles, varargin)
% Plot the (theortical) response of the filter and save coefficients for target
ftype = get(handles.type,'Value');
n = get(handles.order,'UserData');
wb(1) = get(handles.w1,'UserData');
wb(2) = get(handles.w2,'UserData');
if ftype ==1, %Low Pass
set(handles.w2,'Enable','off');
bcoef = fir1(n,wb(1));
elseif ftype == 2, %High pass
set(handles.w2,'Enable','off');
bcoef = fir1(n,wb(1),'high');
elseif ftype ==3, %Band pass
set(handles.w2,'Enable','on');
if wb(1) > wb(2),
warndlg('Warning - adjust freq. so that W1 < W2 ','Cut-Off Frequency Error');
return;
end
bcoef = fir1(n,wb);
elseif ftype == 4, %Band Stop
set(handles.w2,'Enable','on');
if wb(1) > wb(2),
warndlg('Warning - adjust freq. so that W1 < W2 ','Cut-Off Frequency Error');
return;
end
bcoef = fir1(n,wb,'stop');
else
error('Unknown filter type selected.');
end
handles.bcoef = bcoef; % save for later
% Now plot response
warnsave = warning; % turn off "Log of zero" messages
warning('off')
[sco sw]=freqz(bcoef,1);
scodb = 20*log10(abs(sco));
swdb = sw./pi;
plot(swdb,scodb,'Parent',handles.axes);
grid(handles.axes);
warning(warnsave);
handles.swdb = swdb;
handles.scodb = scodb;
guidata(gcbo,handles); % store the changes...
set(handles.titletxt,'Visible','on');
set(handles.xlabeltxt,'Visible','on');
% set(gca,'UserData',h)
%----------------------------------------------------------------
% functions used to create block diagram of MATLAB <-> CCS <-> Target
function blockdiagram(ph)
% Inserts a sketch of the Link for Code Composer Studio(tm) IDE
patch([0 1 1 0 0],[0 0 1 1 0],'w','LineStyle','none','Parent',ph);
box(ph,0.02,0.98,0.78,0.95,'c','Host Computer');
box(ph,0.04,0.85,0.30,0.78,[0.9 0.9 0.9],{'MATLAB', 'Application', '>.'});
box(ph,0.06,0.60,0.26,0.25,'w',{'Link to CCS:', 'cc = ccsdsp;'});
box(ph,0.06,0.35,0.26,0.25,'w',{'Link to RTDX:', 'cc.rtdx(i);'});
box(ph,0.38,0.85,0.38,0.78,[0.7 0.7 0.9],{'Code Composer', 'Studio(tm) IDE'})
box(ph,0.40,0.60,0.30,0.40,[0.9 0.7 0.7],{'DSP Project:', 'ccsfir.mak'})
box(ph,0.82,0.80,0.17,0.60,[0.8 0.8 0.8],{'Board'});
box(ph,0.84,0.67,0.13,0.40,[0.9 0.8 0.7],{'Target', 'DSP','Proc.'});
arrow(ph,0.23,0.20,0.51,0.36,0.04);
arrow(ph,0.23,0.42,0.50,0.40,0.04);
arrow(ph,0.60,0.30,0.9,0.42,0.04);
function box(ph,x,y,xle,yle,color,tstr)
% upper left hand corner + length
pH = patch([x x x+xle x+xle x],[y y-yle y-yle y y],color,'Parent',ph);
set(pH,'LineWidth',2);
tH = text(x+0.02,y-0.02,tstr,'Parent',ph);
set(tH,'VerticalAlignment','Top');
function arrow(ph,x1,y1,x2,y2,len)
% Draws an arrow that is +/-25 degrees from straight
el = atan2(y2-y1,x2-x1);
dle = 0.3;
x1a = x1+len*cos(el+dle);
x1b = x1+len*cos(el-dle);
y1a = y1+len*sin(el+dle);
y1b = y1+len*sin(el-dle);
el = atan2(y1-y2,x1-x2);
x2a = x2+len*cos(el-dle);
x2b = x2+len*cos(el+dle);
y2a = y2+len*sin(el-dle);
y2b = y2+len*sin(el+dle);
lH = line([x1 x1a x1b x1 x2 x2a x2b x2],[y1 y1a y1b y1 y2 y2a y2b y2],'Parent',ph);
set(lH,'Color','r')
%| ABOUT CALLBACKS:
%| GUIDE automatically appends subfunction prototypes to this file, and
%| sets objects' callback properties to call them through the FEVAL
%| switchyard above. This comment describes that mechanism.
%|
%| Each callback subfunction declaration has the following form:
%| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN)
%|
%| The subfunction name is composed using the object's Tag and the
%| callback type separated by '_', e.g. 'slider2_Callback',
%| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'.
%|
%| H is the callback object's handle (obtained using GCBO).
%|
%| EVENTDATA is empty, but reserved for future use.
%|
%| HANDLES is a structure containing handles of components in GUI using
%| tags as fieldnames, e.g. handles.figure1, handles.slider2. This
%| structure is created at GUI startup using GUIHANDLES and stored in
%| the figure's application data using GUIDATA. A copy of the structure
%| is passed to each callback. You can store additional information in
%| this structure at GUI startup, and you can change the structure
%| during callbacks. Call guidata(h, handles) after changing your
%| copy to replace the stored original so that subsequent callbacks see
%| the updates. Type "help guihandles" and "help guidata" for more
%| information.
%|
%| VARARGIN contains any extra arguments you have passed to the
%| callback. Specify the extra arguments by editing the callback
%| property in the inspector. By default, GUIDE sets the property to:
%| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo))
%| Add any extra arguments after the last argument, before the final
%| closing parenthesis.
% --------------------------------------------------------------------
function varargout = boardnum_Callback(h, eventdata, handles, varargin)
% Callback for Board number entry box. This allows user to directly
% define the 'boardnum' parameter of the Link
oldval = get(h,'UserData');
newstr = get(h,'String');
newval = eval(newstr,num2str(oldval));
if newval<1, newval = oldval;end
newval = round(newval);
set(h,'Userdata',newval,'String',num2str(newval));
% --------------------------------------------------------------------
function varargout = procnum_Callback(h, eventdata, handles, varargin)
% Callback for Processor number entry box. This allows user to directly
% define the 'procnum' parameter of the Link
oldval = get(h,'UserData');
newstr = get(h,'String');
newval = eval(newstr,num2str(oldval));
if newval<1, newval = oldval;end
newval = round(newval);
set(h,'Userdata',newval,'String',num2str(newval));
% --------------------------------------------------------------------
function varargout = select_Callback(h, eventdata, handles, varargin)
% Invokes the Board/Processor Selection GUI
try
[bdnum,prnum] = boardprocsel;
catch
warndlg(...
{ 'Unable to run Board Selection Utility',...
'[bdnum,prnum] = boardprocsel;',...
'Board and Processor must be entered manually',...
lasterr},'GUI Error');
end
if ~isempty(bdnum),
set(handles.boardnum,'String',int2str(bdnum));
set(handles.boardnum,'UserData',bdnum);
end
if ~isempty(prnum),
set(handles.procnum,'String',int2str(prnum));
set(handles.procnum,'UserData',prnum);
end
% --------------------------------------------------------------------
function varargout = type_Callback(h, eventdata, handles, varargin)
% Callback to specify filter type (lowpass, highpass, etc)
% NOTE highpass and bandstop must use even number of coefficients
set(handles.exit,'UserData',1); % This will halt execution!
handles.halt = 1;
pointsave=get(gcbf,'Pointer');
set(gcbf,'Pointer','watch');
process_order_type(handles);
plotfilter(h, eventdata, handles, varargin);
set(gcbf,'Pointer',pointsave);
% --------------------------------------------------------------------
function varargout = order_Callback(h, eventdata, handles, varargin)
% Callback to specify filter order
set(handles.exit,'UserData',1); % This will halt execution!
handles.halt = 1;
pointsave=get(gcbf,'Pointer');
set(gcbf,'Pointer','watch');
process_order_type(handles);
plotfilter(h, eventdata, handles, varargin);
set(gcbf,'Pointer',pointsave);
% --------------------------------------------------------------------
% special implementation to handle odd filters
function varargout = process_order_type(handles)
ftype = get(handles.type,'Value');
oldval = get(handles.order,'UserData');
newstr = get(handles.order,'String');
newval = eval(newstr,num2str(oldval));
if newval<1, newval = oldval; end
if ftype ==2 | ftype == 4, %High or Stop
if mod(newval,2) == 1, %odd!
newval = newval+1;
end
end
if newval>63,
if ftype ==2 | ftype == 4, %High or Stop
newval = 62;
else
newval = 63;
end
end
newval = round(newval);
set(handles.order,'Userdata',newval,'String',num2str(newval));
% --------------------------------------------------------------------
function varargout = w1_Callback(h, eventdata, handles, varargin)
% Callback to specify filter type (lowpass, highpass, etc)
set(handles.exit,'UserData',1); % This will halt execution!
oldval = get(h,'UserData');
newstr = get(h,'String');
newval = eval(newstr,num2str(oldval));
if newval<0, newval = 0;
elseif newval>1, newval =1; end
set(h,'Userdata',newval,'String',num2str(newval));
pointsave=get(gcbf,'Pointer');
set(gcbf,'Pointer','watch');
plotfilter(h, eventdata, handles, varargin);
set(gcbf,'Pointer',pointsave);
% --------------------------------------------------------------------
function varargout = w2_Callback(h, eventdata, handles, varargin)
% Callback to specify filter type (lowpass, highpass, etc)
set(handles.exit,'UserData',1); % This will halt execution!
oldval = get(h,'UserData');
newstr = get(h,'String');
newval = eval(newstr,num2str(oldval));
if newval<0, newval = 0;
elseif newval>1, newval =1; end
set(h,'Userdata',newval,'String',num2str(newval));
pointsave=get(gcbf,'Pointer');
set(gcbf,'Pointer','watch');
plotfilter(h, eventdata, handles, varargin);
set(gcbf,'Pointer',pointsave);
% --------------------------------------------------------------------
function varargout = plotcoeff_Callback(h, eventdata, handles, varargin)
% Callback for next slide buttion -> steps through demo
disp('pushbutton1 Callback not implemented yet.')
set(handles.exit,'UserData',1); % This will halt execution!
% --------------------------------------------------------------------
function varargout = help_Callback(h, eventdata, handles, varargin)
% Callback to specify filter type (lowpass, highpass, etc)
slidenum = get(handles.slide,'UserData');
if slidenum == 1,
ttlStr = 'Selecting a Board and Processor';
hlpStr = [ ...
'This demo applies the ''Link for Code Composer(tm)'' to '
'a simple filter design task. It uses the power of MATLAB '
'to design and characterize a digital FIR filter that '
'executes on a target CPU. '
'The coefficients for the filter are generated with the '
'MATLAB function: FIR1. The resulting coefficents are '
'directly transferred to the DSP processor''s memory. '
'Different filter options can be selected and immediately '
'tested on the target without modifying the target code. '
'The first step is to create the COM/ActiveX link to Code '
'Composer Studio (CCS). The CCS enviroment can support '
'multiple DSP processors and PC boards. The link is to '
'a single device, which is specified by a board number and '
'processor number. If you are unsure what devices are '
'available, use the ''Selection Tool'' button to find the '
'correct board and processor. In single processor systems, '
'the defaults values (0,0) should work. '
' '
' File name: ccsfirdemo.m '];
elseif slidenum == 2,
ttlStr = 'Loading the Target Project';
hlpStr = [ ...
'Code Composer Sudio is an application for developing DSP '
'target code. The resulting target code can be loaded '
'and executed on the target CPU. Debugging tools provided '
'by Code Composer can interactively modify the target''s '
'enviroment, including its local memory. This toolbox '
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -