timer tests with the STM32F303K8 nucleo board

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
OliverKeller
Date:
Fri Jun 10 17:52:10 2016 +0000
Commit message:
test to read pulse width in us on D1

Changed in this revision

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 e40146aa84f7 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jun 10 17:52:10 2016 +0000
@@ -0,0 +1,35 @@
+#include "mbed.h"
+
+Timer t;
+int rise_time = 0;
+int fall_time = 0;
+bool new_rise = false;
+bool new_fall = false;
+
+void pin_up(){
+    rise_time=t.read_us();
+    new_rise=true;
+}
+
+void pin_down(){
+    fall_time=t.read_us();
+    new_fall=true;
+}
+
+Serial pc(USBTX, USBRX);
+ 
+int main() {
+     pc.baud(230400);
+     t.start();
+     InterruptIn _interrupt(D1);
+     _interrupt.rise(&pin_up);
+     _interrupt.fall(&pin_down);
+    pc.printf("Hello World!");
+    while(1) {
+        if(new_rise && new_fall) {
+            pc.printf("%d\n\r", fall_time - rise_time);
+            new_rise=false;
+            new_fall=false;
+        }
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r e40146aa84f7 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Jun 10 17:52:10 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34
\ No newline at end of file