System Management code
Dependencies: mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP
Fork of SystemManagement by
Revision 8:ecf68db484af, committed 2014-10-10
- Comitter:
- martydd3
- Date:
- Fri Oct 10 21:46:52 2014 +0000
- Parent:
- 7:5f6e31faa08e
- Child:
- 9:ada056631cac
- Commit message:
- Added IMD monitoring code based on Kiran's calculations
Changed in this revision
--- a/Get_IMD/Get_IMD.h Fri Oct 10 20:59:36 2014 +0000
+++ b/Get_IMD/Get_IMD.h Fri Oct 10 21:46:52 2014 +0000
@@ -1,26 +1,13 @@
#include "mbed.h"
#include "string.h"
-/*
-#include "Get_IMD.h"
+
DigitalOut myled(LED1);
-int main()
-{
- IMD_Measurement_Output IMD_Result;
- while(1)
- {
- IMD_Result=Get_Measurement();
- pc.printf("Frequency:%f\n\r",IMD_Result.Frequency);
- pc.printf("Duty Cycle:%f\n\r",IMD_Result.Duty_Cycle);
- pc.printf("State:%s\n\n\r",IMD_Result.State);
- }
-}
-*/
-
//Serial pc(USBTX,USBRX);
#ifndef GET_IMD_H
- #define GET_IMD_H
+#define GET_IMD_H
+
typedef struct
{
float Frequency;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Get_IMD/IMD.cpp Fri Oct 10 21:46:52 2014 +0000
@@ -0,0 +1,68 @@
+#include "IMD.h"
+
+CANBuffer *tx_IMD_Buffer;
+
+IMD::IMD(CANBuffer *can): _p(P1_26) {
+ _p.rise(this, &IMD::rise);
+ _p.fall(this, &IMD::fall);
+ _period = 0.0;
+ _pulsewidth = 0.0;
+
+ tx_IMD_Buffer = can;
+}
+
+void IMD::rise() {
+ _period = _t.read();
+ _t.reset();
+}
+
+void IMD::fall() {
+ _pulsewidth = _t.read();
+}
+
+float IMD::frequency() { return 1/_period; }
+float IMD::pulse_width() { return _pulsewidth; }
+float IMD::duty() { return _pulsewidth / _period; }
+
+/*
+ Status State
+ 1 Normal
+ 2 under voltage
+ 3 Insulation measurement: good
+ 4 Insulation measurement: bad
+ 5 Device error
+ 6 Connection fault earth
+*/
+void update_IMD(void const *arg){
+ IMD *instance = (IMD *)arg;
+ char data[4] = {0};
+ while(1){
+ float freq = instance->frequency();
+ float duty = instance->duty();
+
+ if(freq >= 5 && freq <15){
+ data[0] = 1;
+ }else if(freq >= 15 && freq < 25){
+ data[0] = 2;
+ }else if(freq >= 25 && freq < 35){
+ if(duty <= 15){
+ data[0] = 3;
+ } else if(duty > 85 && duty < 100){
+ data[0] = 4;
+ }
+ }else if(freq >= 35 && freq < 45){
+ data[0] = 5;
+ }else if(freq >= 45 && freq < 55){
+ data[0] = 6;
+ }
+
+ CANMessage txMessage(TX_IMD_ID, data, 4);
+ tx_IMD_Buffer->txWrite(txMessage);
+
+ Thread::wait(100); //10 Hz update
+ }
+}
+
+void IMD::start_update(){
+ Thread update_thread(update_IMD, this);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Get_IMD/IMD.h Fri Oct 10 21:46:52 2014 +0000
@@ -0,0 +1,28 @@
+// copied idea from http://developer.mbed.org/forum/mbed/topic/466/?page=1#comment-2457
+
+#ifndef _FILE_IMD_H
+#define _FILE_IMD_H
+
+#include "mbed.h"
+#include "CANBuffer.h"
+#include "rtos.h"
+
+const int TX_IMD_ID = ((4 << 8) | 7);
+
+class IMD{
+ public:
+ IMD(CANBuffer *can);
+ void start_update();
+ float frequency();
+ float pulse_width();
+ float duty();
+
+ private:
+ InterruptIn _p;
+ Timer _t;
+ float _pulsewidth, _period;
+ void rise();
+ void fall();
+};
+
+#endif
\ No newline at end of file
--- a/PollSwitch/PollSwitch.cpp Fri Oct 10 20:59:36 2014 +0000
+++ b/PollSwitch/PollSwitch.cpp Fri Oct 10 21:46:52 2014 +0000
@@ -23,9 +23,12 @@
PollSwitch::PollSwitch(CANBuffer *can){
tx_Poll_Buffer = can;
+
+ /*
for(int i = 0; i < 12; i++){
poll[i].mode(PullDown);
}
+ */
}
uint16_t poll_switches(){
--- a/SysMngmt.cpp Fri Oct 10 20:59:36 2014 +0000
+++ b/SysMngmt.cpp Fri Oct 10 21:46:52 2014 +0000
@@ -19,6 +19,7 @@
#include "FanPump.h"
#include "DC_DC.h"
#include "PollSwitch.h"
+#include "IMD.h"
//Possible problems in IMD coz change of counter
//Possible problems in BatteryStatus coz change in library
@@ -278,10 +279,12 @@
FanPump fanPump(&rxBuffer);
DC dc_dc(&fanPump, &rxBuffer);
PollSwitch pollSwitch(&rxBuffer);
+ IMD imdMonitor(&rxBuffer);
fanPump.start_update();
dc_dc.start_update();
pollSwitch.start_update();
+ imdMonitor.start_update();
while(1)
{
