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: Get_IMD/IMD.cpp
- Revision:
- 8:ecf68db484af
- Child:
- 12:e0adb697fcdb
diff -r 5f6e31faa08e -r ecf68db484af Get_IMD/IMD.cpp
--- /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);
+}
