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_fqm(block, action, varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FUNCTION [VARARGOUT] = MPC555_MTRCTRL_TPU_FQM(BLOCK, ACTION, VARARGIN)
%
% Initialisation and block mask callback functions for TPU FQM block
%
function [varargout] = mpc555_mtrctrl_tpu_fqm(block, action, varargin)

switch lower(action)
    case 'edit_raw_values'
        i_callback_edit_raw_values(block);
    case 'ideal_window_size'
        i_callback_ideal_window_size(block);
    case 'param_window_size'
        i_callback_param_window_size(block);
    case 'base_clock'
        i_callback_ideal_window_size(block);
        i_callback_param_window_size(block);
    case 'model_initialisation'
        % note: no set_params are allowed in block initialisation callback
        varargout{1} = i_model_initialisation(block, varargin{1}, varargin{2});
    otherwise
        error(['Action ' action ' not found!']);
end
end


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

parameterspecs(1).ParamName = 'param_window_size';
parameterspecs(1).PrettyName = 'WINDOW_SIZE';
parameterspecs(1).MinVal = 0;
parameterspecs(1).MaxVal = 32768;
parameterspecs(1).DataType = 'uint16';
parameterspecs(1).ArrayLengthMin = 1;
parameterspecs(1).ArrayLengthMax = 1;
parameterspecs(1).ErrorMessage = '';
parameterspecs(1).SpecialConditions = [];

parameterspecs(2).ParamName = 'ideal_window_size';
parameterspecs(2).PrettyName = 'IDEAL_PERIOD';
parameterspecs(2).MinVal = 0;
parameterspecs(2).MaxVal = inf;
parameterspecs(2).DataType = 'uint16';
parameterspecs(2).ArrayLengthMin = 1;
parameterspecs(2).ArrayLengthMax = 1;
parameterspecs(2).ErrorMessage = '';
parameterspecs(2).SpecialConditions = [];

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function i_callback_edit_raw_values(block)
%
function i_callback_edit_raw_values(block)

enable_conds(1).param_names = {'edit_raw_values'};
enable_conds(1).param_conditions = {'on'};
enable_conds(1).to_enable = {'param_window_size'};
enable_conds(1).to_disable = {'ideal_window_size'};
enable_conds(1).to_hide = {};
enable_conds(1).reciprocal = 1;
mpc555_mtrctrl_maskparam(enable_conds);

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function i_callback_ideal_window_size(block)
%
function i_callback_ideal_window_size(block)

if ~mpc555_mtrctrl_mask_processing(block)
    % Do not calculate if acting in a library or w/o control block
    return;
end

% Get the clock frequency and check to see if it is valid
[clock, clockvalid] = mpc555_mtrctrl_getclock(block);

% Calculate the window size parameter
parameterspecs = i_getparameterspecs();
mpc555_mtrctrl_calc_mask_param(block, ...
    'edit_raw_values', 'off', ...
    parameterspecs(2), parameterspecs(1),...
    clock, clockvalid);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function i_callback_param_window_size(block)
%
function i_callback_param_window_size(block)

if ~mpc555_mtrctrl_mask_processing(block)
    % Do not calculate if acting in a library or w/o control block
    return;
end

% Check that the value that has been entered is within range
parameterspecs = i_getparameterspecs();
[valid_value] = mpc555_mtrctrl_validate_mask_value(block, parameterspecs(1));

% Calculate the actual period time now
[clock, clockvalid] = mpc555_mtrctrl_getclock(block);

mpc555_mtrctrl_calc_mask_actual(block, ...
    'param_window_size', ...
    'actual_window_size', ...
    clock, clockvalid);

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MODEL INITIALISATION FUNCTION
%
function param_window_size = ...
    i_model_initialisation(block, param_window_size, ideal_window_size)

if ~mpc555_mtrctrl_mask_processing(block)
    % Don't process this if acting in a library or without a control block
    return;
end

% Get a copy of the parameter specs
parameterspecs = i_getparameterspecs();

% find the clock speeds for the appropriate TPU module
% Attempt to get clock frequency
[clock, clockvalid] = mpc555_mtrctrl_getclock(block);


edit_raw_values = get_param(block, 'edit_raw_values');
switch edit_raw_values
    case 'on'         % param_window_size is set manually in the mask
        % check value is in range
        [validate] = mpc555_mtrctrl_validate_value(param_window_size, parameterspecs(1));
        if ~validate.Overall
            str_message = mpc555_mtrctrl_validate_error(parameterspecs(1), validate);
            error(str_message);
        end

    case 'off'        % ideal period is set in the mask
        if ~clockvalid
            error('An ideal period cannot be calculated if an external clock is used.');
        end
        % derive param_window_size
        [param_window_size] = ...
            mpc555_mtrctrl_calc_param(ideal_window_size, clock, clockvalid);
        % check value is in range
        [validate] = mpc555_mtrctrl_validate_value(param_window_size, parameterspecs(1));
        if ~validate.Overall
            parameterspecs(2).MinVal = mpc555_mtrctrl_calc_actual(0, clock, clockvalid);
            parameterspecs(2).MaxVal = mpc555_mtrctrl_calc_actual(32768, clock, clockvalid);
            str_message = mpc555_mtrctrl_validate_error(parameterspecs(2), validate);
            error(str_message);
        end
end

end


Contact us