Calculation not working properly

  • Thread starter Thread starter dondigitech
  • Start date Start date
D

dondigitech

I having problems getting this function to return the correct value.
Basically I have a curveDataCalc method that loops as it should, but just
doesn't seem to be working right. I've stepped through the function and the
variables are being passed through correctly its just the clocksPerQREV and
calcAngleTime are never being calculated and are always zero. This causes the
other values to incorrectly calculated, ultimated giving me the wrong
advanceAngle values. Maybe I am missing a conditional statement, but I can't
seem to figure it out right now. Any suggestions would be helpful.


// CALCULATE ADVANCE ANGLE USING curveDataCalc METHOD
double[] advAngle = new double[64];
for (int p = 0; p < 64; p++)
{
advAngle[p] = curveDataCalc(rpmArray[p], multiplier[p],
offset[p]);
}
}
#endregion


public double curveDataCalc(int rpmArray, int multiplier, int offset)
{
//CONSTANTS
int calcAngle = 90;
int leadAngle = 72;
double clockPeriod = 0.000004; //timer clock
period = 4uS
int clocksPerMin = 15000000; //# of clock cycles
per minute

//CALCULATED VALUES
double clocksPerQREV = clocksPerMin*(calcAngle/360);
double calcAngleTime = (clocksPerQREV/(rpmArray*100));
double delayTime = ((calcAngleTime*multiplier)/256) - offset;
double delayAngle = 6*(delayTime*clockPeriod*(rpmArray*100));
double advanceAngle = leadAngle - delayAngle;
return advanceAngle;
}
 
//CONSTANTS
int calcAngle = 90;
//CALCULATED VALUES
double clocksPerQREV = clocksPerMin*(calcAngle/360);

Well, for a start, calcAngle which is 90, divided by 360 in integer
division, will always be zero

- Arnie
 
Arnie said:
Well, for a start, calcAngle which is 90, divided by 360 in integer
division, will always be zero

So take out the parentheses if you want to round to integer, or use 360.0 if
you want fractional results.
 
dondigitech said:
I having problems getting this function to return the correct value.
Basically I have a curveDataCalc method that loops as it should, but just
doesn't seem to be working right. I've stepped through the function and the
variables are being passed through correctly its just the clocksPerQREV and
calcAngleTime are never being calculated and are always zero. This causes the
other values to incorrectly calculated, ultimated giving me the wrong
advanceAngle values. <snip>

Just make all the variables involved in the calculation double, instead of
int.
 
Back
Top