Penn Electric Racing / Mbed 2 deprecated SystemManagement

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Committer:
martydd3
Date:
Sat Oct 25 15:54:19 2014 +0000
Revision:
18:915a235bc099
Parent:
17:c9ce210f6654
Martin's Testing branch

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pspatel321 13:fbd9b3f5a07c 1 #ifndef _FILE_CURRENTMONITOR_H
pspatel321 13:fbd9b3f5a07c 2 #define _FILE_CURRENTMONITOR_H
pspatel321 13:fbd9b3f5a07c 3
pspatel321 13:fbd9b3f5a07c 4 #include "mbed.h"
pspatel321 13:fbd9b3f5a07c 5 #include "CANBuffer.h"
pspatel321 17:c9ce210f6654 6 #include "RTCStore.h"
pspatel321 13:fbd9b3f5a07c 7
pspatel321 13:fbd9b3f5a07c 8 class CoulombCounter {
pspatel321 13:fbd9b3f5a07c 9 public:
pspatel321 13:fbd9b3f5a07c 10
pspatel321 13:fbd9b3f5a07c 11 // Configures for a certain pin, millisecond sample period, and which GPREG in RTC to use to store the ampHours
pspatel321 13:fbd9b3f5a07c 12 CoulombCounter(int _mSec, int _rtcGPREG_counter, int _rtcGPREG_capacity);
pspatel321 13:fbd9b3f5a07c 13
pspatel321 13:fbd9b3f5a07c 14 // Allow zeroing the SOC when the battery is fully charged/dead, SOC in % from 0 to 1
pspatel321 13:fbd9b3f5a07c 15 void resetToSOC(float SOC) { store.write(SOC*capacity(), rtcGPREG_counter); }
pspatel321 13:fbd9b3f5a07c 16
pspatel321 13:fbd9b3f5a07c 17 // Allow zeroing the SOC (via zeroing the Ah) when the battery is fully charged/dead
pspatel321 13:fbd9b3f5a07c 18 void resetToAh(float Ah) { store.write(Ah, rtcGPREG_counter); }
pspatel321 13:fbd9b3f5a07c 19
pspatel321 13:fbd9b3f5a07c 20 // Allow change of capacity spec (changes SOC)
pspatel321 13:fbd9b3f5a07c 21 void changeCapacity(float capAh) {store.write(capAh, rtcGPREG_capacity); }
pspatel321 13:fbd9b3f5a07c 22
pspatel321 13:fbd9b3f5a07c 23 bool overCurrent; // Sensor above range
pspatel321 13:fbd9b3f5a07c 24 float current() { return currentSample; } // Last current reading in Amps
pspatel321 13:fbd9b3f5a07c 25 float ampHours() { return store.read(rtcGPREG_counter); }
pspatel321 13:fbd9b3f5a07c 26 float capacity() { return store.read(rtcGPREG_capacity); }
pspatel321 13:fbd9b3f5a07c 27 float SOC() { return ampHours()/capacity(); }
pspatel321 13:fbd9b3f5a07c 28
pspatel321 13:fbd9b3f5a07c 29 private:
pspatel321 13:fbd9b3f5a07c 30 Ticker sampler; // Used to capture next sample and coulomb count
pspatel321 13:fbd9b3f5a07c 31 void sample();
martydd3 18:915a235bc099 32 RTCStore store;
pspatel321 13:fbd9b3f5a07c 33
pspatel321 17:c9ce210f6654 34 volatile int mSec;
pspatel321 17:c9ce210f6654 35 volatile float currentSample;
pspatel321 17:c9ce210f6654 36 volatile int rtcGPREG_counter;
pspatel321 17:c9ce210f6654 37 volatile int rtcGPREG_capacity;
pspatel321 13:fbd9b3f5a07c 38 AnalogIn BatISense; // Analog input pin
pspatel321 13:fbd9b3f5a07c 39 };
pspatel321 13:fbd9b3f5a07c 40 #endif