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_check(block, system)
function mpc555_mtrctrl_check(block, system)

% Define the blocks we wish to check for and what we wish to check
tocheckfor{1} = 'mpc555_mtrctrl/TPU3 Three-Phase Sine Wave';
tocheckfor{2} = 'mpc555_mtrctrl/TPU3 Space Vector Modulation';
tocheckfor{3} = ['mpc555_mtrctrl/TPU3 Brushless DC Motor', sprintf('\n'), 'Commutation'];
tocheckfor{4} = 'mpc555_mtrctrl/TPU3 DC Motor Drive';

% Check for blocks of the specified type

realblocks = {};

for a = 1:length(tocheckfor)
    realblocks = [realblocks; ...
        find_system(bdroot(system), 'ReferenceBlock', ...
        tocheckfor{a})];
end

for a = 1:length(realblocks)
    refblk = get_param([realblocks{a}], 'ReferenceBlock');
    switch refblk
        case tocheckfor{1}
            i_verify_3sin(realblocks{a}, system, block);

        case tocheckfor{2}
            i_verify_svm(realblocks{a}, system, block);

        case tocheckfor{3}
            i_verify_bldc(realblocks{a}, system, block);

        case tocheckfor{4}
            i_verify_dcm(realblocks{a}, system, block);

    end
end

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [paramvalue] = i_parse_asi_file(block, system, dptramblock, asifile)

dptram_res = get_param(dptramblock, 'userdata');

if isempty(dptram_res)
    error ('Either no image has been compiled yet, or the block referenced is not a DPTRAM Wizard'); 
end

macronumber = 0;
if length(dptram_res.Macros) ~=0
    for n=1:length(dptram_res.Macros)
        if strcmp( upper(dptram_res.Macros{n}.Name), upper(asifile) )
           macronumber = n; 
        end
    end
end

if macronumber == 0;
    error (['The macro for ', asifile, 'has not been compiled in the DPTRAM Wizard']); 
end


paramvalue = mpc555_mtrctrl_invert_macrodata(dptram_res.Macros{macronumber}.Channels, asifile);

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function i_verify_3sin(block, system, dptramblock)

% Find the block variant
chosen_variant = get_param(block, 'threesin_variant');

variantstring{1} = 'Standard';
variantstring{2} = '3 outputs version';
variantstring{3} = 'XOR version';
variantstring{4} = 'Dead-Time correction';
variantstring{5} = '3 outputs version XOR version';
variantstring{6} = 'Dead-Time correction - XOR version';

switch chosen_variant
    case variantstring{1}
        asifile = '3Sin';
        variantnumber = 1;
    case variantstring{2}
        asifile = '3Sin3';
        variantnumber = 2;
    case variantstring{3}
        asifile = '3SinXor';
        variantnumber = 3;
    case variantstring{4}
        asifile = '3SinDt';
        variantnumber = 4;
    case variantstring{5}
        asifile = '3Sin3Xor';
        variantnumber = 5;
    case variantstring{6}
        asifile = '3SinDtXor';
        variantnumber = 6;
    otherwise
        error('Invalid variant');
end

[paramvalue] = i_parse_asi_file(block, system, dptramblock, asifile);

% Find the channels which are being used
upper = str2num(get_param(block, 'upper_channels'));
lower = str2num(get_param(block, 'lower_channels'));
cosine = str2num(get_param(block, 'cosine_channel'));

%%% Now we need to match the numbers
fieldheadings = {'upperrange',  'upperparams',  'lowerrange',   'lowerparams',  'cosineparams'};
fielddata = {   (1:3),          [1,3,5],        (1:3),          [2,4,6],         7; ...
                (1:3),          (1:3),          [],             [],              4; ...
                (1:6),          [1:2,5:6,9:10], (1:6),          [3:4,7:8,11:12], 13; ...
                (1:3),          [1,3,5],        (1:3),          [2,4,6],         7; ...
                (1:6),          (1:6),          [],             [],              7; ...
                (1:6),          [1:2,5:6,9:10], (1:6),          [3:4,7:8,11:12], 13};

param_matches = cell2struct(fielddata, fieldheadings, 2);

i_check_params(upper(param_matches(variantnumber).upperrange), ...
    paramvalue( param_matches(variantnumber).upperparams), ...
    'Upper', 'numbers', 'values', 'are', '3Sin:');

i_check_params(lower(param_matches(variantnumber).lowerrange), ...
    paramvalue( param_matches(variantnumber).lowerparams), ...
    'Lower', 'numbers', 'values', 'are', '3Sin:');

i_check_params(cosine, ...
    paramvalue( param_matches(variantnumber).cosineparams), ...
    'Cosine', 'number', 'value', 'is', '3Sin:');

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function i_verify_svm(block, system, dptramblock)

% Find the block variant
chosen_variant = get_param(block, 'svm_variant');

variantstring{1} = 'Standard';
variantstring{2} = '3 outputs version';
variantstring{3} = 'XOR version';
variantstring{4} = 'Dead-Time correction';
variantstring{5} = '3 outputs version XOR version';
variantstring{6} = 'Dead-Time correction - XOR version';

switch chosen_variant
    case variantstring{1}
        asifile = 'svmStd';
        variantnumber = 1;
    case variantstring{2}
        asifile = 'svmStd3';
        variantnumber = 2;
    case variantstring{3}
        asifile = 'svmStdXor';
        variantnumber = 3;
    case variantstring{4}
        asifile = 'svmStdDt';
        variantnumber = 4;
    case variantstring{5}
        asifile = 'svmStd3Xor';
        variantnumber = 5;
    case variantstring{6}
        asifile = 'svmStdDtXor';
        variantnumber = 6;
    otherwise
        error('Invalid variant');
end

[paramvalue] = i_parse_asi_file(block, system, dptramblock, asifile);

% Find the channels which are being used
upper = str2num(get_param(block, 'upper_channels'));
lower = str2num(get_param(block, 'lower_channels'));

%%% Now we need to match the numbers
fieldheadings = {'upperrange',  'upperparams',  'lowerrange',   'lowerparams'};
fielddata = {   (1:3),          [1,3,5],        (1:3),          [2,4,6]; ...
                (1:3),          (1:3),          [],             [];...
                (1:6),          [1:2,5:6,9:10], (1:6),          [3:4,7:8,11:12];...
                (1:3),          [1,3,5],        (1:3),          [2,4,6];...
                (1:6),          (1:6),          [],             [];...
                (1:6),          [1:2,5:6,9:10], (1:6),          [3:4,7:8,11:12]};

param_matches = cell2struct(fielddata, fieldheadings, 2);

i_check_params(upper(param_matches(variantnumber).upperrange), ...
    paramvalue( param_matches(variantnumber).upperparams), ...
    'Upper', 'numbers', 'values', 'are', 'SVM:');

i_check_params(lower(param_matches(variantnumber).lowerrange), ...
    paramvalue( param_matches(variantnumber).lowerparams), ...
    'Lower', 'numbers', 'values', 'are', 'SVM:');

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function i_verify_bldc(block, system, dptramblock)

% Find the block variant
chosen_variant = get_param(block, 'bldc_variant');

variantstring{1} = 'BLDCm - type I';
variantstring{2} = 'BLDC - type II';

switch chosen_variant
    case variantstring{1}
        asifile = 'BLDCm';
        variantnumber = 1;
    case variantstring{2}
        asifile = 'BLDC';
        variantnumber = 2;
    otherwise
        error('Invalid variant');
end

[paramvalue] = i_parse_asi_file(block, system, dptramblock, asifile);

% Find the channels which are being used
hallchannels = [str2num(get_param(block, 'channel_3hd_a')), ...
    str2num(get_param(block, 'channel_3hd_b')), ...
    str2num(get_param(block, 'channel_3hd_c'))];

bldcchannels = [str2num(get_param(block, 'channel_q1')), ...
    str2num(get_param(block, 'channel_q2')), ...
    str2num(get_param(block, 'channel_q3')), ...
    str2num(get_param(block, 'channel_q4')), ...
    str2num(get_param(block, 'channel_q5')), ...
    str2num(get_param(block, 'channel_q6'))];

%%% Now we need to match the numbers
fieldheadings = {'hallrange',  'hallparams',    'bldcrange',   'bldcparams'};
fielddata = {   (1:3),          (7:9),          (1:6),          (1:6) ; ...
                (1:3),          (7:9),          (1:6),          (1:6) };
            
param_matches = cell2struct(fielddata, fieldheadings, 2);

i_check_params(hallchannels(param_matches(variantnumber).hallrange), ...
    paramvalue( param_matches(variantnumber).hallparams), ...
    'Hall', 'numbers', 'values', 'are', 'BLDC:');

i_check_params(bldcchannels(param_matches(variantnumber).bldcrange), ...
    paramvalue( param_matches(variantnumber).bldcparams), ...
    'Transistor', 'numbers', 'values', 'are', 'BLDC:');

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function i_verify_dcm(block, system, dptramblock)

% Find the block variant
chosen_variant = get_param(block, 'dcm_variant');

variantstring{1} = 'Standard';
variantstring{2} = '2 Outputs Version';
variantstring{3} = 'XOR Version';
variantstring{4} = 'Dead Time Correction Version';
variantstring{5} = '2 Outputs XOR Version';
variantstring{6} = 'XOR Version with Dead Time Correction Version';

switch chosen_variant
    case variantstring{1}
        asifile = 'DCm';
        variantnumber = 1;
    case variantstring{2}
        asifile = 'DCm2';
        variantnumber = 2;
    case variantstring{3}
        asifile = 'DCmXor';
        variantnumber = 3;
    case variantstring{4}
        asifile = 'DCmDt';
        variantnumber = 4;
    case variantstring{5}
        asifile = 'DCm2Xor';
        variantnumber = 5;
    case variantstring{6}
        asifile = 'DCmDtXor';
        variantnumber = 6;
    otherwise
        error('Invalid variant');
end

[paramvalue] = i_parse_asi_file(block, system, dptramblock, asifile);

% Find the channels which are being used
sw_channels = [str2num(get_param(block, 'channel_sw1')), ...
    str2num(get_param(block, 'channel_sw1_2')), ...
    str2num(get_param(block, 'channel_sw2')), ...
    str2num(get_param(block, 'channel_sw2_2')), ...
    str2num(get_param(block, 'channel_sw3')), ...
    str2num(get_param(block, 'channel_sw3_2')), ...
    str2num(get_param(block, 'channel_sw4')), ...
    str2num(get_param(block, 'channel_sw4_2'))];

%%% Now we need to match the numbers
fieldheadings = {'channelrange',        'channelparams'};
fielddata = {   [1,3,5,7],               [1,2,3,4]; ...
                [1,5],                   [1,2]; ...
                (1:8),                   (1:8); ...
                [1,3,5,7],               [1,2,3,4]; ...
                [1:2,5:6],               (1:4); ...
                (1:8),                   (1:8)};

param_matches = cell2struct(fielddata, fieldheadings, 2);

i_check_params(sw_channels(param_matches(variantnumber).channelrange), ...
    paramvalue( param_matches(variantnumber).channelparams), ...
    'DCm', 'numbers', 'values', 'are', 'DCm:');

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function i_check_params(maskparam, fileparam, channeltype, numbers_or_number, values_or_value, is_or_are, chprefix)

% Only perform the check if there is something to compare
if ~isequal(maskparam, [])
    if ~isequal(size(maskparam), size(fileparam)) || ~isequal(maskparam, fileparam)
        error([chprefix, sprintf('\n'), ...
            channeltype, ' channel ', numbers_or_number, ...
            ' should be equal in block setting and in assembled microcode.', ...
            sprintf('\n'), ...
            'The ', values_or_value , ' ', ...
            mat2str(maskparam), ' ', is_or_are, ' configured in the block but the ', ...
            values_or_value, ' ', ...
            mat2str(fileparam), ' ', is_or_are, ' configured in the microcode.']);
    end
end

end

Contact us