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_sample(block, callback_fn, varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function varargout = mpc555_mtrctrl_tpu_sample(block, callback_fn, varargin)
%
function varargout = mpc555_mtrctrl_tpu_sample(block, callback_fn, varargin)
% This is the entry function to allow the appropriate callback functions to
% be run
switch callback_fn
    case 'edit_raw_values'
        i_callback_edit_raw_values(block);
    case 'ideal_period'
        i_callback_ideal_period(block);
    case 'param_period'
        i_callback_param_period(block);
    case 'base_clock'
        i_callback_base_clock(block);
    case 'initialisation'
        varargout = i_initialisation(block, varargin);
    otherwise
        error('Invalid callback');
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function [param_period] = i_initialisation(block, edit_raw_values, base_clock, ...
%    ideal_period, param_period)
%
function [param_period] = i_initialisation(block, edit_raw_values, base_clock, ...
    ideal_period, param_period)

% Get value of current clock
[clock, clockvalid] = mpc555_mtrctrl_getclock(block);

% Ensure that values have been claulcated appropriately
if edit_raw_values
   [param_period] = ... 
       mpc555_mtrctrl_calc_param(ideal_period, clock, clockvalid);
else
    param_period = param_period;
end

% Now check to see if the value created is in fact within range
[param_period, valid_value] = mpc555_mtrctrl_validate_value( ...
    param_period, 0, 32768, 'uint16');

% Now throw an appropriate error dialog if not
if valid_value == 0
    switch edit_raw_values
        case 1
            str_message = mpc555_mtrctrl_validate_error(0, 32768, 'PARAM_NAME', 'uint16');
        case 0
            str_message = mpc555_mtrctrl_validate_error(0, 32768, 'PERIOD', 'uint16');
        otherwise
            str_message = 'Something screwed up';
    end
    error(str_message);
end

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_period'};
enable_conds(1).to_disable = {'ideal_period'};
enable_conds(1).to_hide = {};
enable_conds(1).reciprocal = 1;
mpc555_mtrctrl_maskparam(enable_conds);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function i_callback_ideal_period(block)
%
function i_callback_ideal_period(block)

[clock, clockvalid] = mpc555_mtrctrl_getclock(block);

mpc555_mtrctrl_calc_mask_param(block, ...
    'edit_raw_values', 'off', ...
    'ideal_period', 'IDEAL PERIOD', ...
    'param_period', 'PRETTY PERIOD', ...
    clock, clockvalid, 0, 32768, ...
    'uint16');
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function i_callback_param_period(block)
%
function i_callback_param_period(block)

% Check that the value that has been entered is within range
[new_param_value, valid_value] = mpc555_mtrctrl_validate_mask_value(...
    block, ...
    'param_period', ...
    'WINDOW_PERIOD', ...
    0, 32767, 'uint16');

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

mpc555_mtrctrl_calc_mask_actual(block, ... 
    'param_period', ...
    'actual_period', ...
    clock, clockvalid);

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function i_callback_base_clock(block)
%
function i_callback_base_clock(block)
    i_callback_ideal_period(block);
    i_callback_param_period(block);
end

Contact us