Okay here is the code for the PIC18F26K22:
Code:
include "trig18.inc"
Define OSC 16 'Clock will be configured to 16MHz
OSCCON.6 = 1 ' Set Internal Osc to 16Mhz
OSCCON.5 = 1 ' Set Internal Osc to 16Mhz
OSCCON.4 = 1 ' Set Internal Osc to 16Mhz
OSCCON.1 = 0 ' Use Internal Osc through Primary Clock (not Directly) to Access PLL Block
OSCCON.0 = 0 ' Use Internal Osc through Primary Clock (not Directly) to Access PLL Block
OSCTUNE.6 = 0 '16MHz osc - PLL Disabled
'Configure AN2 as Analog Inputs (PortA2)
ANSELA = %00000000 'Everything Digital
ANSELB = %00000000 'Everything Else Digital
ANSELC = %00000000 'Everything Else Digital
TRISB.7 = 0 'Outout
Serial_out var PORTB.7 'Serial out pin for debugging/developing comms
n var byte
main:
pause 2000
serout2 Serial_out,84, ["Test 123",13,10]
Pause 1000
ang=3000
serout2 Serial_out,84, ["Ang: ",dec ang,13,10]
'sincos example:
'input ang in degrees.dd example: ang = 3000 (= 30.00 degrees)
'call sincos
'result: x = 15004 , Y = 25981
'so, 15004/30000 = sin(ang) = 0.5001 and 25981/30000 = cos(ang) = 0.8660
call sincos
serout2 Serial_out,84, ["Sin ang: ",dec x,13,10]
serout2 Serial_out,84, ["Cos ang: ",dec y,13,10]
serout2 Serial_out,84, [13,10]
x = 12000
y = 8000
serout2 Serial_out,84, ["x input: ",sdec x,13,10]
serout2 Serial_out,84, ["y input: ",sdec y,13,10]
call atan2
'result: x = 14422 = hypotenuse or distance to x,y, y = angle to x,y in degrees.dd = 5631 (=56.31 degrees), ang = 6133 = radians 0 to 65535
serout2 Serial_out,84, ["hypotenuse: ",sdec x,13,10]
serout2 Serial_out,84, ["Ang in degrees.dd: ",sdec y/100,".",dec2 y,13,10]
serout2 Serial_out,84, ["Ang in Rad: ",dec ang,13,10]
serout2 Serial_out,84, [13,10]
x = -12000
y = 8000
serout2 Serial_out,84, ["x input: ",sdec x,13,10]
serout2 Serial_out,84, ["y input: ",sdec y,13,10]
call atan2
'result: x = 14422 = hypotenuse or distance to x,y, y = angle to x,y in degrees.dd = 3037 (=303.70 degrees), ang = 26634 = radians 0 to 65535
serout2 Serial_out,84, ["hypotenuse: ",sdec x,13,10]
serout2 Serial_out,84, ["Ang in degrees.dd: ",sdec y/100,".",dec2 y,13,10]
serout2 Serial_out,84, ["Ang in Rad: ",dec ang,13,10]
serout2 Serial_out,84, [13,10]
x = -12000
y = -8000
serout2 Serial_out,84, ["x input: ",sdec x,13,10]
serout2 Serial_out,84, ["y input: ",sdec y,13,10]
call atan2
'result: x = 14422 = hypotenuse or distance to x,y, y = angle to x,y in degrees.dd = 23632 (=236.32 degrees), ang = 38899 = radians 0 to 65535
serout2 Serial_out,84, ["hypotenuse: ",sdec x,13,10]
serout2 Serial_out,84, ["Ang in degrees.dd: ",sdec y/100,".",dec2 y,13,10]
serout2 Serial_out,84, ["Ang in Rad: ",dec ang,13,10]
serout2 Serial_out,84, [13,10]
x = 12000
y = -8000
serout2 Serial_out,84, ["x input: ",sdec x,13,10]
serout2 Serial_out,84, ["y input: ",sdec y,13,10]
call atan2
'result: x = 14422 = hypotenuse or distance to x,y, y = angle to x,y in degrees.dd = 12367 (=123.67 degrees), ang = 59405 = radians 0 to 65535
serout2 Serial_out,84, ["hypotenuse: ",sdec x,13,10]
serout2 Serial_out,84, ["Ang in degrees.dd: ",sdec y/100,".",dec2 y,13,10]
serout2 Serial_out,84, ["Ang in Rad: ",dec ang,13,10]
Goto main
Results of the 18F26K22 code running on a 18F26K22:

Here is the (COPY & PASTED) code for the PIC18F26K83 - note the only difference is the osc setting method:
Code:
include "trig18.inc"
'Configure OSC postscaler to provide 16mhz system clock
OSCFRQ = %0101
Define OSC 16
'Configure AN2 as Analog Inputs (PortA2)
ANSELA = %00000000 'Everything Digital
ANSELB = %00000000 'Everything Else Digital
ANSELC = %00000000 'Everything Else Digital
TRISB.7 = 0 'Outout
Serial_out var PORTB.7 'Serial out pin for debugging/developing comms
n var byte
main:
pause 2000
serout2 Serial_out,84, ["Test 123",13,10]
Pause 1000
ang=3000
serout2 Serial_out,84, ["Ang: ",dec ang,13,10]
'sincos example:
'input ang in degrees.dd example: ang = 3000 (= 30.00 degrees)
'call sincos
'result: x = 15004 , Y = 25981
'so, 15004/30000 = sin(ang) = 0.5001 and 25981/30000 = cos(ang) = 0.8660
call sincos
serout2 Serial_out,84, ["Sin ang: ",dec x,13,10]
serout2 Serial_out,84, ["Cos ang: ",dec y,13,10]
serout2 Serial_out,84, [13,10]
x = 12000
y = 8000
serout2 Serial_out,84, ["x input: ",sdec x,13,10]
serout2 Serial_out,84, ["y input: ",sdec y,13,10]
call atan2
'result: x = 14422 = hypotenuse or distance to x,y, y = angle to x,y in degrees.dd = 5631 (=56.31 degrees), ang = 6133 = radians 0 to 65535
serout2 Serial_out,84, ["hypotenuse: ",sdec x,13,10]
serout2 Serial_out,84, ["Ang in degrees.dd: ",sdec y/100,".",dec2 y,13,10]
serout2 Serial_out,84, ["Ang in Rad: ",dec ang,13,10]
serout2 Serial_out,84, [13,10]
x = -12000
y = 8000
serout2 Serial_out,84, ["x input: ",sdec x,13,10]
serout2 Serial_out,84, ["y input: ",sdec y,13,10]
call atan2
'result: x = 14422 = hypotenuse or distance to x,y, y = angle to x,y in degrees.dd = 3037 (=303.70 degrees), ang = 26634 = radians 0 to 65535
serout2 Serial_out,84, ["hypotenuse: ",sdec x,13,10]
serout2 Serial_out,84, ["Ang in degrees.dd: ",sdec y/100,".",dec2 y,13,10]
serout2 Serial_out,84, ["Ang in Rad: ",dec ang,13,10]
serout2 Serial_out,84, [13,10]
x = -12000
y = -8000
serout2 Serial_out,84, ["x input: ",sdec x,13,10]
serout2 Serial_out,84, ["y input: ",sdec y,13,10]
call atan2
'result: x = 14422 = hypotenuse or distance to x,y, y = angle to x,y in degrees.dd = 23632 (=236.32 degrees), ang = 38899 = radians 0 to 65535
serout2 Serial_out,84, ["hypotenuse: ",sdec x,13,10]
serout2 Serial_out,84, ["Ang in degrees.dd: ",sdec y/100,".",dec2 y,13,10]
serout2 Serial_out,84, ["Ang in Rad: ",dec ang,13,10]
serout2 Serial_out,84, [13,10]
x = 12000
y = -8000
serout2 Serial_out,84, ["x input: ",sdec x,13,10]
serout2 Serial_out,84, ["y input: ",sdec y,13,10]
call atan2
'result: x = 14422 = hypotenuse or distance to x,y, y = angle to x,y in degrees.dd = 12367 (=123.67 degrees), ang = 59405 = radians 0 to 65535
serout2 Serial_out,84, ["hypotenuse: ",sdec x,13,10]
serout2 Serial_out,84, ["Ang in degrees.dd: ",sdec y/100,".",dec2 y,13,10]
serout2 Serial_out,84, ["Ang in Rad: ",dec ang,13,10]
Goto main
(Erroneous) Results of the 18F26K83 code running on a 18F26K83:

I've also attached my slightly modifed Trig18.inc file - only modified to allow the use of longs for PIC18s. Same inc file is used for both examples.
Bookmarks