473,326 Members | 2,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Calculation not working properly

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;
}
Oct 21 '08 #1
5 1522
//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
Oct 21 '08 #2
On Tue, 21 Oct 2008 10:28:01 -0700, dondigitech
<do*********@discussions.microsoft.comwrote:
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. [...]
Try changing "calcAngle/360" to "calcAngle/360.0". Make sure you don't
have any other similar examples of an integer division where you really
wanted a floating point division (if you find any, fix them so that they
do floating point division by making sure at least one operand is floating
point).
Oct 21 '08 #3
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

Oct 21 '08 #4


"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.
Oct 21 '08 #5
MC
I think what's getting you is that when you put the operator / between two integers, it does integer division; thus (to take a simple example) 3/4 comes out 0 rather than 0.75. For floating-point division, at least one of the arguments needs to be a floating-point type.
Oct 22 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: DebbieG | last post by:
I have no idea how to start with this one. I have a subform where records could look similar to: Infraction Date Points 01/01/2000 3 06/01/2002 1 Somehow, I've got to...
7
by: Vinoth | last post by:
I'm working in an ARM (ARM9) system which does not have Floating point co-processor or Floating point libraries. But it does support long long int (64 bits). Can you provide some link that would...
9
by: Klaus Bonadt | last post by:
I have found strange behaviour in casting floating point values in C++ 6.0 to int: If I enter in the watch window while debugging in version 6.0 the following term: (1.4 - 1.0) * 10.0 the...
4
by: qbproger | last post by:
I'm developing a plugin for some software. The previous version of the software didn't require a start in directory to be set. This allowed me to leave the working directory to the default in the...
10
by: roygon | last post by:
Hello, I have a C# application that runs a relatively complex simulation which, on a typical computer, could take up to 10 seconds. I am now trying to port this application over to ASP.NET so...
33
by: ram.ragu | last post by:
hi i have problem to calculate idle time of cpu and if idle time is more then i have to shut down the system. can anyone tell me the idea to so that please
10
by: 60325 | last post by:
This is the page where I collect the data in drop-down boxes with values of 1-10 and send it to a submitted page to do calculations. Example: Employee1 TeamScore(1-10) Employee2 ...
28
by: beach.dk | last post by:
Hi, I'm trying to implement a simple hash algorith called rs_hash in javascript, but I cannot get a correct result. In c the code looks like this:
30
by: Barry L. Bond | last post by:
Greetings! I just got a new Peet Brothers Ultimeter 2100 Weather Station. This new one has a way to display the heat index, if you press the "dew point" key twice. Being aware of all the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.