Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FreescaleIAP mbed-rtos mbed
Fork of RAJANGAM_REVIEW_BAE_CODE by
Diff: EPS.cpp
- Revision:
- 44:da258a0977a4
- Parent:
- 39:670133e7ffd8
--- a/EPS.cpp Thu Jul 07 19:45:45 2016 +0000
+++ b/EPS.cpp Mon Jul 11 19:01:12 2016 +0000
@@ -92,6 +92,9 @@
//m_I2C.frequency(10000)
const char RCOMP0= 0x97;// don't know what it is now
+extern int eps_btg_read_flag; // flag to check I2C ack on reading from BTG
+extern int eps_btg_writ_flag; // flag to check I2C ack on writing from BTG
+
BAE_HK_actual actual_data;
BAE_HK_quant quant_data;
BAE_HK_min_max bae_HK_minmax;
@@ -197,7 +200,7 @@
//value_u &=0x0001;
if(value_u & 0x0001 == 0x0001) // battery gauge not initialised
{
- actual_data.power_mode = 1;
+ actual_data.power_mode = 0;
EPS_BATTERY_GAUGE_STATUS = 0; //clear EPS_BATTERY_GAUGE_STATUS
printf(" init BTG fail - %d\n\r", value_u);
}
@@ -214,7 +217,7 @@
printf("REG_VERSION = %d\r\n",read(REG_VERSION));
FCTN_BATTTEMP_INIT();
- EPS_BATTERY_GAUGE_STATUS = 1;
+ //EPS_BATTERY_GAUGE_STATUS = 1;
EPS_INIT_STATUS = 0 ; //clear EPS_INIT_STATUS flag
@@ -395,14 +398,13 @@
void FCTN_EPS_POWERMODE(float soc) //dummy algo
{
- if(soc >= 80)
- actual_data.power_mode = 4;
- else if(soc >= 70 & soc < 80)
+ if(soc >= EPS_SOC_LEVEL_23*100 )
actual_data.power_mode = 3;
- else if(soc >= 60 & soc < 70)
+ else if(soc >= EPS_SOC_LEVEL_12*100 )
actual_data.power_mode = 2;
- else if(soc < 60)
- actual_data.power_mode = 1;
+ //else if(soc >= 60 & soc < 70)
+ // actual_data.power_mode = 2;
+ else actual_data.power_mode = 1;
}
//...................................................HK...........................................//
@@ -426,6 +428,8 @@
for(Iteration=0; Iteration<16; Iteration++)
{
actual_data.voltage_actual[Iteration]=VoltageInput.read();
+ printf("%d %f\r\n",Iteration, VoltageInput.read()*3.3);//actual_data.voltage_actual[Iteration]);
+ wait(1);
actual_data.current_actual[Iteration]=CurrentInput.read();
SelectLinea0=!(SelectLinea0);
@@ -468,7 +472,9 @@
actual_data.current_actual[Iteration]=3365.4/log(7.60573*resistance);
}
}
- actual_data.BAE_temp_actual=(-90.7*3.3*actual_data.BAE_temp_actual)+190.1543;
+
+ actual_data.BAE_temp_actual=(-90.7*3.3*BAE_temp_sensor.read())+190.1543;
+ //actual_data.BAE_temp_actual=(-90.7*3.3*actual_data.BAE_temp_actual)+190.1543;
actual_data.Batt_voltage_actual=Batt_voltage.read()*3.3*5.63;
@@ -832,30 +838,32 @@
//// printf("\n\r battery gauge \n");
//float temp=30; //=Battery_temp (from temp sensor on battery board) //value of battery temperature in C currently given a dummy value. Should be updated everytime.
- tempCompensation(temp);
+ int flag = tempCompensation(temp);
-
- Battery_parameters[0]=vcell();
- Battery_parameters[1]=soc();
- Battery_parameters[2]=crate();
-
-//// printf("\nVcell=%f",vcell()); //remove this for final code
-//// printf("\nSOC=%f",soc()); //remove this for final code
-//// printf("\nC_rate=%f",crate()); //remove this for final code
-
-
- if (alerting()== true) //alert is on
- {
- Battery_parameters[3]=alertFlags();
- clearAlert();//clear alert
- clearAlertFlags();//clear all alert flags
+ if( flag == 0 )
+ {
+ Battery_parameters[0]=vcell();
+ Battery_parameters[1]=soc();
+ Battery_parameters[2]=crate();
+
+ //// printf("\nVcell=%f",vcell()); //remove this for final code
+ //// printf("\nSOC=%f",soc()); //remove this for final code
+ //// printf("\nC_rate=%f",crate()); //remove this for final code
+
+
+ if (alerting()== true) //alert is on
+ {
+ Battery_parameters[3]=alertFlags();
+ clearAlert();//clear alert
+ clearAlertFlags();//clear all alert flags
+ }
}
- if( soc() == 200) return 0;
- else return 1;
+ if( soc() == 200 || flag != 0) return 1;
+ else return 0;
}
-void tempCompensation(float temp)
+int tempCompensation(float temp)
{
//Calculate the new RCOMP value
char rcomp;
@@ -866,10 +874,10 @@
}
//Update the RCOMP value
- compensation(rcomp);
+ return(compensation(rcomp));
}
-void compensation(char rcomp)
+int compensation(char rcomp)
{
//Read the current 16-bit register value
unsigned short value = read(REG_CONFIG);
@@ -879,11 +887,12 @@
value |= rcomp << 8;
//Write the value back out
- write(REG_CONFIG, value);
+ return(write(REG_CONFIG, value));
}
int write(char reg, unsigned short data)
{
+ eps_btg_writ_flag = -1;
//Create a temporary buffer
char buff[3];
@@ -898,7 +907,10 @@
{
flag = m_I2C.write(m_ADDR, buff, 3); //Write the data and return ack
if( data != read(reg) ) //Verify written data
- EPS_BATTERY_GAUGE_STATUS = 0; //clear EPS_BATTERY_GAUGE_STATUS
+ eps_btg_writ_flag = 1;
+ //EPS_BATTERY_GAUGE_STATUS = 0; //clear EPS_BATTERY_GAUGE_STATUS
+ else eps_btg_writ_flag = 0;
+
}
return flag;
@@ -906,6 +918,7 @@
unsigned short read(char reg)
{
+ eps_btg_read_flag = -1;
int flag = 1;
char buff[2]; //Create a temporary buffer
@@ -918,10 +931,11 @@
{
m_I2C.write(m_ADDR, ®, 1, true);
flag = m_I2C.read(m_ADDR, buff, 2);
- if( flag )
- EPS_BATTERY_GAUGE_STATUS = 0; //clear EPS_BATTERY_GAUGE_STATUS
+ //if( flag ) EPS_BATTERY_GAUGE_STATUS = 0; //clear EPS_BATTERY_GAUGE_STATUS
}
-
+
+ eps_btg_read_flag = flag;
+
//Return the combined 16-bit value
return (buff[0] << 8) | buff[1];
}
