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 workinQM_5thJan_azad by
Diff: EPS.cpp
- Revision:
- 24:72bca5be7c4e
- Parent:
- 20:949d13045431
- Child:
- 25:33f8257fcf63
diff -r c65456ec5e61 -r 72bca5be7c4e EPS.cpp
--- a/EPS.cpp Sat Jul 02 10:09:35 2016 +0000
+++ b/EPS.cpp Sat Jul 02 10:18:51 2016 +0000
@@ -805,13 +805,14 @@
vAlertMinMaxThreshold();//set min, max value of Valrt register
vResetThresholdSet();//set threshold voltage for reset
vResetAlertEnabled(true);//enable alert on reset for V < Vreset
+ write(REG_STATUS, read(REG_STATUS) & 0xFEFF); //Clearing Reset Indicator bit
}
-void FCTN_BATTERYGAUGE_MAIN(float Battery_parameters[4])
+int FCTN_BATTERYGAUGE_MAIN(float Battery_parameters[4], float temp)
{
//// 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.
+ //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);
@@ -831,8 +832,11 @@
clearAlertFlags();//clear all alert flags
}
+ if( soc() == 200) return 0;
+ else return 1;
}
+/*
unsigned short read(char reg)
{
@@ -866,9 +870,51 @@
//Write the data
m_I2C.write(m_ADDR, buff, 3);
}
-
+*/
+int write(char reg, unsigned short data)
+ {
+ //Create a temporary buffer
+ char buff[3];
+
+ //Load the register address and 16-bit data
+ buff[0] = reg;
+ buff[1] = data >> 8;
+ buff[2] = data;
+
+ int flag = m_I2C.write(m_ADDR, buff, 3); //Write the data and return ack
+
+ if( flag != 0 )
+ {
+ 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
+ }
+
+ return flag;
+ }
+
+unsigned short read(char reg)
+ {
+ int flag = 1;
+ char buff[2]; //Create a temporary buffer
+ //Select the register
+ m_I2C.write(m_ADDR, ®, 1, true);
+ //Read the 16-bit register
+ flag = m_I2C.read(m_ADDR, buff, 2);
+
+ if( flag )
+ {
+ 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
+ }
+
+ //Return the combined 16-bit value
+ return (buff[0] << 8) | buff[1];
+ }
// Command the MAX17049 to perform a power-on reset
void reset()
{
