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.

FLOATING Point Math for PICMicro

Status
Not open for further replies.

isabelino

Member level 1
Joined
Jun 15, 2001
Messages
39
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
168
Please: I need routines about cosine and sine , on Picbasic or PICC compiler. I need precision , more than 32bit floating point, because I need to calculate seconds. I working on Pic18F452 micro
Thanks .
 

Regnum

Full Member level 5
Joined
Jun 17, 2004
Messages
262
Helped
18
Reputation
36
Reaction score
7
Trophy points
1,298
Location
Hurlingham
Activity points
2,168
All the functions I've seen are 32-bit... maybe you should code it by yourself
Make a search for CORDIC algorithms

Regards.
 

isabelino

Member level 1
Joined
Jun 15, 2001
Messages
39
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
168
Please: I need routines about cosine and sine , on Picbasic or PICC compiler. I need precision , more than 32bit floating point, because I need to calculate seconds. I working on Pic18F452 micro . Cordic is good, but not is a solution because I need to calculate seconds.
Thanks,please
 

SphinX

Advanced Member level 3
Joined
Jan 25, 2002
Messages
822
Helped
58
Reputation
116
Reaction score
29
Trophy points
1,308
Location
EGYPT
Activity points
7,045
Salam,

You can use these codes with PICC with some modification.

Code:
////////////////////////////// Trig Functions //////////////////////////////
#undef PI_DIV_BY_TWO
#define PI_DIV_BY_TWO	1.570796326794896
#undef TWOBYPI
#define TWOBYPI 			0.6366197724
/////////////////////////////////////////////////////////////////////////////

Code:
////////////////////////////////////////////////////////////////////////////
//	float cos(float x)
////////////////////////////////////////////////////////////////////////////
// Description : returns the cosine value of the angle x, which is in radian
// Date : 9/20/2001
//
float cos(float x)
{
	float y, t, t2 = 1.0;
	int quad, i;
	float frac;
	float p[4] = {
		-0.499999993585,
		 0.041666636258,
		-0.0013888361399,
		 0.00002476016134
	};

	if (x < 0) x = -x;                  // absolute value of input

	quad = (int)(x / PI_DIV_BY_TWO);    // quadrant
	frac = (x / PI_DIV_BY_TWO) - quad;  // fractional part of input
	quad = quad % 4;                    // quadrant (0 to 3)

	if (quad == 0 || quad == 2)
		t = frac * PI_DIV_BY_TWO;
	else if (quad == 1)
		t = (1-frac) * PI_DIV_BY_TWO;
	else // should be 3
		t = (frac-1) * PI_DIV_BY_TWO;

	y = 0.999999999781;
	t = t * t;
	for (i = 0; i <= 3; i++)
	{
		t2 = t2 * t;
		y = y + p[i] * t2;
	}

	if (quad == 2 || quad == 1)
		y = -y;  // correct sign

	return (y);
}

and

Code:
////////////////////////////////////////////////////////////////////////////
//	float sin(float x)
////////////////////////////////////////////////////////////////////////////
// Description : returns the sine value of the angle x, which is in radian
// Date : 9/20/2001
//
float sin(float x)
{
	return cos(x - PI_DIV_BY_TWO);
}


Bye
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top