 # FPGA Central

## World's 1st FPGA Portal

 FPGA comp.arch.fpga newsgroup (usenet)  Guest Posts: n/a Implementing sin function in fpga

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

 Piotr Wyderski Guest Posts: n/a Re: Implementing sin function in fpga

[email protected] wrote:

>I am attempting to implement a sine function using cordic method.

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

 John_H Guest Posts: n/a Re: Implementing sin function in fpga

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.

<[email protected]> wrote in message
news:[email protected] oups.com...
> 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

 Berty Guest Posts: n/a Re: Implementing sin function in fpga

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.

 Piotr Wyderski Guest Posts: n/a Re: Implementing sin function in fpga

Berty wrote:

> 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.

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

 Peter Alfke Guest Posts: n/a Re: Implementing sin function in fpga

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

 Guest Posts: n/a Re: Implementing sin function in fpga

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

 Peter Alfke Guest Posts: n/a Re: Implementing sin function in fpga

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

 Piotr Wyderski Guest Posts: n/a Re: Implementing sin function in fpga

[email protected] wrote:

> 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?

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.

> What kind of algorithm does a calculator used?

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

Best regards
Piotr Wyderski

 Guest Posts: n/a Re: Implementing sin function in fpga

> Just multiply your angle by 2^N/360 and that's all.

I see!

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

pvnguyen

 Thread Tools Show Printable Version Email this Page Display Modes Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules Similar Threads Thread Thread Starter Forum Replies Last Post [email protected] Verilog 0 07-21-2007 02:09 PM Stanley FPGA 7 05-16-2005 09:01 PM SD FPGA 2 10-11-2004 04:56 AM SD FPGA 5 10-06-2004 07:53 AM david kong FPGA 2 09-28-2004 06:07 PM

All times are GMT +1. The time now is 05:58 PM. Copyright 2008 @ FPGA Central. All rights reserved