|
|
View previous topic :: View next topic |
Author |
Message |
CoverUp
Joined: 04 May 2010 Posts: 7
|
[Help] Printf strange behaviour: don't plot zero value |
Posted: Fri Aug 02, 2013 9:29 am |
|
|
Hi everyone
I got the following issue, i will really appreciate any help of you guys.
System info:
CCS 4.1
MPLAB 8.88
dSPIC 33FJ256GP506 @60Mhz
All the code it's fully functional, but i got an issue with printf.
Code: |
//...Fuses, clock, use rs232, etc. (all set)
signed int32 temp;
void main(){
//..init dspic, port,etc. (all set)
while(1){
temp=100;
printf("%Ld,",temp);
temp=50;
printf("%Ld,",temp);
temp=0;
printf("%Ld,",temp);
temp=10;
printf("%Ld\r,",temp);
delay_ms(1000);
}//end while
} //end main
|
Expected output:
Code: |
100,50,0,10
100,50,0,10
100,50,0,10
100,50,0,10
...etc.
|
The output that i get
Code: |
100,50,,10
100,50,,10
100,50,,10
100,50,,10
...etc.
|
So the problem is: I can't plot a zero value
temp must be signed int32, because it will be updated in a function, with the real value (this function is disabled for now)
I simplify the code to show my point that printf don't plot zero values
Any help will be appreciated
NOTE: All others variable types work fine, this issue is only with signed int32 variable type.
ie:
Code: |
printf("%4.0f,",(float) temp);
|
Works fine, and is a workaround to this. but i want to understand why this fail using signed int32. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Aug 02, 2013 4:45 pm |
|
|
Quote: | temp=0;
printf("%Ld,",temp);
|
No one else has replied so I'll help somewhat. I don't have the PCD
compiler. So I tested your code with an 18F4620 with versions 4.141
and 5.010 in MPLAB simulator and it works OK. So it may be a bug with
PCD with your version.
Also, this is not a version. Versions have four digits. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Sat Aug 03, 2013 12:54 am |
|
|
I'd suspect the version might be quite early. PCD, had some printf problems in the past with 32bit integers, around the low 4.100's.
It gives the correct answer in 4.107, but is faulty in 4.099.
It will though work correctly, if you specify a field width. Just use:
printf("%1Ld,",temp);
Basically with a zero value, it displays nothing, rather than the zero. Specifying a single character minimum field width forces it to output one character in this situation, and the zero is then displayed.
Best Wishes |
|
|
CoverUp
Joined: 04 May 2010 Posts: 7
|
|
Posted: Wed Aug 07, 2013 9:15 am |
|
|
Our version is CCS 4.104
i tried with
Code: |
printf("%1Ld,",temp);
|
The output is
Code: |
100,50, ,10
100,50, ,10
100,50, ,10
100,50, ,10
...etc.
|
So "nothing" is replaced by "space". So you guys are right, it's a PCD bug and we need to update. |
|
|
|
|
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
|