Callum Ellor / PulseWidthCapture

Dependents:   PulseWidthCapture_Program

Revision:
1:6bb38ae2e503
Parent:
0:7076676dd640
Child:
2:857c3c8e7a2f
--- a/PulseWidthCapture.cpp	Fri Dec 05 10:49:31 2014 +0000
+++ b/PulseWidthCapture.cpp	Wed Dec 10 10:33:32 2014 +0000
@@ -1,10 +1,12 @@
 #include "mbed.h"
 #include "TextLCD_16x4.h"
 #include "USBSerial.h"
-#include "PulseWidthCapture.h"
+#include "PulseWidthCapture/PulseWidthCapture.h"
 #include "rtos.h"
 
 USBSerial serial;
+TextLCD lcd(P0_21, P0_20, P1_15, P0_19, P0_5, P0_4, TextLCD::LCD16x4); // rs, e, d4, d5, d6, d7
+
 DigitalOut led(P0_9);
 DigitalOut led2(P0_8);
 DigitalOut led3(P0_7);
@@ -32,7 +34,7 @@
     
     LPC_CT32B0->PR  =  0;                           // Prescale counter divide by ...
     LPC_CT32B1->PR  =  0;
-    LPC_CT16B0->PR  =  239;             //200KHZ
+    LPC_CT16B0->PR  =  1000;             //
        
     /* Configure IOCON for the proper function of the capture pin. Use a pull-up.     */
     LPC_IOCON->PIO1_29 = (CT32B0_CAP1); // See page 125 of the 11U24 User Guide   
@@ -149,7 +151,7 @@
     // Start the timer
     LPC_CT16B0->TCR =  CT16B0_TCR_CEN; // enable
   
-    LPC_CT16B0->MR0 = 10000000;
+    LPC_CT16B0->MR0 = 1000000000;
      
 }
 
@@ -252,15 +254,45 @@
     //serial.printf("%.2f \n\r",ADCdata);
         
     //serial.printf("fall:%d \n\r", fall);
-    if (serial.writeable())
-    {
-    serial.printf("capturedata:%d \n\r", capturedata);
-    serial.printf("fall:%f \n\r", rise);
-    serial.printf("fall:%f \n\r", fall);
-    serial.printf("i_1:%.8f \n\r\n", i_1);
-    serial.printf("i:%.8f \n\r\n", ((i_1/48003280)*1000000));
+    
+    int x;
+    
+    for (x = 0; x<100; x++){
+    
+    //if (serial.writeable())
+    //{
+       // if ( x == 99) {
+    
+    
+    }
+    
+    period = rise + fall;
+    freq = (1/(float)period)*1000000;
     
-   }   
+    lcd.cls();
+    lcd.locate(0,0);
+   // lcd.printf("capturedata:%d \n\r", capturedata);
+   lcd.printf("rise:%.4f", rise);
+    lcd.locate(0,1);
+    lcd.printf("fall:%.4f", fall);
+    lcd.locate(0,2);
+    lcd.printf("period:%.4f", period);
+    lcd.locate(0,3);
+    lcd.printf("freq:%.2f", freq);
+    
+    
+    
+   // serial.printf("capturedata:%d \n\r", capturedata);
+   // serial.printf("fall:%f \n\r", rise);
+   // serial.printf("fall:%f \n\r", fall);
+   // serial.printf("i_1:%.8f \n\r\n", i_1);
+   // serial.printf("i:%.8f \n\r\n", ((i_1/48003280)*1000000));
+    
+    x = 0;
+ // }   
+  
+  
+  
    // serial.printf("j:%.8f \n\r\n", ((j_1/48003280)*1000000));
        
    // serial.printf("i+j:%.8f \n\r\n", m_1);