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
Diff: CoulombCounter/CoulombCounter.cpp
- Revision:
- 17:c9ce210f6654
- Parent:
- 13:fbd9b3f5a07c
--- a/CoulombCounter/CoulombCounter.cpp Fri Oct 24 22:38:20 2014 +0000
+++ b/CoulombCounter/CoulombCounter.cpp Sat Oct 25 03:28:55 2014 +0000
@@ -2,10 +2,10 @@
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_OFFSET = -0.5*BAT_ISENSE_MULTIPLIER; // Offset to convert float to amps
const float BAT_ISENSE_LIMS = 3.0; // Over-current limit = +/- 3A
-CoulombCounter::CoulombCounter(PinName _IsensePin, int mSec, int _rtcGPREG_counter, int _rtcGPREG_capacity) : BatISense(p19) {
+CoulombCounter::CoulombCounter(int _mSec, int _rtcGPREG_counter, int _rtcGPREG_capacity) : BatISense(p19) {
mSec = _mSec;
rtcGPREG_counter = _rtcGPREG_counter;
rtcGPREG_capacity = _rtcGPREG_capacity;
@@ -19,15 +19,16 @@
sampler.attach_us(this, &CoulombCounter::sample, mSec*1000);
}
-void CouloumbCounter::sample() {
+void CoulombCounter::sample() {
// Take the reading
currentSample = BatISense.read()*BAT_ISENSE_MULTIPLIER+BAT_ISENSE_OFFSET;
// Signal error on over current
- if (currentSample < -BAT_ISENSE_LIMS || currentSample > BAT_ISENSE_LIMS) {
+ if (abs(currentSample) > BAT_ISENSE_LIMS) {
overCurrent = true;
} else overCurrent = false;
// Integrate
- store.write(ampHours()+currentSample*mSec*MSEC_HRS, rtcGPREG_counter);
+ float f = ampHours()+currentSample*mSec*MSEC_HRS;
+ store.write(f, rtcGPREG_counter);
}
\ No newline at end of file
