Penn Electric Racing / Mbed 2 deprecated SystemManagement

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

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?

UserRevisionLine numberNew 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 13:fbd9b3f5a07c 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 13:fbd9b3f5a07c 8 CoulombCounter::CoulombCounter(PinName _IsensePin, 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 13:fbd9b3f5a07c 22 void CouloumbCounter::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 13:fbd9b3f5a07c 27 if (currentSample < -BAT_ISENSE_LIMS || 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 13:fbd9b3f5a07c 32 store.write(ampHours()+currentSample*mSec*MSEC_HRS, rtcGPREG_counter);
pspatel321 13:fbd9b3f5a07c 33 }