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 support@ccsinfo.com

ADC decimal Digit problem

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



Joined: 24 Jul 2007
Posts: 7
Location: Jordan

View user's profile Send private message Yahoo Messenger MSN Messenger

ADC decimal Digit problem
PostPosted: Sun May 03, 2009 3:13 pm     Reply with quote

Hi all
I have a problem with adc
I want to display a float number consists of 3 decimal digits at least, i tried to use the following:


set_adc_channel( 0 )
delay_us(10);
x=read_adc();
y=x/100;
printf("X=%u Y=%1.3f \r\n",x,y);


But i still get 1.000 or 2.000 only without decimal digits
_________________
Eng. Haytham Shyouk
B.A. Electronics Engineering
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 03, 2009 3:52 pm     Reply with quote

Quote:

y=x/100;

i still get 1.000 or 2.000 only

You are doing integer math. If you divide one integer (x) by another
integer (100), the result is an integer.

If you want a floating point result, you must make one of the numbers
in the divison expression into a float. Example:
Quote:
y=x/100.0;


You didn't show any of your variable declarations. 'y' should be declared
as a 'float'. 'x' should be declared as an 'int16' if you are using the A/D
in 10-bit mode. Also, if 'x' is an 'int16', then you should use "%lu" to
display it in printf.
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