Calculating Sin/Cos with GFLIB

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Calculating Sin/Cos with GFLIB

Jump to solution
1,557 Views
aberger
Contributor V

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:

pastedImage_2.png

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?

0 Kudos
1 Solution
1,268 Views
aberger
Contributor V

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

View solution in original post

0 Kudos
3 Replies
1,269 Views
aberger
Contributor V

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

0 Kudos
1,268 Views
Carlos_Mendoza
NXP Employee
NXP Employee

Hi Andy,

Could you tell us which MCU are you using?

Thanks in advance!

Best Regards,
Carlos Mendoza
Technical Support Engineer

0 Kudos
1,268 Views
aberger
Contributor V

I'm using the MK64FN1M0VMD12 (as a part of the TWR-K64F-120M dev board), and am working in MCUXpresso v10.1.0 build 589.

0 Kudos