123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- #include "var.h"
- #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;
- volatile Uint16 Enable_ALLOW = FALSE;
- void InitVar(void){
- FaultFlag.all = 0;
-
- 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);
-
- pid1_spd.Kp = _IQ(1.0);
- pid1_spd.Ki = 360;
- pid1_spd.Umax = _IQ(1.0);
- pid1_spd.Umin = _IQ(0.0);
-
- rc1.RampDelayMax = 5;
- rc1.RampLowLimit = _IQ(-1.0);
- rc1.RampHighLimit = _IQ(1.0);
- }
- void FaultTreat(void){
- OverVoltage();
- OverMotorRpm();
- OverMotCtrTemp();
- Fault_clear_fuc();
- }
- void OverVoltage(void)
- {
- static int16 j = 0;
- if (DCbus_voltage >= 360)
- {
- FaultFlag.bit.OverVolFlag = 1;
- }
- else if (DCbus_voltage <= 200)
- {
- j = 10000;
- FaultFlag.bit.LowVolFlag = 1;
- }
- else
- {
- 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;
- }
- }
- void OverMotCtrTemp(void)
- {
- if (Tmotor >= 100)
- {
- FaultFlag.bit.OverMotTempFlag = 1;
- }
- else if (Tmotor < 50)
- {
- FaultFlag.bit.OverMotTempFlag = 0;
- }
- if (Tvot >= 70)
- {
- FaultFlag.bit.IgbtTempFaultFlag = 1;
- }
- else if (Tvot < 50)
- {
- FaultFlag.bit.IgbtTempFaultFlag = 0;
- }
- }
- void Fault_clear_fuc(void){
- if(Fault_clear == 1) {
- static int16 fault_cnt = 0;
- GpioDataRegs.GPBCLEAR.bit.GPIO32 = 1;
- FaultFlag.bit.OverCurFlag = 0;
- fault_cnt++;
- if(fault_cnt>20000){
- Fault_clear = 0;
- fault_cnt = 0;
- OpenPwm();
- if (speed1.BaseRpm < 700)
- {
- FaultFlag.bit.OverRpmFlag = 0;
- }
- if(GpioDataRegs.GPADAT.bit.GPIO16==1){
- FaultFlag.bit.Ipmfault = 0;
- }
- }
- if(FaultFlag.bit.OverVolFlag == 1 && DCbus_voltage<320){
- FaultFlag.bit.OverVolFlag = 0;
- }
- }else{
- GpioDataRegs.GPBSET.bit.GPIO32 = 1;
- }
- }
- int16 LimitMotCtrTemp(int32 period){
- static int16 result = 32767;
- static int32 cnt1=0;
- static int32 cnt2=0;
- if(Tmotor>30){
- cnt1++;
- cnt2 = 0;
- if(cnt1>period){
- result = (int32)result*31128>>15;
- cnt1 =0;
- }
- }else{
- cnt1 =0;
- if(result<31128){
- cnt2++;
- if(cnt2>period){
- cnt2 = 0;
- int32 tmp = (int32)result*34491>>15;
- if(tmp>32767){
- result = 32767;
- }else{
- result = tmp;
- }
- }
- }else{
- result = 32767;
- cnt2 = 0;
- }
- }
- test = result;
- return result;
- }
|