2013-11-01 34 views
0

我正在爲TI C2000 Piccolo微控制器編寫一系列C文件。以下是我的電池充電狀態算法示例。 構建時,Code Composer Studio報告「#31表達式必須具有整數類型」的第三行到最後一行出現錯誤(第二個「discharge_capacity」)呃,受我的經驗限制,我無法多作出貢獻。你能提供一些幫助嗎?謝謝!C語言,數據類型錯誤報告


#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. 

}

回答

2

你做的按位異或,不求冪。

discharge_capacity = (p5 - p1*x^4 - p2*x^3 + p3*x^2 - p4*x); 

我懷疑上面的行應該是:

discharge_capacity = (p5 - p1*(x*x*x*x) - p2*(x*x*x) + p3*x*x - p4*x); 

這可以更簡潔地寫爲:

discharge_capacity = p5 - (((p1 * x - p2) * x + p3) * x - p4) * x; 
+0

謝謝!我在MATLAB中編寫了這個程序,並沒有意識到用C編寫數學表達式有點複雜。問題解決了! – tm602502