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_mask_copy_values(block, fn)
function mpc555_mtrctrl_mask_copy_values(block, fn)

% Declare the mask values for the current block as persistent
persistent blockmaskvalues
persistent blocknames

% If the parameters have not been initialised, do so
if ~iscell(blockmaskvalues)
    blockmaskvalues = {};
end

if ~iscell(blocknames)
    blocknames = {};
end

switch fn
    case 'save'
        [blocknames, blockmaskvalues] =...
            i_save_block(block, blocknames, blockmaskvalues);
    case 'restore'
        i_restore_block(block, blocknames, blockmaskvalues);
    case 'delete'
        [blocknames, blockmaskvalues] = ...
            i_clear_block(block, blocknames, blockmaskvalues);
    otherwise
        error('Invalid function');
end

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  SAVE VALUES FROM THE CURRENT BLOCK
%
function [blocknames, blockmaskvalues] = i_save_block(block, blocknames, blockmaskvalues)
        % First we should check to see that the block isn't already in
        % memory
        current_posn = strmatch(block, blocknames, 'exact');
        % If there is not a value
        if isempty(current_posn)
            % Take a copy of the name of the block so we can check
            % later on
            blocknames = [blocknames, block];
            % Take a copy of the current mask values in the persistent variable
            blockmaskvalues = [blockmaskvalues, {get_param(block, 'MaskValues')}];
        else
            blockmaskvalues{current_posn} = get_param(block, 'MaskValues');
        end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  RESTORE VALUES INTO THE CURRENT BLOCK
%
function i_restore_block(block, blocknames, blockmaskvalues)
            % Restore the current mask values from the persistent variable
            % First we should check to see that the block isn't already in
            % memory
            current_posn = strmatch(block, blocknames, 'exact');
            if ~isempty(current_posn)
                set_param(block, 'MaskValues', blockmaskvalues{current_posn});
            else
                warning('No backed up values for this block');
            end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  CLEAR VALUES FOR CURRENT BLOCK
%
function [blocknames, blockmaskvalues] = i_clear_block(block, blocknames, blockmaskvalues)
        % First we should check to see that the block isn't already in
        % memory
        current_posn = strmatch(block, blocknames, 'exact');
        % If there is not a value
        if isempty(current_posn)
            % Do nothing
        else
            blockmaskvalues{current_posn} = [];
        end

end

Contact us