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

PCD sprintf

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



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

PCD sprintf
PostPosted: Thu Oct 07, 2010 7:10 pm     Reply with quote

Hi,
I am having problem with sprintf and PCD compiler on a PIC24, other users
have had the same problem. I am trying to display a temperature values from a DS18B20 on a LCD. I would like to be able to display the value without losing precision. How can I transform a float (ex:25.37) using integer math or functions? Is there a good small efficient routine to replace sprintf command. Thanks!

AC
----------------------------------
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Oct 07, 2010 11:36 pm     Reply with quote

Unfortunately you didn't tell about the problem.
Chibouraska



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

PostPosted: Fri Oct 08, 2010 5:24 am     Reply with quote

Yes you are right, the problem with sprintf is that when it is included in the
code the MCU restarts all the time. So for now till it is fix in the compiler i would like to find a way to transform a float to a string without loosing precision on my temperature reading. Thanks your help is well appreciated.

AC
--------
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Oct 08, 2010 7:12 am     Reply with quote

I give up, I was going to post a load of crap because that is basically what you have given us.

Some simple questions,
What precision do you want ?
What are your parameters for sprintf ?
What are the types of vars you are using ?
How are you assigning the float ?

BASICALLY, POST THE DAMN CODE, including fuses and compiler version.

This post has wasted too much of my time already with me trying to post a reasonable response without getting totally wound up by such a stupid question as this.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Oct 08, 2010 8:01 am     Reply with quote

In most cases, a stack overflow is the reason for restart with PCD float applications, it can be easily avoided by increasing the stack assignment. Please review the respective CCS forum contributions. There's of course a certain chance to trigger float related PCD bugs.
Chibouraska



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

PostPosted: Fri Oct 08, 2010 8:04 am     Reply with quote

Wayne don't get nervous, the quest was simple, how to convert a float to string (ftoa), because sprintf doesn't work with floats (and prinf too) on the PCD compiler whatever version. It's easy to get all hyped up when we are not face to face. My code, the version of the compiler whatever.. doesn't change nothing, if i needed to post code i would of done it, in this case it was clear the question. Anyway i found a work around, i converted the fractional part of the float temperature reading to a integer and used integer in the sprintf function call.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Oct 08, 2010 8:22 am     Reply with quote

Nervous ? lol.
Glad you fixed it by multiplying your float by an unknown number to get the precision you require.
I assume this is what you did.

I am sure this post will help many others who run in to a similar problem as well Exclamation

And if they do fix it in a version of PCD later on (assuming they haven't done so already) then this post will surely help guide these people in the right direction for a fix Razz Razz Razz

I thought you said sprintf didn't work, you must have meant for floats only. doh silly me.

And if you know what you need to post in order to get this problem fixed then surely you know enough to fix it yourself, oh, you did. Glad to have not helped.

Have fun.
Chibouraska



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

PostPosted: Fri Oct 08, 2010 8:37 am     Reply with quote

Thanks FvM, I search the forum on increasing stack but can't find where to go
can you tell me where, thx.

AC
-------
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Oct 08, 2010 1:53 pm     Reply with quote

Quote:
search the forum on increasing stack but can't find where to go

Of course, this information can be expected from the compiler manual in the first place. The problem is to indentify, that there's a stack problem with float operations. After you know about, it's very easy.
Simply try:
Code:
#build (stack=256)

Some explanation can be found here:
http://www.ccsinfo.com/forum/viewtopic.php?t=40083
Chibouraska



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

PostPosted: Fri Oct 08, 2010 6:56 pm     Reply with quote

Yes you are right i am not sure it's a stack problem, because i am not doing anything complicated that need a lot of stack space, but your feedback is well appreciated i will try and post back my findings. Best regards

AC
-------
Chibouraska



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

PostPosted: Fri Oct 08, 2010 7:08 pm     Reply with quote

OK great increasing stack did solve the problem, i guess because i have a lot of interrupts it takes up a bunch of stack space. Thanks again!
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Oct 09, 2010 2:39 am     Reply with quote

The default PCD stack assignment is 128 bytes respectively 64 words. A standard ISR call consumes already 16 words of stack space.

The stack usage report in the PCD list file can be read as follows:
Quote:
Stack: 29 worst case (21 in main + 8 for interrupts)

Calculate 2 words for each stack level in the report (29*2=58) and add 14 words for interrupt processing if interrupt nesting is disabled (default setting), otherwise a lot more. Add a few words for additional stack usage in regular inline code.

58 + 14 + x = 72+x words = 144 + 2*x bytes

In other words, the above reported stack usage necessarily causes a stack overflow with default stack=128. Unfortunately, a similar calculation can't be found in a PCD manual, as far as I'm aware of.
Chibouraska



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

PostPosted: Sat Oct 09, 2010 7:42 am     Reply with quote

Great your info is well appreciated. That's why the PIC was resetting, anyway i'm starting to program a commercial produit with the CCS PCD
compiler it's very easy to use, but ROM seams to be filling up fast ? I still love to use CCS product but i need a lot of learning time. I tried not to use floats at all, you think that's a better way to go, i guess it all depends on the amount of calculations, in my case not so much so i didn't see a big difference in mem usage. The _fixed(x) directive is very interresting as a replacement to floating point but i am not sure it's working properly on the PCD compiler, i tried and it gave me stange result, i will try it on a PIC18 device to see the difference.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Oct 09, 2010 1:26 pm     Reply with quote

My general opinion regarding float is this: As we are using a high level language instead of assembler, we should also be able to use float arithmetic where the problem suggest it.
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