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 CCS Technical Support

using the sin function in ccs c compiler for pic 16f877a

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







using the sin function in ccs c compiler for pic 16f877a
PostPosted: Sun Jul 24, 2005 11:39 pm     Reply with quote

hey everyone !!

i have a problem using the sin or cos function in my program. when ever i use the sin or cos function in my program, the while program stops working and nothing is displayed the way it should be. however if i use the exp() function in the same place .then no problem occurs. there is no issue with rom or ram. this problem is really baffling, if any one has any idea, please do reply

thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 25, 2005 12:08 am     Reply with quote

Here's a test program. Try it. I compiled it with PCH vs. 3.188
and it displayed the following correct result:

result = 1.000000

Code:
#include <18F452.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP   
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#include <math.h>

void main()
{
float result;

// Calculate the sine of 90 degrees.  The CCS sin() function
// requires the argument to be in radians.  90 degrees is
// PI/2 radians.

result = sin(PI/2);   

printf("result %f \n\r", result);

while(1);
}
ftsame
Guest







help with the sin function
PostPosted: Mon Jul 25, 2005 12:34 am     Reply with quote

thankyou for your reply.

the thing is that if i use just the sin function in a separate program , it works fine, but in my specific program it just does not work, i dont know why, not only that but the rest of the program which works fine before the inclusion of sin , also seizes to work. other maths functions like 'exp' work fine. there is this problem with sin function. is there any ram or rom issues with sin or something

this problem is really buggin me,
please help

ft
Ttelmah
Guest







PostPosted: Mon Jul 25, 2005 2:44 am     Reply with quote

Not particularly.
It uses a significant amount of RAM (about 40bytes in the worst case), and a lot of ROM (about 1700 bytes). Unless you are short of either, or are manually using memory addresses, this should not be a problem. Obvious things would be that sin also takes a significant amount of time, and if (for instance), there is some floating point arithmetic in an interrupt function, though the memory used by this should be protected, the possibility does arise of a problem here. Also if the processor was close to a watchdog 'timeout', the time needed for this, might cause a reset to occur.

Best Wishes
ftsame2
Guest







PostPosted: Mon Jul 25, 2005 3:34 am     Reply with quote

thanx again for your reply.

well i am not using a watch dog timer.nor am i using interrupts. what i am doing is using "calloc" and "free" commands to allocate and free memory for a pointer to the array. also there shouldnt really be any problem with the rom and ram as there is plenty left. also the "exp" command seems to work with out a problem in the same place where the sin command doesnt work.


plz help
Ttelmah
Guest







PostPosted: Mon Jul 25, 2005 9:38 am     Reply with quote

Exp, uses about the same amount of ROM (slightly more if I remember correctly), but a _lot_ less RAM (only about 10 bytes). I think it points to RAM memory management as the problem. Have you got '#device *=16' near the start of your program (the line after loading the processor include file)?. Otherwise you are only able to access the first bank of RAM, and could be getting problems with the memory management, functions (which assume this is set).

Best Wishes
ftsame3
Guest







PostPosted: Mon Jul 25, 2005 11:29 pm     Reply with quote

thank you for your advice Ttelmah, the sin is now working, but there is another problem now belive it or not. the thing is that the whole program is working only once, that is now i have to reset the microcontroller everytime to make it work. in my program i am dynamically allocating memory by using "ptr=calloc(62,1)". and then freeing up that memory at the end of 'while(1)' by doing "free(ptr)". can u plz help me again, so that the whole program keeps working over and over as it was before i used "device *=16" and "sin(x)".


thankyou for your useful guidance once again

ft
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