Implementing sin function in fpga

May 31, 2005 9 Replies

I am attempting to implement a sine function using cordic method. I can't figure out how to reduce an arbitrary angle to -90 and 90 deg. For example, if an input is 390 deg, it should be reduced to 30 deg before passing to the cordic method. What algorithm can i use to efficiently reduce a arbitrary angle down to -90 and 90 deg.



Any help would be much appreciated



Thanks pvn



Forget about CORDIC, computing 17-bit accurate sin(x) using linear interpolation needs much smaller hardware and is conceptually simpler. It could be as fast as your RAM is -- my implementation of this method at a speed grade 6 Cyclone generates up to 256*10^6 sin(x) values per second.

Best regards Piotr Wyderski

Rather than running the CORDIC off degrees, run it off a phase value from

0-1 corresponding to 0-360 degrees. Just multiply an 18-bit input by 2^18/360 and use only the bottom 18 bits from the multiply, effectively truncating the integer portion of a fixed-decimal number. The 18 bits are (phase/360 - int(phase/360)) * 2^18 or using a less popular notation frac(phase/360)*2^18.

Depend on the accuracy you need, but if it is not "too bad" you can simple use memories as LUT which you preload with the sin result. The amount of logic is minimal and the speed is as fast as you can run the memory.

Have fun.

If you use two memories with 256 entries each (the first one for sin(k),

18-bit wide and the second one, 11-bit wide for sin(k+1)-sin(k)) and an unsigned 11x8 multiplier, then you can compute sin(x) with 17 significant binary digits. It will consume about 450 LEs.

Best regards Piotr Wyderski

I remember that every high-school student used to learn that sin(90 + x) = sin(90 -x), and sin(180+x) = -sin(180-x), and sin-x = -sinx Peter Alfke

I am very comfortable with using Cordic method, however i will definitely look into linear interpolation.

No matter what algorithm I use, I would still need to determine the offset of an angle in order to compute its sine result. The most obvious way to calculate the offset is to devide by 360 and extract the remainder. However, i was hoping not having to implement a divide block due to speed and area. Are there shifting combinations that can result in an exact division of 360? What kind of algorithm does a calculator used?

Thanks pvnguyen

I would just perform a repetitive subtraction of 360, until the result is smaller than 360. You are only interested in the remainder... Peter Alfke

IMHO the best way is to scale a given angle so that 360 degrees is represented by 2^N for some appropriately large N and then simply throw away everything except the N least significant bits. Just multiply your angle by 2^N/360 and that's all.

If you really need to know true modulo, then the Russian peasants division algorithm would be a good idea.

Best regards Piotr Wyderski

I see!

John_H mention that earlier but i wasn't fully understood. I know what I need to do now.

Thanks for your help

pvnguyen

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required