In the script we have to perform the following tasks:
- When the GUI is launched the DSK should be loaded with a default model (SQRT)
- When the user selects a new model> Its correspondent *.out file should be loaded to the DSP.
- When the modulation index is changed, its new value should be written to the DSP through the correspondent RTDX channel.
- When the carrier frequency modulation index is changed, its new value should be written to the DSP through the correspondent RTDX channel.
The following steps describe this implementation.
- The initialization routine “AM_OpeningFcn”:
function AM_OpeningFcn(hObject, eventdata, handles, varargin)
last_model=1;
handles.last_model=last_model;
modelName = gcs;
%connect to the board
CCS_Obj = connectToCCS(modelName);
% Identify RTDX channel names/modes
chan_struct(1).name = 'InputModulation';
chan_struct(1).mode = 'w';
chan_struct(2).name = 'freq';
chan_struct(2).mode = 'w';
handles.rtdx_chan1=chan_struct(1);
handles.rtdx_chan2=chan_struct(2);
% Identify RTDX host buffer parameters
RTDX_config_struct.Buffsize= 32768;
RTDX_config_struct.Nbuffers = 4;
RTDX_config_struct.Mode = 'continuous';
%building the full path of the file to be loaded
CodegenDir = fullfile(pwd, ['AM_Coherent' '_c6000_rtw']);
OutFile = fullfile(CodegenDir, ['AM_Coherent' '.out']);
%Load is needed for rtdx setup
CCS_Obj.load(OutFile,20);
% Set up RTDX
r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct);
handles.pipe=r;
handles.CCS_Obj=CCS_Obj;
%last_x and last_y are the initial values of
%the Index and the carrier respectively
last_x=1;
last_y=15000;
handles.last_x=last_x;
handles.last_y=last_y;
handles.output = hObject;
% Enable all RTDX channels
r.enable('all');
% Update handles structure
guidata(hObject, handles);
%use the change-model function in order to load the current model.
%this function loads a model to the DSK after initiallization (= the code
%above)
ChangeModel(handles.last_model,handles.CCS_Obj,handles.pipe,handles.last_x,handles.last_y);
)
- When you select a new model, the following code is invoked:
function listbox1_Callback(hObject, eventdata, handles)
handles.last_model=get(hObject,'Value') ;
ChangeModel(handles.last_model,handles.CCS_Obj,handles.pipe,handles.last_x,handles.last_y);
An external function (written in the ChangeModel.m file) will be used to select the model:
%1. halts the current model
%2. free the rtdx channel
%3. redefine the rtdx channel
%4. loads the current model
%5. binds the rtdx to the current model
%6. run the CCS and enable the rtdx.
%7.writes the last given index modulation to the rtdx
%parameters:
%m - flag that tells if the model is coherential or sqrt
%CCS_Obj - the target
%r_old - the old rtdx channel
%last_x - to keep the current Index
%last_y - to keep the current carrier frequency
function r=ChangeModel(m,CCS_Obj,r_old,last_x,last_y)
%halt the current model
CCS_Obj.halt;
%free the curent rtdx channel
cleanupRTDX(CCS_Obj,r_old);
%redefine the rtdx:
chan_struct(1).name = 'InputModulation';
chan_struct(1).mode = 'w';
chan_struct(2).name = 'freq';
chan_struct(2).mode = 'w';
handles.rtdx_chan1=chan_struct(1);
handles.rtdx_chan2=chan_struct(2);
% Identify RTDX host buffer parameters
RTDX_config_struct.Buffsize= 32768;
RTDX_config_struct.Nbuffers = 4;
RTDX_config_struct.Mode = 'continuous';
%reload the new model
switch m
case 1
model='AM_Coherent';
case 2
model='AM_Sqrt';
end
CodegenDir = fullfile(pwd, [model '_c6000_rtw']);
OutFile = fullfile(CodegenDir, [model '.out']);
CCS_Obj.load(OutFile,20);
% set up the new rtdx channel and run the target
r = setupRTDX(CCS_Obj, chan_struct, RTDX_config_struct);
CCS_Obj.run;
r.enable('all');
% keep the last Index and carrier frequency:
if last_x~=1
r.writemsg(chan_struct(2).name,1/last_x);
end
- Changing the modulation index:
function slider1_Callback(hObject, eventdata, handles)
last_x=handles.last_x;
r=handles.pipe;
x=single(get(hObject,'Value'));
if or (y<last_y,y>last_y) %if the Index was changed:
r.writemsg(handles.rtdx_chan1.name,1/x);
%the Index increases when the added amplitude decreases
%and thats the reason that we write 1/x to the rtdx
handles.last_x=x;
end
guidata(hObject, handles);
- Changing the carrier frequency:
function slider2_Callback(hObject, eventdata, handles)
last_y=handles.last_y;
r=handles.pipe;
y=single(get(hObject,'Value'));
if or (y<last_y,y>last_y)
r.writemsg(handles.rtdx_chan2.name,y);
handles.last_y=y;
end
guidata(hObject, handles);
You may change the modulation index and frequency for both models, and observe its influence on the modulated and demodulated signals.