View previous topic :: View next topic |
Author |
Message |
Chibouraska
Joined: 11 May 2007 Posts: 57 Location: Montreal,Canada
|
PCD sprintf |
Posted: Thu Oct 07, 2010 7:10 pm |
|
|
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
|
|
Posted: Thu Oct 07, 2010 11:36 pm |
|
|
Unfortunately you didn't tell about the problem. |
|
|
Chibouraska
Joined: 11 May 2007 Posts: 57 Location: Montreal,Canada
|
|
Posted: Fri Oct 08, 2010 5:24 am |
|
|
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
|
|
Posted: Fri Oct 08, 2010 7:12 am |
|
|
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
|
|
Posted: Fri Oct 08, 2010 8:01 am |
|
|
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
|
|
Posted: Fri Oct 08, 2010 8:04 am |
|
|
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
|
|
Posted: Fri Oct 08, 2010 8:22 am |
|
|
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
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
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
|
|
Posted: Fri Oct 08, 2010 8:37 am |
|
|
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
|
|
Posted: Fri Oct 08, 2010 1:53 pm |
|
|
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:
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
|
|
Posted: Fri Oct 08, 2010 6:56 pm |
|
|
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
|
|
Posted: Fri Oct 08, 2010 7:08 pm |
|
|
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
|
|
Posted: Sat Oct 09, 2010 2:39 am |
|
|
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
|
|
Posted: Sat Oct 09, 2010 7:42 am |
|
|
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
|
|
Posted: Sat Oct 09, 2010 1:26 pm |
|
|
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. |
|
|
|