Penn Electric Racing / Mbed 2 deprecated SystemManagement

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Revision:
36:0afc0fc8f86b
Parent:
34:18bcf276d3bf
Child:
38:8efacce315ae
--- a/Libs/CoulombCounter/CoulombCounter.cpp	Wed Jan 07 03:36:43 2015 +0000
+++ b/Libs/CoulombCounter/CoulombCounter.cpp	Thu Jan 22 07:58:51 2015 +0000
@@ -1,8 +1,8 @@
 #include "CoulombCounter.h"
 
 const float MSEC_HRS = 2.77778e-7;                          // Multiplier to convert milliseconds to hours
-const float BAT_ISENSE_MULTIPLIER = 6.2299;                 // Multiplier to convert float to amps
-const float BAT_ISENSE_OFFSET = -0.5*BAT_ISENSE_MULTIPLIER; // Offset to convert float to amps
+const float BAT_ISENSE_MULTIPLIER = /*6.2299*/6.640114;     // Multiplier to convert float to amps, calibrated using 3 points with Fluke 87V meter and code on 1/9/15
+const float BAT_ISENSE_OFFSET = /*-0.5*BAT_ISENSE_MULTIPLIER*/-3.344968; // Offset to convert float to amps, calibrated using 3 points with Fluke 87V meter and code on 1/9/15
 const float BAT_ISENSE_LIMS = 3.0;                          // Over-current limit = +/- 3A
 
 CoulombCounter::CoulombCounter(PinName _pin, int _mSec) : BatISense(_pin) {
@@ -22,18 +22,15 @@
     
     // Take the initial readings, fill the buffer
     for (int i = 0; i < CC_FILTER_TAPS; i++) {
-        buffArr[i] = BatISense.read() * BAT_ISENSE_MULTIPLIER + BAT_ISENSE_OFFSET;
+        buffArr[i] = BatISense.read()*BAT_ISENSE_MULTIPLIER+BAT_ISENSE_OFFSET;
     }
-    current();      // Get avg and fill out overCurrent flag
+    updateAvg();      // Get avg and fill out overCurrent flag
     tracker=0;
-    
-    // Start counting
-    // sampler.attach_us(this, &CoulombCounter::sample, mSec*1000);
 }
 
 void CoulombCounter::sample() {
     // Take the reading
-    currentSample = BatISense.read()*BAT_ISENSE_MULTIPLIER+BAT_ISENSE_OFFSET;
+    float currentSample = BatISense.read()*BAT_ISENSE_MULTIPLIER+BAT_ISENSE_OFFSET;
         
     // Integrate
     float f = ampHours()-currentSample*mSec*MSEC_HRS;
@@ -50,16 +47,17 @@
     buffArr[tracker] = currentSample;
     tracker++;
     if (tracker >= CC_FILTER_TAPS) tracker = 0;
+    updateAvg();
 }
 
-float CoulombCounter::current() { 
+void CoulombCounter::updateAvg() {
     float avg = 0;
     for (int i = 0; i < CC_FILTER_TAPS; i++) {
         avg += buffArr[i];   
     }
     avg /= CC_FILTER_TAPS;
     if (abs(avg) > BAT_ISENSE_LIMS) overCurrent = true;
-    return avg;
+    currentFiltered = avg;
 }
 
 bool CoulombCounter::overCurrentDetected() {