I am trying to write some simple code making use of GFLIB for an ARM Cortex M4F MCU. I have successfully included the library files, and have some code making use of the GFLIB_Sin_FLT_C function from gflib_FP.h:
In the below code, I am trying to build a sine-wave array (and phase-shifted copies) and store them in current_U, current_V, and current_W.
int main(void) {
float current_U[36];
float current_V[36];
float current_W[36];
int i;
for(i=0; i<NUM_PTS; i++) {
current_U[i] = GFLIB_Sin_FLT_C(i*10*PI/180.0); // input argument in radians
current_V[i] = GFLIB_Sin_FLT_C(i*10*PI/180.0 + 2*PI/3); // phase shift by +120deg
current_W[i] = GFLIB_Sin_FLT_C(i*10*PI/180.0 - 2*PI/3); // phase shift by -120deg
}
}
Strangely, the current_V calculation gives erroneous results:
Why would this be? Since GFLIB is a pre-compiled library, I can't examine the code that is calculating the sine value. Why would the calculation only fail for one of the function calls?
已解决! 转到解答。
Problem solved:
The GFLIB_Sin_FLT_C and Cos functions require the input argument in the range of -pi to +pi. I was inputting values >+pi.
See: https://www.nxp.com/docs/en/user-guide/CM4FGFLIBUG.pdf
Discussion of GFLIB_Sin algorithm on pg 35
Problem solved:
The GFLIB_Sin_FLT_C and Cos functions require the input argument in the range of -pi to +pi. I was inputting values >+pi.
See: https://www.nxp.com/docs/en/user-guide/CM4FGFLIBUG.pdf
Discussion of GFLIB_Sin algorithm on pg 35