Code covered by the BSD License  

Highlights from
MPC555 Motor Control Function Blockset

MPC555 Motor Control Function Blockset

by

 

20 Mar 2006 (Updated )

Additional I/O blocks for MPC555 target - specifically targetting TPU functionality

mpc555_tcr_convert_gui(currentblock)
function mpc555_tcr_convert_gui(currentblock)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FUNCTION MPC555_TCR_CONVERT_GUI(CURRENTBLOCK)
%
% Example:
%       mpc555_tcr_convert_gui(gcb)

% Get a handle to the resource config block for the current block
[TCR1clock, TCR1clockvalid] = mpc555_mtrctrl_getclock(currentblock, 'TCR1', get_param(currentblock, 'module'));
[TCR2clock, TCR2clockvalid] = mpc555_mtrctrl_getclock(currentblock, 'TCR2', get_param(currentblock, 'module'));

modulesavailable = {'A', 'B'};

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Check for TPU_C
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
try
    target = RTWConfigurationCB('get_target', currentblock);
catch
    % NOTE: we only end up here if there is no config
    % block in the model.
    return;
end;

config = target.findConfigForClass('MPC555dkConfig.SYSTEM_CLOCKS');

if mpc555_module_available(config.MPC5xx_Variant, 'TPU_C')
    modulesavailable = [modulesavailable, 'C'];
end

h.f = figure;

currpos = get(h.f, 'position');

set(h.f, 'position', [currpos(1), currpos(2), 350, 210]);
set(h.f, 'Menubar', 'none');
set(h.f, 'Name', ['Calculate TCR values on TPU_', get_param(currentblock, 'module')]);
set(h.f, 'NumberTitle', 'Off');
set(h.f, 'Resize', 'Off');

backgroundcolor = get(h.f, 'color');

h.popupmodule = uicontrol('style', 'popup', ...
    'backgroundcolor', 'w', ...
    'string', modulesavailable, ...
    'value', strmatch(get_param(currentblock, 'module'),  modulesavailable, 'exact'), ...
    'position', [110 170 100 20]);

h.editrealtime = uicontrol('style', 'edit', ...
    'backgroundcolor', 'w', ...
    'position', [110 140 100 20]);
h.editTCR1freq = uicontrol('style', 'edit', ...
    'string', num2str(TCR1clock), ...
    'enable', 'off', ...
    'position', [110 110 100 20]);
h.editTCR2freq = uicontrol('style', 'edit', ...
    'string', num2str(TCR2clock), ...
    'enable', 'off', ...
    'position', [110 80 100 20]);
h.editTCR1time = uicontrol('style', 'edit', ...
    'backgroundcolor', 'w', ...
    'position', [110 50 100 20]);
h.editTCR2time = uicontrol('style', 'edit', ...
    'backgroundcolor', 'w', ...
    'position', [110 20 100 20]);

h.editTCR1valid = uicontrol('style', 'edit', ...
    'string', num2str(TCR1clockvalid), ...
    'enable', 'off' ,...
    'visible', 'off');
h.editTCR2valid = uicontrol('style', 'edit', ...
    'string', num2str(TCR2clockvalid), ...
    'enable', 'off' ,...
    'visible', 'off');


h.editTCR1real = uicontrol('style', 'edit', ...
    'enable', 'off', ...
    'position', [230 50 100 20]);
h.editTCR2real = uicontrol('style', 'edit', ...
    'enable', 'off', ...
    'position', [230 20 100 20]);

h.labelmodule = uicontrol('style', 'text', ...
    'background', backgroundcolor, ...
    'fontweight', 'bold',...
    'string', 'TPU module',...
    'position', [20 167 70 20]);
h.labelrealtime = uicontrol('style', 'text', ...
    'background', backgroundcolor, ...
    'fontweight', 'bold',...
    'string', 'Time /s',...
    'position', [20 137 70 20]);
h.labelTCR1freq = uicontrol('style', 'text', ...
    'background', backgroundcolor, ...
    'fontweight', 'bold',...
    'string', 'TCR1 freq',...
    'position', [20 107 70 20]);
h.labelTCR2freq = uicontrol('style', 'text', ...
    'background', backgroundcolor, ...
    'fontweight', 'bold',...
    'string', 'TCR2 freq',...
    'position', [20 77 70 20]);
h.labelTCR1time = uicontrol('style', 'text', ...
    'background', backgroundcolor, ...
    'fontweight', 'bold',...
    'string', 'TCR1 counts',...
    'position', [20 47 70 20]);
h.labelTCR2time = uicontrol('style', 'text', ...
    'background', backgroundcolor, ...
    'fontweight', 'bold',...
    'string', 'TCR2 counts',...
    'position', [20 17 70 20]);

h.labelreal = uicontrol('style', 'text', ...
    'background', backgroundcolor, ...
    'fontweight', 'bold',...
    'string', 'Actual time',...
    'position', [230 77 100 20]);

set(h.popupmodule, ...
    'callback', ...
    {@i_callback_change_module, h, currentblock});

set(h.editrealtime, ...
    'callback', ...
    {@i_callback_calc_tcrs, h, currentblock});

set(h.editTCR1time, ...
    'callback', ...
    {@i_callback_calc_tcr1, h, currentblock});

set(h.editTCR2time, ...
    'callback', ...
    {@i_callback_calc_tcr2, h, currentblock});

if ~TCR1clockvalid
   set(h.editTCR1time, 'enable', 'off'); 
else
    set(h.editTCR1time, 'enable', 'on');
end

if ~TCR2clockvalid
   set(h.editTCR2time, 'enable', 'off'); 
else
    set(h.editTCR2time, 'enable', 'on');
end
end

function i_callback_calc_tcrs(src, evt, h, currentblock)

tcrvalues = mpc555_tcr_convert(currentblock, get_param(currentblock, 'module'), ...
    'time', str2num(get(h.editrealtime, 'string')));

if tcrvalues.TCR1 ~= -inf
    set(h.editTCR1freq, 'string', num2str(tcrvalues.TCR1ClockFreq));
else
    set(h.editTCR1freq, 'string', 'N/A');
end
if tcrvalues.TCR2 ~= -inf
    set(h.editTCR2freq, 'string', num2str(tcrvalues.TCR2ClockFreq));
else
    set(h.editTCR2freq, 'string', 'N/A');
end

if tcrvalues.TCR1 ~= -inf
    set(h.editTCR1time, 'string', num2str(tcrvalues.TCR1));
    set(h.editTCR1real, 'string', num2str(tcrvalues.ActualTimeTCR1));
else
    set(h.editTCR1time, 'string', 'N/A');
    set(h.editTCR1real, 'string', 'N/A');
end

if tcrvalues.TCR2 ~= -inf
    set(h.editTCR2time, 'string', num2str(tcrvalues.TCR2));
    set(h.editTCR2real, 'string', num2str(tcrvalues.ActualTimeTCR2));
else
    set(h.editTCR2time, 'string', 'N/A');
    set(h.editTCR2real, 'string', 'N/A');
end

end

function i_callback_calc_tcr1(src, evt, h, currentblock)

tcrvalues = mpc555_tcr_convert(currentblock, get_param(currentblock, 'module'), ...
    'TCR1', str2num(get(h.editTCR1time, 'string')));
if tcrvalues.TCR1 ~= -inf
    set(h.editTCR1freq, 'string', num2str(tcrvalues.TCR1ClockFreq));
else
    set(h.editTCR1freq, 'string', 'N/A');
end
if tcrvalues.TCR2 ~= -inf
    set(h.editTCR2freq, 'string', num2str(tcrvalues.TCR2ClockFreq));
else
    set(h.editTCR2freq, 'string', 'N/A');
end


if tcrvalues.ActualTimeTCR1 ~= -inf
    set(h.editrealtime, 'string', num2str(tcrvalues.ActualTimeTCR1));
    set(h.editTCR1real, 'string', num2str(tcrvalues.ActualTimeTCR1));
else
    set(h.editTCR1time, 'string', 'N/A');
    set(h.editTCR1real, 'string', 'N/A');
end

if tcrvalues.ActualTimeTCR2 ~= -inf
    set(h.editTCR2time, 'string', num2str(tcrvalues.TCR2));
    set(h.editTCR2real, 'string', num2str(tcrvalues.ActualTimeTCR2));
else
    set(h.editTCR2time, 'string', 'N/A');
    set(h.editTCR2real, 'string', 'N/A');
end

end

function i_callback_calc_tcr2(src, evt, h, currentblock)

tcrvalues = mpc555_tcr_convert(currentblock, get_param(currentblock, 'module'), ...
    'TCR2', str2num(get(h.editTCR2time, 'string')));
if tcrvalues.TCR1 ~= -inf
    set(h.editTCR1freq, 'string', num2str(tcrvalues.TCR1ClockFreq));
else
    set(h.editTCR1freq, 'string', 'N/A');
end
if tcrvalues.TCR2 ~= -inf
    set(h.editTCR2freq, 'string', num2str(tcrvalues.TCR2ClockFreq));
else
    set(h.editTCR2freq, 'string', 'N/A');
end

if tcrvalues.ActualTimeTCR2 ~= -inf
    set(h.editrealtime, 'string', num2str(tcrvalues.ActualTimeTCR2));
    set(h.editTCR2real, 'string', num2str(tcrvalues.ActualTimeTCR2));
else
    set(h.editTCR2time, 'string', 'N/A');
    set(h.editTCR2real, 'string', 'N/A');
end

if tcrvalues.ActualTimeTCR1 ~= -inf
    set(h.editTCR1time, 'string', num2str(tcrvalues.TCR1));
    set(h.editTCR1real, 'string', num2str(tcrvalues.ActualTimeTCR1));
else
    set(h.editTCR1time, 'string', 'N/A');
    set(h.editTCR1real, 'string', 'N/A');
end

end

function i_callback_change_module(src, evt, h, currentblock)

switch get(h.popupmodule, 'value')
    case 1
        [TCR1clock, TCR1clockvalid] = mpc555_mtrctrl_getclock(currentblock, 'TCR1', 'A');
        [TCR2clock, TCR2clockvalid] = mpc555_mtrctrl_getclock(currentblock, 'TCR2', 'A');
        set_param(currentblock, 'module', 'A');
    case 2
        [TCR1clock, TCR1clockvalid] = mpc555_mtrctrl_getclock(currentblock, 'TCR1', 'B');
        [TCR2clock, TCR2clockvalid] = mpc555_mtrctrl_getclock(currentblock, 'TCR2', 'B');
        set_param(currentblock, 'module', 'B');
    case 3
        [TCR1clock, TCR1clockvalid] = mpc555_mtrctrl_getclock(currentblock, 'TCR1', 'C');
        [TCR2clock, TCR2clockvalid] = mpc555_mtrctrl_getclock(currentblock, 'TCR2', 'C');
        set_param(currentblock, 'module', 'C');
end

set(h.editTCR1freq, 'string', num2str(TCR1clock));
set(h.editTCR2freq, 'string', num2str(TCR2clock));

set(h.editTCR1valid, 'string', num2str(TCR1clockvalid));
set(h.editTCR2valid, 'string', num2str(TCR2clockvalid));

if ~TCR1clockvalid
   set(h.editTCR1time, 'enable', 'off'); 
else
    set(h.editTCR1time, 'enable', 'on');
end

if ~TCR2clockvalid
   set(h.editTCR2time, 'enable', 'off'); 
else
    set(h.editTCR2time, 'enable', 'on');
end

set(h.editrealtime, 'string', '');
set(h.editTCR1time, 'string', '');
set(h.editTCR2time, 'string', '');
set(h.editTCR1real, 'string', '');
set(h.editTCR2real, 'string', '');

set(h.f, 'Name', ['Calculate TCR values on TPU_', get_param(currentblock, 'module')]);

end

Contact us