Tummas Tomasson / Mbed 2 deprecated PingDetector_mbedadc

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
tummastt
Date:
Tue Aug 21 14:23:03 2012 +0000
Parent:
0:efb27fbc92c0
Commit message:
Pinger detection program for mbed

Changed in this revision

Parameters.h Show annotated file Show diff for this revision Revisions of this file
PingDetect/FFT.cpp Show annotated file Show diff for this revision Revisions of this file
PingDetect/FFT.h Show annotated file Show diff for this revision Revisions of this file
PingDetect/PingDetect.cpp Show annotated file Show diff for this revision Revisions of this file
PingDetect/PingDetect.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Parameters.h	Mon Jul 30 09:57:42 2012 +0000
+++ b/Parameters.h	Tue Aug 21 14:23:03 2012 +0000
@@ -14,7 +14,7 @@
 //-------------------------------
 // Used for FFT class
 #define SAMPLES 256  // Number of points used for FFT
-#define FREQ 15000 // Frequency in Hz of pinger 
+#define FREQ 13000 // Frequency in Hz of pinger 
 #define AMPLITUDE_LIMIT 35 // amplitude limit for detection
 #define SAMPLE_RATE 60500 // Sampling frequency
 #define DCOFFSET 2048 // Binary offset voltage
--- a/PingDetect/FFT.cpp	Mon Jul 30 09:57:42 2012 +0000
+++ b/PingDetect/FFT.cpp	Tue Aug 21 14:23:03 2012 +0000
@@ -1,3 +1,7 @@
+/*
+    Program to caluclate the FFT strength of a frequency 
+*/
+
 #include "FFT.h"
 
 // Using the Mellen FFT
@@ -7,10 +11,8 @@
 
     CalculateFFT(data);
 
-    // adding the center frequencies with the 4 closesed frequencies
-//    amp = my[centerFreq-2]+my[centerFreq]+my[centerFreq+2];
+    // adding the center frequencies with the 2 closesed frequencies
     amp = my[centerFreq-2]+my[centerFreq]+my[centerFreq+2];
-//    return amp;
     if (amp >= AMPLITUDE_LIMIT)
         return found; // indicating pinger signal found
 
--- a/PingDetect/FFT.h	Mon Jul 30 09:57:42 2012 +0000
+++ b/PingDetect/FFT.h	Tue Aug 21 14:23:03 2012 +0000
@@ -1,7 +1,6 @@
-/*  
-
-    
- */
+/*
+    Program to caluclate the FFT strength of a frequency 
+*/
  
 #ifndef FFT_H
 #define FFT_H
--- a/PingDetect/PingDetect.cpp	Mon Jul 30 09:57:42 2012 +0000
+++ b/PingDetect/PingDetect.cpp	Tue Aug 21 14:23:03 2012 +0000
@@ -1,3 +1,7 @@
+/*
+    Program to control the system. 
+*/
+
 #include "PingDetect.h"
 
 #define ClearBuffer LPC_UART0->FCR | 0x06
@@ -24,12 +28,7 @@
         DataBack[i] = adc.read(p20);
     }
 
-//    pc.printf("%i\n\r", fft.DetectSignal(DataFront));
-//    return notFound;
-    l0=1;
-    // return found;
     if (fft.DetectSignal(DataFront) == found) {
-        l0=1;
         return found;
     } else {
         return notFound;
--- a/PingDetect/PingDetect.h	Mon Jul 30 09:57:42 2012 +0000
+++ b/PingDetect/PingDetect.h	Tue Aug 21 14:23:03 2012 +0000
@@ -1,7 +1,6 @@
-/*  
-    
-    
- */
+/*
+    Program to control the system. 
+*/
  
 #ifndef PINGDETECT_H
 #define PINGDETECT_H
@@ -14,7 +13,7 @@
 
 class PingDetect {
 public:
-    PingDetect () : pc(USBTX, USBRX), adc(mbedSAMPLE_RATE,1), l0(LED1), local("local"),TempCmd(0) {
+    PingDetect () : pc(USBTX, USBRX), adc(mbedSAMPLE_RATE,1), local("local"),TempCmd(0) {
         pc.baud(921600);
         
         //Set up ADC on pin 20
@@ -32,7 +31,9 @@
     }
     int Search();
     /*  
-        
+        Samples data from the filter and checks it the pinger frequency
+        is above the defined threshold.
+            returns 
     */
     
     void Run();
@@ -57,7 +58,6 @@
     Serial pc;
     FFT fft;
     mbedADC adc;
-    DigitalOut l0;
     LocalFileSystem local;
     char TempCmd;
     int i,k, no;
--- a/main.cpp	Mon Jul 30 09:57:42 2012 +0000
+++ b/main.cpp	Tue Aug 21 14:23:03 2012 +0000
@@ -1,9 +1,6 @@
 /*
-    D- (Orange) is pin5 on AUX
-    D+ (Yellow) is pin8 on AUX
-    GND is pin 1 on AUX
-    +12V is pin 3 on AUX
-
+    Program to detect a pinger signal and send
+    it back to the PC for processing
  */
 
 #include "mbed.h"
@@ -38,7 +35,6 @@
 
     while (1) {
 
-//        PD.SendSerial(Command);
         //
         switch (Command) {
             case start:
@@ -63,6 +59,7 @@
     }
 }
 
+// Stops all functions.
 void Stop() {
     t.detach();
     l2=0;
@@ -71,32 +68,38 @@
     Command = doNothing;
 }
 
+// sets the find function to run every 5ms
 void Start() {
     l2=1;
     t.detach();
-//    t.attach_us(&Find,10000);
     t.attach_us(&Find,5000);
     Command = doNothing;
 }
 
+// Calculates the FFT and sends to the PC 100 times
 void CalculateFFT() {
     t.detach();
     PD.CalculateFFT();    
     Command = doNothing;
 }
 
+// The run function samples the data from the filters
+// and sends to it to the PC
 void Run () {
+    l4=0;
     l3=!l3;
     PD.Run();
 }
 
+// Run the find function, if the signal is is found,
+// it sets the run function to run every second and 
+// ensures the detected signal is in the centre of
+// the sampling window
 void Find() {
-    l4=!l4;
+    l4=1;
     Found = PD.Search();
     if(Found == found){
-        l2=0;
         t.detach();
-//        wait_ms(1000-TIME_OFFSET);
         wait_ms(1000-TIME_OFFSET);
         t.attach(&Run,1);
         Run();