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_cpu14(currentblock, tpumodule)
function cpu14 = mpc555_mtrctrl_cpu14(currentblock, tpumodule)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FUNCTION CPU14 = MPC555_MTRCTRL_CPU14(CURRENTBLOCK, TPUMODULE)
%
% Returns the number of TCR1 cycles required to represent 14 IMB clocks
% on the given TPU module.
%
% Example:
%       cpu14 = mpc555_mtrctrl_cpu14(gcb, 'A');

switch tpumodule
    case {'A', 'B', 'C'}
        
    otherwise
        error('Invalid TPU module selected');
end

% Get a handle to the configuration block
target = RTWConfigurationCB('get_target',currentblock);
if ~isempty(target)
    sys_tpu = target.findConfigForClass('MPC555dkConfig.TPU');
    sys_res = target.findConfigForClass('MPC555dkConfig.SYSTEM_CLOCKS');
else
    error('No target block');
end

tpufreq = eval(['sys_tpu.TPU_' ,tpumodule, '.TCR1.TCR1_Clock_Frequency']);
cpufreq = sys_res.System_Clock;

% CPU14 is the time of 14 IMB clocks in TCR1 clocks

time_of_fourteen_imb_clocks = 14 * 1/cpufreq;
time_of_one_TCR_clock = 1/tpufreq;

cpu14 = time_of_fourteen_imb_clocks/time_of_one_TCR_clock;

uint16_cpu14 = uint16(cpu14);

if ~eq(cpu14, uint16_cpu14)
   error(['The TCR1 Clock Frequency must be able to exactly represent 14 IMB clock cycles.',...
       sprintf('\n'), ...
       'It is advised to set the TCR1 clock frequency to IMB Clock/2']); 
end

end

Contact us