Trig functions in C18 3.10


I am aware that numerous trig lookup tables and algorithms are available for the RC. However, as far as I can tell, none of them are compatible with Kevin Watson’s new code.

Does anyone know of a method to calculate trig functions that works under the new version of C18?


Team 1751

Can you point me toward code that doesn’t work? I’ll have a look to see what it would take to get it working.

Unless you need to do hundreds of trig calculations per second, I would just go ahead and use the built-in functions. If you’re the adventurous type and just want to do it yourself, you could very easily get my eeprom code code moved over and then use the trig table generation and lookup code I wrote a few years back.


The code in this whitepaper doesn’t seem to compile correctly.


It compiles for me using the attached file that calls sin().


teleop.c (4.69 KB)

teleop.c (4.69 KB)

Sorry, I linked to an old version of the math library.

The updated library is here.


Just to clarify, the new version does NOT compile under C18 3.10. (My previous post was a bit unclear).

From experience we stay away from PIC floating point in our team. Its emulated, bloated and problematic to debug. It was even worse in the 2004 and 2005 years when the processors only had 32KB.

How widespread is the use of floating point by the teams out there?


We avoid it if at all possible, and never once have we found it impossible to avoid. In short, we haven’t used it. We just make sure that we multiply two integers before diving them (ex in a PID calculation with Kp being 33 / 100 we do 33 * delta / 100 rather than 33 / 100 * delta).

In recent years, Team 95 has been around 50/50. Two years ago we prototyped an omnidrive that worked in field coordinates, and we did sin(), cos(), asin(), and acos() every loop, with no problems.

And last year, our infrared ranging system used lots of floating point as well, with no real problems, although I did help the students develop a fixed-point equivalent (we never subbed it in, however).

did this ever get resolved? Could someone point me in the direction of one that does work with the new code?