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_tcr_convert(currentblock, module, wherefrom, valuefrom)
function tcrvalues = mpc555_tcr_convert(currentblock, module, wherefrom, valuefrom)
% FUNCTION TCRVALUES = MPC555_TCR_CONVERT(CURRENTBLOCK, MODULE, WHEREFROM,
% VALUEFROM)
%
% Convert between seconds and TCR clock values.
%
% 'CURRENTBLOCK':       The block in the model you wish to calculate
%                       times for (this must have a "module" mask value)
%
% 'MODULE':             TPU module to use - valid values are A,B,C
%
% 'WHEREFROM':          Valid values are 'time', 'TCR1' and 'TCR2'
% 
% 'VALUEFROM':          This is the value in the units from which you are
%                       converting
%
% Example:
%            tcrvalues = mpc555_tcr_convert(gcb, 'A', 'time', 0.01)
%            tcrvalues = mpc555_tcr_convert(gcb, 'B', 'TCR1', 31415)
%            tcrvalues = mpc555_tcr_convert(gcb, 'C', 'TCR2', 10020)

[TCR1clock, TCR1clockvalid] = mpc555_mtrctrl_getclock(currentblock, 'TCR1', module);
[TCR2clock, TCR2clockvalid] = mpc555_mtrctrl_getclock(currentblock, 'TCR2', module);

tcrvalues.TCR1ClockFreq = TCR1clock;
tcrvalues.TCR1ClockValid = TCR1clockvalid;

tcrvalues.TCR2ClockFreq = TCR2clock;
tcrvalues.TCR2ClockValid = TCR2clockvalid;

switch wherefrom
    case 'time'
        tcrvalues.Time = valuefrom;
        if TCR1clockvalid
            tcrvalues.TCR1 = round(TCR1clock * valuefrom);
            tcrvalues.ActualTimeTCR1 = tcrvalues.TCR1/TCR1clock;
        else
            tcrvalues.TCR1 = -inf;
            tcrvalues.ActualTimeTCR1 = -inf;
        end

        if TCR2clockvalid
            tcrvalues.TCR2 = round(TCR2clock * valuefrom);
            tcrvalues.ActualTimeTCR2 = TCR2time/TCR2clock;
        else
            tcrvalues.TCR2 = -inf;
            tcrvalues.ActualTimeTCR2 = -inf;
        end

    case 'TCR1'
        tcrvalues.TCR1 = valuefrom;
        
        if TCR1clockvalid
            tcrvalues.ActualTimeTCR1 = tcrvalues.TCR1/TCR1clock;
            tcrvalues.Time = tcrvalues.TCR1/TCR1clock;
        else
            tcrvalues.ActualTimeTCR1 = -inf;
            tcrvalues.Time = -inf;
        end

        if TCR2clockvalid
            tcrvalues.TCR2 = round(TCR2clock * tcrvalues.Time);
            tcrvalues.ActualTimeTCR2 = tcrvalues.TCR2/TCR2clock;
        else
            tcrvalues.ActualTimeTCR2 = -inf;
            tcrvalues.TCR2 = -inf;
        end
    case 'TCR2'
        tcrvalues.TCR2 = valuefrom;
        
        if TCR2clockvalid
            tcrvalues.ActualTimeTCR2 = tcrvalues.TCR2/TCR2clock;
            tcrvalues.Time = tcrvalues.TCR2/TCR2clock;
        else
            tcrvalues.ActualTimeTCR2 = -inf;
            tcrvalues.Time = -inf;
        end

        if TCR1clockvalid
            tcrvalues.TCR1 = round(TCR1clock * tcrvalues.Time);
            tcrvalues.ActualTimeTCR1 = tcrvalues.TCR1/TCR1clock;
        else
            tcrvalues.ActualTimeTCR1 = -inf;
            tcrvalues.TCR1 = -inf;
        end
    otherwise
        error('Invalid type of time - valid are ''time'', ''TCR1'' and ''TCR2''');
end

Contact us