Anthony Mukuka Mwila / Mbed OS InterruptCounterTimertestUnit
Revision:
2:4772acaa0e64
Parent:
1:6017f9971cc8
Child:
3:369add4c5412
--- a/main.cpp	Tue Oct 03 17:54:57 2017 +0000
+++ b/main.cpp	Tue Oct 03 19:52:03 2017 +0000
@@ -4,39 +4,54 @@
 InterruptIn BLM_CHANNEL_A(PG_5);
 
 //Variable Initialisation
-int A_count = 0 ;
-int FinalCountTime =0 ;
+int A_count = 0 , FinalCountTime = 0 , CountFlag = 0 ;
 Timer Count_Timer ;
+
 // Interrupt Counter Increment Function
 void IncA()
 {
     A_count ++ ;
-    printf("%d",A_count);
- }
+    
+    
+    if(A_count == 1){
+        CountFlag = 1;
+        }
+        
+    if(A_count == 10000){
+        CountFlag = 2;
+        }    
+        
+        }
+    
+    
+    
+ 
             
  int main()
-{  
+{  printf(" The Program Is Running  ");
                 
     while (true) {
         
-        if (A_count == 1)
+        if ( CountFlag == 1)
         {
          // Starting timer at 1 Count
             Count_Timer.start();
+            CountFlag = 0 ;
         }
-        if (A_count == 10000)
+        if (CountFlag == 2 )
         {
          // Stopping timer at 10000 Counts 
             Count_Timer.stop();
             
          // Reading Counter Time 
-            FinalCountTime = Count_Timer.read();
+            FinalCountTime = Count_Timer.read_us();
             
         // Outputting Final count to Terminal
             printf("Final Count Time for 10000 counts is : %d ",FinalCountTime);
        
-        //Setting Counter to 0 again
+        //Setting Counter and CountFlag to 0
             A_count = 0;
+            CountFlag = 0;
         }
         
         // Calling of the increment function on the rising edge of a pulse