Based the Library PwmIn by Simon Ford expanded with enable_irq and disable_irq for separate input signals. Program gives no real advantage above the original Library.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
GerritPathuis
Date:
Fri Jan 03 18:47:33 2014 +0000
Parent:
1:4bd14d5374c3
Commit message:
Tested with two channels connected to a function generator

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 4bd14d5374c3 -r 79b52803da22 main.cpp
--- a/main.cpp	Thu Jan 02 14:01:30 2014 +0000
+++ b/main.cpp	Fri Jan 03 18:47:33 2014 +0000
@@ -1,8 +1,14 @@
 //////////////////////////////////////
-// basen on PwmIn Library
-// Basis is to disable the interrupts
+// Based on PwmIn Library
+// The basis is to disable the interrupts
 // of the other PwmIn inputs
-///////////////////////////////////////
+// Connected to the function generator
+// puls on both inputs at the exact
+// same time.
+// Works excellent but further testing
+// showed that there is no real advantage 
+// above the original PmwIn library
+//////////////////////////////////////
 #include "mbed.h"
 #include "InterruptIn.h"
 #define NR 20
@@ -14,7 +20,8 @@
     float period();
     float pulsewidth();
     float dutycycle();
-    void disable();  
+    void disable();
+    void enable();
 
 protected:
     void rise();
@@ -55,7 +62,12 @@
 
 void PwmIn::disable()
 {
-   // _p.enable_irq();
+    _p.disable_irq();
+}
+
+void PwmIn::enable()
+{
+    _p.enable_irq();
 }
 
 void PwmIn::rise()
@@ -70,27 +82,50 @@
 }
 
 struct product {
-    float pulse;
-    float width;
-    float duty;
+    float pulsewidth;
+    float period;
+    float cycle;
 } acc_a[NR], acc_b[NR], acc_c[NR],acc_d[NR];
 
 
 int main()
 {
-    char pbuffer[60]="---";
+    char pbuffer[512]="---";
     int i;
 
+    pc.baud(9600);
+    sprintf(pbuffer, "Start test, baudrate is set to 9600 \n\r");
+    pc.puts(pbuffer);
+
+    a.disable();
+    b.disable();
     while(1) {
-     //   a.disable();                            // Stop interrupts for sensor B
+        //-------------- sensor a--------------------
+        a.enable(); // signal on input 50Hz is period of 20 milli second
+        wait_ms(40); // signal on input 50Hz is period of 20 milli second
         for (i=0; i<NR; i++) {
-            acc_a[i].duty= a.dutycycle();       // Sensor A
-            acc_b[i].duty= b.dutycycle();
+            acc_a[i].pulsewidth= a.pulsewidth();    // Sensor A
+            acc_a[i].period= a.period();            // Sensor A
+            acc_a[i].cycle= a.dutycycle();          // Sensor A
         }
+        a.disable();
+
+        //-------------- sensor b--------------------
+        b.enable(); // signal on input 50Hz is period of 20 milli second
+        wait_ms(40); // 50Hz is period of 20 milli second
+        for (i=0; i<NR; i++) {
+            acc_b[i].pulsewidth= b.pulsewidth();    // Sensor B
+            acc_b[i].period= b.period();            // Sensor B
+            acc_b[i].cycle= b.dutycycle();          // Sensor B
+        }
+        b.disable();
 
         for (i=0; i<NR; i++) {
-            sprintf(pbuffer, " a= %f, b= %f \n\r", acc_a[i].duty, acc_b[i].duty);
+            sprintf(pbuffer, "a_pulse= %f, a_period= %f, a_c= %f, b_puls= %f, b_period= %f, b_cycle %f\n\r", acc_a[i].pulsewidth, acc_a[i].period, acc_a[i].cycle, acc_b[i].pulsewidth, acc_b[i].period, acc_b[i].cycle);
             pc.puts(pbuffer);
         }
+        sprintf(pbuffer, "\n\r");
+        pc.puts(pbuffer);
+        wait_ms(100);
     }
 }
diff -r 4bd14d5374c3 -r 79b52803da22 mbed.bld
--- a/mbed.bld	Thu Jan 02 14:01:30 2014 +0000
+++ b/mbed.bld	Fri Jan 03 18:47:33 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/dc225afb6914
\ No newline at end of file