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_calc_range(input_value, ...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function new_value = mpc555_mtrctrl_calc_range(input_value, ...
%    input_min, input_max, ...
%    output_min, output_max, ...
%    output_type)
%
% This function scales and offsets an input value from one range to
% another and then casts the output to the required type.
%
function new_value = mpc555_mtrctrl_calc_range(input_value, ...
    input_min, input_max, ...
    output_min, output_max, ...
    output_type)

% In this function we shall assume that the input values have already been
% verified to be within range.

% Check to make sure values are sane
if input_min > input_max
    error('Input lower boundary should be lower than input upper boundary');
end
if output_min > output_max
    error('Output lower boundary should be lower than output upper boundary');
end

% Find ranges (remember to work in double precision here)
input_range = double(input_max - input_min);
output_range = double(output_max - output_min);

% Remove input offset
input_without_offset = double(input_value - input_min);

% Scale
input_without_offset_scaled = ...
    input_without_offset * output_range / input_range;

% Add output offset
output_value = input_without_offset_scaled + double(output_min);

% Cast to type
new_value = cast(output_value, output_type);

end

Contact us