switchhall.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * @file switchhall.c
  3. * @author
  4. * @brief
  5. * @version
  6. * @date 2021-11-22
  7. *
  8. * @copyright Copyright (c) 2021
  9. *
  10. */
  11. /************************************************************************
  12. Beginning of File, do not put anything above here except notes
  13. Compiler Directives:
  14. *************************************************************************/
  15. #ifndef SWITCHHALL_H
  16. #define SWITCHHALL_H
  17. #include "typedefine.h"
  18. /************************************************************************
  19. Compiler Directives (N/A)
  20. *************************************************************************/
  21. //#ifdef _SWITCHHALL_C_
  22. // #define _SWITCHHALL_EXT
  23. //#else
  24. // #define _SWITCHHALL_EXT extern
  25. //#endif
  26. /****************************************
  27. *
  28. * Definitions & Macros
  29. *
  30. ****************************************/
  31. #define HALL3_SPD_CAL_COEF ((((SQWORD)TIM2CNTCLK_KHZ * 1000 / FBASE)<< 15) / 6 ) // pi/3*(7200kHz) PU(pi/3)=2^15/6
  32. #define HALL1_SPD_CAL_COEF (((SQWORD)TIM2CNTCLK_KHZ * 1000 / FBASE)<< 15)
  33. #define HALL3_SPD_CAP_LEVEL1 (TIM2CNTCLK_KHZ*1000/((2)*6)) // electrical frequency 2Hz 6 hal edge pules per electrical cycle
  34. #define HALL3_SPD_CAP_LEVEL2 (TIM2CNTCLK_KHZ*1000/((1500)*6)) //motor electrical frequency 1500Hz 6 hal edge pules per electrical cycle
  35. #define HALL3_SPD_CAP_STARTUP_LEVEL (TIM2CNTCLK_KHZ*1000/((5)*6)) //motor electrical frequency 5Hz 6 hal edge pules per electrical cycle
  36. #define HALL_SPD_SWITCH_LEVEL (TIM2CNTCLK_KHZ*1000/((20)*6)) //motor electrical frequency 5Hz 6 hal edge pules per electrical cycle
  37. #define HALL_THETEA_OFFSET 7357 // (X)/360*2^15
  38. #define HALL_THETEA_OFFSET_FANXIANG 0 // (X)/360*2^15
  39. #define SWITCHHALL_CAP_DEFAULT \
  40. { \
  41. 0, 0, 0 \
  42. }
  43. #define SWITCHHALL_OUT_DEFAULT \
  44. { \
  45. 0, 0, 0, 0, 0, 0, 0, 0 \
  46. }
  47. /***************************************
  48. *
  49. * Type Definations
  50. *
  51. ***************************************/
  52. typedef struct
  53. {
  54. ULONG ulCapValue;
  55. SLONG slCapValueDelta;
  56. ULONG ulCapValuePre;
  57. SLONG slDeltaPre;
  58. UWORD uwCaptureOverFlowCnt;
  59. ULONG ulHighCapValue;
  60. SLONG slHighCapValueDelta;
  61. ULONG ulHighCapValuePre;
  62. UWORD uwHighCapOverFlowCnt;
  63. UWORD uwState;
  64. } SWITCHHALL_CAP;
  65. typedef struct
  66. {
  67. UWORD uwSectorNum;
  68. UWORD uwSectorNumPre;
  69. SWORD swSpdCWorCCW;
  70. SLONG slLowThetaPu;
  71. UWORD uwLowThetaPu;
  72. SLONG slInitThetaPu;
  73. SWORD swLowSpdPu;
  74. SWORD swLowSpdLpfPu;
  75. SWORD swLowThetaOffsetPu;
  76. SLONG slHighThetaPu;
  77. UWORD uwHighThetaPu;
  78. SWORD swHighSpdPu;
  79. SWORD swHighSpdLpfPu;
  80. } SWITCHHALL_OUT;
  81. /****************************************
  82. *
  83. * Exported Variables
  84. *
  85. ****************************************/
  86. extern SWITCHHALL_OUT switchhall_stOut;
  87. /***************************************
  88. *
  89. * Function Definations
  90. *
  91. ***************************************/
  92. void switchhall_voInit(void);
  93. void switchhall_voTim3Int(void);
  94. void switchhall_voPosCalTbc(void);
  95. /************************************************************************/
  96. #endif
  97. /************************************************************************
  98. End of this File (EOF):
  99. Do not put anything after this part!
  100. *************************************************************************/