Capstone project files

Dependencies:   mbed-dsp mbed capstone_display_2

Files at this revision

API Documentation at this revision

Comitter:
ryanyuyu
Date:
Thu Apr 24 23:52:30 2014 +0000
Parent:
8:dcc69fc6d88b
Child:
10:ab4209a25811
Commit message:
Final? All 4 gain stages and adjustable gain worked in.

Changed in this revision

capstone_display.lib 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/capstone_display.lib	Thu Apr 24 22:59:51 2014 +0000
+++ b/capstone_display.lib	Thu Apr 24 23:52:30 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/ryanyuyu/code/capstone_display_2/#a2b4e76a5f01
+http://mbed.org/users/ryanyuyu/code/capstone_display_2/#51ab9f11c992
--- a/main.cpp	Thu Apr 24 22:59:51 2014 +0000
+++ b/main.cpp	Thu Apr 24 23:52:30 2014 +0000
@@ -8,8 +8,8 @@
 #define f_sampling 2000 //the sampling frequency
 #define NumTaps 27      //the number of filter coefficients
 #define BlockSize 512  //the size of the buffer
-#define numCallibrationSteps 6 //the number of callibration steps or points
-#define numGainStages 2
+#define numCallibrationSteps 12 //the number of callibration steps or points
+#define numGainStages 4
 Serial pc(USBTX, USBRX); //USB serial for PC, to be removed later
 AnalogOut waveOut(p18); //for debugging
 
@@ -39,18 +39,19 @@
 float minThreshold;
 float maxThresholds[numGainStages];
 float average = 0;
-float pastAverage = 0;
+float pastAverage1 = 0;
+float pastAverage2 = 0;
 int callibrationStep;
 int state;
 int gainStage;
 float gainMultiplier;
-float gainCutoffs[numGainStages] = {20.0, 100.0};
+float gainCutoffs[numGainStages] = {20.0, 100.0, 1200.0, 10000.0};
 //gainCutoffs = {20.0, 100.0, 1200.0, 10000.0};
 float gain1;
 float gain0;
 //These constants are for linear interpolation for the varius gain stage.  Two linear equations per stage (piecewise)
 float linearSamples[numCallibrationSteps];
-int callibrationPoints[numCallibrationSteps] = {6, 10, 14, 14, 20, 24};
+int callibrationPoints[numCallibrationSteps] = {6, 10, 14, 14, 20, 24, 26, 36, 50, 50, 62, 78};
 //callibrationPoints = {6, 10, 14, 14, 20, 24, 26, 36, 50, 50, 62, 78};
 
 float mLower[numGainStages]; //m (slope)  lower portion
@@ -270,7 +271,10 @@
     while(button.read() == 0) wait_ms(10); //poll button press every 10ms
     //char* outputString = newString(32);
     //outputString = "Button pressed.";
+    lcd.clearscreen();
     lcd.print("Button pressed.");
+    wait_ms(250);
+    lcd.clearscreen();
 }
 
 
@@ -297,14 +301,13 @@
     case 1:
         if (value > mid[1]) return mLower[1]*value + bLower[1];
         else return mUpper[1]*value + bUpper[1];
-    /*
     case 2:
         if (value > mid[2]) return mLower[2]*value + bLower[2];
         else return mUpper[2]*value + bUpper[2];
     case 3:
         if (value > mid[3]) return mLower[3]*value + bLower[3];
         else return mUpper[3]*value + bUpper[3];
-        */
+        //*/
     default:
         return 0;
     }
@@ -329,7 +332,7 @@
         if (gainStage < numGainStages) gainStage++;
         else lcd.print("No beacon found.");
     }
-    else lcd.print("");
+    else lcd.clearscreen();
     setGain( gainCutoffs[gainStage] );
     //return gainStage; 
 }
@@ -361,22 +364,24 @@
         }
         else
         {
-            pc.printf("Av=%f gainStage=%d\n\r", gainMultiplier, gainStage);
-            if (pastAverage*1.15 < average || pastAverage < minThreshold*3) //not yet maxed, so bump up gainMultiplier
+            //pc.printf("Av=%f gainStage=%d\n\r", gainMultiplier, gainStage);
+            if (pastAverage1*1.15 < average || pastAverage1 < minThreshold*3) //not yet maxed, so bump up gainMultiplier
             {
                 gainMultiplier *= 1.2;
                 gainCutoffs[ gainStage ] *= 1.2;
                 enforceGainStage();
-                pastAverage = average;
+                pastAverage2 = pastAverage1;
+                pastAverage1 = average;
             }
             else //move onto next callibration step
             {
                 adjusting = true;
-                linearSamples[ callibrationStep-1 ] = pastAverage; //record the intensity
-                maxThresholds[ gainStage ] = average;
-                gainCutoffs[ gainStage ] /= 1.2;
+                linearSamples[ callibrationStep-1 ] = pastAverage2; //record the intensity from 2 stages ago
+                maxThresholds[ gainStage ] = pastAverage1;
+                gainCutoffs[ gainStage ] /= 1.44;
                 enforceGainStage();
-                pastAverage = minThreshold;
+                pastAverage1 = minThreshold;
+                pastAverage2 = minThreshold;
                 callibrationStep++;
             }
             state = 1;