BMS Master HW test - 20/21

Dependencies:   mbed

Revision:
0:4fedfbc3c6b8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PwmIn.h	Mon Jun 21 11:38:14 2021 +0000
@@ -0,0 +1,48 @@
+#ifndef MBED_PWMIN_H
+#define MBED_PWMIN_H
+
+#include "mbed.h"
+
+/** PwmIn class to read PWM inputs
+ * 
+ * Uses InterruptIn to measure the changes on the input
+ * and record the time they occur
+ *
+ * @note uses InterruptIn, so not available on p19/p20
+ */
+class PwmIn {
+public:
+    /** Create a PwmIn
+     *
+     * @param p The pwm input pin (must support InterruptIn)
+     */ 
+    PwmIn(PinName p);
+    
+    /** Read the current period
+     *
+     * @returns the period in seconds
+     */
+    float period();
+    
+    /** Read the current pulsewidth
+     *
+     * @returns the pulsewidth in seconds
+     */
+    float pulsewidth();
+    
+    /** Read the current dutycycle
+     *
+     * @returns the dutycycle as a percentage, represented between 0.0-1.0
+     */
+    float dutycycle();
+
+protected:        
+    void rise();
+    void fall();
+    
+    InterruptIn _p;
+    Timer _t;
+    float _pulsewidth, _period;
+};
+
+#endif