switchhall.h 3.5 KB

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