/* * var.c * * Created on: 2023年5月17日 * Author: wangd */ #include "var.h" // DSP2803x Examples Include File #ifndef TRUE #define FALSE 0 #define TRUE 1 #endif union FAULTFLAG_UNI FaultFlag; Uint16 DCbus_voltage=0; Uint32 IsrTime = 0; _iq test =0; int16 test2 =0; int16 Tmotor = 0; PI_CONTROLLER pid1_idc = PI_CONTROLLER_DEFAULTS; PI_CONTROLLER pid1_spd = PI_CONTROLLER_DEFAULTS; RMPCNTL rc1 = RMPCNTL_DEFAULTS; int32 pwmlimit = 32768; _iq SpeedRef=_IQ(0.0);//初始速度 int16 Direction = 1; _iq BemfA=0; _iq BemfB=0; _iq BemfC=0; _iq Iphase=0; _iq DC_current_real = 0; _iq DC_current_filer = 0; int32 DC_current_avr = 0; int32 DC_current_filter_avr = 0; int16 Tvot = 0; _iq CurrentSet = _IQ(0.0); Uint16 Fault_clear = 0; int32 XintTime = 60000000; volatile Uint16 EnableFlag = FALSE; void InitVar(void){ FaultFlag.all = 0; // Initialize the PI module for dc-bus current pid1_idc.Kp = _IQ(0.05); pid1_idc.Ki = _IQ(0.0002); pid1_idc.Umax = _IQ((float)pwmlimit/32767); pid1_idc.Umin = _IQ((float)(-pwmlimit)/32767); // Initialize the PI module for speed pid1_spd.Kp = _IQ(1.0); pid1_spd.Ki = 360;//_IQ(0.0002); pid1_spd.Umax = _IQ(1.0); pid1_spd.Umin = _IQ(0.0); // Initialize RMPCNTL module rc1.RampDelayMax = 5; rc1.RampLowLimit = _IQ(-1.0); rc1.RampHighLimit = _IQ(1.0); } void FaultTreat(void){ OverVoltage(); OverMotorRpm(); OverMotCtrTemp(); } void OverVoltage(void) { static int16 i = 0; static int16 j = 0; if (DCbus_voltage >= 360) { i = 20000; FaultFlag.bit.OverVolFlag = 1; } else if (DCbus_voltage <= 200) //80 { j = 10000; FaultFlag.bit.LowVolFlag = 1; } else { if (FaultFlag.bit.OverVolFlag == 1) { i--; if (i <= 0) { i = 0; FaultFlag.bit.OverVolFlag = 0; } } else { i = 0; } if (FaultFlag.bit.LowVolFlag == 1) { j--; if (j <= 0) { j = 0; FaultFlag.bit.LowVolFlag = 0; } } else { j = 0; } } } void OverMotorRpm(void) { if (speed1.BaseRpm >= 3800) { FaultFlag.bit.OverRpmFlag = 1; } else if (speed1.BaseRpm < 100) { FaultFlag.bit.OverRpmFlag = 0; } } void OverMotCtrTemp(void) { if (Tmotor >= 85) { FaultFlag.bit.OverMotTempFlag = 1; } else if (Tmotor < 50) { FaultFlag.bit.OverMotTempFlag = 0; } if (Tvot >= 85) { FaultFlag.bit.IgbtTempFaultFlag = 1; } else if (Tvot < 50) { FaultFlag.bit.IgbtTempFaultFlag = 0; } }