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

% Get a list of parameters which would be valid to pass to this block
callback_params = get_param(block, 'MaskNames');

% Get a list of parameters which have specifications which must be adhered
% to
[f,c] = i_parameterspecs();

% Create a list of parameters which will be numerically validated
params_to_validate = c(:,1);

% Create a list of parameters to ignore
params_to_ignore = callback_params;
for a = 1:length(params_to_validate)
   paramtokill = strmatch(params_to_validate{a}, params_to_ignore, 'exact');
   params_to_ignore(paramtokill) = '';
end

paramtokill = strmatch('init_dcm', params_to_ignore, 'exact');
params_to_ignore(paramtokill) = '';

switch callback_fn
    case 'channel_faultpin'
        i_callback_channel_faultpin(block);
        [validate] = mpc555_mtrctrl_validate_mask_value(block, i_getparameterspecs(callback_fn));
    case params_to_validate
        [validate] = mpc555_mtrctrl_validate_mask_value(block, i_getparameterspecs(callback_fn));
    case 'dcm_variant'
        i_callback_dcm_variant(block);
    case params_to_ignore
        % Just save that the parameter has changed
        mpc555_mtrctrl_mask_copy_values(block, 'save');
        return;
    case 'init_dcm_get_data'
        varargout{1} = i_init_bldc_get_data(varargin{1});
    case 'init_dcm'
        [varargout{1}, varargout{2}] = i_init_bldc(block, varargin{:});
    otherwise
        error(['Invalid callback ', callback_fn]);
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function [f,c] = i_parameterspecs()
%
function [f,c] = i_parameterspecs()

f = {'ParamName',               'PrettyName',               'MinVal',   'MaxVal',   'DataType', 'ArrayLengthMin',   'ArrayLengthMax',   'ErrorMessage', 'SpecialConditions'};

c = {'channel_faultpin',        'Fault Channels',           0,          15,         'uint8',    0,                  1,                  '',             []; ...
     'channel_resolver',        'Resolver Channels',        0,          15,         'uint8',    0,                  15,                 '',             []; ...
     'channel_sync',            'Synchronization Channels', 0,          15,         'uint8',    0,                  15,                 '',             []; ...
     'param_dc',                'Initial duty cycle',       -2^15,      (2^15)-1,   'int16',    1,                  1,                  '',             []; ...
     'param_t',                 'T',                        0,          (2^16)-1,   'uint16',   1,                  1,                  '',             []; ...     
     'param_dt',                'DT',                       0,          (2^16)-1,   'uint16',   1,                  1,                  '',             []; ...          
     'param_mpw',               'MPW',                      0,          (2^16)-1,   'uint16',   1,                  1,                  '',             []; ...               
     'param_sync_move',         'Synchronisation offset',   -2^15,      (2^15)-1,   'int16',    0,                  15,                 '',             []; ...
     'param_sync_pw',           'Synchronization pulse width', 0,       2^16-1,     'uint16',   0,                  15,                 '',             []; ...
     'param_sync_presc',        'Synchronization prescaler',0,          2^16-1,     'uint16',   0,                  15,                 '',             []; ...
     'param_res_move',          'Resolver offset',          -2^15       2^15-1,     'int16',    0,                  15,                 '',             []; ...
     'param_res_presc',         'Resolver prescaler',       0,          2^16-1,     'uint16',   0,                  15,                 '',             []; ...
     };

end

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

% Get the raw table of parameterspecs
[f,c] = i_parameterspecs();

% Convert the table to a cell structure
parameterspecs = cell2struct(c,f,2);

switch nargin
    case 0 
        % If no parameters are specified when the function is called return
        % the whole list
        return;
    case 1
        % If a parameter is specified then return the specification
        % table for only this item
        paramnumber = strmatch(varargin(1), c(:,1), 'exact');
        if isempty(paramnumber)
           error(['Invalid parameter name ', varargin(1)]);
        else
           parameterspecs = parameterspecs(paramnumber); 
        end
    otherwise
        error('Invalid number of parameters')
        
end

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Disabling output port if there are no fault pins enabled.
%
function i_callback_channel_faultpin(block)
    channel_faultpin = get_param(block, 'channel_faultpin');
    if isempty(str2num(channel_faultpin))
       simUtil_maskParam('disable', block, 'outport_faultpin'); 
       set_param(block, 'outport_faultpin', 'off');
    else
       simUtil_maskParam('enable', block, 'outport_faultpin');  
    end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Initialisation function for Brushless DC function
%
function [cmdstring, paramvaluesout] = i_init_bldc(block, paramvaluesin, structurename)

[f,c] = i_parameterspecs();

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

OutputValues = c(:,1);

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

% In this case, just get the whole list of parameter specs.
parameterspecs = i_getparameterspecs();

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_bldc_get_data(structurename)

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

[f,c] = i_parameterspecs();
InputValues = c(:,1);

%% Build up the string
cmdstring = '';

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

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
function i_callback_dcm_variant(block)

enable_conds(1).param_names = {'dcm_variant'};
enable_conds(1).param_conditions = {'Standard'};
enable_conds(1).to_enable = {'channel_sw1', 'channel_sw2', 'channel_sw3', 'channel_sw4', 'param_dt', 'param_mpw'};
enable_conds(1).to_disable = {'channel_sw1_2', 'channel_sw2_2', 'channel_sw3_2', 'channel_sw4_2'};
enable_conds(1).to_hide = {'channel_sw1_2', 'channel_sw2_2', 'channel_sw3_2', 'channel_sw4_2'};
enable_conds(1).reciprocal = 0;

enable_conds(2).param_names = {'dcm_variant'};
enable_conds(2).param_conditions = {'2 Outputs Version'};
enable_conds(2).to_enable = {'channel_sw1', 'channel_sw3', 'param_mpw'};
enable_conds(2).to_disable = {'channel_sw1_2', 'channel_sw2', 'channel_sw2_2', 'channel_sw3_2', 'channel_sw4', 'channel_sw4_2', 'param_dt'};
enable_conds(2).to_hide = {'channel_sw1_2', 'channel_sw2', 'channel_sw2_2', 'channel_sw3_2', 'channel_sw4', 'channel_sw4_2'};
enable_conds(2).reciprocal = 0;

enable_conds(3).param_names = {'dcm_variant'};
enable_conds(3).param_conditions = {'XOR Version'};
enable_conds(3).to_enable = {'channel_sw1', 'channel_sw2', 'channel_sw3', 'channel_sw4', 'param_dt', 'channel_sw1_2', 'channel_sw2_2', 'channel_sw3_2', 'channel_sw4_2'};
enable_conds(3).to_disable = { 'param_mpw' };
enable_conds(3).to_hide = {};
enable_conds(3).reciprocal = 0;

enable_conds(4).param_names = {'dcm_variant'};
enable_conds(4).param_conditions = {'Dead Time Correction Version'};
enable_conds(4).to_enable = {'channel_sw1', 'channel_sw2', 'channel_sw3', 'channel_sw4', 'param_dt', 'param_mpw'};
enable_conds(4).to_disable = {'channel_sw1_2', 'channel_sw2_2', 'channel_sw3_2', 'channel_sw4_2'};
enable_conds(4).to_hide = {'channel_sw1_2', 'channel_sw2_2', 'channel_sw3_2', 'channel_sw4_2'};
enable_conds(4).reciprocal = 0;

enable_conds(5).param_names = {'dcm_variant'};
enable_conds(5).param_conditions = {'2 Outputs XOR Version'};
enable_conds(5).to_enable = {'channel_sw1', 'channel_sw1_2', 'channel_sw3', 'channel_sw3_2'};
enable_conds(5).to_disable = {'channel_sw2', 'channel_sw2_2', 'channel_sw4', 'channel_sw4_2', 'param_dt', 'param_mpw'};
enable_conds(5).to_hide = {'channel_sw2', 'channel_sw2_2', 'channel_sw4', 'channel_sw4_2'};
enable_conds(5).reciprocal = 0;

enable_conds(6).param_names = {'dcm_variant'};
enable_conds(6).param_conditions = {'XOR Version with Dead Time Correction Version'};
enable_conds(6).to_enable = {'channel_sw1', 'channel_sw2', 'channel_sw3', 'channel_sw4', 'param_dt', 'channel_sw1_2', 'channel_sw2_2', 'channel_sw3_2', 'channel_sw4_2'};
enable_conds(6).to_disable = { 'param_mpw' };
enable_conds(6).to_hide = {};
enable_conds(6).reciprocal = 0;

mpc555_mtrctrl_maskparam(enable_conds);

end

Contact us