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_svm(block, callback_fn, varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function varargout = mpc555_mtrctrl_tpu_svm(block, callback_fn, varargin)
%
function varargout = mpc555_mtrctrl_tpu_svm(block, callback_fn, varargin)
% This is the entry function to allow the appropriate callback functions to
% be run

svm_variants = { ...
    'Standard', ...
    '3 outputs version', ...
    'XOR version', ...
    'Dead-Time correction', ...
    '3 outputs version XOR version', ...
    'Dead-Time correction - XOR version', ...
    };

svm_variant_num = strmatch(get_param(block, 'svm_variant'), svm_variants, 'exact');

switch callback_fn
    case 'param_alpha'
        parameterspecs = i_getparameterspecs(svm_variant_num);
        [validate] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(1));
    case 'param_beta'
        parameterspecs = i_getparameterspecs(svm_variant_num);
        [validate] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(2));
    case 'upper_channels'
        i_callback_channels(block, 6);
    case 'lower_channels'
        i_callback_channels(block, 7);
    case 'svm_variant'
        i_callback_svm_variant(block);
    case 'param_t'
        parameterspecs = i_getparameterspecs(svm_variant_num);
        [validate] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(16));
    case 'param_prescaler'
        parameterspecs = i_getparameterspecs(svm_variant_num);
        [validate] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(3));
    case 'param_dt'
        parameterspecs = i_getparameterspecs(svm_variant_num);
        [validate] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(4));
    case 'param_MPW'
        parameterspecs = i_getparameterspecs(svm_variant_num);
        [validate] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(5));
    case 'fault_channels'
        parameterspecs = i_getparameterspecs(svm_variant_num);
        [validate] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(8));
    case 'resolver_channels'
        parameterspecs = i_getparameterspecs(svm_variant_num);
        [validate] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(9));
    case 'sync_channels'
        parameterspecs = i_getparameterspecs(svm_variant_num);
        [validate] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(10));
    case 'param_sync_move'
        parameterspecs = i_getparameterspecs(svm_variant_num);
        [validate] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(11));
    case 'param_sync_pw'
        parameterspecs = i_getparameterspecs(svm_variant_num);
        [validate] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(12));        
    case 'param_sync_prescaler'
        parameterspecs = i_getparameterspecs(svm_variant_num);
        [validate] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(13));        
    case 'param_resolver_move'
        parameterspecs = i_getparameterspecs(svm_variant_num);
        [validate] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(14));        
    case 'param_resolver_prescaler'
        parameterspecs = i_getparameterspecs(svm_variant_num);
        [validate] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(15));
    case 'init_svm_get_data'
        varargout{1} = i_init_svm_get_data(varargin{1});
    case 'init_svm'
        [varargout{1}, varargout{2}] = i_init_svm(block, varargin{:});
    otherwise
        error(['Invalid callback ', callback_fn]);
end
end

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

parameterspecs(1).ParamName = 'param_alpha';
parameterspecs(1).PrettyName = 'Alpha';
parameterspecs(1).MinVal = -2^15;
parameterspecs(1).MaxVal = 2^15-1;
parameterspecs(1).DataType = 'int16';
parameterspecs(1).ArrayLengthMin = 1;
parameterspecs(1).ArrayLengthMax = 1;
parameterspecs(1).ErrorMessage = '';
parameterspecs(1).SpecialConditions = [];

parameterspecs(2).ParamName = 'param_beta';
parameterspecs(2).PrettyName = 'Beta';
parameterspecs(2).MinVal = -2^15;
parameterspecs(2).MaxVal = 2^15-1;
parameterspecs(2).DataType = 'int16';
parameterspecs(2).ArrayLengthMin = 1;
parameterspecs(2).ArrayLengthMax = 1;
parameterspecs(2).ErrorMessage = '';
parameterspecs(2).SpecialConditions = [];

parameterspecs(3).ParamName = 'param_prescaler';
parameterspecs(3).PrettyName = 'prescaler';
parameterspecs(3).MinVal = 0;
parameterspecs(3).MaxVal = 2^16-1;
parameterspecs(3).DataType = 'uint16';
parameterspecs(3).ArrayLengthMin = 1;
parameterspecs(3).ArrayLengthMax = 1;
parameterspecs(3).ErrorMessage = '';
parameterspecs(3).SpecialConditions = [];

parameterspecs(4).ParamName = 'param_dt';
parameterspecs(4).PrettyName = 'DT';
parameterspecs(4).MinVal = 0;
parameterspecs(4).MaxVal = 2^16-1;
parameterspecs(4).DataType = 'uint16';
parameterspecs(4).ArrayLengthMin = 1;
parameterspecs(4).ArrayLengthMax = 1;
parameterspecs(4).ErrorMessage = '';
parameterspecs(4).SpecialConditions = [];

parameterspecs(5).ParamName = 'param_MPW';
parameterspecs(5).PrettyName = 'MPW';
parameterspecs(5).MinVal = 0;
parameterspecs(5).MaxVal = 2^16-1;
parameterspecs(5).DataType = 'uint16';
parameterspecs(5).ArrayLengthMin = 1;
parameterspecs(5).ArrayLengthMax = 1;
parameterspecs(5).ErrorMessage = '';
parameterspecs(5).SpecialConditions = [];

parameterspecs(6).ParamName = 'upper_channels';
parameterspecs(6).PrettyName = 'UPPER CHANNEL';
parameterspecs(6).MinVal = 0;
parameterspecs(6).MaxVal = 15;
parameterspecs(6).DataType = 'uint8';
parameterspecs(6).ArrayLengthMin = 3;
parameterspecs(6).ArrayLengthMax = 3;
parameterspecs(6).ErrorMessage = '';
parameterspecs(6).SpecialConditions = [];

parameterspecs(7).ParamName = 'lower_channels';
parameterspecs(7).PrettyName = 'LOWER CHANNEL';
parameterspecs(7).MinVal = 0;
parameterspecs(7).MaxVal = 15;
parameterspecs(7).DataType = 'uint8';
parameterspecs(7).ArrayLengthMin = 3;
parameterspecs(7).ArrayLengthMax = 3;
parameterspecs(7).ErrorMessage = '';
parameterspecs(7).SpecialConditions = [];

parameterspecs(8).ParamName = 'fault_channels';
parameterspecs(8).PrettyName = 'Fault Channels';
parameterspecs(8).MinVal = 0;
parameterspecs(8).MaxVal = 15;
parameterspecs(8).DataType = 'uint8';
parameterspecs(8).ArrayLengthMin = 0;
parameterspecs(8).ArrayLengthMax = 1;
parameterspecs(8).ErrorMessage = '';
parameterspecs(8).SpecialConditions = [];

parameterspecs(9).ParamName = 'resolver_channels';
parameterspecs(9).PrettyName = 'Resolver Channels';
parameterspecs(9).MinVal = 0;
parameterspecs(9).MaxVal = 15;
parameterspecs(9).DataType = 'uint8';
parameterspecs(9).ArrayLengthMin = 0;
parameterspecs(9).ArrayLengthMax = 15;
parameterspecs(9).ErrorMessage = '';
parameterspecs(9).SpecialConditions = [];

parameterspecs(10).ParamName = 'sync_channels';
parameterspecs(10).PrettyName = 'Synchronization Channels';
parameterspecs(10).MinVal = 0;
parameterspecs(10).MaxVal = 15;
parameterspecs(10).DataType = 'uint8';
parameterspecs(10).ArrayLengthMin = 0;
parameterspecs(10).ArrayLengthMax = 15;
parameterspecs(10).ErrorMessage = '';
parameterspecs(10).SpecialConditions = [];

parameterspecs(11).ParamName = 'param_sync_move';
parameterspecs(11).PrettyName = 'Synchronisation offset';
parameterspecs(11).MinVal = -2^15;
parameterspecs(11).MaxVal = (2^15)-1;
parameterspecs(11).DataType = 'int16';
parameterspecs(11).ArrayLengthMin = 0;
parameterspecs(11).ArrayLengthMax = 15;
parameterspecs(11).ErrorMessage = '';
parameterspecs(11).SpecialConditions = [];

parameterspecs(12).ParamName = 'param_sync_pw';
parameterspecs(12).PrettyName = 'Synchronisation pulse width';
parameterspecs(12).MinVal = 0;
parameterspecs(12).MaxVal = 2^16;
parameterspecs(12).DataType = 'uint16';
parameterspecs(12).ArrayLengthMin = 0;
parameterspecs(12).ArrayLengthMax = 15;
parameterspecs(12).ErrorMessage = '';
parameterspecs(12).SpecialConditions = [];

parameterspecs(13).ParamName = 'param_sync_prescaler';
parameterspecs(13).PrettyName = 'Synchronisation prescaler';
parameterspecs(13).MinVal = 0;
parameterspecs(13).MaxVal = 2^16;
parameterspecs(13).DataType = 'uint16';
parameterspecs(13).ArrayLengthMin = 0;
parameterspecs(13).ArrayLengthMax = 15;
parameterspecs(13).ErrorMessage = '';
parameterspecs(13).SpecialConditions = [];

parameterspecs(14).ParamName = 'param_resolver_move';
parameterspecs(14).PrettyName = 'Resolver offset';
parameterspecs(14).MinVal = -2^15;
parameterspecs(14).MaxVal = (2^15)-1;
parameterspecs(14).DataType = 'int16';
parameterspecs(14).ArrayLengthMin = 0;
parameterspecs(14).ArrayLengthMax = 15;
parameterspecs(14).ErrorMessage = '';
parameterspecs(14).SpecialConditions = [];

parameterspecs(15).ParamName = 'param_resolver_prescaler';
parameterspecs(15).PrettyName = 'Resolver prescaler';
parameterspecs(15).MinVal = 0;
parameterspecs(15).MaxVal = 2^16-1;
parameterspecs(15).DataType = 'uint16';
parameterspecs(15).ArrayLengthMin = 0;
parameterspecs(15).ArrayLengthMax = 15;
parameterspecs(15).ErrorMessage = '';
parameterspecs(15).SpecialConditions = [];

parameterspecs(16).ParamName = 'param_t';
parameterspecs(16).PrettyName = 'T';
parameterspecs(16).MinVal = 0;
parameterspecs(16).MaxVal = 2^16-1;
parameterspecs(16).DataType = 'uint16';
parameterspecs(16).ArrayLengthMin = 1;
parameterspecs(16).ArrayLengthMax = 1;
parameterspecs(16).ErrorMessage = '';
parameterspecs(16).SpecialConditions = [];

%% Adjust values as appropriate
%%
%% Length of upper and lower channels
%% 8 is upper
%% 9 is lower
%% For XOR variants only 1 resolver and only 1 prescaler channel are
%% allowed
switch svm_variant
    case 1 %% Standard
        parameterspecs(6).ArrayLengthMin = 3;
        parameterspecs(6).ArrayLengthMax = 3;
        parameterspecs(7).ArrayLengthMin = 3;
        parameterspecs(7).ArrayLengthMax = 3;
    case 2 %% Three outputs
        parameterspecs(6).ArrayLengthMin = 3;
        parameterspecs(6).ArrayLengthMax = 3;
        parameterspecs(7).ArrayLengthMin = 0;
        parameterspecs(7).ArrayLengthMax = inf;
    case 3 %% XOR version
        parameterspecs(6).ArrayLengthMin = 6;
        parameterspecs(6).ArrayLengthMax = 6;
        parameterspecs(7).ArrayLengthMin = 6;
        parameterspecs(7).ArrayLengthMax = 6;
%        for a = 9:15
%            parameterspecs(a).ArrayLengthMax = 1;
%        end
    case 4 %% Dead Time Correction
        parameterspecs(6).ArrayLengthMin = 3;
        parameterspecs(6).ArrayLengthMax = 3;
        parameterspecs(7).ArrayLengthMin = 3;
        parameterspecs(7).ArrayLengthMax = 3;
    case 5 %% 3Out XOR
        parameterspecs(6).ArrayLengthMin = 6;
        parameterspecs(6).ArrayLengthMax = 6;
        parameterspecs(7).ArrayLengthMin = 0;
        parameterspecs(7).ArrayLengthMax = inf;
%        for a = 9:15
%            parameterspecs(a).ArrayLengthMax = 1;
%        end        
    case 6 %% DT XOR
        parameterspecs(6).ArrayLengthMin = 6;
        parameterspecs(6).ArrayLengthMax = 6;
        parameterspecs(7).ArrayLengthMin = 6;
        parameterspecs(7).ArrayLengthMax = 6;
%        for a = 9:15
%            parameterspecs(a).ArrayLengthMax = 1;
%        end        
end

end


function i_callback_channels(block, position)

svm_variants = { ...
    'Standard', ...
    '3 outputs version', ...
    'XOR version', ...
    'Dead-Time correction', ...
    '3 outputs version XOR version', ...
    'Dead-Time correction - XOR version', ...
    };

svm_variant_num = strmatch(get_param(block, 'svm_variant'), svm_variants, 'exact');
parameterspecs = i_getparameterspecs(svm_variant_num);
[validate] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(position));

end

function i_callback_svm_variant(block)

svm_variant = get_param(gcb, 'svm_variant');

switch svm_variant
    case 'Standard'
        set_param(block, 'svm_threeoutputs', 'off');
        set_param(block, 'svm_xor', 'off');
        set_param(block, 'svm_dt', 'off');
    case '3 outputs version'
        set_param(block, 'svm_threeoutputs', 'on');
        set_param(block, 'svm_xor', 'off');
        set_param(block, 'svm_dt', 'off');
    case 'XOR version'
        set_param(block, 'svm_threeoutputs', 'off');
        set_param(block, 'svm_xor', 'on');
        set_param(block, 'svm_dt', 'off');
    case 'Dead-Time correction'
        set_param(block, 'svm_threeoutputs', 'off');
        set_param(block, 'svm_xor', 'off');
        set_param(block, 'svm_dt', 'on');
    case '3 outputs version XOR version'
        set_param(block, 'svm_threeoutputs', 'on');
        set_param(block, 'svm_xor', 'on');
        set_param(block, 'svm_dt', 'off');
    case 'Dead-Time correction - XOR version'
        set_param(block, 'svm_threeoutputs', 'off');
        set_param(block, 'svm_xor', 'on');
        set_param(block, 'svm_dt', 'on');
end

% Enable and disable mask parameters as appropriate
enable_conds(1).param_names = {'svm_variant'};
enable_conds(1).param_conditions = {'Standard'};
enable_conds(1).to_enable = {'param_dt', 'lower_channels', 'param_MPW'};
enable_conds(1).to_disable = {};
enable_conds(1).to_hide = {};
enable_conds(1).reciprocal = 0;
enable_conds(2).param_names = {'svm_variant'};
enable_conds(2).param_conditions = {'3 outputs version'};
enable_conds(2).to_enable = {'param_MPW'};
enable_conds(2).to_disable = {'lower_channels', 'param_dt'};
enable_conds(2).to_hide = {};
enable_conds(2).reciprocal = 0;
enable_conds(3).param_names = {'svm_variant'};
enable_conds(3).param_conditions = {'XOR version'};
enable_conds(3).to_enable = {'param_dt', 'lower_channels'};
enable_conds(3).to_disable = {'param_MPW'};
enable_conds(3).to_hide = {};
enable_conds(3).reciprocal = 0;
enable_conds(4).param_names = {'svm_variant'};
enable_conds(4).param_conditions = {'Dead-Time correction'};
enable_conds(4).to_enable = {'param_dt', 'lower_channels','param_MPW'};
enable_conds(4).to_disable = {};
enable_conds(4).to_hide = {};
enable_conds(4).reciprocal = 0;
enable_conds(5).param_names = {'svm_variant'};
enable_conds(5).param_conditions = {'3 outputs version XOR version'};
enable_conds(5).to_disable = {'param_dt', 'lower_channels','param_MPW'};
enable_conds(5).to_enable = {};
enable_conds(5).to_hide = {};
enable_conds(5).reciprocal = 0;
enable_conds(6).param_names = {'svm_variant'};
enable_conds(6).param_conditions = {'Dead-Time correction - XOR version'};
enable_conds(6).to_enable = {'param_dt', 'lower_channels'};
enable_conds(6).to_disable = {'param_MPW'};
enable_conds(6).to_hide = {};
enable_conds(6).reciprocal = 0;

mpc555_mtrctrl_maskparam(enable_conds);

end

function [cmdstring, paramvaluesout] = i_init_svm(block, paramvaluesin, structurename)

% Just create the output structure so we can add to it later
paramvaluesout.c = 1;

OutputValues = { 'param_alpha';
    'param_beta';
    'param_prescaler';
    'param_dt';
    'param_MPW';
    'param_sync_move';
    'param_sync_pw';
    'param_sync_prescaler';
    'param_resolver_move';
    'param_resolver_prescaler';
    'upper_channels';
    'lower_channels';
    'fault_channels';
    'resolver_channels';
    'sync_channels'};

%% Build up the string
cmdstring = '';
for currentparam = 1:length(OutputValues)
    cmdstring = [cmdstring,OutputValues{currentparam},' = ', structurename,'.', OutputValues{currentparam},'; '];
end

% Now validate values to ensure they are within range
parameterspecs = i_getparameterspecs(paramvaluesin.svm_variant);

for b = 1:length(OutputValues)
    currentvalidatename = OutputValues{b};
    currentvalidatenum = 0;
    for a = 1:length(parameterspecs)
        if strcmp(parameterspecs(a).ParamName, currentvalidatename)
            currentvalidatenum = a;
        end
    end
    if currentvalidatenum == 0
        error('Invalid parameter name');
    else
        % Run the standard validation routines
        [validate] = mpc555_mtrctrl_validate_value(...
            paramvaluesin.(currentvalidatename), ...
            parameterspecs(currentvalidatenum));
        if ~validate.Overall
            %%%%% Do this if not validated correctly
            str_message = mpc555_mtrctrl_validate_error(parameterspecs(currentvalidatenum), validate);
            error(str_message);
        else
            %% If validated correctly copy to the output
            field_temp = paramvaluesin.(currentvalidatename);
            paramvaluesout.(currentvalidatename) = field_temp;
        end
    end
end

end

function [cmdstring] = i_init_svm_get_data(structurename)

% Cell array of strings containing the variables which should be passed
% into the initialisation function

InputValues = {
    'param_alpha';
    'param_beta';
    'param_prescaler'; %% This _IS_ required
    'param_dt'; %% This _IS_ required
    'param_MPW'; %% This _IS_ required
    'param_sync_move'; %% This _IS_ required
    'param_sync_pw'; %% This _IS_ required
    'param_sync_prescaler'; %% This _IS_ required
    'param_resolver_move'; %% This _IS_ required
    'param_resolver_prescaler'; %% This _IS_ required
    'upper_channels';
    'lower_channels';
    'fault_channels';
    'resolver_channels';
    'sync_channels';
    'svm_variant'};

%% Build up the string
cmdstring = '';

for currentparam = 1:length(InputValues)
    cmdstring = [cmdstring, structurename,'.',InputValues{currentparam},' = ', InputValues{currentparam},'; '];
end

end

Contact us