VoltageCompensation.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* --------------------------- (C) COPYRIGHT 2021 Fortiortech ShenZhen -----------------------------
  2. File Name : MotorFiledWeaken.c
  3. Author : Fortiortech Appliction Team
  4. Version : V1.0
  5. Date : 2021-12-08
  6. Description : This file contains motor filed weaken function used for Motor Control.
  7. ----------------------------------------------------------------------------------------------------
  8. All Rights Reserved
  9. ------------------------------------------------------------------------------------------------- */
  10. #include "FU68xx_5.h"
  11. #include <Myproject.h>
  12. VOLCOMP xdata VoltageComp;
  13. /* -------------------------------------------------------------------------------------------------
  14. Function Name : VoltageCompensation
  15. Description : µçѹ²¹³¥
  16. Date : 2021-12-08
  17. Parameter : None
  18. ------------------------------------------------------------------------------------------------- */
  19. void VoltageCompensation(void)
  20. {
  21. if ((mcFocCtrl.CtrlMode == 1) && (mcFaultSource == FaultNoSource) && (motorControl.ActualSpeed > _Q15(2000 / MOTOR_SPEED_BASE)))
  22. {
  23. //SetBit(ADC_CR, ADCBSY);
  24. while (ReadBit(ADC_CR, ADCBSY));
  25. VoltageComp.testUq = FOC__UQ;
  26. VoltageComp.testUq1 = VoltageComp.testUq >> 4 ;
  27. VoltageComp.mcDcbus = ADC2_DR;
  28. VoltageComp.mcDcbuschazhi = VoltageComp.mcDcbus - mcFocCtrl.mcDcbus_min;
  29. DIV0_DAH = VoltageComp.testUq1; // rw--
  30. DIV0_DAL = 0; // rw--
  31. DIV0_DB = mcFocCtrl.mcDcbus_min; // rw--
  32. SMDU_RunBlock(0, DIV); // rw--
  33. VoltageComp.testUq2 = DIV0_DQL; // rw--
  34. MUL0_MA = VoltageComp.testUq2; // rw--
  35. MUL0_MB = mcFocCtrl.mcDcbus_min + mcFocCtrl.mcDcbus_chazhi + VoltageComp.mcDcbuschazhi; // rw--
  36. SMDU_RunBlock(0, S1MUL); //
  37. VoltageComp.testUq3 = MUL0_MCH; // rw--
  38. // if(VoltageComp.testUq3>=4095) // rw--
  39. // {
  40. // VoltageComp.testUq3=4095;
  41. // }
  42. VoltageComp.testUq4 = (VoltageComp.testUq3 << 3) - VoltageComp.testUq; //
  43. if (VoltageComp.testUq4 >= 3000)
  44. {VoltageComp.testUq4 = 3000;}
  45. if (VoltageComp.testUq4 < -3000)
  46. {VoltageComp.testUq4 = -3000;}
  47. FOC_UQCPS = VoltageComp.testUq4; //
  48. }
  49. }