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_drawing_command(blockhandle, ...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FUNCTION DRAWINGCOMMAND = MPC555_MTRCTRL_DRAWING_COMMAND(BLOCKHANDLE, ...
%    BLOCKTITLE, IMAGEFILE, IMAGESIZE, INPUTPORTMATCH, OUTPUTPORTMATCH)   
%
% Returns the command to be added to the mask to draw the title, port
% labels etc... on the Simulink block.  Also turns on/off dynamically
% enabled ports
%

function drawingcommand = mpc555_mtrctrl_drawing_command(blockhandle, ...
    blocktitle, imagefile, imagesize, inputportmatch, outputportmatch)

% Enable / disable ports according to mask selections
inputportcell = i_enable_ports(blockhandle, inputportmatch);
outputportcell = i_enable_ports(blockhandle, outputportmatch);

% Define the carriage-return character
cr=sprintf('\n');
drawingcommand = '';

% Include the image if necessary
if length(imagefile) ~= 0
    drawingcommand=['image(imread(''', imagefile, '''),', mat2str(imagesize), ', ''on'' )',cr];
end

% Include the name of the block
drawingcommand=[drawingcommand, 'disp(''', blocktitle, ''');',cr];

% Now include the input and output ports
drawingcommand = [drawingcommand, i_drawing_command_block( 'input', inputportcell)];
drawingcommand = [drawingcommand, i_drawing_command_block( 'output', outputportcell)];


end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
function portcell = i_enable_ports(blockhandle, portmatch)

% Initialise portcell
portcell = {};

if size(portmatch,2) == 0
    return;
end

for n = 1:size(portmatch,2)
    if portmatch{1,n} ~= 0
       portcell = [portcell, portmatch{2,n}];
    end
    if portmatch{1,n} ~= -1
        simulinkPortControl(blockhandle, 'enable', portmatch{2,n}, portmatch{1,n});
    end
end

end
    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
function drawingcommandline = i_drawing_command_line( port_type, portcell, n )

drawingcommandline = ['port_label(''', port_type ,''',',num2str(n),',''', portcell{n}, ''')'];

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
function drawingcommandblock = i_drawing_command_block(port_type, portcell)

% Initialise drawingcommandblock
cr=sprintf('\n');
drawingcommandblock = '';

if size(portcell,2) == 0
    return;
end

% For each command in the cell array add it to the list
for n = 1:size(portcell,2)
    drawingcommandblock=[drawingcommandblock, i_drawing_command_line(port_type, portcell, n), cr];
end

end

Contact us