|
|
View previous topic :: View next topic |
Author |
Message |
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
fprint formating in 4.132 |
Posted: Fri Apr 20, 2012 1:34 pm |
|
|
Hi all,
Just forced back to updating an old project and returning to PICs and the horrible world of MPLAB after 5 years of wonderful trouble free ARM7/9 development and I immediately have a problem with fprintf in the latest compiler release !
My old PCH compiler (v3.236) had no issues with the following statement:
Code: | fprintf(PC, "T,%lu,%3.2f,%3.2f,*\r\n", elapsedtime, temp1, ((elapsedtime == 0) ? 0.0f : deltatemp1)); |
where: PC is an rs232 stream, elapsedtime is an int16, temp1 is a float and deltatemp1 is a float.
the output looks like :
If i change the %3.2f to %f i get:
Code: | T,3,21.500000,-0.500000,* |
All as expected :-)
However ..... using 4.130 and 4.132, it fails compilation with:
Code: | *** Error 114 "main.c" Line 745(123,124): Printf format type is invalid :: |
... and the only options that it will accept for the float is %f, which produces fairly random values (which are all truncated to 2 decimal places). ie.
Does anyone else have issues with fprintf of is this just CCS doing the same-ole same-ole fix one issue and break something else ???
If anyone can tell me what the latest STABLE version is, I would appreciate that.
I'm currently using MPLAB 8.84 and CCS PCH (3.236, 4.130 or 4.132) and PIC18F4620. I've tried MPLAB X (nice editor), but the CCS integration and lack of builtin type/function syntax checking is doing my head in !!
Cheers,
Simon.
P.S. I should have never gone back to PIC's. _________________ Regards,
Simon. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 20, 2012 2:05 pm |
|
|
I was able to make it compile by casting the conditional expression to a float:
Quote: | fprintf(PC, "T,%lu,%3.2f,%3.2f,*\r\n", elapsedtime, temp1, (float)((elapsedtime == 0) ? 0.0f : deltatemp1)); |
Test program:
Code: |
#include <18F4620.H>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS, stream=PC)
//======================================
void main(void)
{
int16 elapsedtime;
float temp1;
float deltatemp1;
fprintf(PC, "T,%lu,%3.2f,%3.2f,*\r\n", elapsedtime, temp1, (float)((elapsedtime == 0) ? 0.0f : deltatemp1));
while(1);
}
|
|
|
|
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Fri Apr 20, 2012 2:12 pm |
|
|
Hi PCM,
Tried that! the compiler is happy, but output is still random :
Code: | v3.236 Output with no cast
---------------
T,367,21.75,0.00,*
T,368,21.50,-0.50,*
T,369,21.50,-0.50,*
T,370,21.25,-1.50,*
T,371,22.00,0.00,*
T,372,21.50,-0.50,*
T,373,22.25,1.00,*
T,374,21.75,-0.50,*
T,375,21.75,-1.00,*
T,376,22.25,1.00,*
T,377,21.25,0.00,*
T,378,22.00,0.50,*
T,379,22.00,0.50,*
T,380,22.00,0.50,*
T,381,22.00,0.50,*
v4.130 Output with float cast
---------------
T,0,22.00,0.00,*
T,1,21.75,0.00,*
T,2,22.00,0.00,*
T,3,21.75,0.00,*
T,4,22.00,0.00,*
T,5,21.75,0.00,*
T,6,21.75,0.00,*
T,7,21.75,255.00,*
T,8,22.00,0.00,*
T,9,21.75,0.00,*
T,10,21.75,0.00,*
T,11,21.75,255.00,*
T,12,22.00,0.00,*
T,13,22.00,0.00,*
T,14,21.75,255.00,*
T,15,21.75,0.00,*
T,16,22.00,0.00,*
T,17,22.25,1.00,*
T,18,21.75,255.00,*
T,19,22.00,0.00,* |
Something in fprintf is not right !!! _________________ Regards,
Simon. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 20, 2012 2:17 pm |
|
|
Post a test program (similar to the one I posted, i.e. short) that gives the bad output. |
|
|
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Fri Apr 20, 2012 2:29 pm |
|
|
Hi PCM,
I'm trying to repeat it as a standalone app ... with no success (at getting it to fail!!).
So, i'm checking the effects if interrupts in my application and if the variable deltatemp1 is getting trampled on. Also looking at the differences in the generated code to see what is different between the two compiler versions of that line ....
... I may be some time !!!! but I will post my findings.
Thanks anyway. _________________ Regards,
Simon. |
|
|
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Fri Apr 20, 2012 2:54 pm |
|
|
I have not found the exact cause yet, but I can say that moving the compare from the 3rd param out of the fprintf, it works ok !
Code: | float t;
t = (float)((elapsedtime == 0) ? 0.0f : deltatemp1);
fprintf(PC, "T,%lu,%3.2f,%3.2f,*\r\n", elapsedtime, temp1, t); |
Edit : Also don't need the float cast in this workaround.
... so I suspect its a bug in fprintf. I need to be able to reproduce it in a simple demo before I can fire it off to support. _________________ Regards,
Simon. |
|
|
|
|
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
|