PC Review


Reply
Thread Tools Rate Thread

Calculation not working properly

 
 
dondigitech
Guest
Posts: n/a
 
      21st Oct 2008
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;
}
 
Reply With Quote
 
 
 
 
Arnie
Guest
Posts: n/a
 
      21st Oct 2008
> //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


 
Reply With Quote
 
Ben Voigt [C++ MVP]
Guest
Posts: n/a
 
      21st Oct 2008
Arnie wrote:
>> //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


So take out the parentheses if you want to round to integer, or use 360.0 if
you want fractional results.

>
> - Arnie



 
Reply With Quote
 
Arthur Parker
Guest
Posts: n/a
 
      21st Oct 2008


"dondigitech" wrote:

> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is this working properly? Dominick Windows Vista Networking 2 12th Sep 2009 02:48 PM
CTRL-F (Find) quit working after 6-months of working properly =?Utf-8?B?YmNyZWVu?= Microsoft Access Form Coding 0 31st May 2006 08:55 PM
XP NOT WORKING PROPERLY NO COLOUR NO SOUND NO DEVICES WORKING....M =?Utf-8?B?RG9v?= Windows XP General 1 5th Jan 2005 01:23 AM
Calculation Order on a Form and Code Not Running Properly =?Utf-8?B?U0MgQ2hpZWZzRmFu?= Microsoft Access Form Coding 1 28th Sep 2004 01:43 PM
range.calculation with UDF not working when calculation is set to automatic Brian Murphy Microsoft Excel Programming 5 14th Oct 2003 07:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:00 AM.