Walter,
I added three lines as shown in red. With the additions all 4 quadrants are returning correct magnitude and sign values.
See attached test file.
- Martin
;************************************************* *****************************/
i var byte BANK0
j Var byte BANK0
quad var byte BANK0
x var word bank0
y var word bank0
ang var word bank0
ang_temp var word bank0
dy var word bank0
dx var word bank0
atans var word[15] bank0
atans(0) = 16384
atans(1) = 9672
atans(2) = 5110
atans(3) = 2594
atans(4) = 1302
atans(5) = 652
atans(6) = 326
atans(7) = 163
atans(8) = 81
atans(9) = 41
atans(10) = 20
atans(11) = 10
atans(12) = 5
atans(13) = 3
atans(14) = 1
goto overcordic
atan2:
asm
call atan2_sqrt
endasm
'convert to degrees.dd y is degrees
If ang < 16384 then y = 16383 - ang
if ang > 16383 then
y = 65535 - ang
y = y + 16383 'correct 90 degrees for radian
endif
y = y * 256 'divides radians to get degrees within 57ppm
y = div32 466 'degrees.dd is y, radians is ang
return
sincos:
'use angle as deg.dd for example 35999 is 359.99 degrees
ang_temp = ang ' Store ang.
if ang < 9001 then ang = 9000 - ang
if ang > 9000 then ang = 27000 - (36000 - ang)
ang = ang * 466
ang = div32 256TRIG.basTrig_example.bas
asm
call sin_cos
endasm
if ang_temp > 9000 then y = ~y + 1 ' Perform 2's complement of y if ang > 90 for cos(ang).
return
asm
; Calculates the sine and cosine of the given angle
sin_cos:
Bookmarks