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_mtrctrl_tpu_pmm(block, callback_fn, varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function varargout = mpc555_mtrctrl_tpu_pmm(block, callback_fn, varargin)
%
function varargout = mpc555_mtrctrl_tpu_pmm(block, callback_fn, varargin)
% This is the entry function to allow the appropriate callback functions to
% be run
switch callback_fn
    case 'pmm_mode'
        i_callback_pmm_mode(block);
        i_fn_rearrange_wiring(block);
    case 'inport_bank_signal'
        i_callback_pmm_mode(block);
    case 'param_self_banking'
        i_callback_pmm_mode(block);
    case 'param_max_missing'
        i_callback_param_max_missing(block);
    case 'param_tcr2_max_value'
        i_callback_param_tcr2_max_value(block);
    case 'param_num_of_teeth'
        i_callback_param_num_of_teeth(block);
        i_fn_rearrange_wiring(block);
    case 'param_ratio'
        i_callback_param_ratio(block);
    case 'initialisation'
        [varargout{1}, varargout{2}, varargout{3}, varargout{4}] = ...
            i_initialisation(block, varargin{1}, varargin{2}, varargin{3}, varargin{4});
    otherwise
        error('Invalid callback');
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function parameterspecs = i_getparameterspecs()
%
function parameterspecs = i_getparameterspecs()

parameterspecs(1).ParamName = 'param_max_missing';
parameterspecs(1).PrettyName = 'MAX_MISSING';
parameterspecs(1).MinVal = 1;
parameterspecs(1).MaxVal = 2^8-1;
parameterspecs(1).DataType = 'uint8';
parameterspecs(1).ArrayLengthMin = 1;
parameterspecs(1).ArrayLengthMax = 1;
parameterspecs(1).ErrorMessage = '';
parameterspecs(1).SpecialConditions = [];

parameterspecs(2).ParamName = 'param_tcr2_max_value';
parameterspecs(2).PrettyName = 'TCR2_MAX_VALUE';
parameterspecs(2).MinVal = 1;
parameterspecs(2).MaxVal = 2^13-1;
parameterspecs(2).DataType = 'uint16';
parameterspecs(2).ArrayLengthMin = 1;
parameterspecs(2).ArrayLengthMax = 1;
parameterspecs(2).SpecialConditions = [];

parameterspecs(3).ParamName = 'param_num_of_teeth';
parameterspecs(3).PrettyName = 'NUM_OF_TEETH';
parameterspecs(3).MinVal = 1;
parameterspecs(3).MaxVal = 2^8-1;
parameterspecs(3).DataType = 'uint16';
parameterspecs(3).ArrayLengthMin = 1;
parameterspecs(3).ArrayLengthMax = inf;
parameterspecs(3).SpecialConditions(1).Condition = '~isequal(sort(param_value),param_value)';
parameterspecs(3).SpecialConditions(1).ErrorMsg = 'The values specified in the array should be the positions of the missing teeth, in increasing number.';
parameterspecs(3).SpecialConditions(2).Condition = '~eq(sum( eq(abs(diff(param_value)),1) ),0)';
parameterspecs(3).SpecialConditions(2).ErrorMsg = 'Missing teeth cannot be immediately adjacent.';

parameterspecs(4).ParamName= 'param_ratio';
parameterspecs(4).PrettyName= 'RATIO';
parameterspecs(4).MinVal = 0;
parameterspecs(4).MaxVal = 1.99;
parameterspecs(4).DataType = 'double';
parameterspecs(4).ArrayLengthMin = 1;
parameterspecs(4).ArrayLengthMax = 1;
parameterspecs(4).SpecialConditions = [];

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function [param_max_missing, ...
%   param_tcr2_max_value, ...
%   param_num_of_teeth, ...
%   param_ratio] = i_initialisation(block, param_max_missing, ...
%        param_tcr2_max_value, param_num_of_teeth, param_ratio]
%
%
function [param_max_missing, ...
    param_tcr2_max_value, ...
    param_num_of_teeth, ...
    param_ratio] = i_initialisation(block, param_max_missing, ...
    param_tcr2_max_value, param_num_of_teeth, param_ratio)

parameterspecs = i_getparameterspecs();
% First validate MAX_MISSING
[validate] = mpc555_mtrctrl_validate_value(param_max_missing, parameterspecs(1));
if ~validate.Overall
    str_message = mpc555_mtrctrl_validate_error(parameterspecs(1), validate)
    error(str_message);
end

% Second validate NUM_OF_TEETH
[validate] = mpc555_mtrctrl_validate_value(param_num_of_teeth, parameterspecs(3));
if ~validate.Overall
    str_message = mpc555_mtrctrl_validate_error(parameterspecs(3), validate);
    error(str_message);
end

%*****************************************************************%
%* This code here is to automatically calculate the value of     *%
%* TCR2_MAX_VALUE.  It is assumed that this value should pretty  *%
%* much always be set as  the position of the final              *%
%* missing    tooth.                                             *%
%*****************************************************************%
% If this constraint is not acceptable, comment out the 1 line   *%
% below, and unhide the mask parameter 'param_tcr2_max_value'    *%
param_tcr2_max_value = max(param_num_of_teeth);
%*****************************************************************%


% Third validate TCR2_MAX_VALUE
[validate] = mpc555_mtrctrl_validate_value(param_tcr2_max_value, parameterspecs(2));
if ~validate.Overall
    str_message = mpc555_mtrctrl_validate_error(parameterspecs(2), validate);
    error(str_message);
end

% Fourth validate RATIO
[validate] = mpc555_mtrctrl_validate_value(param_ratio, parameterspecs(4));
if ~validate.Overall
    str_message = mpc555_mtrctrl_validate_error(parameterspecs(4), validate);
    error(str_message);
end

end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function i_callback_edit_raw_values(block)
%
function i_callback_pmm_mode(block)
enable_conds(1).param_names = {'pmm_mode'};
enable_conds(1).param_conditions = {'Count Mode'};
enable_conds(1).to_enable = {'param_max_missing'};
enable_conds(1).to_disable = {'inport_bank_signal', 'alias_bank_signal', 'param_self_banking'};
enable_conds(1).to_hide = {};
enable_conds(1).reciprocal = 0;

enable_conds(2).param_names = {'pmm_mode', 'inport_bank_signal', 'param_self_banking'};
enable_conds(2).param_conditions = {'Bank Mode', 'on', 'off'};
enable_conds(2).to_enable = {'inport_bank_signal'};
enable_conds(2).to_disable = {'param_max_missing', 'alias_bank_signal', 'param_self_banking'};
enable_conds(2).to_hide = {};
enable_conds(2).reciprocal = 0;

enable_conds(3).param_names = {'pmm_mode', 'inport_bank_signal', 'param_self_banking'};
enable_conds(3).param_conditions = {'Bank Mode', 'off', 'off'};
enable_conds(3).to_enable = {'inport_bank_signal', 'alias_bank_signal', 'param_self_banking'};
enable_conds(3).to_disable = {'param_max_missing'};
enable_conds(3).to_hide = {};
enable_conds(3).reciprocal = 0;

enable_conds(4).param_names = {'pmm_mode', 'inport_bank_signal', 'param_self_banking'};
enable_conds(4).param_conditions = {'Bank Mode', 'off', 'on'};
enable_conds(4).to_enable = {'param_self_banking'};
enable_conds(4).to_disable = {'param_max_missing', 'alias_bank_signal', 'inport_bank_signal'};
enable_conds(4).to_hide = {};
enable_conds(4).reciprocal = 0;

mpc555_mtrctrl_maskparam(enable_conds);

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function i_callback_param_max_missing(block)
%
function i_callback_param_max_missing(block)
parameterspecs = i_getparameterspecs();
[valid_value] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(1));
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function i_callback_param_tcr2_max_value(block)
%
function i_callback_param_tcr2_max_value(block)
parameterspecs = i_getparameterspecs();
[valid_value] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(2));
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function i_callback_param_num_of_teeth(block)
%
function i_callback_param_num_of_teeth(block)

pmm_mode = get_param(block, 'pmm_mode');
numofteeth = str2num(get_param(block, 'param_num_of_teeth'));

if strcmp(pmm_mode, 'Count Mode') && (length(numofteeth) > 1)
    str_message = ['In PMM Count Mode one must have only one missing tooth or evenly spaced teeth', ...
        sprintf('\n'), sprintf('\n'), 'Consider using Bank Mode with Self Banking enabled if this is necessary.'];
    mpc555_mtrctrl_mask_error(block, str_message, 'Invalid value');
    return;
end

parameterspecs = i_getparameterspecs();
[valid_value] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(3));

%*****************************************************************%
%* This code here is to automatically calculate the value of     *%
%* TCR2_MAX_VALUE.  It is assumed that this value should pretty  *%
%* much always be set as  the position of the final              *%
%* missing    tooth.                                             *%
%*****************************************************************%
% If this constraint is not acceptable, comment out the 3 lines  *%
% below, and unhide the mask parameter 'param_tcr2_max_value'    *%
automatic_tcr2_max_value = max(numofteeth);
set_param(block, 'param_tcr2_max_value', num2str(automatic_tcr2_max_value));
mpc555_mtrctrl_mask_copy_values(block, 'save');
%****************************************************************%
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function i_callback_param_ratio(block)
%
function i_callback_param_ratio(block)

parameterspecs = i_getparameterspecs();
[valid_value] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(4));

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function i_fn_rearrange_wiring(block)
%
function i_fn_rearrange_wiring(block)

pmm_mode = get_param(block, 'pmm_mode');
numofteeth = str2num(get_param(block, 'param_num_of_teeth'));
mainfnname = [block, '/PMM Main Function'];

if strcmp(pmm_mode, 'Bank Mode') && (length(numofteeth) > 1)
    try
        delete_line(mainfnname, ['NumOfTeethGround/', num2str(1)], ...
            ['sfun_mtrctrl_tpu3_pmm S-function/', num2str(3)]);
    catch
    end
    try
        delete_line(mainfnname, ['PMM Interrupt Handler/', num2str(2)], ...
            ['TerminateTeeth/', num2str(1)]);
    catch
    end
    try
        delete_block([mainfnname,'/TerminateTeeth']);
    catch
    end
    try
        delete_block([mainfnname,'/NumOfTeethGround']);
    catch
    end
    try
        add_line(mainfnname, ['PMM Interrupt Handler/', num2str(2)], ...
            ['sfun_mtrctrl_tpu3_pmm S-function/', num2str(3)], 'autorouting', 'on');
    catch
    end
else
    try
        delete_line(mainfnname, ['PMM Interrupt Handler/', num2str(2)], ...
            ['sfun_mtrctrl_tpu3_pmm S-function/', num2str(3)]);
    catch
    end
    try
        add_block('simulink/Sinks/Terminator', [mainfnname,'/TerminateTeeth'], ...
            'Position', [750, 78 + 40, 780, 92 + 40]);
    catch
    end
    try
        add_block('simulink/Sources/Ground', [mainfnname,'/NumOfTeethGround'], ...
            'Position', [120, 168 + 100, 150, 182 + 100]);
    catch
    end
    try
        add_line(mainfnname, ['NumOfTeethGround/', num2str(1)], ...
            ['sfun_mtrctrl_tpu3_pmm S-function/', num2str(3)], 'autorouting', 'on');
    catch
    end
    try
        add_line(mainfnname, ['PMM Interrupt Handler/', num2str(2)], ...
            ['TerminateTeeth/', num2str(1)], 'autorouting', 'on');
    catch
    end
end

end

Contact us