mathtool.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /************************************************************************
  2. Project: Welling Motor Control Paltform
  3. Filename: mathtool.h
  4. Partner Filename: mathtool.c
  5. Description: The header file of mathtool.c
  6. Complier: IAR Embedded Workbench for ARM 7.80, IAR Systems.
  7. CPU TYPE : GD32F3x0
  8. *************************************************************************
  9. Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
  10. All rights reserved.
  11. *************************************************************************
  12. *************************************************************************
  13. Revising History (ECL of this file):
  14. ************************************************************************/
  15. /************************************************************************
  16. Beginning of File, do not put anything above here except notes
  17. Compiler Directives:
  18. *************************************************************************/
  19. #ifndef MATHTOOL_H
  20. #define MATHTOOL_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif // __cplusplus
  24. /************************************************************************
  25. Modules used (included header files)
  26. *************************************************************************/
  27. /************************************************************************
  28. Compiler Directives (N/A)
  29. *************************************************************************/
  30. #ifdef _MATHTOOL_C_
  31. #define _MATHTOOL_EXT
  32. #else
  33. #define _MATHTOOL_EXT extern
  34. #endif
  35. /************************************************************************
  36. Definitions & Macros (#define ...)
  37. *************************************************************************/
  38. #define SINTABSIZE 256 + 1
  39. #define ARCTANTABSIZE 16
  40. #define SINCOS_DEFAULT \
  41. { \
  42. 0, 0 \
  43. } // Default value of SINCOS_DEFAULT
  44. #define ARCTAN_IN_DEFAULT \
  45. { \
  46. 0, 0 \
  47. } // Default value of ARCTAN_IN
  48. /************************************************************************
  49. TypeDefs & Structure defines
  50. *************************************************************************/
  51. typedef struct
  52. { // Outputs of sin-cos table
  53. SWORD swSinPu; // Q15 Output SIN
  54. SWORD swCosPu; // Q15 Output COS
  55. } SINCOS; // Struct of sin&cos
  56. typedef struct
  57. { // Outputs of LPF
  58. UWORD uwKx; // Q15
  59. SLONG_UNION slY; // Q?+Q16
  60. } LPF_OUT; // Struct of LPF_OUT
  61. typedef struct
  62. {
  63. SWORD swAlphaPu; // Alpha axis component
  64. SWORD swBetaPu; // Beta axis component
  65. } ARCTAN_IN;
  66. /************************************************************************
  67. Constant Table
  68. *************************************************************************/
  69. /************************************************************************
  70. Exported Variables (Start definitions w/ _MATHTOOL_EXT)
  71. *************************************************************************/
  72. #ifdef _MATHTOOL_C_
  73. _MATHTOOL_EXT SINCOS mth_stSinCosPu = SINCOS_DEFAULT;
  74. _MATHTOOL_EXT ARCTAN_IN mth_stArctanIn = ARCTAN_IN_DEFAULT;
  75. #else
  76. _MATHTOOL_EXT SINCOS mth_stSinCosPu;
  77. _MATHTOOL_EXT ARCTAN_IN mth_stArctanIn;
  78. #endif
  79. /************************************************************************
  80. Exported Function Call Prototypes (Start definitions w/ _MATHTOOL_EXT)
  81. *************************************************************************/
  82. #ifdef _MATHTOOL_C_
  83. _MATHTOOL_EXT void mth_voSinCos(UWORD angle, SINCOS *v);
  84. _MATHTOOL_EXT void mth_voLPFilterCoef(ULONG ulLpfTime_us, ULONG ulExeFreq, UWORD *uwLPFCof);
  85. _MATHTOOL_EXT void mth_voLPFilter(SWORD swLpfIn, LPF_OUT *out);
  86. _MATHTOOL_EXT SLONG mth_slSqrt(SLONG slInput);
  87. _MATHTOOL_EXT SLONG mth_slRamp(SLONG slInput, SLONG slDelta, SLONG slOutputLimit);
  88. _MATHTOOL_EXT UWORD mth_voArctan(const ARCTAN_IN *in);
  89. #else
  90. _MATHTOOL_EXT void mth_voSinCos(UWORD angle, SINCOS *v);
  91. _MATHTOOL_EXT void mth_voLPFilterCoef(ULONG ulLpfTime_us, ULONG ulExeFreq, UWORD *uwLPFCof);
  92. _MATHTOOL_EXT void mth_voLPFilter(SWORD swLpfIn, LPF_OUT *out);
  93. _MATHTOOL_EXT SLONG mth_slSqrt(SLONG slInput);
  94. _MATHTOOL_EXT SLONG mth_slRamp(SLONG slInput, SLONG slDelta, SLONG slOutputLimit);
  95. _MATHTOOL_EXT UWORD mth_voArctan(const ARCTAN_IN *in);
  96. #endif
  97. /************************************************************************
  98. RAM ALLOCATION: N/A
  99. *************************************************************************/
  100. /************************************************************************
  101. Flag Define (N/A)
  102. *************************************************************************/
  103. #ifdef __cplusplus
  104. }
  105. #endif // __cplusplus
  106. #endif
  107. /*************************************************************************
  108. Copyright (c) 2011 Welling Motor Technology(Shanghai) Co. Ltd.
  109. All rights reserved.
  110. *************************************************************************
  111. End of this File (EOF):
  112. Do not put anything after this part!
  113. *************************************************************************/