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:
- 25:33f8257fcf63
- Parent:
- 24:72bca5be7c4e
- Child:
- 26:c8655e0ec73a
--- a/EPS.cpp Sat Jul 02 10:18:51 2016 +0000
+++ b/EPS.cpp Sat Jul 02 14:06:10 2016 +0000
@@ -836,42 +836,33 @@
else return 1;
}
-/*
-unsigned short read(char reg)
- {
-
- //Create a temporary buffer
- char buff[2];
-
- //Select the register
- m_I2C.write(m_ADDR, ®, 1, true);
-
- //Read the 16-bit register
- m_I2C.read(m_ADDR, buff, 2);
-
- //Return the combined 16-bit value
- return (buff[0] << 8) | buff[1];
+void tempCompensation(float temp)
+{
+ //Calculate the new RCOMP value
+ char rcomp;
+ if (temp > 20.0) {
+ rcomp = RCOMP0 + (temp - 20.0) * -0.5;
+ } else {
+ rcomp = RCOMP0 + (temp - 20.0) * -5.0;
}
-
-
+ //Update the RCOMP value
+ compensation(rcomp);
+}
-
- void write(char reg, unsigned short data)
- {
- //Create a temporary buffer
- char buff[3];
+void compensation(char rcomp)
+{
+ //Read the current 16-bit register value
+ unsigned short value = read(REG_CONFIG);
- //Load the register address and 16-bit data
- buff[0] = reg;
- buff[1] = data >> 8;
- buff[2] = data;
+ //Update the register value
+ value &= 0x00FF;
+ value |= rcomp << 8;
- //Write the data
- m_I2C.write(m_ADDR, buff, 3);
- }
-*/
-
+ //Write the value back out
+ write(REG_CONFIG, value);
+}
+
int write(char reg, unsigned short data)
{
//Create a temporary buffer
@@ -915,11 +906,51 @@
//Return the combined 16-bit value
return (buff[0] << 8) | buff[1];
}
+
+/*
+unsigned short read(char reg)
+ {
+
+ //Create a temporary buffer
+ char buff[2];
+
+ //Select the register
+ m_I2C.write(m_ADDR, ®, 1, true);
+
+ //Read the 16-bit register
+ m_I2C.read(m_ADDR, buff, 2);
+
+ //Return the combined 16-bit value
+ return (buff[0] << 8) | buff[1];
+ }
+
+
+
+
+
+ void 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;
+
+ //Write the data
+ m_I2C.write(m_ADDR, buff, 3);
+ }
+*/
+
+
// Command the MAX17049 to perform a power-on reset
void reset()
{
//Write the POR command
write(REG_CMD, 0x5400);
+ //Re-initialise gauge
+ FCTN_BATTERYGAUGE_INIT();
}
// Command the MAX17049 to perform a QuickStart
@@ -967,7 +998,7 @@
write(REG_CONFIG, value);
}
-
+/*
void compensation(char rcomp)
{
//Read the current 16-bit register value
@@ -995,6 +1026,7 @@
//Update the RCOMP value
compensation(rcomp);
}
+*/
// Command the MAX17049 to de-assert the ALRT pin
void clearAlert()
