Continue to Site

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
Full Member level 4
Joined
Nov 19, 2003
Messages
208
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
Lahore Pakistan
Activity points
1,763
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
 

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.
 

ok sir. but actually my concern is to calculate trigonometric values and want the result in decimal. like
the value of cos45.
 

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.
 

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) ) ;
 

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();
}
}
 

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.
 

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)
 

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.
 

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
 

Did you try the code recommended at the post #5 ?
I'm assuming you'll search for int2bcd() functions on the Web.
 

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

Back
Top