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

floating point printf with suppressed decimal point

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

floating point printf with suppressed decimal point
PostPosted: Mon Jun 21, 2010 2:30 pm     Reply with quote

In an instrumentation project that is already working as expected,
I am reading a number of channels with an ADS8371 A/D, with pic 18f4620 @ 14.7456mhz oscillator and baud rate of 460800.

The system generates a LOT of pipelined data (doing calcs and sending previous reading while new data settles for next reading)
that is corrected and is comma delimited in blocks of 8 readings/output string:
now as (typically)

123.45,12.34,1234.56,12345.66 ......<cr>
and terminate with a naked carriage return

Usually data is in the range of 9999 or less but sometimes there is a value over 10000 - we ALWAYS Output only 2 decimal points resolution.

newfloat holds the floating point result of the
present adc 16 bit ( unsigned int16) sample,
multiplied by a FLOAT correction adjustment factor, generally in the range of about .975 to 1.25

The formatting is done with printf (%.2g,",newfloat);

I've been asked to compress the output data and try to squeeze out more data points per unit time. I know it is a SMALL gain but

the question is:

Does anyone know of any efficient easy EASY way to suppress the
printf() output of the DECIMAL point ??
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon Jun 21, 2010 2:36 pm     Reply with quote

The obvious way, is just to multiply the value by 100, and put it into an int32.
Also has the advantage that the output maths will be faster to...

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Jun 21, 2010 2:39 pm     Reply with quote

Why not multiply by 100?
Instead of a correction factor 0.975 to 1.25 you use 97.5 to 125

Or multiply by 1000 and you can get rid of all the slow float arithmetic at all, only using integers for the calculations. In the presentation of the data you insert the dot at the right location (this technique is called 'fixed point floating point').
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Jun 21, 2010 3:07 pm     Reply with quote

thanks for the jolt in the
new direction
much appreciated
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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