A long time since I was here the last time.. So please apologize if there is already a discussion about this in another thread, I have no time to read them all
(But some of them are realy interesting, release two workspace for example)
Back to topic. Currently I'm building a onboard computer (right word?) for my motorcycle that should fully integrate into the speedo. So no external device in my case. I'm using the Arduino pro mini and a 4 digit 8 segment LED display. Some of the basic fuel calc code is from MPGuino Project of course.
In the last days, I had a look on the MPGuino 64bit math. I know it was written because of the "old" ATMega 168 space limitations. But they are so incredible slow, and the code is very hard to read for a person that is not familiar with MPGuino code..
So I transformed the calculations to normal 64bit math (normal *, /, +, - and so on), removing the 64bitmath code. Yes, the code is about 4kB bigger now. But I wrote a small benchmark, it does 10.000 distanceperfuelunit() calculations, first with MPGuino math, then with Arduino math.
The MPGuino math needs 8707ms for this job, while the "Arduino" math needs only 616
µs!! This is a 14135x speed up! I think this is worth 4kB of additional code if you are using a ATMega328 based device
If you want to test it on your own, here is the benchmark code. Just add the 64bit MPGuino code to the bottom, I removed them so the code stays clear:
Code:
unsigned long tmp1[2];
unsigned long tmp2[2];
unsigned long tmp3[2];
void setup (void){
Serial.begin(9600);
}
unsigned long time;
unsigned long result;
unsigned long injHiSec = 10; //some value, yust to have something for calc
unsigned long injHius = 5; //some value, yust to have something for calc
unsigned long x = 7734;
unsigned long y = 261221646;
unsigned long vssPulses = 25; //some value, yust to have something for calc
void loop (void){
Serial.print("10.000 64bit math MPGuino: ");
time = millis();
for (int i = 0; i < 10000; i++){ //start 10.000 caclulations. In real code, this would give you the average L/100km
init64(tmp1,0,injHiSec);
init64(tmp3,0,1000000);
mul64(tmp3,tmp1);
init64(tmp1,0,injHius);
add64(tmp3,tmp1);
init64(tmp1,0,x);
mul64(tmp3,tmp1);
init64(tmp2,0,1000);
mul64(tmp3,tmp2);
init64(tmp1,0,y);
init64(tmp2,0,vssPulses);
mul64(tmp1,tmp2);
div64(tmp3,tmp1);
init64(tmp2,0,100);
mul64(tmp3,tmp2);
}
Serial.println(millis() - time);
Serial.print("10.000 64bit math Arduino: ");
time = micros();
for (int i = 0; i < 10000; i++){ //Same code as above, but written for standard math.
result = ((((unsigned long long)injHiSec * 1000000ull + (unsigned long long)injHius) * (unsigned long long)x * 1000ull) / ((unsigned long long)y * (unsigned long long)vssPulses)) * 100ull;
}
Serial.println(micros() - time);
delay(10000);
}
Edit: Bug corrected.