Test session

Dependencies:   FatFileSystem MCP23017 WattBob_TextLCD mbed

Fork of Assignment_2_herpe by Xavier Herpe

Revision:
4:48761259552a
Parent:
3:5883d1a2c5b0
--- a/XG_2.cpp	Tue Mar 07 17:20:46 2017 +0000
+++ b/XG_2.cpp	Tue Mar 14 14:46:43 2017 +0000
@@ -31,7 +31,7 @@
 PwmOut servo(p21); // Servo output
 DigitalOut TestPin(p20); // Pin only used to test program and measure time
 SDFileSystem sd(p5, p6, p7, p8, "sd"); // The pinout on the mbed Cool Components workshop board
-
+DigitalIn  switch_pin(p14, PullDown);
 
 //=====================================================================================
 // Internal objects declaration
@@ -47,7 +47,6 @@
 //=====================================================================================
 const int SampFreq = 100; // Sampling frequency is 10kHz (100us)
 
-
 //=====================================================================================
 // Variables declaration
 //=====================================================================================
@@ -196,38 +195,17 @@
 // Tasks
 //=====================================================================================
 
-// Task 1: Measure TTL input frequency
+// Task 1: Measure the freqeuncy of a 3.3v square wave signal
 void Task1()
 {
+task 1
+
     timer.reset();
-    
-    // If the input signal is low, wait for a rising edge to start counting
-    if (TTL == 0)
-    {
-        WaitRisEdge(); // Call subroutine to wait for rising edge
-        timer.start(); // Start timer
-        while(TTL == 1) // Keep counting as long as signal is high
-        {
-            wait_us(SampFreq);
-        }
-    }
-    
-    // If the input signal is high, wait for a falling edge to start counting
-    else if (TTL == 1)
-    {
-        WaitFalEdge(); // Call subroutine to wait for falling edge
-        timer.start(); // Start timer
-        while(TTL == 0) // Keep counting as long as signal is high
-        {
-            wait_us(SampFreq);
-        }
-    }
-
-    timer.stop(); // Stop counting when signal changes
-    period = timer.read_us()*2; // Convert the time into a period
-    frequency = 1000000/period; // Convert the period into a frequency
-}
-
+    while(freqCountPin == 0) {}
+    timer.start();      
+    while(freqCountPin == 1) {}
+    timer.stop();
+    frequency =  2000000 / timer.read_us()
 
 
 // Task 2: display the measured frequency on LCD screen