Simple code to control 3 or 4 Wire Fans with tacho signal as feedback

Dependencies:   PwmIn mbed

Files at this revision

API Documentation at this revision

Comitter:
kevinganhito
Date:
Thu May 02 10:31:56 2019 +0000
Commit message:
Fan Controller;

Changed in this revision

PwmIn.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r d111bbbfd9e2 PwmIn.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PwmIn.lib	Thu May 02 10:31:56 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/simon/code/PwmIn/#6d68eb9b6bbb
diff -r 000000000000 -r d111bbbfd9e2 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu May 02 10:31:56 2019 +0000
@@ -0,0 +1,31 @@
+// STM32L432KC
+// https://os.mbed.com/platforms/ST-Nucleo-L432KC/
+
+
+#include "mbed.h"
+#include "PwmIn.h"
+
+#define PWM_FAN_1       D9
+#define TACHO_FAN_1     D11
+
+#define PWM_FREQUENCY   25000
+#define DUTY_CYCLE      50
+
+PwmOut  mypwm1(PWM_FAN_1);
+
+PwmIn   tacho1(TACHO_FAN_1);
+
+int main() {
+    
+    //PWM period
+
+    mypwm1.period_us((int) (PWM_FREQUENCY/25));
+    mypwm1.pulsewidth_us((int)(PWM_FREQUENCY*DUTY_CYCLE/100));       // Not lower than 10 us
+  
+    printf("PWM Duty is set to %.2f %%\n", mypwm1.read() * 100);
+    float speed1;
+    while(1) {
+        speed1 = tacho1.period() * 1000;
+        printf("Speed: %f\n",speed1);
+    }
+}
diff -r 000000000000 -r d111bbbfd9e2 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu May 02 10:31:56 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file