mathtool.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #include "typedefine.h"
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif // __cplusplus
  25. /************************************************************************
  26. Modules used (included header files)
  27. *************************************************************************/
  28. /************************************************************************
  29. Compiler Directives (N/A)
  30. *************************************************************************/
  31. #ifdef _MATHTOOL_C_
  32. #define _MATHTOOL_EXT
  33. #else
  34. #define _MATHTOOL_EXT extern
  35. #endif
  36. /************************************************************************
  37. Definitions & Macros (#define ...)
  38. *************************************************************************/
  39. #define SINTABSIZE 256 + 1
  40. #define ARCTANTABSIZE 16
  41. #define SINCOS_DEFAULT \
  42. { \
  43. 0, 0 \
  44. } // Default value of SINCOS_DEFAULT
  45. #define ARCTAN_IN_DEFAULT \
  46. { \
  47. 0, 0 \
  48. } // Default value of ARCTAN_IN
  49. /************************************************************************
  50. TypeDefs & Structure defines
  51. *************************************************************************/
  52. typedef struct
  53. { // Outputs of sin-cos table
  54. SWORD swSinPu; // Q15 Output SIN
  55. SWORD swCosPu; // Q15 Output COS
  56. } SINCOS; // Struct of sin&cos
  57. typedef struct
  58. { // Outputs of LPF
  59. UWORD uwKx; // Q15
  60. SLONG_UNION slY; // Q?+Q16
  61. } LPF_OUT; // Struct of LPF_OUT
  62. typedef struct
  63. {
  64. SWORD swAlphaPu; // Alpha axis component
  65. SWORD swBetaPu; // Beta axis component
  66. } ARCTAN_IN;
  67. /************************************************************************
  68. Constant Table
  69. *************************************************************************/
  70. /************************************************************************
  71. Exported Variables (Start definitions w/ _MATHTOOL_EXT)
  72. *************************************************************************/
  73. #ifdef _MATHTOOL_C_
  74. _MATHTOOL_EXT SINCOS mth_stSinCosPu = SINCOS_DEFAULT;
  75. _MATHTOOL_EXT ARCTAN_IN mth_stArctanIn = ARCTAN_IN_DEFAULT;
  76. #else
  77. _MATHTOOL_EXT SINCOS mth_stSinCosPu;
  78. _MATHTOOL_EXT ARCTAN_IN mth_stArctanIn;
  79. #endif
  80. /************************************************************************
  81. Exported Function Call Prototypes (Start definitions w/ _MATHTOOL_EXT)
  82. *************************************************************************/
  83. #ifdef _MATHTOOL_C_
  84. _MATHTOOL_EXT void mth_voSinCos(UWORD angle, SINCOS *v);
  85. _MATHTOOL_EXT void mth_voLPFilterCoef(ULONG ulLpfTime_us, ULONG ulExeFreq, UWORD *uwLPFCof);
  86. _MATHTOOL_EXT void mth_voLPFilter(SWORD swLpfIn, LPF_OUT *out);
  87. _MATHTOOL_EXT SLONG mth_slSqrt(SLONG slInput);
  88. _MATHTOOL_EXT SLONG mth_slRamp(SLONG slInput, SLONG slDelta, SLONG slOutputLimit);
  89. _MATHTOOL_EXT UWORD mth_voArctan(const ARCTAN_IN *in);
  90. #else
  91. _MATHTOOL_EXT void mth_voSinCos(UWORD angle, SINCOS *v);
  92. _MATHTOOL_EXT void mth_voLPFilterCoef(ULONG ulLpfTime_us, ULONG ulExeFreq, UWORD *uwLPFCof);
  93. _MATHTOOL_EXT void mth_voLPFilter(SWORD swLpfIn, LPF_OUT *out);
  94. _MATHTOOL_EXT SLONG mth_slSqrt(SLONG slInput);
  95. _MATHTOOL_EXT SLONG mth_slRamp(SLONG slInput, SLONG slDelta, SLONG slOutputLimit);
  96. _MATHTOOL_EXT UWORD mth_voArctan(const ARCTAN_IN *in);
  97. #endif
  98. /************************************************************************
  99. RAM ALLOCATION: N/A
  100. *************************************************************************/
  101. /************************************************************************
  102. Flag Define (N/A)
  103. *************************************************************************/
  104. #ifdef __cplusplus
  105. }
  106. #endif // __cplusplus
  107. #endif
  108. /*************************************************************************
  109. Copyright (c) 2011 Welling Motor Technology(Shanghai) Co. Ltd.
  110. All rights reserved.
  111. *************************************************************************
  112. End of this File (EOF):
  113. Do not put anything after this part!
  114. *************************************************************************/