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_calc_mask_param(block, condition_var, ...
%function mpc555_mtrctrl_calc_mask_param(block, condition_var, ...
%    condition_val, parameterspec_ideal, parameterspec_param, ...
%    clock, clockvalid)
% This function returns the calculated parameter and whether this parameter
% is valid.
%
% Inputs are:
%       'block':                The block for which this is relevant
%       'condition_var':        The name of the condition variable
%       'condition_val':        Value of the condition variable to run
%       'parameterspec_ideal':  Parameterspecs structure for ideal value
%       'parameterspec_param':  Parameterspecs structure for the final
%       'clock':                Clock frequency as appropriate
%       'clockvalid':
function mpc555_mtrctrl_calc_mask_param(block, condition_var, ...
    condition_val, parameterspec_ideal, parameterspec_param, ...
    clock, clockvalid)

% Do nothing and return if conditions for allowing this to be calculated
% are not met.
if ~strcmp(get_param(block, condition_var), condition_val)
    return;
end

% Get the ideal value from the mask parameters
ideal_var_value = str2num(get_param(block, parameterspec_ideal.ParamName));

% Calculate the new parameter value
[new_param_value] = mpc555_mtrctrl_calc_param(ideal_var_value, ...
    clock, clockvalid);

% Check that the value is in fact valid
[valid_value] = mpc555_mtrctrl_validate_value(...
    new_param_value, ...
    parameterspec_param);

% If the value is valid, set it.
if (valid_value.Overall == 1)
    set_param(block, parameterspec_param.ParamName, num2str(new_param_value));
    % Back up the valid values
    mpc555_mtrctrl_mask_copy_values(block, 'save');
else % throw an error
    min_val_act = mpc555_mtrctrl_calc_actual(parameterspec_param.MinVal, clock, clockvalid);
    max_val_act = mpc555_mtrctrl_calc_actual(parameterspec_param.MaxVal, clock, clockvalid);
    parameterspec_ideal.MinVal = min_val_act;
    parameterspec_ideal.MaxVal = max_val_act;
    str_message = mpc555_mtrctrl_validate_error(parameterspec_ideal, valid_value);
    mpc555_mtrctrl_mask_error(block, str_message, 'Invalid value');
end

end

Contact us