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
CurrentMonitor/CurrentMonitor.cpp
- Committer:
- martydd3
- Date:
- 2014-10-19
- Revision:
- 10:db13782f05d9
File content as of revision 10:db13782f05d9:
#include "mbed.h"
#include "CurrentMonitor.h"
#include "Store_RTC.h"
#define MSEC_HRS 2.77778e-7
#define DC_DC_ISENSE_OFFSET_V 0.5
#define DC_DC_ISENSE_INCREMENT 0.133
#define BAT_ISENSE_OFFSET_V 1.65
#define BAT_ISENSE_INCREMENT 0.5297
CANBuffer *tx_Current_Buffer;
double BATmA_Hr;
float DCA_msec,BATA_msec;
float Bat_I_Ratio,DC_I_Ratio;
AnalogIn BatISense(p19);
AnalogIn DCSense(p20);
RTCStore store;
union converter{
float data;
char ch[4];
} convert;
CurrentMonitor::CurrentMonitor(CANBuffer *can){
tx_Current_Buffer = can;
}
void update_current(const void *arg){
char data[4] = {0};
while(1){
float bat_reading = store.read(1);
convert.data = bat_reading;
data[0] = convert.ch[0];
data[1] = convert.ch[1];
data[2] = convert.ch[2];
data[3] = convert.ch[3];
CANMessage txMessage(TX_CURRENT_ID, data, 4);
tx_Current_Buffer->txWrite(txMessage);
Thread::wait(100); //10 Hz update
}
}
void monitor_current(const void *arg){
while(1){
Bat_I_Ratio=BatISense.read();
BATA_msec=(((Bat_I_Ratio*3.3) - BAT_ISENSE_OFFSET_V)/BAT_ISENSE_INCREMENT);
BATmA_Hr+=(BATA_msec*MSEC_HRS);
store.write(BATmA_Hr,0);
DC_I_Ratio=DCSense.read();
DCA_msec=(((DC_I_Ratio*3.3) - DC_DC_ISENSE_OFFSET_V)/DC_DC_ISENSE_INCREMENT);
store.write(DCA_msec,1);
Thread::wait(1); //1 Khz coulomb counter
}
}
void CurrentMonitor::start_update(){
Thread monitor_thread(monitor_current);
Thread update_thread(update_current);
}
