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.cpp@24:f58a3c0071c3, 2014-11-07 (annotated)
- Committer:
- martydd3
- Date:
- Fri Nov 07 21:26:46 2014 +0000
- Revision:
- 24:f58a3c0071c3
- Parent:
- 17:c9ce210f6654
finally compiles
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| pspatel321 | 13:fbd9b3f5a07c | 1 | #include "CoulombCounter.h" |
| pspatel321 | 13:fbd9b3f5a07c | 2 | |
| pspatel321 | 13:fbd9b3f5a07c | 3 | const float MSEC_HRS = 2.77778e-7; // Multiplier to convert milliseconds to hours |
| pspatel321 | 13:fbd9b3f5a07c | 4 | const float BAT_ISENSE_MULTIPLIER = 6.2299; // Multiplier to convert float to amps |
| pspatel321 | 17:c9ce210f6654 | 5 | const float BAT_ISENSE_OFFSET = -0.5*BAT_ISENSE_MULTIPLIER; // Offset to convert float to amps |
| pspatel321 | 13:fbd9b3f5a07c | 6 | const float BAT_ISENSE_LIMS = 3.0; // Over-current limit = +/- 3A |
| pspatel321 | 13:fbd9b3f5a07c | 7 | |
| pspatel321 | 17:c9ce210f6654 | 8 | CoulombCounter::CoulombCounter(int _mSec, int _rtcGPREG_counter, int _rtcGPREG_capacity) : BatISense(p19) { |
| pspatel321 | 13:fbd9b3f5a07c | 9 | mSec = _mSec; |
| pspatel321 | 13:fbd9b3f5a07c | 10 | rtcGPREG_counter = _rtcGPREG_counter; |
| pspatel321 | 13:fbd9b3f5a07c | 11 | rtcGPREG_capacity = _rtcGPREG_capacity; |
| pspatel321 | 13:fbd9b3f5a07c | 12 | |
| pspatel321 | 13:fbd9b3f5a07c | 13 | // Take the initial reading |
| pspatel321 | 13:fbd9b3f5a07c | 14 | currentSample = BatISense*BAT_ISENSE_MULTIPLIER+BAT_ISENSE_OFFSET; |
| pspatel321 | 13:fbd9b3f5a07c | 15 | if (currentSample < -BAT_ISENSE_LIMS || currentSample > BAT_ISENSE_LIMS) overCurrent = true; |
| pspatel321 | 13:fbd9b3f5a07c | 16 | else overCurrent = false; |
| pspatel321 | 13:fbd9b3f5a07c | 17 | |
| pspatel321 | 13:fbd9b3f5a07c | 18 | // Start counting |
| pspatel321 | 13:fbd9b3f5a07c | 19 | sampler.attach_us(this, &CoulombCounter::sample, mSec*1000); |
| pspatel321 | 13:fbd9b3f5a07c | 20 | } |
| pspatel321 | 13:fbd9b3f5a07c | 21 | |
| pspatel321 | 17:c9ce210f6654 | 22 | void CoulombCounter::sample() { |
| pspatel321 | 13:fbd9b3f5a07c | 23 | // Take the reading |
| pspatel321 | 13:fbd9b3f5a07c | 24 | currentSample = BatISense.read()*BAT_ISENSE_MULTIPLIER+BAT_ISENSE_OFFSET; |
| pspatel321 | 13:fbd9b3f5a07c | 25 | |
| pspatel321 | 13:fbd9b3f5a07c | 26 | // Signal error on over current |
| pspatel321 | 17:c9ce210f6654 | 27 | if (abs(currentSample) > BAT_ISENSE_LIMS) { |
| pspatel321 | 13:fbd9b3f5a07c | 28 | overCurrent = true; |
| pspatel321 | 13:fbd9b3f5a07c | 29 | } else overCurrent = false; |
| pspatel321 | 13:fbd9b3f5a07c | 30 | |
| pspatel321 | 13:fbd9b3f5a07c | 31 | // Integrate |
| pspatel321 | 17:c9ce210f6654 | 32 | float f = ampHours()+currentSample*mSec*MSEC_HRS; |
| pspatel321 | 17:c9ce210f6654 | 33 | store.write(f, rtcGPREG_counter); |
| pspatel321 | 13:fbd9b3f5a07c | 34 | } |
