![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
MdeVries
Joined: 07 Feb 2012 Posts: 2
|
Calculate value |
Posted: Tue Feb 07, 2012 9:14 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19387
|
|
Posted: Tue Feb 07, 2012 9:25 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
MdeVries
Joined: 07 Feb 2012 Posts: 2
|
|
Posted: Tue Feb 07, 2012 9:43 am |
|
|
Fantastic, Thank you! How simple can it be! |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|