View Single Post
Old 10-04-2010, 12:48 AM   #1 (permalink)
FalconFour
EcoModding Lurker
 
FalconFour's Avatar
 
Join Date: Sep 2010
Location: Fresno, CA
Posts: 78

LEAF - '11 Nissan LEAF
Thanks: 4
Thanked 9 Times in 7 Posts
Math functions in MPGuino giving me a migraine - HELP!!

So I've made a lot of threads here lately... would help if I wasn't the only one making threads though.

Hacking away at the MPGuino code, I've spent ALL DAY trying to figure out the convoluted (but probably nice and efficient) "64-bit" math code in MPGuino. Well, first I don't understand that part, since the only math really needed here is 32-bit, but... *shrug*.

I don't get it. What are the types of values being used in these functions?! format() only takes a 5-digit number, which is really low precision. Yet, it seems like I can't get a straight answer out of things like tank.mpg() or tank.gallons() because their result was produced by the 64-bit math functions.

I can't figure out what tmp1 and tmp2 are used for (not to mention that the Arduino IDE's font is terrible, no difference between "i" and "1"), or how data flows in and out of them. I made a guess but the system totally EXPLODED with compiler errors about "invalid conversion from 'long unsigned int' to 'long unsigned int*'" and "initializing argument 2 of 'void sub64(long unsigned int*, long unsigned int*'"... along with a nice dose of "incompatible types in assignment of 'double' to 'long unsigned int [2]'"... and every time I apply one solution I found in the code, the list of errors grows.

Here's the code that explodes:
Code:
void doDisplayF4(void) {
  unsigned long tmp1[2];
  unsigned long tmp2[2];
  LCD::gotoXY(0,0);
  tmp1 = 17.9999999; // tank mpg temp
  tmp2 = parms[tankSizeIdx];
  if (tank.mpg() > 0) tmp1 = tank.mpg();

  LCD::print("Rem miles:");
  sub64(tmp2,tank.gallons());
  mul64(tmp2,tmp1);
  LCD::print(format(tmp2));
}
Makes no sense. None of this stuff makes sense. The Arduino docs don't help a hell of a lot either, basically saying that "*" is an advanced topic we're not going to cover.

And as I mentioned in a previous topic, apparently just doing standard math doesn't get me anywhere. It works for a brief moment but once any of the values depart from zero, it explodes and the math goes haywire (something like 80495 beyond the limits of format()).

I'd love just a little commenting on the math functions... :/

  Reply With Quote