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

Printf not printing floating point numbers correctly.
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 29, 2011 5:15 pm     Reply with quote

Yes, I built it and saw the problem. But it's too hard for me
to scan it easily and pick out where the problem is.
brock



Joined: 29 Jun 2011
Posts: 8

View user's profile Send private message

PRINTF NOT PRINTING FLOATING POINT NUMBERS CORRECTLY
PostPosted: Wed Jun 29, 2011 9:23 pm     Reply with quote

Thanks for your help anyway!
CCS newby



Joined: 27 May 2011
Posts: 5

View user's profile Send private message

PostPosted: Thu Jun 30, 2011 2:01 am     Reply with quote

I was using a PIC16F886, compiler version PCM V4.109.
brock



Joined: 29 Jun 2011
Posts: 8

View user's profile Send private message

PRINTF NOT PRINTING FLOATING POINT NUMBERS CORRECTLY
PostPosted: Thu Jun 30, 2011 7:29 am     Reply with quote

I found this thread interesting:
http://pic-c.ccsinfo.com/forum/viewtopic.php?t=6334&view=previous

Perhaps when the additional printf is added, the compiler recognises the variables as floats?

Also, I think I'll check my optimisation settings to see if that has an effect.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 30, 2011 2:50 pm     Reply with quote

To CCS newby,
I made a test program according to your description and compiled it
with vs. 4.109 and ran it in MPLAB simulator. It works for me.
It displays this in the Output window:
Quote:

tempf= 1.23


Can you modify this program so that it fails ? If possible, keep the
program short. Maybe the problem only occurs if you have a lot of code,
but try to keep it short. If the program is short, it's easier for me to find
the problem.

Here's the test program that works:
Code:

#include <16F886.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

void my_func(void)
{
float tempf = 1.234;

printf("tempf= %f",tempf);
}

//======================================
void main()
{

my_func();

while(1);
}
CCS newby



Joined: 27 May 2011
Posts: 5

View user's profile Send private message

PostPosted: Fri Jul 01, 2011 1:30 am     Reply with quote

Hi PCM Programmer,
I will try to "break" your program. Please bare with me though, I am very busy at work at the moment so I won't be able to do this straight away.
brock



Joined: 29 Jun 2011
Posts: 8

View user's profile Send private message

PRINTF NOT PRINTING FLOATING POINT NUMBERS CORRECTLY
PostPosted: Fri Jul 08, 2011 10:32 am     Reply with quote

Hey PCM:

I took some time to reduce the code size to make the issue simpler to find. Comments describe how to make it work or fail:

Code:

 /**********************************************************************
 *
 *  Name:  Why can't I print a float OR Man, there's a bug in this compiler
 * 
 **********************************************************************/
#include <16F887.h>
#include <stdio.h>

#FUSES INTRC,NOWDT,PUT,MCLR,NOPROTECT,NOCPD,BROWNOUT,NOIESO,NOFCMEN,NOLVP

// Setup Clock
#use delay(internal=8M)
// Setup the Serial Port to (9600,8,N,1)
#use rs232(baud=9600,BITS=8,PARITY=N,STOP=1,xmit=PIN_C6,rcv=PIN_C7)

float adc_sample(int target_pot)                                    // Function isn't called    
{                                                            //
   return;                                                      //
//   printf(" ADCS: %4.3f\r",2.2222);                                 // (1) Uncomment this printf to make the main() printf work
}                                                            //

void set_pot_to_voltage(int pot_address, float target_voltage)               // Function isn't called
{                                                            //
   return;                                                      //
   printf("Note: In > Actual, Steps:  0x%04lx    %Ld\r",0x4321,0x4321);        // (2) Comment this printf and it works
}                                                            //
void main()
{
   printf("\r\rTry to print a float...*\rTESTFLOAT:   %4.3f\r",1.1111);      // (3) Remove * and it works
   while (1);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 08, 2011 11:51 am     Reply with quote

Doing some version testing with the PCM compiler gave these results.
It fails starting with vs. 4.100:

4.014 works
4.093 works
4.099 works
4.100 Fails
4.105 Fails
4.110 Fails
4.111 Fails
4.121 Fails
4.122 Fails

I know that CCS considered vs. 4.100 to be a major change:
http://www.ccsinfo.com/newsdesk_info.php?newsdesk_id=120

I also tested it with the PCH compiler with vs. 4.122 and an 18F452 and
it works. So the problem may be confined to the PCM compiler.
The next step is to compile test programs (smaller, if possible) for
versions 4.099 and 4.100 and look at the differences in the .LST file.
I'll try to do that later today.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 08, 2011 4:30 pm     Reply with quote

I think there is a bug in the CCS printf library code starting with vs. 4.100
(at least for the PCM compiler) and I've been trying to come up with
some kind of work-around. But it's difficult to know for sure if a work-
around will work in every case.
freeman



Joined: 18 Jul 2011
Posts: 1

View user's profile Send private message

Possible Bug
PostPosted: Mon Jul 18, 2011 8:53 am     Reply with quote

Try to initialize the variables float to 1 (not zero), or other value, I have same problem and with this it is solved.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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