You are here: Math Resources > Sine Table

Sine Table

The sine table resides in locations $E000 - $F001 in Main Memory. It can be used for calculations related to angular phenomena. There is also a Log Table and an Anti-Log Table .

The sine table provides 2,049 unsigned 16-bit sine samples spanning from 0° to 90°, inclusively (0.0439° resolution).  Sine values for all other quadrants covering > 90° to < 360° can be calculated from simple transformations on this single-quadrant sine table.

A small amount of assembly code can mirror and flip the sine table samples to create a full-cycle sine/cosine lookup routing which has a 13-bit angle resolution and a 17-bit sample resolution. As with the log and anti-log tables, linear interpolation could be applied to the sine table to achieve higher resolution.

DAT

' Get sine/cosine
'
'      quadrant:  1             2             3             4
'         angle:  $0000..$07FF  $0800..$0FFF  $1000..$17FF  $1800..$1FFF
'   table index:  $0000..$07FF  $0800..$0001  $0000..$07FF  $0800..$0001
'        mirror:  +offset       -offset       +offset       -offset
'          flip:  +sample       +sample       -sample       -sample
'
' on entry: sin[12..0] holds angle (0° to just under 360°)
' on exit:  sin holds signed value ranging from $0000FFFF ('1') to 
' $FFFF0001 ('-1')
'
getcos          add     sin,sin_90          'for cosine, add 90°
getsin          test    sin,sin_90      wc  'get quadrant 2|4 into c
                test    sin_sin_180     wz  'get quadrant 3|4 into nz
                negc    sin,sin             'if quadrant 2|4, negate offset
                or      sin,sin_table       'or in sin table address >> 1
                shl     sin,#1              'shift left to get final word address
                rdword  sin,sin             'read word sample from $E000 to $F000
                negnz   sin,sin                 'if quadrant 3|4, negate sample
getsin_ret
getcos_ret      ret                         '39..54 clocks
                                            '(variance due to HUB sync on RDWORD)


sin_90          long    $0800   
sin_180         long    $1000
sin_table       long    $E000 >> 1          'sine table base shifted right

sin             long    0

 

Propeller Help Version 1.1

Copyright © Parallax Inc.

5/13/2009