Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

trigonometric functions in mikro C pic compiler problem

Status
Not open for further replies.

Noman Yousaf

Full Member level 4
Joined
Nov 19, 2003
Messages
210
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
Lahore Pakistan
Activity points
1,774
hi
i want to perform some trigonometric functions in mikroC like get the value of sin90, cos30 etc.
i wrote this code but when i run it and watch RAM, values are not correct.
even when i do it with float, incorrect values occur.

please help


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
long val3;
 
void calculate (void)
{
val3=sin(90);
}
 
void main() 
{
 
while(1)
{
calculate();
}
}

 
Last edited by a moderator:

andre_luis

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,308
Helped
1,166
Reputation
2,351
Reaction score
1,152
Trophy points
1,403
Location
Brazil
Activity points
54,227
It is expected an argument in radians, not in degrees.
You must multiply it by a factor of ( 2*PI / 360 ).
 

Noman Yousaf

Full Member level 4
Joined
Nov 19, 2003
Messages
210
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
Lahore Pakistan
Activity points
1,774
It is expected an argument in radians, not in degrees.
You must multiply it by a factor of ( 2*PI / 360 ).

it shows in RAM is 8.5090 ok?
when it is multiplied to 2*pi/360 (0.01744), answer is 0.1483
where as its answer must be 0.707

- - - Updated - - -

can anyone tell the simplest way to get sin value in degrees?
what does mean by the following?
i got it from help

sin
Prototype

double sin(double f);

Description Function returns the sine of f in radians. The return value is from -1 to 1.

Example doub = sin(PI/2.); // doub = 1.000000



how can i use it for my purpose?
please help
 

andre_luis

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,308
Helped
1,166
Reputation
2,351
Reaction score
1,152
Trophy points
1,403
Location
Brazil
Activity points
54,227
when it is multiplied to 2*pi/360 (0.01744), answer is 0.1483
where as its answer must be 0.707

You're having some mistake:

  • 45*( 2*pi/360 ) = 0,785
  • sin ( 0,785 ) = 0,7068... [ operation in rads ]
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top