/* ÖÍÈÈ ÑÝÒ (ñ) 2002 ã. Processor: TMS320C32 Filename: vector_troll.h ÑÈÑÒÅÌÀ ÂÅÊÒÎÐÍÎÃÎ ÓÏÐÀÂËÅÍÈy Edit date: 04-12-02 Function: Revisions: */ #include "IQmathLib.h" #include "DSP281x_Device.h" // DSP281x Headerfile Include File #include "DSP281x_Examples.h" // DSP281x Examples Include File #include #include "mathlib.h" #include _iq SQRT_32 = _IQ(0.8660254037844); _iq CONST_23 = _IQ(2.0/3.0); _iq CONST_15 = _IQ(1.5); #define real float float my_satur_float(float Input, float Positive, float Negative) { if (Input>=Positive) Input=Positive; if (Input<=Negative) Input=Negative; return Input; } int my_satur_int(int Input, int Positive, int Negative) { if (Input>=Positive) Input=Positive; if (Input<=Negative) Input=Negative; return Input; } long my_satur_long(long Input, long Positive, long Negative) { if (Input>=Positive) Input=Positive; if (Input<=Negative) Input=Negative; return Input; } /* real pid_regul(real Kp_regul, real Tperiod_regul, real Minimum, real Maximum, real yk, real *uk1, real *yk1, real *yzad, real *ek, real *ek1, real *ek2, real d0, real d1, real d2) { real uk; *ek = - yk + *yzad; uk = *uk1 + Kp_regul * ( d0 * *ek + d1 * *ek1 + d2 * *ek2 ); if (uk>Maximum) uk=Maximum; if (ukMaximum) uk=Maximum; if (ukMaximum) *VarIntegral=Maximum; if (*VarIntegralMaximum) VarOut=Maximum; if (VarOutStepP) || (deltaVar<-StepN)) { if (deltaVar>0) InpVarCurr += StepP; else InpVarCurr -= StepN; } else InpVarCurr=InpVarInstant; VarOut = InpVarCurr; return VarOut; } */ #pragma CODE_SECTION(zad_intensiv_q,".fast_run"); _iq zad_intensiv_q(_iq StepP, _iq StepN, _iq InpVarCurr, _iq InpVarInstant) { _iq deltaVar, VarOut; deltaVar = InpVarInstant-InpVarCurr; if ((deltaVar>StepP) || (deltaVar<-StepN)) { if (deltaVar>0) InpVarCurr += StepP; else InpVarCurr -= StepN; } else InpVarCurr=InpVarInstant; VarOut = InpVarCurr; return VarOut; } real pi_regul3(real Kp_regul, real ki_regul, real Tperiod_regul, real Minimum, real Maximum, real InpVar, real *InpVarPrev, real *OutVarPrev) { real VarOut; VarOut = Kp_regul*(ki_regul/Kp_regul*Tperiod_regul/2.0+1)*InpVar + Kp_regul*(ki_regul/Kp_regul*Tperiod_regul/2.0-1) * (*InpVarPrev) + *OutVarPrev; if (VarOut>Maximum) VarOut=Maximum; if (VarOutMaximum) VarOut=Maximum; if (VarOutdata_array == 0) return 0; for (i = 0; i < v->size_array; ++i) { summ_squares += _IQmpy(v->data_array[i], v->data_array[i]); } return _IQsqrt(summ_squares / v->size_array); } //_iq calc_rms_array_var_period(RMS_CALC_ARRAY_THINNING *v) { // _iq summ_squares = 0; // int i = 0; // int count_elem = 0; // if (v->signal_period > v->size_array) { // v->signal_period = v->size_array; // } // count_elem = v->signal_period; // i = v->last_elem_position; // while (count_elem > 0) { // summ_squares += _IQmpy(v->data_array[i], v->data_array[i]); // i -= 1; // if (i < 0) { i = v->size_array - 1; } // count_elem -= 1; // // } // v->Out_rms = _IQsqrt(summ_squares / v->signal_period); // return v->Out_rms; //} _iq calc_rms_array_var_period_IQ15(RMS_CALC_ARRAY_THINNING *v) { _iq16 summ_squares = 0; int i = 0; int count_elem = 0; if (v->data_array == 0) { return 0; } if (v->signal_period > v->size_array) { v->signal_period = v->size_array; } count_elem = v->signal_period; i = v->last_elem_position; while (count_elem > 0) { summ_squares += 0;//_IQ15mpy(v->data_array[i], v->data_array[i]); i -= 1; if (i < 0) { i = v->size_array - 1; } count_elem -= 1; } v->Out_rms =_IQ15toIQ(_IQ15sqrt(summ_squares / v->signal_period)); return v->Out_rms; } float fast_round(float x) { float d; long i; i = (long)x; if (x<0) { d = i - x; if (d>=0.5) i = i - 1; } else { d = x - i; if (d>=0.5) i = i + 1; } return (float)i; }