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.

CCS trigonometric calculation

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
when i put the value 0x7543 in an "int16", in RAM that is shown as it is. But
when i put 0x7543 in float, it gives an other 32 bit value in RAM which is "866A8D"

what does it mean?
an i want to calculate trigonometry like
cos45*sin90... etc. (in degrees)
how can i do it ?
urgent help is needed
 

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 i put 0x7543 in float, it gives an other 32 bit value in RAM which is "866A8D"

When programming in C you don't have to concern on the actual formatting of numbers stored in memory, just write the formula and get the result.
 

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
ok sir. but actually my concern is to calculate trigonometric values and want the result in decimal. like
the value of cos45.
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,119
Helped
14,379
Reputation
29,022
Reaction score
13,130
Trophy points
1,393
Location
Bochum, Germany
Activity points
283,155
Please try to ask clear questions. CCS is ambiguous, can mean at least

Code composer studio (an IDE and C compiler for TI processors)
Custom Computer Services (CCS C PIC compiler)

You also don't say where you see "an other 32 bit value in RAM". Is it in MPLab debugger? How do you "put 0x7543 in float"? Show actual code.

C trigonometric functions are using radian units for angles. Can be easily converter to degree 180° = pi in radian.
 

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
You perhaps need to search for some int2bcd function, not forgetting to first cast the result to int, like that:

Code:
int2bcd ( (int)cos(x) ) ;

You only have to be aware of the fact that normally the trigonometric functions are performed by the compiler in radian, so that the ultimate formula would be:

Code:
int2bcd ( (int)cos(x*PI/180) ) ;
 

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
Code:
///////////////////////////////////////////////////

#include <16f887.h>

#use		delay(clock=4000000)

#fuses	BROWNOUT, HS, NOWDT
#fuses	NODEBUG, NOLVP, PROTECT

 float  reg1;



void cal (void)
{
reg1 = (3.14/180);
}


void main()
{
reg1 = 0x7543;

while(1)
{
cal();
}
}
 

BradtheRad

Super Moderator
Staff member
Joined
Apr 1, 2011
Messages
14,227
Helped
2,814
Reputation
5,636
Reaction score
2,754
Trophy points
1,393
Location
Minneapolis, Minnesota, USA
Activity points
106,136
It is common for computer routines to do trig functions in radians, not degrees. If we start with degrees then multiply by Pi/180, to get radians.
 

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
in above code, i may get the right result but how can i get the result in decimal in degrees?
means simply please tell any simple code to covert bcd to decimal.
(0xff to 255)
 

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,854
Helped
1,815
Reputation
3,640
Reaction score
1,780
Trophy points
1,393
Location
USA
Activity points
59,344
means simply please tell any simple code to covert bcd to decimal.
(0xff to 255)

0xff nor 255 are BCD (Binary Coded Decimal). The first 0xff is an 8-bit binary number displayed in HEX the second 255 is a decimal number.

A BCD value for 255 displayed in hex notation is 0x255, where each nibble is coded as a decimal number.
 

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
ok
now next problem is how to convert bcd to decimal?
can anybody send code for conversion?
(0xffff to 65535)

- - - Updated - - -

or hex to decimal
 

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
Did you try the code recommended at the post #5 ?
I'm assuming you'll search for int2bcd() functions on the Web.
 

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
yes i am looking for int2bcd() sir.
i tried the code you sent but i am not expert in C so can you please send complete code?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top