PES_4_Spleisser / X_NUCLEO_IHM02A1

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   Fabian_Test

Files at this revision

API Documentation at this revision

Comitter:
scherfa2
Date:
Wed Apr 03 07:35:42 2019 +0000
Parent:
24:ff67801d7cd7
Commit message:
Source_File

Changed in this revision

PWM.cpp Show annotated file Show diff for this revision Revisions of this file
PWM.h Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PWM.cpp	Wed Apr 03 07:35:42 2019 +0000
@@ -0,0 +1,77 @@
+#include "mbed.h"
+#include "PWM.h"
+
+Timeout timer;
+Timeout timer2;
+
+DigitalOut my_pwm(D10); // IO used by pwm_io function
+DigitalOut my_pwm2(D5);
+
+
+int on_delay = 0;
+int off_delay = 0;
+int on_delay2 = 0;
+int off_delay2 = 0;
+
+void toggleOff(void);
+
+void toggleOn(void) {
+    my_pwm = 1;
+    timer.attach_us(toggleOff, on_delay);
+}
+
+void toggleOff(void) {
+    my_pwm = 0;
+    timer.attach_us(toggleOn, off_delay);
+}
+
+// p_us = signal period in micro_seconds
+// dc   = signal duty-cycle (0.0 to 1.0)
+void pwm_io(int p_us, float dc) {
+    timer.detach();
+    if ((p_us == 0) || (dc == 0)) {
+        my_pwm = 0;
+        return;
+    }
+    if (dc >= 1) {
+        my_pwm = 1;
+        return;
+    }
+    on_delay = (int)(p_us * dc);
+    off_delay = p_us - on_delay;
+    toggleOn();
+}
+
+////PMW2
+void toggleOff2(void);
+
+void toggleOn2(void) {
+    my_pwm2 = 1;
+    timer2.attach_us(toggleOff2, on_delay2);
+}
+
+void toggleOff2(void) {
+    my_pwm2 = 0;
+    timer2.attach_us(toggleOn2, off_delay2);
+}
+
+// p_us = signal period in micro_seconds
+// dc   = signal duty-cycle (0.0 to 1.0)
+void pwm_io2(int p_us, float dc) {
+    timer2.detach();
+    if ((p_us == 0) || (dc == 0)) {
+        my_pwm2 = 0;
+        return;
+    }
+    if (dc >= 1) {
+        my_pwm2 = 1;
+        return;
+    }
+    on_delay2 = (int)(p_us * dc);
+    off_delay2 = p_us - on_delay2;
+    toggleOn2();
+}
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PWM.h	Wed Apr 03 07:35:42 2019 +0000
@@ -0,0 +1,12 @@
+
+#ifndef MBED_PWM_H
+#define MBED_PWM_H
+
+//#include "mbed.h
+
+
+void pwm_io(int p_us, float dc);
+void pwm_io2(int p_us, float dc);
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Wed Apr 03 07:35:42 2019 +0000
@@ -0,0 +1,1 @@
+