PDA

View Full Version : how can i calculate?



enrique
- 20th March 2016, 15:07
hi everybody;
sory for my bad english...
3 days i am working but i could not....

how to calculate on pic basic pro this formula?
my pic 18f452

calculate as word
B2 as long
B3 as long
C2 as long
C3 as long
F2 as long
A2=35,110681 ' i know picbasic not support double
B2=35,110765
B3=33,960657
C3=33,961749
F2= 3,141593


calculate=ACOS( SİN(B2*F2/180)*SİN(C2*F2/180) + COS(B2*F2/180)*COS(C2*F2/180)*COS(C3*F2/180-B3*F2/180) ) * 6371000

if calculate = 99,7687 then true


can you help me?

Thanks

richard
- 20th March 2016, 23:50
SIN
returns the 8-bit sine of a value. The result is in two’s complement form (i.e. -
127 to 127). It uses a quarter-wave lookup table to find the result. SIN starts with a
value in binary radians, 0 to 255, as opposed to the usual 0 to 359 degrees.

I assume that the F2/180 term below is an attempt to convert B2 (35.110765 degrees ) to radians with increased resolution

SİN(B2*F2/180)
it won't work
for a start pbp sin function wants the input to be a Brad and the result will be a signed byte .
the best you can get with pbp is :-
all vars here are words
B0=351 ; 35.1 deg * 10 ie degrees x 10
B1=B0 */ 182 ; convert to brad ( B0 * 255)/360
B1=(B1+5)/10 ; scale back to degrees x 1 ( with rounding )
B2= sin(B1) ; sin 35.1 = 0.575 === pbp sin(25)=73
serout2 PORTA.0,84, ["brad 35.1 =",# B1,13,10 ] ;===== 25
serout2 PORTA.0,84, ["sin 35.1 =",# B2,13,10 ] ;==== 73
73 ====== 73/127 ===== 0.5748

its more likely you will get a better result from the forum if you explain what you are trying to achieve .
along with your attempted code

btw there is no acos function in pbp