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

tstMPC555_test_multifn()
function buildresults = tstMPC555_test_multifn()

% Get a path to the test build directory
[filePath, fileName] = fileparts( which('SMTest') );
buildpath = [filePath, filesep, 'build'];

% Take a copy of the local directory and move to the build directory
currentdirectory = pwd;
cd(buildpath);

buildresults = {'Title', 'Variant', 'Result', 'Error'; ...
    '-----', '------', '-----', '-----'};

threesinvariantsavailable = {'Standard';
    '3 outputs version';
    'XOR version';
    'Dead-Time correction';
    '3 outputs version XOR version';
    'Dead-Time correction - XOR version'};

svmvariantsavailable = {'Standard';
    '3 outputs version';
    'XOR version';
    'Dead-Time correction';
    '3 outputs version XOR version';
    'Dead-Time correction - XOR version'};

bldcvariantsavailable = {'BLDCm - type I';
    'BLDC - type II'};

dcmvariantsavailable = {'Standard';
    '2 Outputs Version';
    'XOR Version';
    'Dead Time Correction Version';
    '2 Outputs XOR Version';
    'XOR Version with Dead Time Correction Version'};

modelstotest.DCmTest.buildfile = 'DCmTest';
modelstotest.DCmTest.refblockname = 'mpc555_mtrctrl/TPU3 DC Motor Drive';
modelstotest.DCmTest.prefixnames = {'DCm', 'DCm2', 'DCmXor', 'DCmDt', 'DCm2Xor', 'DCmDtXor'};
modelstotest.DCmTest.channelsettings = { {'1234'}, {'23'}, {'01234567'}, {'2345'}, {'2345'}, {'23456789'} };
modelstotest.DCmTest.paramnames = {'dcm_variant',               'channel_sw1',    'channel_sw1_2',    'channel_sw2',    'channel_sw2_2',    'channel_sw3',    'channel_sw3_2',    'channel_sw4',    'channel_sw4_2',    'outport_faultpin',    'channel_faultpin',  'channel_sync',    'param_sync_move',    'param_sync_pw',    'param_sync_presc',    'channel_resolver',    'param_res_move',    'param_res_presc'};
modelstotest.DCmTest.paramvalues = {dcmvariantsavailable{1},    '1',              '0',                '2',              '0',                '3',              '0',                '4',              '0',                'on',                  '[15]',              '[13 14]',         '[10 11]',            '[12 13]',          '[14 15]',             '[11 12]',             '[16 17]',           '[18 19]';...
                                    dcmvariantsavailable{2},    '2',              '0',                '0',              '0',                '3',              '0',                '0',              '0',                'on',                  '[15]',              '[13 14]',         '[10 11]',            '[12 13]',          '[14 15]',             '[11 12]',             '[16 17]',           '[18 19]';...
                                    dcmvariantsavailable{3},    '0',              '1',                '2',              '3',                '4',              '5',                '6',              '7',                'on',                  '[15]',              '[13 14]',         '[10 11]',            '[12 13]',          '[14 15]',             '[11 12]',             '[16 17]',           '[18 19]';...                                    
                                    dcmvariantsavailable{4},    '2',              '0',                '3',              '0',                '4',              '0',                '5',              '0',                'on',                  '[15]',              '[13 14]',         '[10 11]',            '[12 13]',          '[14 15]',             '[11 12]',             '[16 17]',           '[18 19]';...
                                    dcmvariantsavailable{5},    '2',              '3',                '0',              '0',                '4',              '5',                '0',              '0',                'on',                  '[15]',              '[13 14]',         '[10 11]',            '[12 13]',          '[14 15]',             '[11 12]',             '[16 17]',           '[18 19]';...
                                    dcmvariantsavailable{6},    '2',              '3',                '4',              '5',                '6',              '7',                '8',              '9',                'on',                  '[15]',              '[13 14]',         '[10 11]',            '[12 13]',          '[14 15]',             '[11 12]',             '[16 17]',           '[18 19]'};
                                
modelstotest.BLDCTest.buildfile = 'BLDCtest';
modelstotest.BLDCTest.refblockname = ['mpc555_mtrctrl/TPU3 Brushless DC Motor', sprintf('\n'), 'Commutation'];
modelstotest.BLDCTest.prefixnames = {'BLDCm', 'BLDC'};
modelstotest.BLDCTest.channelsettings = { {'012345678'}, {'012345678'} };
modelstotest.BLDCTest.paramnames = {'bldc_variant',         'channel_3hd_a',    'channel_3hd_b',    'channel_3hd_c',    'channel_q1',    'channel_q2',    'channel_q3',    'channel_q4',    'channel_q5',    'channel_q6',    'outport_faultpin',    'outport_direction',    'outport_sector',    'outport_period',    'outport_3hd',    'channel_faultpin',    'channel_sync',    'param_sync_move',    'param_sync_pw',    'param_sync_presc',    'channel_resolver',    'param_res_move',    'param_res_presc'};
modelstotest.BLDCTest.paramvalues = {bldcvariantsavailable{1}, '6',             '7',                '8',                '0',             '1',             '2',             '3',             '4',             '5',             'on',                  'on',                   'on',                'on',                'on',             '15',                  '[13,14]',         '[10 12]',            '[13 14]',          '[100 200]',           '[11 12]',             '[14 15]',           '[16 17]';...
                                    bldcvariantsavailable{2}, '6',             '7',                '8',                '0',             '1',             '2',             '3',             '4',             '5',             'on',                  'on',                   'on',                'on',                'on',             '15',                  '[13,14]',         '[10 12]',            '[13 14]',          '[100 200]',           '[11 12]',             '[14 15]',           '[16 17]'};

modelstotest.SVMTest.buildfile = 'SVMTest';
modelstotest.SVMTest.refblockname = 'mpc555_mtrctrl/TPU3 Space Vector Modulation';
modelstotest.SVMTest.prefixnames = {'svmStd', 'svmStd3', 'svmStdXor', 'svmStdDt', 'svmStd3Xor', 'svmStdDtXor'};
modelstotest.SVMTest.channelsettings = { {'012345'}, {'012'}, {'0123456789AB'}, {'012345'}, {'012345'}, {'0123456789AB'} };
modelstotest.SVMTest.paramnames =  {'svm_variant',                  'upper_channels',   'lower_channels',           'fault_channels',   'sync_channels',    'resolver_channels',    'param_sync_move',  'param_sync_pw',    'param_sync_prescaler', 'param_resolver_move',  'param_resolver_prescaler'};
modelstotest.SVMTest.paramvalues = {svmvariantsavailable{1},   '[0 2 4]',          '[1 3 5]',                  '15',               '[11, 12]',         '[13, 14]',             '[10, 20]',         '[11, 21]',         '[2, 4]',               '[30, 40]',             '[6, 8]'; ...
                                    svmvariantsavailable{2},   '[0 1 2]',          '[]',                       '15',               '[3, 4, 5]',        '[6,  7, 8]',           '[10, 20, 30]',     '[11, 21, 31]',     '[2, 4,  6]',           '[30, 40, 50]',         '[6, 8, 9]'; ...
                                    svmvariantsavailable{3},   '[0 1 4 5 8 9]',    '[2 3 6 7 10 11]',          '15',               '[12]',             '[13]',                 '[10]',             '[11]',             '[2]',                  '[30]',                 '[6]'; ...
                                    svmvariantsavailable{4},   '[0 2 4]',          '[1 3 5]',                  '15',               '[11, 12]',         '[13, 14]',             '[10, 20]',         '[11, 21]',         '[2, 4]',               '[30, 40]',             '[6, 8]'; ...
                                    svmvariantsavailable{5},   '[0 1 2 3 4 5]',    '[]',                       '15',               '[3, 4, 5]',        '[6, 7, 8]',             '[10, 20, 30]',     '[11, 21, 31]',    '[2, 4,  6]',           '[30, 40, 50]',         '[6, 8, 9]'; ...
                                    svmvariantsavailable{6},   '[0 1 4 5 8 9]',    '[2 3 6 7 10 11]',          '15',               '[12]',             '[13]',                 '[10]',             '[11]',             '[2]',                  '[30]',                 '[6]'};

modelstotest.ThreeSinTest.buildfile = 'ThreeSinTest';
modelstotest.ThreeSinTest.refblockname = 'mpc555_mtrctrl/TPU3 Three-Phase Sine Wave';
modelstotest.ThreeSinTest.prefixnames = {'3Sin', '3Sin3', '3SinXor', '3SinDt', '3Sin3Xor', '3SinDtXor'};
modelstotest.ThreeSinTest.channelsettings = { {'0123457'}, {'012B'}, {'0123456789ABC'}, {'0123457'}, {'012345C'}, {'0123456789ABC'} };
modelstotest.ThreeSinTest.paramnames =  {'threesin_variant',            'upper_channels',   'lower_channels',   'cosine_channel',   'fault_channels',   'sync_channels',    'resolver_channels',    'param_sync_move',  'param_sync_pw',    'param_sync_prescaler', 'param_resolver_move',  'param_resolver_prescaler'};
modelstotest.ThreeSinTest.paramvalues = {threesinvariantsavailable{1},  '[0 2 4]',          '[1 3 5]',          '7',                '15',               '[11, 12]',         '[13, 14]',             '[10, 20]',         '[11, 21]',         '[2, 4]',               '[30, 40]',             '[6, 8]'; ...
                                          threesinvariantsavailable{2},  '[0 1 2]',          '[]',               '11',               '15',               '[3, 4, 5]',        '[6,  7, 8]',           '[10, 20, 30]',     '[11, 21, 31]',     '[2, 4,  6]',           '[30, 40, 50]',         '[6, 8, 9]'; ...
                                          threesinvariantsavailable{3},  '[0 1 4 5 8 9]',    '[2 3 6 7 10 11]',  '12',               '15',               '[12]',             '[13]',                 '[10]',             '[11]',             '[2]',                  '[30]',                 '[6]'; ...
                                          threesinvariantsavailable{4},  '[0 2 4]',          '[1 3 5]',          '7',                '15',               '[11, 12]',         '[13, 14]',             '[10, 20]',         '[11, 21]',         '[2, 4]',               '[30, 40]',             '[6, 8]'; ...
                                          threesinvariantsavailable{5},  '[0 1 2 3 4 5]',    '[]',               '12',               '15',               '[3, 4, 5]',        '[6, 7, 8]',             '[10, 20, 30]',     '[11, 21, 31]',    '[2, 4,  6]',           '[30, 40, 50]',         '[6, 8, 9]'; ...
                                          threesinvariantsavailable{6},  '[0 1 4 5 8 9]',    '[2 3 6 7 10 11]',  '12',               '15',               '[12]',             '[13]',                 '[10]',             '[11]',             '[2]',                  '[30]',                 '[6]'};
                                                                          
%% Start cycle here
f = fieldnames(modelstotest);
for ff = 1:length(f)
    currmodel = modelstotest.(f{ff});
    buildfile = currmodel.buildfile;

    % Open the test file
    open(buildfile);

    for p = 1:length(currmodel.prefixnames)
        pp = currmodel.prefixnames{p};

        %% Set up the microcode
        refblockname = 'mpc555_mtrctrl/DPTRAM Configuration Wizard';
        wizblock = find_system(buildfile, 'ReferenceBlock', refblockname);
        wizblock = (wizblock{:});

        %% Create a preset template
        fn_names = mpc555_dptram_wizard_preset(pp);
        %% Set the data in the simulink data class
        mpc555_dptram_wizard_set(wizblock, 'AB', 'autotest.asc', fn_names, {pp, currmodel.channelsettings{p}{:}}, 'RE', '00');
        %% Compile the microcode
        mpc555_dptram_wizard(buildfile, wizblock, 'COMPILE');
        

        %% Change the variant as appropriate
        driverblock = find_system(buildfile, 'ReferenceBlock', currmodel.refblockname);
        disp(driverblock);
        driverblock = driverblock{:};

        for n=1:length(currmodel.paramnames)
            set_param(driverblock, currmodel.paramnames{1,n}, currmodel.paramvalues{p,n});
        end
        %%
        buildresults = i_build_model(buildfile, buildresults, pp);
    end
    bdclose(buildfile);
    i_fn_cleanup_mess(buildfile);
end

end

function buildresults = i_build_model(buildfile, buildresults, variant)

% Turn off the generation of the HTML report
set_param(buildfile, 'GenerateReport', 'off');
% Ensure that code is compiled
set_param(buildfile, 'GenCodeOnly', 'off');
% Optimize for debug
set_param(buildfile, 'MPC555_OPTIMIZATION_SWITCH', 'debug');
% Enable local block outputs - ensure that models correctly accommodate
% these
set_param(buildfile, 'LocalBlockOutputs', 'on');
% Enable inline parameters
set_param(buildfile, 'InlineParams', 'on');
% Ensure there is no action after build
set_param(buildfile, 'BuildAction', 'None');

try
    rtwbuild(buildfile);
    buildresults = [buildresults; {buildfile, variant, 'PASS', ''}];
catch
    buildresults = [buildresults; {buildfile, variant, 'FAIL', lasterr}];
    keyboard;
end

end

function i_fn_cleanup_mess(buildfile)

% Clean up the mess made
if exist([buildfile,'_mpc555rt'], 'dir')
    rmdir([buildfile,'_mpc555rt'],'s');
end
if exist([buildfile,'_ram_Data'],'dir')
    rmdir([buildfile,'_ram_Data'],'s');
end

for suffx = {'bin', 'elf', 'map', 'mcp', 's19'}
    if exist([buildfile,'_ram.', suffx{:}], 'file')
        delete([buildfile,'_ram.', suffx{:}]);
    end
end

end

Contact us