Hi all,
I think i have a problem with a variable type, but I can't find the trick ! >:(
I have a basic multiplication to do, but the result is not the right one...
here are the variables that I declare :
const uint8_t XstepsNbr = 200 ;
const uint8_t YstepsNbr = 200 ;
float coilWidth = 6 ;
float wireDia = 0.25 ;
uint16_t totalTurnsNbr = 100 ;
...
...
// calculated constants
const float Xpitch = XthreadedRodPitch / XstepsNbr ;
float XwireStepsNbr ;
float XYratio ;
float YturnsPerLayer ;
uint16_t XstepsPerLayer ;
uint16_t YstepsPerLayer ;
float totalLayerNumber ;
uint32_t YtotalSteps ;
Here are the formula for computing these variables (and a bunch of serial.print to debug my problem...):
void updateCoilData (){
XwireStepsNbr = wireDia / Xpitch ;
XYratio = XwireStepsNbr / YstepsNbr ;
YturnsPerLayer = coilWidth / wireDia ;
XstepsPerLayer = XwireStepsNbr * YturnsPerLayer ;
YstepsPerLayer = YstepsNbr * YturnsPerLayer ;
totalLayerNumber = totalTurnsNbr / YturnsPerLayer ;
YtotalSteps = YstepsPerLayer * totalLayerNumber ;
//YtotalSteps = YstepsNbr * totalTurnsNbr ;
Xcount = 0 ;
XtotalCount = 0 ;
Xdirection = HIGH ; // ====> DIRECTION !!!
YstepsCount = 0 ; // Count the number of Y steps done.
Ydirection = LOW ; // ====> DIRECTION !!!
Serial.print("XwireStepsNbr : ");
Serial.println(XwireStepsNbr,4);
Serial.print("XYratio : ");
Serial.println(XYratio,4);
Serial.print("YturnsPerLayer : ");
Serial.println(YturnsPerLayer,4);
Serial.print("XstepsPerLayer : ");
Serial.println(XstepsPerLayer,4);
Serial.print("YstepsPerLayer : ");
Serial.println(YstepsPerLayer,4);
Serial.print("totalLayerNumber : ");
Serial.println(totalLayerNumber,4);
Serial.print("YtotalSteps : ");
Serial.println(YtotalSteps,4);
}
And here is the result of this computing :
XwireStepsNbr : 62.5001 Ok :-\
XYratio : 0.3125 Ok :-\
YturnsPerLayer : 24.0000 Ok :-\
XstepsPerLayer : 113130 but... :o WTF :o How 62.5001 * 24.0000 can be equal to 113130 !? This must be 1500
YstepsPerLayer : 1022333 NO ! This must be 4800 !!!
totalLayerNumber : 4.1667 Ok
YtotalSteps : 10320123 NO ! This must be 20000 !!!
I suppose that it is a question of variable type but I don't understand this stuff ...
Thanks for your help ![]()