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_sm_remote.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Description: 
%
% This is the callback that occurs on initialisation
% when the TPU SM Remote block is initialised within
% the model.
% 
% Example:  None necessary!
% 
channel = channel-1;

system = gcs;
block = gcb;
blockh = gcbh;


if ~strcmp(get_param(bdroot(gcb), 'BlockDiagramType'), 'library')
    % A few constants related to the block mask display
    block_name = '';
    image_name = '';
    image_posn = [];

    % Define the relationship between settings and input ports
    inputportmatch = { ...
        eq(mode_inout,1); ...
        'NEWCURR'};

    % Define the relationship settings and output ports
    outputportmatch = { ...
        eq(mode_inout,2); ...
        'CURR'};

    % Enable and disable correct ports as appropriate
    drawingcommand = mpc555_mtrctrl_drawing_command(blockh, ...
        block_name, ...
        image_name, ...
        image_posn, ...
        inputportmatch, ...
        outputportmatch);

    oldcommand = get_param(block,'MaskDisplay');

    if ~strcmp(oldcommand, drawingcommand)
        % Update port labels
        set_param(block,'MaskDisplay',drawingcommand);
        return;
    end
end

realblocks = find_system((system), 'ReferenceBlock', ...
        'mpc555_mtrctrl/TPU3 Stepper Motor');
realblocks = [realblocks, ...
        find_system((system), 'ReferenceBlock', ...
        'mpc555_mtrctrl/TPU3 Table Stepper Motor')];

    
buildup = 'popup(';

if length(realblocks) ~= 0
    buildup = 'popup(<empty>|';
    for n = 1:length(realblocks)
        buildup=[buildup,realblocks{n}];
        if n~=length(realblocks)
           buildup=[buildup,'|']; 
        else
            buildup = [buildup, ')'];
        end
    end
else
   buildup='popup(<empty>)';
end

if strcmp(get_param(bdroot(gcb), 'BlockDiagramType'), 'library')
    buildup='popup(<empty>)';
end

aaa = get_param(block, 'maskstyles');

aaa{1} = buildup;

% Cancel the closing block dialog warning for the moment
[tempwarning] = warning('off', 'Simulink:SL_MaskClosingBlockDialog');

set_param(block, 'maskstyles', aaa);

% Set the warning status to back how it was before
[tempwarning] = warning(tempwarning.state, 'Simulink:SL_MaskClosingBlockDialog');


if length(realblocks) ~= 0
   if strcmp(get_param(block, 'linkto'), '<empty>')
       error('Please select TSM or SM blocks in the model to trigger'); 
   end
   channel = str2num(get_param( get_param(block, 'linkto'), 'channel'));
   module = (get_param( get_param(block, 'linkto'), 'module'));

   switch( get_param( get_param(block, 'linkto'), 'referenceblock') )
       case 'mpc555_mtrctrl/TPU3 Stepper Motor'
           smortsm = 1;
       case 'mpc555_mtrctrl/TPU3 Table Stepper Motor'
           smortsm = 2;
   end
else
   error('No TSM or SM blocks in the model to trigger'); 
end

Contact us