Reputation: 3
I am writing a series of C files for TI C2000 Piccolo microcontroller. Below is an example of my battery state-of-charge algorithm. While building, Code Composer Studio reports that the third line to the last has an error (second "discharge_capacity") on "#31 expression must have integral type" Well, limited by my experience, I could not contribute more. Could you provide some help? Thanks!
#include "F2806x_Device.h"
#include "math.h"
/*Global Variables*/
//float32 SOC; // State of Charge for the entire battery pack
float32 discharge_capacity; // capacity that that has been discharged by the battery determined the curve fitting equation.
/* Inputs*/
int current = 6500; // Input battery stack current in mA.
float32 voltage = 2.5; // Input battery voltage in V. In this case this should be the average of the 27 cells voltage.
/* Assumed Constants */
int capacity = 3250; // in mAh. Minimum Nominal Capacity at 25 degrees Celcius for an individual cell.
/* Curve Fitting Equation Parameters*/
float32 p1 = 3095.00;
float32 p2 = 40090.00;
float32 p3 = 191000.00;
float32 p4 = 398300.00;
float32 p5 = 310900.00;
float32 socPct;
float32 packSoc;
float32 SOC(float32 voltage, float32 current);
float32 voltage_b;
float32 current_b;
int main()
{
float32 packSoc = SOC(voltage, current); // Average state of charge for each cell in the batter pack.
//printf(packSoc);
}
float32 SOC(float32 voltage_b, float32 current_b)
{
/* Purpose of this code is to receive the (1) average cell voltage
* for all 27 cells and (2) current running through all the cells,
* and output the State of Charge for the entire battery pack.
*
*
*
*
*/
/*Curve fitting algorithm */
float32 x = voltage_b + 0.23*((current_b-650)/3250); // Voltage is adjusted by the current.
if (x >= 4.2)
{// When voltage is at 4.2V or more, battery is at full capacity regardless of the current.
discharge_capacity = 0.00;
}
else {
discharge_capacity = (p5 - p1*x^4 - p2*x^3 + p3*x^2 - p4*x); // Finds the capacity of the batteries that has been used up. ERROR FOUND HERE!!!!!!
}
socPct = 100*(capacity - discharge_capacity)/capacity;
return socPct; // Return State of Charge of a battery in percent.
}
Upvotes: 0
Views: 169
Reputation: 11531
You're doing bitwise XORs, not exponentiation.
discharge_capacity = (p5 - p1*x^4 - p2*x^3 + p3*x^2 - p4*x);
I suspect that the above line should be:
discharge_capacity = (p5 - p1*(x*x*x*x) - p2*(x*x*x) + p3*x*x - p4*x);
This can be written more succinctly as:
discharge_capacity = p5 - (((p1 * x - p2) * x + p3) * x - p4) * x;
Upvotes: 2