Penn Electric Racing / Mbed 2 deprecated SystemManagement

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Revision:
13:fbd9b3f5a07c
Child:
17:c9ce210f6654
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IMD/IMD.h	Fri Oct 24 22:09:04 2014 +0000
@@ -0,0 +1,53 @@
+// 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 "LPCDigitalIn.h"
+
+const float ZERO_HZ_TIMEOUT = 0.1;     // Time (sec) that must pass without an edge to call it 0 Hz, set to greater than the longest expected pulse width
+
+enum EdgeT {
+    RISING=5,
+    FALLING=6,
+    BOTH=7,  
+};
+class IMD{
+public:
+    IMD();
+    
+    // Get the IMD status
+    /*
+    Status      State
+    0           IMD off
+    1           Normal
+    2           under voltage
+    3           Speed Start
+    4           IMD error
+    5           Ground error
+    */
+    char status();
+    
+    // Gets the insulation resistance reading
+    // Returns 0 to 50,000,000 in normal/UV modes
+    // Returns 0 or 50,000,000 in speed start (good/bad only)
+    // -1 for invalid measurement (out of permissible range)
+    // and NaN for not applicable mode
+    float resistance();
+    
+    // Interrupt function for the edge type detected
+    void edgeIRQ();
+    // Used to zero (reset) the data on timeout
+    void zeroIRQ();
+    
+private:
+    float frequency();
+    float duty();
+    uint32_t startTime;
+    uint32_t widthTicks;
+    uint32_t periodTicks;
+    bool first;
+};
+
+#endif
\ No newline at end of file