switchhall.h 3.5 KB

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