54 lines
2.7 KiB
C
54 lines
2.7 KiB
C
#include "type.h"
|
|
|
|
#define SQRT_2 1.4142
|
|
#define SQRT_3 1.732
|
|
|
|
/**
|
|
* @brief Macro to compute logarithm of two
|
|
*/
|
|
#define LOG2(x) \
|
|
((x) == 65535 ? 16 : ((x) == 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 ? 15 : ((x) == 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 ? 14 : ((x) == 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 ? 13 : ((x) == 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 ? 12 : ((x) == 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 ? 11 : ((x) == 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 ? 10 : ((x) == 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 ? 9 : ((x) == 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 ? 8 : ((x) == 2 * 2 * 2 * 2 * 2 * 2 * 2 ? 7 : ((x) == 2 * 2 * 2 * 2 * 2 * 2 ? 6 : ((x) == 2 * 2 * 2 * 2 * 2 ? 5 : ((x) == 2 * 2 * 2 * 2 ? 4 : ((x) == 2 * 2 * 2 ? 3 : ((x) == 2 * 2 ? 2 : ((x) == 2 ? 1 : ((x) == 1 ? 0 : -1)))))))))))))))))
|
|
|
|
/**
|
|
* @brief This function transforms stator currents Ia and qIb (which are
|
|
* directed along axes each displaced by 120 degrees) into currents
|
|
* Ialpha and Ibeta in a stationary qd reference frame.
|
|
* Ialpha = Ia
|
|
* Ibeta = -(2*Ib+Ia)/sqrt(3)
|
|
* @param Curr_Input: stator current Ia and Ib in ab_t format
|
|
* @retval Stator current Ialpha and Ibeta in alphabeta_t format
|
|
*/
|
|
alphabeta_t math_clarke(ab_t Input);
|
|
|
|
/**
|
|
* @brief This function transforms stator values alpha and beta, which
|
|
* belong to a stationary qd reference frame, to a rotor flux
|
|
* synchronous reference frame (properly oriented), so as Iq and Id.
|
|
* Id= Ialpha *sin(theta)+qIbeta *cos(Theta)
|
|
* Iq=qIalpha *cos(Theta)-qIbeta *sin(Theta)
|
|
* @param Curr_Input: stator values alpha and beta in alphabeta_t format
|
|
* @param Theta: rotating frame angular position in q1.15 format
|
|
* @retval Stator current q and d in qd_t format
|
|
*/
|
|
qd_t math_park(alphabeta_t Input, int16_t Theta);
|
|
|
|
/**
|
|
* @brief This function transforms stator voltage qVq and qVd, that belong to
|
|
* a rotor flux synchronous rotating frame, to a stationary reference
|
|
* frame, so as to obtain qValpha and qVbeta:
|
|
* Valfa= Vq*Cos(theta)+ Vd*Sin(theta)
|
|
* Vbeta=-Vq*Sin(theta)+ Vd*Cos(theta)
|
|
* @param Curr_Input: stator voltage Vq and Vd in qd_t format
|
|
* @param Theta: rotating frame angular position in q1.15 format
|
|
* @retval Stator values alpha and beta in alphabeta_t format
|
|
*/
|
|
alphabeta_t math_rev_park(qd_t Input, int16_t Theta);
|
|
|
|
/**
|
|
* @brief It calculates the square root of a non-negative s32. It returns 0
|
|
* for negative s32.
|
|
* @param Input int32_t number
|
|
* @retval int32_t Square root of Input (0 if Input<0)
|
|
*/
|
|
int32_t math_sqrt(int32_t wInput);
|