EmbeddedRelated.com
Forums

sine routines

Started by CAFxX January 14, 2004
does anybody know where to find some FAST sine routines to be run on an
8052? sdcc's math.h is just an empty file... just an #error directive! thank
you in advance.


On Wed, 14 Jan 2004 21:43:20 +0100, "CAFxX" <cafxx@n-side.it> wrote in
comp.arch.embedded:

> does anybody know where to find some FAST sine routines to be run on an > 8052? sdcc's math.h is just an empty file... just an #error directive! thank > you in advance.
There are no FAST routines for calculating sine with the 8051 instruction set, and probably no fast ones either. How much accuracy and precision do you need? The fastest approach would be a look-up table. -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
Jack Klein wrote:
> "CAFxX" <cafxx@n-side.it> wrote > > > does anybody know where to find some FAST sine routines to be > > run on an 8052? sdcc's math.h is just an empty file... just an > > #error directive! thank you in advance. > > There are no FAST routines for calculating sine with the 8051 > instruction set, and probably no fast ones either. How much > accuracy and precision do you need? The fastest approach would > be a look-up table.
and what sort of floating point arithmetic has he available, if any? Does he have polynomial evaluation routines? etc. What input range is required? -- Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net) Available for consulting/temporary embedded and systems. <http://cbfalconer.home.att.net> USE worldnet address!
On Thu, 15 Jan 2004 04:47:12 GMT, CBFalconer <cbfalconer@yahoo.com>
wrote in comp.arch.embedded:

> Jack Klein wrote: > > "CAFxX" <cafxx@n-side.it> wrote > > > > > does anybody know where to find some FAST sine routines to be > > > run on an 8052? sdcc's math.h is just an empty file... just an > > > #error directive! thank you in advance. > > > > There are no FAST routines for calculating sine with the 8051 > > instruction set, and probably no fast ones either. How much > > accuracy and precision do you need? The fastest approach would > > be a look-up table. > > and what sort of floating point arithmetic has he available, if > any? Does he have polynomial evaluation routines? etc. What > input range is required?
All good questions, but do you know of any fast routines to calculate, as opposed to look up, sines on an 8051? Any floating point is hideously slow on that platform, I know, I've used it a few times. -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
> does anybody know where to find some FAST sine routines to be run on an > 8052? sdcc's math.h is just an empty file... j
You can use a Taylor series. And if your angles are small you can get away with a limited number of terms, depending on the required precision. You may do it with integer math and the approprate scaling. For example, for small angles, sin(x)=x (in radians) The next refinement: sin(x) = x - x*x /2 For angles below 1 radian this may be sufficient. Wim
Jack Klein wrote:
> CBFalconer <cbfalconer@yahoo.com> wrote in comp.arch.embedded: > > Jack Klein wrote: > > > "CAFxX" <cafxx@n-side.it> wrote > > > > > > > does anybody know where to find some FAST sine routines to be > > > > run on an 8052? sdcc's math.h is just an empty file... just an > > > > #error directive! thank you in advance. > > > > > > There are no FAST routines for calculating sine with the 8051 > > > instruction set, and probably no fast ones either. How much > > > accuracy and precision do you need? The fastest approach would > > > be a look-up table. > > > > and what sort of floating point arithmetic has he available, if > > any? Does he have polynomial evaluation routines? etc. What > > input range is required? > > All good questions, but do you know of any fast routines to calculate, > as opposed to look up, sines on an 8051? Any floating point is > hideously slow on that platform, I know, I've used it a few times.
I was thinking of some Tchebychev polynomials or ratio of polynomials I used 25 years ago for 4.5 digit accuracy. I have the source somewhere for the 8080 code I developed for them, which took about 10 millisec on a 2 Mhz 8080, as I recall. Floating multiply was in the order of 300 uSec. and divide headed for 1 millisec. -- Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net) Available for consulting/temporary embedded and systems. <http://cbfalconer.home.att.net> USE worldnet address!
On Wed, 14 Jan 2004 21:43:20 +0100, CAFxX wrote:

> does anybody know where to find some FAST sine routines to be run on an > 8052? sdcc's math.h is just an empty file... just an #error directive! thank > you in advance.
Sorry, no such animal. The fastest way to calculate sines is table lookup and interpolation. Also think 'octents' rather than quadrants to preserve accuracy. -- Regards, Albert ---------------------------------------------------------------------- AM Research, Inc. The Embedded Systems Experts http://www.amresearch.com 916.780.7623 ----------------------------------------------------------------------
CAFxX wrote:

> does anybody know where to find some FAST sine routines to be > run on an 8052? sdcc's math.h is just an empty file... just an > #error directive!
Fastest I've seen was look-up with linear interpolation on a twice-folded (at pi and pi/2) table of numerators for a fraction with denominator 65535. All of the processing was performed in integer math except the final division. Accuracy was pretty good and the code was completely portable (the application wasn't for an 8052). -- Morris Dovey West Des Moines, Iowa USA C links at http://www.iedu.com/c Read my lips: The apple doesn't fall far from the tree.
On Thu, 15 Jan 2004 06:48:19 GMT, Jack Klein <jackklein@spamcop.net>
wrote:

>On Thu, 15 Jan 2004 04:47:12 GMT, CBFalconer <cbfalconer@yahoo.com> >wrote in comp.arch.embedded: > >> Jack Klein wrote: >> > "CAFxX" <cafxx@n-side.it> wrote >> > >> > > does anybody know where to find some FAST sine routines to be >> > > run on an 8052? sdcc's math.h is just an empty file... just an >> > > #error directive! thank you in advance. >> > >> > There are no FAST routines for calculating sine with the 8051 >> > instruction set, and probably no fast ones either. How much >> > accuracy and precision do you need? The fastest approach would >> > be a look-up table. >> >> and what sort of floating point arithmetic has he available, if >> any? Does he have polynomial evaluation routines? etc. What >> input range is required? > >All good questions, but do you know of any fast routines to calculate, >as opposed to look up, sines on an 8051? Any floating point is >hideously slow on that platform, I know, I've used it a few times.
If only sin/cos is required (and not tan), then why use floating point numbers in the first place. Use some fixed point format e.g. the decimal point to the _left_ of the most significant bit or two bits for the integer part and 30 bits for the decimal part, thus avoiding any normalisation and denormalisation required by floating point additions. The fixed point arithmetic can be done with integer hardware, but some rounding due to discarded low order decimal bits must be done after multiplication and some shifts with a predetermined number of bits may be required if the number of integer bits is something else than 0 or 8. The polynomial method is just an refined table look up with some multiplications and additions. The quadrant (0..90 degrees) is divided into a few ranges and the polynomial coefficients are extracted from the table. A fourth order polynomial is usually sufficient for single precision accuracy, while 6-8 order is required for double precision. By dividing the quadrant into a larger number of ranges, a lower order polynomial can be used. Paul
what i need to do is to generate a custom-frequency sine wave to be
outputted at CD-quality frequency (44100 samples/second) to a DAC.
If possible i'd prefer working with 16 bit integers since float needs
cpu-time-expensive libraries.
thanks to all of you for your replies.
"Jack Klein" <jackklein@spamcop.net> ha scritto nel messaggio
news:bc0c00tijn9u6i0h5trab1kiuj5m9c58op@4ax.com...
> On Wed, 14 Jan 2004 21:43:20 +0100, "CAFxX" <cafxx@n-side.it> wrote in > comp.arch.embedded: > > > does anybody know where to find some FAST sine routines to be run on an > > 8052? sdcc's math.h is just an empty file... just an #error directive!
thank
> > you in advance. > > There are no FAST routines for calculating sine with the 8051 > instruction set, and probably no fast ones either. How much accuracy > and precision do you need? The fastest approach would be a look-up > table. > > -- > Jack Klein > Home: http://JK-Technology.Com > FAQs for > comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html > comp.lang.c++ http://www.parashift.com/c++-faq-lite/ > alt.comp.lang.learn.c-c++ > http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html