|
brazos-trapezoidal
|
#include "uc.h"

Go to the source code of this file.
Classes | |
| struct | ABC_t |
| struct | DQ_t |
| struct | AlphaBeta_t |
| struct | trig_t |
Macros | |
| #define | BASE_IQ (15) |
| #define | _IQ(x) |
| #define | _IQX_TO_IQY(x, qx, qy) |
| #define | _IQX(x, qx) ((x) * ((mc_t)1 << (qx))) |
| #define | _FLOAT_TO_IQ(x, base) (((x) * (1 << (BASE_IQ)))/(base)) |
| #define | _FLOAT_TO_IQY(x, base_iq, base) (((float)(x) * ((mc_t)1 << (base_iq)))/(float)(base)) |
| #define | _IQ_TO_FLOATY(x, y, base) ((float32_t)(((float32_t)(x)*(float32_t)(base)) / (float32_t)(1 << y))) |
| #define | _IQ_TO_FLOAT(x) ((float32_t)(((float32_t)(x)) / (float32_t)(1 << BASE_IQ))) |
| #define | MATHLIB_MIN_VALUE ((mc_t)1) |
| #define | MATHLIB_IQMPY(a, b, a_format, b_format, out_format) |
| #define | MATHLIB_MPY(a, b) MATHLIB_IQMPY(a, b, BASE_IQ, BASE_IQ, BASE_IQ) |
| #define | MATHLIB_DIV(x, y) ((((x) << BASE_IQ) / (y))) |
| #define | MATHLIB_ABS(x) ((x < 0) ? -x : x) |
| #define | MATHLIB_SAT(x, lim_inf, lim_sup) |
| #define | MATHLIB_MPY_BY_TWO(a) ((a)<<1) |
| #define | MATHLIB_MPY_BY_FOUR(a) ((a)<<2) |
| #define | MATHLIB_MPY_BY_EIGHT(a) ((a)<<3) |
| #define | MATHLIB_DIV_BY_TWO(a) ((a)>>1) |
| #define | MATHLIB_DIV_BY_FOUR(a) ((a)>>2) |
| #define | MATHLIB_DIV_BY_EIGHT(a) ((a)>>3) |
| #define | MATHLIB_SQRT(x) MathLib_SqrtLUT((x)) |
| #define | MATHLIB_SINCOS(th, sc) MathLib_SinCosIQ(th, sc) |
| #define | MATHLIB_MOD(x, y) MathLib_ModIq(x, y) |
| #define | MATHLIB_SINCOSMODAB(ab, m, sc) MathLib_SinCosModAbIq(ab, m, sc) |
| #define | ONE_OVER_PI _IQ(0.31830988618379067153776752674503) |
| #define | ONE_OVER_4PI _IQ(0.07957747154594766788444188168626/2) |
| #define | ONE_OVER_TWO _IQ(0.5) |
| #define | ONE_OVER_THREE _IQ(0.33333) |
| #define | ONE_OVER_SQRT3 _IQ(0.57735026918962576450914878050196) |
| #define | SQRT3_OVER_TWO _IQ(0.86602540378443864676372317075294) |
| #define | SQRT3 _IQ(0.86602540378443864676372317075294*2) |
Functions | |
| u_mc_t | MathLib_SqrtLUT (uint16_t value) |
| Calculates the square root of IQ1.15 number using a Look-up table that needs to have a size of a power of 2. More... | |
| void | MathLib_SinCosPoly (mc_t theta, trig_t *sinCos) |
| Calculates the sine and cosine using a sixth order polynomial approximation, the approximation is just valid for the range -0.5 to 0.5 which represents the range from 0 to pi/2. More... | |
| mc_t | MathLib_ModIq (mc_t x, mc_t y) |
| Modulus function, it calculates hypotenusa in Q1.15. More... | |
| void | MathLib_SinCosModAbIq (AlphaBeta_t *ab, mc_t mod, trig_t *sinCos) |
| Modulus function, it calculates hypotenusa in Q1.15. More... | |
| void | MathLib_SinCosIQ (mc_t theta, trig_t *sinCos) |
| Sin and Cosine calculation of a Q1.15 angle. More... | |
Definition in file MathLib_Iq.h.
| #define _FLOAT_TO_IQ | ( | x, | |
| base | |||
| ) | (((x) * (1 << (BASE_IQ)))/(base)) |
Definition at line 74 of file MathLib_Iq.h.
| #define _FLOAT_TO_IQY | ( | x, | |
| base_iq, | |||
| base | |||
| ) | (((float)(x) * ((mc_t)1 << (base_iq)))/(float)(base)) |
Definition at line 75 of file MathLib_Iq.h.
| #define _IQ | ( | x | ) |
Definition at line 65 of file MathLib_Iq.h.
| #define _IQ_TO_FLOAT | ( | x | ) | ((float32_t)(((float32_t)(x)) / (float32_t)(1 << BASE_IQ))) |
Definition at line 82 of file MathLib_Iq.h.
| #define _IQ_TO_FLOATY | ( | x, | |
| y, | |||
| base | |||
| ) | ((float32_t)(((float32_t)(x)*(float32_t)(base)) / (float32_t)(1 << y))) |
Definition at line 81 of file MathLib_Iq.h.
| #define _IQX | ( | x, | |
| qx | |||
| ) | ((x) * ((mc_t)1 << (qx))) |
Definition at line 72 of file MathLib_Iq.h.
| #define _IQX_TO_IQY | ( | x, | |
| qx, | |||
| qy | |||
| ) |
Definition at line 68 of file MathLib_Iq.h.
| #define BASE_IQ (15) |
Defines the base IQ, unless otherwise noted, all the variables use this base
Definition at line 64 of file MathLib_Iq.h.
| #define MATHLIB_ABS | ( | x | ) | ((x < 0) ? -x : x) |
Definition at line 97 of file MathLib_Iq.h.
| #define MATHLIB_DIV | ( | x, | |
| y | |||
| ) | ((((x) << BASE_IQ) / (y))) |
Definition at line 95 of file MathLib_Iq.h.
| #define MATHLIB_DIV_BY_EIGHT | ( | a | ) | ((a)>>3) |
Definition at line 112 of file MathLib_Iq.h.
| #define MATHLIB_DIV_BY_FOUR | ( | a | ) | ((a)>>2) |
Definition at line 111 of file MathLib_Iq.h.
| #define MATHLIB_DIV_BY_TWO | ( | a | ) | ((a)>>1) |
Definition at line 110 of file MathLib_Iq.h.
| #define MATHLIB_IQMPY | ( | a, | |
| b, | |||
| a_format, | |||
| b_format, | |||
| out_format | |||
| ) |
Multiply two variables defined by BASE_IQ, assuming the integer part is never bigger than 1.41pu (1.41^2 would overflow the multiplication in the Q15 format
Definition at line 90 of file MathLib_Iq.h.
| #define MATHLIB_MIN_VALUE ((mc_t)1) |
Definition at line 84 of file MathLib_Iq.h.
| #define MATHLIB_MOD | ( | x, | |
| y | |||
| ) | MathLib_ModIq(x, y) |
Definition at line 119 of file MathLib_Iq.h.
| #define MATHLIB_MPY | ( | a, | |
| b | |||
| ) | MATHLIB_IQMPY(a, b, BASE_IQ, BASE_IQ, BASE_IQ) |
Definition at line 93 of file MathLib_Iq.h.
| #define MATHLIB_MPY_BY_EIGHT | ( | a | ) | ((a)<<3) |
Definition at line 109 of file MathLib_Iq.h.
| #define MATHLIB_MPY_BY_FOUR | ( | a | ) | ((a)<<2) |
Definition at line 108 of file MathLib_Iq.h.
| #define MATHLIB_MPY_BY_TWO | ( | a | ) | ((a)<<1) |
Multiply a variable by two, this macro was created to optimize multiplications by multiples of two in fixed point logic
Definition at line 107 of file MathLib_Iq.h.
| #define MATHLIB_SAT | ( | x, | |
| lim_inf, | |||
| lim_sup | |||
| ) |
Definition at line 98 of file MathLib_Iq.h.
| #define MATHLIB_SINCOS | ( | th, | |
| sc | |||
| ) | MathLib_SinCosIQ(th, sc) |
Definition at line 118 of file MathLib_Iq.h.
| #define MATHLIB_SINCOSMODAB | ( | ab, | |
| m, | |||
| sc | |||
| ) | MathLib_SinCosModAbIq(ab, m, sc) |
Definition at line 120 of file MathLib_Iq.h.
| #define MATHLIB_SQRT | ( | x | ) | MathLib_SqrtLUT((x)) |
| #define ONE_OVER_4PI _IQ(0.07957747154594766788444188168626/2) |
Definition at line 127 of file MathLib_Iq.h.
| #define ONE_OVER_PI _IQ(0.31830988618379067153776752674503) |
| #define ONE_OVER_SQRT3 _IQ(0.57735026918962576450914878050196) |
Definition at line 130 of file MathLib_Iq.h.
| #define ONE_OVER_THREE _IQ(0.33333) |
Definition at line 129 of file MathLib_Iq.h.
| #define ONE_OVER_TWO _IQ(0.5) |
Definition at line 128 of file MathLib_Iq.h.
| #define SQRT3 _IQ(0.86602540378443864676372317075294*2) |
Definition at line 132 of file MathLib_Iq.h.
| #define SQRT3_OVER_TWO _IQ(0.86602540378443864676372317075294) |
Definition at line 131 of file MathLib_Iq.h.
| mc_t MathLib_ModIq | ( | mc_t | x, |
| mc_t | y | ||
| ) |
Modulus function, it calculates hypotenusa in Q1.15.
| y | y-axis value to be calculated |
| x | x-axis value to be calculated |
Definition at line 363 of file MathLib_Iq.c.

| void MathLib_SinCosIQ | ( | mc_t | theta, |
| trig_t * | sinCos | ||
| ) |
Sin and Cosine calculation of a Q1.15 angle.
Sin table in the range of [0:2*pi]
| mc_t | theta: the angle |
Definition at line 301 of file MathLib_Iq.c.
| void MathLib_SinCosModAbIq | ( | AlphaBeta_t * | ab, |
| mc_t | mod, | ||
| trig_t * | sinCos | ||
| ) |
Modulus function, it calculates hypotenusa in Q1.15.
| y | y-axis value to be calculated |
| x | x-axis value to be calculated |
Definition at line 377 of file MathLib_Iq.c.
| void MathLib_SinCosPoly | ( | mc_t | theta, |
| trig_t * | sinCos | ||
| ) |
Calculates the sine and cosine using a sixth order polynomial approximation, the approximation is just valid for the range -0.5 to 0.5 which represents the range from 0 to pi/2.
| theta | the angle |
| sinCos | pointer to the struct that will hold the results |
get the quadrant of the angle
wrap the angle between 0 and pi/2, the range of the polynomial approximation
Rearrange 0 -> -1/2 and pi/2 -> 1/2, that's how the approximation use the angles
Definition at line 253 of file MathLib_Iq.c.
| u_mc_t MathLib_SqrtLUT | ( | uint16_t | value | ) |
Calculates the square root of IQ1.15 number using a Look-up table that needs to have a size of a power of 2.
| value | the number in 1.15 format |
The modulus operation is getting how much the input value is far from the table value, this is being used to interpolate, since everything is in the power of two, tmp will be in the IQ 1.(15-SIZE_SQRT_TABLE_2N) format.
Definition at line 216 of file MathLib_Iq.c.
