intint.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include "FU68xx_5.h"
  2. #include <Myproject.h>
  3. void VREFConfigInit(void)
  4. {
  5. #if (HW_ADC_VREF == VREF3_0)
  6. {
  7. SetBit(VREF_VHALF_CR, VRVSEL1); //00-->4.5V 01-->VDD5
  8. ClrBit(VREF_VHALF_CR, VRVSEL0); //10-->3.0V 11-->4.0V
  9. }
  10. #elif (HW_ADC_VREF == VREF4_0)
  11. {
  12. SetBit(VREF_VHALF_CR, VRVSEL1); //00-->4.5V 01-->VDD5
  13. SetBit(VREF_VHALF_CR, VRVSEL0); //10-->3.0V 11-->4.0V
  14. }
  15. #elif (HW_ADC_VREF == VREF4_5)
  16. {
  17. ClrBit(VREF_VHALF_CR, VRVSEL1); //00-->4.5V 01-->VDD5
  18. ClrBit(VREF_VHALF_CR, VRVSEL0); //10-->3.0V 11-->4.0V
  19. }
  20. #elif (HW_ADC_VREF == VREF5_0)
  21. {
  22. ClrBit(VREF_VHALF_CR, VRVSEL1); //00-->4.5V 01-->VDD5
  23. SetBit(VREF_VHALF_CR, VRVSEL0); //10-->3.0V 11-->4.0V
  24. }
  25. #endif
  26. #if (VREF_OUT_EN)
  27. SetBit(P3_AN, PIN5);
  28. SetBit(P3_OE, PIN5);
  29. #endif
  30. #if (VHALF_OUT_EN)
  31. SetBit(P3_AN, P32);
  32. #endif
  33. SetBit(VREF_VHALF_CR, VREFEN | VHALFEN);
  34. }
  35. void HardwareInit(void)
  36. {
  37. // 上电等待
  38. uint16 PowerUpCnt = 0;
  39. for (PowerUpCnt = 0; PowerUpCnt < 10000; PowerUpCnt++) {};
  40. // 参考电压初始化
  41. VREFConfigInit();
  42. // 外部中断初始化 预驱故障中断保护
  43. PreDriverFalutInt();
  44. GPIO_Init();
  45. ADC_Init();
  46. AMP_Init();
  47. Driver_Init();
  48. CMP3_Interrupt_Init();
  49. SYST_ARR = 24000;
  50. SetBit(IP2, PSYSTICK0);
  51. SetBit(DRV_SR, SYSTIE);
  52. _nop_(); _nop_();
  53. #if (PFCEnable==1)//PFC初始化
  54. PFC_init();
  55. #endif
  56. PI2_Init();
  57. }
  58. /* ---------------------------------------------------------------------------------
  59. Function Name : void SoftwareInit(void)
  60. Description : 软件初始化,初始化所有定义变量,按键初始化扫描
  61. Input : 无
  62. Output : 无
  63. ----------------------------------------------------------------------------------*/
  64. void SoftwareInit(void)
  65. {
  66. memset(&mcFaultDect, 0, sizeof(FaultVarible)); // FaultVarible变量清零
  67. /************保护次数*************/
  68. memset(&mcProtectTime, 0, sizeof(ProtectVarible)); // ProtectVarible保护次数清零
  69. /***********过流保护**************/
  70. memset(&mcCurVarible, 0, sizeof(CurrentVarible)); // 电流保护的变量清零
  71. memset(&Time, 0, sizeof(TIMERTypeDef));
  72. memset(&PFCFaultDect, 0, sizeof(PFCFaultVarible));
  73. memset(&ConTrolCmd, 0, sizeof(CONTROLCMDD));
  74. /*****电机状态机时序变量***********/
  75. McStaSet.SetMode = 0;
  76. /*************外部控制环************/
  77. memset(&mcFocCtrl, 0, sizeof(FOCCTRL)); // mcFocCtrl变量清零
  78. mcFocCtrl.mcDcbus_chazhi = 32760;
  79. /******ADC采样滤波值*********/
  80. memset(&AdcSampleValue, 0, sizeof(ADCSample)); // ADCSample变量清零
  81. /**************************电流偏置校准变量**********************/
  82. memset(&mcCurOffset, 0, sizeof(CurrentOffset)); // mcCurOffset变量清零
  83. mcCurOffset.IuOffsetSum = 16383;
  84. mcCurOffset.IvOffsetSum = 16383;
  85. mcCurOffset.Iw_busOffsetSum = 16383;
  86. /*****速度环的响应***/
  87. memset(&mcSpeedRamp, 0, sizeof(MCRAMP)); // mcSpeedRamp变量清零
  88. mcSpeedRamp.IncValue = Motor_Speed_Inc;
  89. mcSpeedRamp.DecValue = Motor_Speed_Dec;
  90. mcState = mcReady;
  91. mcFaultSource = 0;
  92. }