Hi J,
I had to change the XZY by adding 'a' as they were reserved letters.
I made an attempt at the FUNCTION, which all compiles, but gives only AZI = 083456. 8
Here is Oshonsofts FUNCTION from the Manual:
Function square(arg1 As Word) As Word
square = arg1 * arg1
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Here's my DIMs
'READ COMPASS X
Dim x_raw As Word
Dim ax As Single
'READ COMPASS Z
Dim z_raw As Word
Dim az As Single
'READ COMPASS Y
Dim y_raw As Word
Dim ay As Single
Dim azi As Single 'word
Dim strazimuth As String 'For Screen
Dim picalc As Single
Const pi = 3.14159
picalc = 180 / pi
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Here's the section of program:
'READ COMPASS XZY REGISTER
SPICSOn
For i = 0 To 5 'READ XZY Xx2 Zx2 Yx2
compss = 0 'CHIP SELECT COMPASS ON
addr = 0x83 + i
SPISend addr
SPIReceive data
b(i) = data
compss = 1 'CHIP SELECT COMPASS OFF
Next i
SPICSOff
x_raw.HB = b(0)
x_raw.LB = b(1)
z_raw.HB = b(2)
z_raw.LB = b(3)
y_raw.HB = b(4)
y_raw.LB = b(5)
ax = x_raw
az = z_raw
ay = y_raw
'VVVVVVVV 2'S COMPLIMENT CALC VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
If ax > 32767 Then
ax = 65535 - ax
ax = ax + 1
Endif
If ay > 32767 Then
ay = 65535 - ay
ay = ay + 1
Endif
'AAAAAAAAAAAA 2'S COMPLIMENT CALC AAAAAAAAAAAAAAAAAAAAAAAAAAAA
If ax < ay Then
If ax > 0 And ay > 0 Then
azi = arctn(ax, ay)
Endif
Endif
l
l
l
l
END
____________________________________________________
'Azimuth CALC Function
Function arctn(ax As Single, ay As Single) As Single
arctn = (ax / ay) * picalc '180/pi
End Function
NOTE: There is a Z component. Should it be introduced now, or once the XY is working?
EDITED. EDITED.
C.