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

Calculate value

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



Joined: 07 Feb 2012
Posts: 2

View user's profile Send private message

Calculate value
PostPosted: Tue Feb 07, 2012 9:14 am     Reply with quote

Hi you all,

I'm trying to do some math using the CCS compiler. I'm trying to do some modifications on a value readed by the ADC.


My code:
Code:



    float xfloat, yfloat;
    float DeltaX, DeltaY;


                        if (Xuit > PreRefValue){
          DeltaX = X - PreRefValue;
         Xfloat = PreRefValue + (DeltaY / 1,5);
         }
         else
         {
         DeltaX = PreRefValue - X;
         Xfloat = PreRefValue - (DeltaX / 1,5);
         }      
X = Xfloat;      




X is an 8bit integer.

The value in Xfloat is always a integer (don't know how to exactly call it in english), a whole number like 1,2,3 etc. What I want is that the number is 1,23 or 3,4.
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Tue Feb 07, 2012 9:25 am     Reply with quote

Try using '.' for the decimal separator.
You obviously come from one of the countries where ',' is used as the decimal separator. This is _not_ legal in C. In C, the ',' is a command separator, and will cause the lines to be interpreted incorrectly.
How are you actually testing the value of XFloat?. You don't show any output, except it being put back into the integer register 'X'. X can only store an integer, so the value at this point will be converted to integer. So are you looking at 'X', or Xfloat?.

Best Wishes
MdeVries



Joined: 07 Feb 2012
Posts: 2

View user's profile Send private message

PostPosted: Tue Feb 07, 2012 9:43 am     Reply with quote

Fantastic, Thank you! How simple can it be!
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