CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

compilation error

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
student
Guest







compilation error
PostPosted: Wed Jul 22, 2009 1:33 am     Reply with quote

The following code is compiled under Borland but in CCS 4.084 I get bulk of errors.
Any clue.
Main c file.
Code:

#include <dev.h>
#include <stdlib.h>
#include <cordic-32bit.h>

void main(void)
{
    float val,var,angle=150.0001;
       
        val=sin(angle);
        var=cos(angle);
      printf("sin %f cos %f \n ", val,var);
           
}


here is the cordic-32bit.h file.
Code:

//Cordic in 32 bit signed fixed point math
//Function is valid for arguments in range -pi/2 -- pi/2
//for values pi/2--pi: value = half_pi-(theta-half_pi) and similarly for values -pi---pi/2
//
// 1.0 = 1073741824
// 1/k = 0.6072529350088812561694
// pi = 3.1415926536897932384626
//Constants
#define cordic_1K 0x26DD3B6A
#define half_pi 0x6487ED51
#define MUL 1073741824.000000
#define CORDIC_NTAB 32
#define Pi 3.14159265358979323846
#define N 90
int cordic_ctab [] = {0x3243F6A8, 0x1DAC6705, 0x0FADBAFC, 0x07F56EA6, 0x03FEAB76, 0x01FFD55B, 0x00FFFAAA, 0x007FFF55, 0x003FFFEA, 0x001FFFFD, 0x000FFFFF, 0x0007FFFF, 0x0003FFFF, 0x0001FFFF, 0x0000FFFF, 0x00007FFF, 0x00003FFF, 0x00001FFF, 0x00000FFF, 0x000007FF, 0x000003FF, 0x000001FF, 0x000000FF, 0x0000007F, 0x0000003F, 0x0000001F, 0x0000000F, 0x00000008, 0x00000004, 0x00000002, 0x00000001, 0x00000000,};

float cordic(int theta, int *s, int *c, int n)
{
  int k, d, tx, ty, tz;
  int x=cordic_1K,y=0,z=theta;
  n = (n>CORDIC_NTAB) ? CORDIC_NTAB : n;
  for (k=0; k<n; ++k)
  {
    d = z>>31;
    //get sign. for other architectures, you might want to use the more portable version
    //d = z>=0 ? 0 : -1;
    tx = x - (((y>>k) ^ d) - d);
    ty = y + (((x>>k) ^ d) - d);
    tz = z - ((cordic_ctab[k] ^ d) - d);
    x = tx; y = ty; z = tz;
  } 
 *c = x; *s = y;
 return *s/MUL;
}
float cos(float angle)
{
 float res;
 int *s, *c;
 angle=N-angle;
 angle=angle*Pi/180;
 res=cordic((angle*MUL), &s ,&c,32);
 return res;
}
float sin(float angle)
{
 float res;
 int *s, *c;
 if (angle>90)
    angle=180-angle;
 angle=angle*Pi/180;
 res=cordic((angle*MUL), &s ,&c,32);
 return res;
}


dev.h file is device related config file i.e
Code:

#include <16F877A.h>
#device *=16
#device ICD=TRUE
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES                       
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7)

thnx...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 22, 2009 1:52 am     Reply with quote

There are Cordic functions for CCS in the Code Library forum:
http://www.ccsinfo.com/forum/viewtopic.php?t=27947
student
Guest







PostPosted: Wed Jul 22, 2009 1:57 am     Reply with quote

PCM programmer wrote:
There are Cordic functions for CCS in the Code Library forum:


I know but they have some problem with scaling.
What's wrong with the code posted.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 22, 2009 2:10 am     Reply with quote

The sizes of the basic datatypes are different in CCS, compared to
Borland. Also, they are unsigned by default. You need to edit the code
and make it be compatible with CCS. Look in the CCS manual, in the
Basic and Special Types section:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Ttelmah
Guest







PostPosted: Wed Jul 22, 2009 2:19 am     Reply with quote

Also, remember you are working in radians. 150.0001 radians, not degrees....

Best Wishes
student
Guest







data type sizes
PostPosted: Wed Jul 22, 2009 3:42 am     Reply with quote

PCM programmer wrote:
The sizes of the basic datatypes are different in CCS, compared to
Borland.


Mainly two data types are used in the above program. i.e float and int.
in ccs int32 is used which i have tried with but no luck.And float is same in standard c and ccs c.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Jul 22, 2009 8:51 am     Reply with quote

The compiler errors are easily understandable, apparently you didn't yet try to identify them individually.

The code expects case sensitive code processing, so you have to specify a #case at the entry.

Also int x=cordic_1K,y=0,z=theta; is C++ coding style, because theta is a variable. You have to separate the definition from the assignment.

As already said, int has to be changed to int32 in many places. When defining int to 32 bit globally, I got an out-of-RAM error, not that surprizing with PIC16. I doubt, if the code can compile at all.
student
Guest







compilation error
PostPosted: Thu Jul 23, 2009 3:47 am     Reply with quote

I separated the assignment from definition. It reduced the no. of errors.
But I was able to compile the code successfully not until renaming the variable n to a, strange ! Isnt it ?
I compiled it on 18f452 and it used almost 15% of RAM. But failed on 16f877A.
FvM u was of great help ! Thnx a lot .
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

Re: compilation error
PostPosted: Thu Jul 23, 2009 3:57 am     Reply with quote

student wrote:
I separated the assignment from definition.It reduced the no. of errors.
But I was able to compile the code successfully not until renaming the variable n to a , strange ! Isnt it ?
I compiled it on 18f452 and it used almost 15% of RAM.But failed on 16f877A.
FvM u was of great help ! Thnx a lot .


As FvM stated

#define N 90
float cordic(int theta, int *s, int *c, int n)

CCS is not case sensitive so you are reusing N (n) They are the same. So not strange at all really Very Happy

Probably Question
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 9:29 am     Reply with quote

I've always had the itch that case sensitivity was a bad idea.

If you think of N vs n or MyVar vs myvar... I always consider them the SAME to avoid confusion.

A different var/constant should have a different name to make sure that it doesn't get confused... AND THIS IS WHY.

:D

(Although I like to make constants ALL CAPS for my own edification and am happy when compiling blows up because I name a variable the same thing. Keeps me honest.)

Cheers,

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 10:59 am     Reply with quote

There are basic C style conventions that should be followed. The reason
is that then other people will find it easier to understand your code.

Indian Hill Style Guide, section 11, on page 13 says:
Quote:

#define constants should be in all CAPS.

Function, typedef, and variable names, as well as struct, union, and enum tag names should be in lower case.

http://www.chris-lott.org/resources/cstyle/indhill-cstyle.pdf

and
http://www.cs.uiowa.edu/~jones/syssoft/style.html#caps

There are many more C style documents on the net.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group