cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate tan angles..

parag
Associate II
Posted on February 02, 2011 at 22:12

How to calculate tan angles..

7 REPLIES 7
madhu13
Associate III
Posted on May 17, 2011 at 14:23

add ''math.h'' lib and use tan(x) function.

picguy2
Associate II
Posted on May 17, 2011 at 14:23

Use the tan(x) from your C compiler.

Posted on May 17, 2011 at 14:23

''add 'math.h' lib''

 

Note that math.h is

not

  a library - it is just a header file!

In addition to #include-ing math.h, you will also have to add the appropriate floating-point lirary/libraries to your project.

For details, see the documentation for your particular toolset.

Note that some free/restricted toolset versions may not allow use of floating point

parag
Associate II
Posted on May 17, 2011 at 14:23

Thanks a lot guys.

@neil: I am using Ride7 and working on STM32F103ZE. Do you know how to add that floating library file in it?? is it available for this controller?. Thanks a lot for help.

Posted on May 17, 2011 at 14:23

Note that floating-point has a very significantly greater overhead (both code size and execution time) than integer maths - therefore you should think very carefully indeed whether you really  need floating point in your application.

This is one reason why many (most?) embedded toolchains do not include floating-point by default.

In most cases, it is easy enough to scale you values so that you can do everything in integer maths; eg, instead of processing 3.3V as a floating-point number, think of it as 3300mV - an integer!

You can choose any scaling factor that is convenient to your particular application.

Functions such as tan() can be implemented as lookup tables,  or integer implementations - so-called ''fixed point'' - are available.

eg, CORDIC algorithms: 

http://en.wikipedia.org/wiki/CORDIC

So, try it first using floating-point; but be aware that this may give you code-size and/or performance issues - so be prepared to explore the alternatives...
John F.
Senior
Posted on May 17, 2011 at 14:23

If you want to learn more about methods and approximations, have a look at the book ''Math toolkit for real-time programming'' by Jack W. Crenshaw.

picguy2
Associate II
Posted on May 17, 2011 at 14:23

Integer vs. floating point makes a BIG difference in execution time.  My DTMF decode went from 10 milliseconds to 0.6 milliseconds.  

This was for a 100 sample Goertzel algorithm performing sums and power calculation using integer arithmetic returning a signed 64-bit integer.  I used 16 different frequencies -- the basic 8(*) and their second harmonics.  C code converted that to 32-bit fp.  Column/row selection used fp to pick a winner that had to be 3x the sum of the other three items.  Sum of all 8 harmonics had to be a factor of 3 or 4 less than the winning row value.

(*) that included the almost never present ABCD column to the right of 369#.