www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgprecfix/hwincrement.m

    function HWValuesOut = hwincrement(Prec, HWValuesIn, varargin)
%HWINCREMENT Increment fixed point hardware values.
%
%   HWValuesOut = HWINCREMENT(FIXPREC, HWValuesIn) increments hardware
%   values HWValuesIn by 1 unit of hardware resolution.  The achievable
%   resolution is specified by the cgprecfix object FIXPREC.
%
%   HWValuesOut = HWINCREMENT(FIXPREC, HWValuesIn, HWMultiplier) imcrements
%   hardware values by HWMultiplier units of hardware resolution.

%   Copyright 2000-2006 The MathWorks, Inc. and Ford Global Technologies, Inc.


% Error check on HWValues
HWValuesIn = i_check(Prec, HWValuesIn, 'HWValues');

% Error check on varargin (HWIncrement)
if nargin>2
    % Try to use extra input as a multiplier HWMultiplier such that the
    % increment is the product of HWMultiplier and the hardware resolution
    HWMultiplier = i_check(Prec, varargin{1}, 'HWMultiplier');
else
    % Information about increment not specified, use the default value of 1
    % unit of hardware resolution
    HWMultiplier = 1;
end 
HWIncrement = HWMultiplier.*get(Prec, 'HWResolution');

% Increment hardware values
HWValuesOut = HWValuesIn + HWIncrement;

% Resolve to achievable hardware values
HWValuesOut = hwresolve(Prec, HWValuesOut);


% -------------------------------------------------------------------------
function out = i_check(Prec, in, VarName)

% Check input variables
switch VarName
    case 'HWValues'
        if pCheckNumeric(Prec, in, true, 'HWValues')
            % HWValues is valid
            out = in;
        end
    case 'HWMultiplier'
        if pCheckNumeric(Prec, in) && isscalar(in)
            % HWMultiplier is a real scalar
            out = in;
        else
            % HWMultiplier is not a real scalar, use default value
            warning(message('mbc:cgprecfix:InvalidArgument1'));
            out = 1;
        end
end