Hi All,
I have been working on a project for a while now, and ive got to the stage of writing libraries for it. Unfortunately there is no library available for the chip i chose I have used the STC3117 gas gauge fron ST micro. while there is a repo for it on there github, it only has pseudo code! so i have been busily updating the older STC3115 library to suit the new little brother with more features. So i started by updating registers and addresses and the likes, implemented a couple of new functions etc. but im stuck at this point waiting for hardware, and i wanted to make sure i was doing it the best way possible.
So the old 3115 has a 16byte table for the OCV (open circuit voltage, mV) Offset, the new 3117 has changed to a 32byte table and they also added a SOC (state of charge, %) Offset table that has 16bytes.
so basically i have done this
/* New in STC3117 the OCV offset is now 2bytes per table entry*/
#define OCV_OFFSET_TAB {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} // OCVTAB (Open Circuit Voltage curve, ie when the battery is relaxed (no charge or discharge)
#define SOC_OFFSET_TAB {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} // SOCTAB (State of Charge curve, ie when the battery is relaxed (no charge or discharge)
and this is in the function that makes use of it
int OCVOffset[32] = OCV_OFFSET_TAB;
int SOCOffset[16] = SOC_OFFSET_TAB;
for(loop=0; loop<32; loop++)
{
if(OCVOffset[loop] > 127) OCVOffset[loop] = 127;
if(OCVOffset[loop] < -127) OCVOffset[loop] = -127;
ConfigData->OCVOffset[loop] = OCVOffset[loop];
}
for(loop=0; loop<16; loop++)
{
if(SOCOffset[loop] > 127) SOCOffset[loop] = 127;
if(SOCOffset[loop] < -127) SOCOffset[loop] = -127;
ConfigData->SOCOffset[loop] = SOCOffset[loop];
}
is there a better way i should be doing the OCV offset? should the define still have 16 numbers and when writing preparing to write them to the RAM it should be something like
for(loop=0; loop<32; loop = loop + 2)
{
if(OCVOffset[loop] > 255) OCVOffset[loop] = 255;
if(OCVOffset[loop] < -255) OCVOffset[loop] = -255;
ConfigData->OCVOffset[loop] = OCVOffset[loop];
ConfigData->OCVOffset[loop + 1] = (OCVOffset[loop + 1] << 8 )
}
Ill push sone stuff to my github now for the full library, and update this post… there is still alot more questions to come!
edit:
my version: https://github.com/Hootie81/STC3117
original : https://github.com/st-sw/STC3115GenericDriver/