A follow up to the above to say that the
printf w format is very buggy, at least in the latest CCS PCD compiler for the dsPIC I'm using.
I've just used printf w to do a debug output for a scaled float-in-an-integer (I don't usually use w) and it was giving me odd characters. After some testing to make sure I wasn't doing anything wrong, I ended up with the following simple test code:
printf("%u %5.3w\r\n",t,t);
where t is an unsigned int and the above line was in a loop reading out measurements. This was the output:
11166 11.1@0
18544 18.5;0
14401 14.400
18548 18.5<0
20694 20.6G0
23665 23.6@0
27208 27.220
28961 28.9?0
As you can see, it's rubbish. Yet another bug in CCS - can't those people write a working compiler??? I've found a few comments searching the web about pcd being buggy for printf w, so it's not just me.
It works if you stick to one decimal place, at two decimal places it gets the last number wrong, and at three or more it's like the above output.
Note that the w format does seem to accept and work with a 32 bit unsigned integer as well as a standard int, but with the same buggy behaviour as above in the decimal places.