# Peukert Equation Float^1.3?? How to get 5 to the power of 1.3

HI

Im a bit stuck and cant seem to figure out how to do this.

Peukert’s equation is time = batterycapacity/(current drawn^1.3)
so
Time = 105/(3.12 to the power of 1.3)

But the output on the LCD looks like binary.

``````tleft=(pcapacity/(pow(amps,1.3)));
``````

I display it on the LCD with normal lcd.print() but use the answer further in the code for other calculations.

What am I missing. At 3.2Amps the answer should be 1.9hours for my 21Ah battery. But i get 101 and 10111 which I am sure is binary?
How can I do this correctly?

Please post all your code. The problem may be in how the variables have been declared.

You showed us one line, also known as a snippet. We aren't very good with snippeets. Please post ALL of your code and you may get better help. Furthermore, you showed one line and described two (yes, two!) outputs. I am confused.

Its over a 1000 lines of code.

Here is the specific function-The commented out code is how I used to do it.
capacity, ahout,ahin is all float.
I use the answer in other areas.
Its an opensource project for a bunch of guys here in South Africa on a battery monitor. All the detail and a video of how it works is here.
and the video is here

Please let me know what other info you need and il post it here.

``````float gettimeleft(float ampsoutnow,float ampsinnow, float ahleftnow)
{
float amps;
float tleft;
float pcapacity;
amps=(ampsoutnow-ampsinnow);
pcapacity=capacity-ahout+ahin;
tleft=(pcapacity/(pow(amps,1.3)));

//  if(amps>0)
//  {
//    tleft = ahleftnow/amps;
//    if (tleft<0.0)
//    {
//      tleft = 0.0;
//    }
//    if(tleft>999)
//    {
//      tleft = 999;
//    }
//  }
//  if(amps<=0)
//  {
//    tleft=999;
//  }
return tleft;
}
``````

This is how I call the subroutine

`````` timeah = gettimeleft(ampout,ampin,amphoursleftreading);
``````

and display it here

``````case 2:
lcd.print("Est Hours ");
lcd.print(timeah,2);
lcd.print("      ");
break;
``````

Gerhardl: Its over a 1000 lines of code. ;)

Reply Click [u]Additional Options[/u] Click [u]Browse[/u] next to [u]Attach[/u] Select the file Click Open If necessary click u[/u] Post

Thanks.
Did not know about that option.

BatteryMonitorV7_9.ino (26 KB)

``````int timeah=0;
``````
``````float gettimeleft(float ampsoutnow,float ampsinnow, float ahleftnow)
``````
``````timeah = gettimeleft(ampout,ampin,amphoursleftreading);
``````

Also ...

``````lcd.print(timeah,2);
``````

lcd.print(data, BASE)

Thanks, Its working.

So I changed it and got it back to lcd.print(timeah,DEC)

It gives me the correct value of 4 Hours on a 21Ah battery at 3Amps.

Now, going forward. How do I get that back to a float number? I need it to be something like 4.31Hours * 3.3Amps = 14.22Ah??

Im am not sure what type conversion function to call to get that back to float point number?

Does it work if you change `timeah` declaration from int to float?

Yes. It still works.

But gives me an answer of 4 on both.

Where it should give an answer of 4.23. I am just not sure how or what the actual value stored in timeah is. Is it 4 or 4.32? And when i display it, it has to be done with print(val,base). But what would happen if i say 5xtimeah?

I think it could be that lcd.print() can't handle floats.

Try this instead (with timeah declared as type float):

``````char buffer[10];
dtostrf(timeah, 5, 1, buffer);  // Convert float to string 5 characters wide, 1 character after decimal point
lcd.print(buffer);
``````

I changed it to the string.

It now displays correctly as 4.0 and 5.0, but i do not get any 4.2 or 4.7 values. Or any decimal value on the right side of point. No fractions?

My concern is not such that it displays correctly, but more in using the result in further calculations. I need more than integer precision. The LCD.print(val,xx) allows printing of float point numbers.

The main question is how do I get the answer for "tleft" as a normal float point number?

tleft=(pcapacity/(pow(amps,1.3)));

The LCD.print(val,xx) allows printing of float point numbers.

The documentation for the LiquidCrystal library does not support this claim. See http://arduino.cc/en/Reference/LiquidCrystalPrint

Syntax lcd.print(data) lcd.print(data, BASE)

Parameters lcd: a variable of type LiquidCrystal data: the data to print (char, byte, int, long, or string) BASE (optional): the base in which to print numbers: BIN for binary (base 2), DEC for decimal (base 10), OCT for octal (base 8), HEX for hexadecimal (base 16).

Thats interesting:

If you look at the youtube video. All the items i display on the LCD is float.

I use lcd.print(val,1) and it prints the float number rounded to just 1 number after the point. If i change it to (val,2) it prints with 2 numbers at the end. And so on.

I must just find the reference where I learnt that but its been working fine like that the whole time?

Arduino release 0018 has a precision parameter for printing

I picked this line from another thread. Seems to be the reason why I can do it.

What a nice example of people asking for help and others helping.

Congratulations to you both.

P.S. To you all.

Thanks.

But I think I have more questions than answers at the moment.

So obviously the calculation to get X^1.3 is sorted.

But then:

How can I get the answer in a workable float value.

Secondly

How am I able to display all the values in print() which are float values to the correct decimal by changing the second value in the argument?

Just to recap ...

Float values other than `timeah` print correctly with non-zero values to the right of the decimal point when using `lcd.print()`.

I changed it to the string. It now displays correctly as 4.0 and 5.0, but i do not get any 4.2 or 4.7 values. Or any decimal value on the right side of point. No fractions?

With `timeah` declared as float, you can display decimal places with the conversion to string, but the decimal places are zero.

What happens if you Serial.print `timeah`?

The problem may lie in `gettimeleft()`. You could try a couple of things in that function:

Add a local float variable for the intermediate step in the calculation.

``````float tempPower = pow(amps, 1.3);
``````

Add Serial.print statements for all the values involved. For example:

``````Serial.print("amps: ");
Serial.println(amps);
Serial.print("capacity: ");
Serial.println(capacity);
etc
``````

Yes correct. All other floats values print correct as 12.34 or 3.65. On the lcd.print(value,2)

Yes timeah shows as 4.0 and 5.0 with the conversion to string.

I will try the local float variable as you mention as soon as Im home again later today and revert. And add serial.print.

Do you maybe know why lcd.print(float,val) is different than lcd.print(int,BASE)

Did something change in the library at some point?

Thanks for the assistance thus far.