create and send the file to pc

Dependencies:   MCP23017 WattBob_TextLCD mbed

Fork of HelloWorld by Simon Ford

Files at this revision

API Documentation at this revision

Comitter:
haseo1989
Date:
Tue Mar 04 15:37:21 2014 +0000
Parent:
6:94ee12962e13
Commit message:
test whole system

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 94ee12962e13 -r 0c36c40f2ffd main.cpp
--- a/main.cpp	Mon Mar 03 10:33:15 2014 +0000
+++ b/main.cpp	Tue Mar 04 15:37:21 2014 +0000
@@ -30,6 +30,7 @@
 MCP23017 *par_port; // pointer to 16-bit parallel I/O object 
 WattBob_TextLCD *lcd; // pointer to 2*16 chacater LCD object 
 Timer tmr;            //define a timer for calculating the frequency
+Timer Tcheck;                           //define a timer for testing whether task1 is overtime of not
 
 LocalFileSystem local("local"); //Create the local filesystem under the name "local"
 FILE *fp;           //define a file
@@ -54,46 +55,51 @@
 {
     float tm_val1,tm_val2 = 0;
     int flag,flag_err = 0;
-    
-    Timer Tcheck;                           //define a timer for calculating the frequency
-        
+               
     Tcheck.reset();                 //to check wether the testing is over time or not
     Tcheck.start();
               
-    tmr.reset();
+    
         
     while(IP_wave)
     {   
         tm_val2 = Tcheck.read();
         flag = tm_val2*1000;
         
-        if(flag >= 20)                    //if the signal keeps hi in 20ms , it will end testing. the flag_err will be set one
+        if(flag >= 10)                    //if the signal keeps hi in 20ms , it will end testing. the flag_err will be set one
             {
                 flag_err = 1;             
                 break;
-                }
+            }
         }
 
     while( !IP_wave ) 
     {    
         tm_val2 = Tcheck.read();
         flag = tm_val2*1000;
-        if((flag >= 40) || flag_err == 1)                    //if the signal keeps low in 50ms , it will end testing.
-            flag_err = 1;
-            break;
+        
+        if((flag >= 20) || flag_err == 1)                    //if the signal keeps low in 50ms , it will end testing.
+            {
+                flag_err = 1;
+                break;
+            }
     }
     Tcheck.stop();
-    Tcheck.reset();
     
+    if( flag_err == 0 )
+    {
+    tmr.reset();
     tmr.start();
-    while(IP_wave)
+    while( IP_wave )
     {
 
         }
     tmr.stop();
     
     tm_val1 = tmr.read_us();
-    if( (tm_val1 > 500.0) && (flag_err == 0) )               //if impulse last more than 500us, it will get its frequency
+    }
+    
+    if( tm_val1 > 500.0 )               //if impulse last more than 500us, it will get its frequency
         freq = 500000/tm_val1;                               //the frenquency of the wave
     else 
         freq = 0;
@@ -229,9 +235,7 @@
         if(tick%4 == 0)
             T2_checkSW();
             
-        tick = tick%900;
-
-          
+        if(tick == 1800) tick = 1;    
         }
     return 0;
     }