FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > FPGA

FPGA comp.arch.fpga newsgroup (usenet)

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-31-2005, 09:13 PM
Guest
 
Posts: n/a
Default 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

Reply With Quote
  #2 (permalink)  
Old 05-31-2005, 09:52 PM
Piotr Wyderski
Guest
 
Posts: n/a
Default 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

Reply With Quote
  #3 (permalink)  
Old 05-31-2005, 09:57 PM
John_H
Guest
 
Posts: n/a
Default 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



Reply With Quote
  #4 (permalink)  
Old 05-31-2005, 11:21 PM
Berty
Guest
 
Posts: n/a
Default 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.

Reply With Quote
  #5 (permalink)  
Old 05-31-2005, 11:30 PM
Piotr Wyderski
Guest
 
Posts: n/a
Default 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

Reply With Quote
  #6 (permalink)  
Old 06-01-2005, 02:35 AM
Peter Alfke
Guest
 
Posts: n/a
Default 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

Reply With Quote
  #7 (permalink)  
Old 06-01-2005, 04:04 PM
Guest
 
Posts: n/a
Default 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

Reply With Quote
  #8 (permalink)  
Old 06-01-2005, 04:18 PM
Peter Alfke
Guest
 
Posts: n/a
Default 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

Reply With Quote
  #9 (permalink)  
Old 06-01-2005, 04:33 PM
Piotr Wyderski
Guest
 
Posts: n/a
Default 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

Reply With Quote
  #10 (permalink)  
Old 06-01-2005, 05:29 PM
Guest
 
Posts: n/a
Default 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.

Thanks for your help

pvnguyen

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
implementing arinc429 controller in fpga [email protected] Verilog 0 07-21-2007 02:09 PM
How to implement this C function in FPGA Stanley FPGA 7 05-16-2005 09:01 PM
Sine function implementation in FPGA SD FPGA 2 10-11-2004 04:56 AM
Sine function implementation in FPGA?? SD FPGA 5 10-06-2004 07:53 AM
has anyone tried implementing Serpent? david kong FPGA 2 09-28-2004 06:07 PM


All times are GMT +1. The time now is 05:58 PM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved