mag_pic, CORDIC on the PIC

I was writing the atan function for x,y to angle last night, and got working code using very simple gonio, where I calculated the hypotenuse, and then took the sine and looked it up in my existing sine table (from scope_pic). However (and this is all about doing it without fleetwood point math, it still took some multiplies, (32 bit) and a square root, and some lookup, and it was not really that accurate (about around one degree), so basically it sucked. I thought, well, CORDIC works in FPGA, so why not in a PIC, and did a web search for PIC 18F and CORDIC.

Least what I expected to find was asm for atan... So I found asm for atan, of course it did not work, but after some changes (tables to RAM at 0x100) I got it working.

Here are some interesting links, this is the original CORDIC code for PIC18, but is as called from C:

formatting link

Here is a nice discussion, and a port to PIC BASIC that I found very helpful for testing:

formatting link
That links also has speed compares, and MAN IS IT FAST, especially on a 64 MHz 18F14K22. No multiplies, no square roots, CORDIC uses basically successive approximation, and I love that. Was actually the reason I bothered with all that strange asm, always takes a while to figure out somebody else's asm. Here is wikipedia on CORDIC:
formatting link
And this is the'old' way:
formatting link
If anybody wants my working CORDIC for 18F14K22 they will have to ask via email, as I will not release any code before the fluxgate magnetometer PIC project is sort of finished,

Anyways it is fun, will play with it some more.

PS If you think CORDIC is a strange word, look wat NASA came up with:

quote (from sci.space.news): The mission, called Origins-Spectral Interpretation-Resource Identification-Security-Regolith Explorer, or OSIRIS-REx, will be the first U.S. mission to carry samples from an asteroid back to Earth. end quote

LOL

Reply to
Jan Panteltje
Loading thread data ...

Corected link: Here is a nice discussion, and a port to PIC BASIC that I found very helpful for testing:

formatting link

Reply to
Jan Panteltje

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.