How to calculate arctan(x)?

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

How to calculate arctan(x)?

Jump to solution
2,026 Views
aaronlee
Contributor V

How to calculate arctan(x), sin(x), cos(x) in S12ZVCA ?

 

Best Regards,

Aaron

0 Kudos
1 Solution
2,019 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

you can use standard CodeWarrior library functions. however they are relatively (depends on application) slow:

#include <math.h>

double atan(double x);

float atanf(float x);

long double atanl(long double x);

 

Another possibility is to use math and control library which uses fractional arithmetics and polynomial substitution of the functions:

 

Search for mc9s12zvm_ammclib at nxp.com to get more info or

https://www.nxp.com/design/automotive-software-and-tools/nxp-automotive-math-and-motor-control-libra...

to download. (you must press "more" to find library in collapsed list)

 

Best regards,

Ladislav

 

 

 

The last possibility is to use own searching table...depends on required precisiion.

 

View solution in original post

0 Kudos
3 Replies
2,020 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

you can use standard CodeWarrior library functions. however they are relatively (depends on application) slow:

#include <math.h>

double atan(double x);

float atanf(float x);

long double atanl(long double x);

 

Another possibility is to use math and control library which uses fractional arithmetics and polynomial substitution of the functions:

 

Search for mc9s12zvm_ammclib at nxp.com to get more info or

https://www.nxp.com/design/automotive-software-and-tools/nxp-automotive-math-and-motor-control-libra...

to download. (you must press "more" to find library in collapsed list)

 

Best regards,

Ladislav

 

 

 

The last possibility is to use own searching table...depends on required precisiion.

 

0 Kudos
1,814 Views
aaronlee
Contributor V

Share my code "Clockwise Rotation"

 from (A, B) to (X,Y)

 

#include "math.h"

double atan(double);
float atanf(float);

int16_t iA, iB, iX, iY;
float fAngle, fDistance, fRotate;

fAngle = atan2f (iB, iA);
fDistance = sqrt(pow(iA,2) + pow(iB,2));
iX = fDistance * cos(fAngle - fRotate);
iY = fDistance * sin(fAngle - fRotate);

 

Best Regards,

Aaron

 

Reference:

Determining clockwise vs counter clockwise rotations

Determining angle of rotation

0 Kudos
2,012 Views
aaronlee
Contributor V

Hi Ladislav,

Very useful. Thank you.

Best Regards,

Aaron

0 Kudos