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: mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP
Fork of SystemManagement by
CoulombCounter/CoulombCounter.h@13:fbd9b3f5a07c, 2014-10-24 (annotated)
- Committer:
- pspatel321
- Date:
- Fri Oct 24 22:09:04 2014 +0000
- Revision:
- 13:fbd9b3f5a07c
- Child:
- 17:c9ce210f6654
Fork showing Parth's changes to current monitor, IMD, and fanpump.
Who changed what in which revision?
| User | Revision | Line number | New 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 | 13:fbd9b3f5a07c | 6 | #include "Store_RTC.h" |
| pspatel321 | 13:fbd9b3f5a07c | 7 | |
| pspatel321 | 13:fbd9b3f5a07c | 8 | RTCStore store; |
| pspatel321 | 13:fbd9b3f5a07c | 9 | |
| pspatel321 | 13:fbd9b3f5a07c | 10 | class CoulombCounter { |
| pspatel321 | 13:fbd9b3f5a07c | 11 | public: |
| pspatel321 | 13:fbd9b3f5a07c | 12 | |
| pspatel321 | 13:fbd9b3f5a07c | 13 | // Configures for a certain pin, millisecond sample period, and which GPREG in RTC to use to store the ampHours |
| pspatel321 | 13:fbd9b3f5a07c | 14 | CoulombCounter(int _mSec, int _rtcGPREG_counter, int _rtcGPREG_capacity); |
| pspatel321 | 13:fbd9b3f5a07c | 15 | |
| pspatel321 | 13:fbd9b3f5a07c | 16 | // Allow zeroing the SOC when the battery is fully charged/dead, SOC in % from 0 to 1 |
| pspatel321 | 13:fbd9b3f5a07c | 17 | void resetToSOC(float SOC) { store.write(SOC*capacity(), rtcGPREG_counter); } |
| pspatel321 | 13:fbd9b3f5a07c | 18 | |
| pspatel321 | 13:fbd9b3f5a07c | 19 | // Allow zeroing the SOC (via zeroing the Ah) when the battery is fully charged/dead |
| pspatel321 | 13:fbd9b3f5a07c | 20 | void resetToAh(float Ah) { store.write(Ah, rtcGPREG_counter); } |
| pspatel321 | 13:fbd9b3f5a07c | 21 | |
| pspatel321 | 13:fbd9b3f5a07c | 22 | // Allow change of capacity spec (changes SOC) |
| pspatel321 | 13:fbd9b3f5a07c | 23 | void changeCapacity(float capAh) {store.write(capAh, rtcGPREG_capacity); } |
| pspatel321 | 13:fbd9b3f5a07c | 24 | |
| pspatel321 | 13:fbd9b3f5a07c | 25 | bool overCurrent; // Sensor above range |
| pspatel321 | 13:fbd9b3f5a07c | 26 | float current() { return currentSample; } // Last current reading in Amps |
| pspatel321 | 13:fbd9b3f5a07c | 27 | float ampHours() { return store.read(rtcGPREG_counter); } |
| pspatel321 | 13:fbd9b3f5a07c | 28 | float capacity() { return store.read(rtcGPREG_capacity); } |
| pspatel321 | 13:fbd9b3f5a07c | 29 | float SOC() { return ampHours()/capacity(); } |
| pspatel321 | 13:fbd9b3f5a07c | 30 | |
| pspatel321 | 13:fbd9b3f5a07c | 31 | private: |
| pspatel321 | 13:fbd9b3f5a07c | 32 | Ticker sampler; // Used to capture next sample and coulomb count |
| pspatel321 | 13:fbd9b3f5a07c | 33 | void sample(); |
| pspatel321 | 13:fbd9b3f5a07c | 34 | int mSec; |
| pspatel321 | 13:fbd9b3f5a07c | 35 | float currentSample; |
| pspatel321 | 13:fbd9b3f5a07c | 36 | |
| pspatel321 | 13:fbd9b3f5a07c | 37 | int rtcGPREG_counter; |
| pspatel321 | 13:fbd9b3f5a07c | 38 | int rtcGPREG_capacity; |
| pspatel321 | 13:fbd9b3f5a07c | 39 | AnalogIn BatISense; // Analog input pin |
| pspatel321 | 13:fbd9b3f5a07c | 40 | }; |
| pspatel321 | 13:fbd9b3f5a07c | 41 | #endif |
