v.Out= _IQsat(v.v1, v.Umax, v.Umin);这句具体什么意思?数据手册里讲的是防止溢出
Gavin J:
是的。
详见:C:\ti\controlSUITE\libs\math\IQmath\v160\doc\IQmath_Quickstart.pdf
This intrinsic saturates an IQ value to the given Positive and Negative limits. This operation is useful in areas where there is potential for overflow in a calculation.
Example:Calculate the linear equation "Y = M*X + B", with saturation.All variables are GLOBAL_Q = 26. However, there is a possibility that the variable ranges may cause overflow, so we must perform the calculation and saturate the result.To do this, we perform the intermediate operations using IQ = 20 and then saturate before converting the result back to the appropriate GLOBAL_Q value:
#include “IQmathLib.hvoid main(void){ _iq Y, M, X, B; // GLOBAL_Q = 26 (+/- 32 range) _iq20 temp; // IQ = 20 (+/- 2048 range) temp = _IQ20mpy(_IQtoIQ20(M), _IQtoIQ20(X)) + _IQtoIQ20(B); temp = _IQsat(temp, _IQtoIQ20(MAX_IQ_POS), _IQtoIQ20(MAX_IQ_NEG)); Y = _IQ20toIQ(temp);}