Log Test Code

Dependencies:   C12832 mbed

Fork of VoltageThreshold by A Clark

Files at this revision

API Documentation at this revision

Comitter:
ajclark2
Date:
Tue Apr 08 21:01:31 2014 +0000
Parent:
2:d5b23f4e6884
Commit message:
Log Test

Changed in this revision

AntennaLog.cpp Show annotated file Show diff for this revision Revisions of this file
C12832.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show diff for this revision Revisions of this file
diff -r d5b23f4e6884 -r 9b47638100af AntennaLog.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AntennaLog.cpp	Tue Apr 08 21:01:31 2014 +0000
@@ -0,0 +1,85 @@
+#include "mbed.h"
+#define PI 3.1415
+#include "C12832.h"
+
+LocalFileSystem local("local");               // Create the local filesystem under the name "local"
+
+C12832 lcd(p5, p7, p6, p8, p11);
+
+Timer     t;
+
+AnalogIn   ain_v1(p19); // Input voltage from antenna
+
+    // Global variables declared
+    float v1, m, b, p_in, Pt, Gt, Gr, Pr, f, c, r;
+    float lv_r[250], lv_v1[250];
+    int k;
+
+int main()
+{
+    
+    // Open logging file
+    FILE *fp = fopen("/local/mBedOutp.m", "w"); 
+    
+    //logging setup 
+    for(k=0;k<250;k++)
+     { 
+        lv_r[k]      = 0.0;
+        lv_v1[k]     = 0.0;
+     }
+    k = 0;
+    
+    t.start();
+    while(k<250)
+    {
+    // Voltage to Power calculations
+    v1      = ain_v1*3.33;           // ain_v1;   // Comes from antenna (Can adjust manually for now) (3.3 is for scaling voltage properly... ask Feemster why this is necessary.
+    b       = 2.095;            // (volts) Direct function generator measurement
+    m       = .0316;            // volts/dBm (Calculated at 2000 MHz and 0 and -40 dBm)
+    p_in    = (v1-b)/m;         // Derived from v = m*p+b (linear relationship of voltage and power)
+   
+    // Range equation Terms
+    Pt      = .0398;            //(watts or 1mW or 0 dBm) Power Transmitted. This is ~16 dBm (.0398 watts) for an iphone 5
+    Gt      = 1;                // Unitless (1 for FG)                      Shouldn't both of these gains be 'directive' gains, not power gains
+    Gr      = .007;                // (.007) (7 mW) How do we get this? 7 milliwatt?
+    Pr      = pow(10, ((p_in-30)/10)); // (watts)
+    
+    // Free Space Loss Terms
+    f       = 2400000000;       // (Hz) This will be constant for a phone... but what to put for the FG
+    c       = 300000000;        // m/s
+    
+    r       = (c*(sqrt(Pt*Gt*Gr)/Pr))/(4*PI*f);
+    
+    printf("\rRange (meters)    = %.3f\n\r",r);
+    //printf("Power (watts)     = %.3f\n\r",Pr);
+    printf("Voltage into mBed = %.4f\n\r",v1);
+    //printf("%.4f\n\r",v1);
+    
+    lcd.cls();
+    lcd.locate(0,3);
+    lcd.printf("Voltage (volts) = %.4f",v1);
+    
+    lcd.locate(0,15);
+    lcd.printf("Range (meters) = %.4f",r);
+    
+      //LOG stuff
+    if(k<250)
+    {   lv_r[k]     = r;
+        lv_v1[k]    = v1;
+        k++;
+    }
+    
+    } // End of while=======================================================
+    
+    if(1)
+    {
+    
+    for(k=0;k<250;k++)
+    {   fprintf(fp,"lv.r(%d,1)  = %.3f;\n",k+1,lv_r[k]);
+        fprintf(fp,"lv.v1(%d,1) = %.4f;\n",k+1,lv_v1[k]);
+    }
+    
+    }// End of IF loop
+    
+    fclose(fp);
+} // End of main loop=======================================================
\ No newline at end of file
diff -r d5b23f4e6884 -r 9b47638100af C12832.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832.lib	Tue Apr 08 21:01:31 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/chris/code/C12832/#7de323fa46fe
diff -r d5b23f4e6884 -r 9b47638100af main.cpp
--- a/main.cpp	Wed Apr 02 12:26:31 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-#include "mbed.h"
-#define PI 3.1415
-
-Timer     t;
-
-AnalogIn   ain_v1(p20); // Input voltage from antenna
-
-
-int main()
-{
-    float v1, m, b, p_in, Pt, Gt, Gr, Pr, f, c, r;
-    
-    t.start();
-    while(t.read()<10.0)
-    {
-    // Voltage to Power calculations
-    v1      = ain_v1;           // ain_v1;   // Comes from mBed (Can adjust manually for now)
-    b       = 2.095;            // (volts) Direct function generator measurement
-    m       = .0316;            // volts/dBm (Calculated at 2000 MHz and 0 and -40 dBm)
-    p_in    = (v1-b)/m;         // Derived from v = m*p+b (linear relationship of voltage and power)
-   
-    // Range equation Terms
-    Pt      = .001;             //(watts or 1mW or 0 dBm) Power Transmitted. This is ~16 dBm (.0398 watts) for an iphone 5
-    Gt      = 1;                // Unitless (1 for FG)                      Shouldn't both of these gains be 'directive' gains, not power gains
-    Gr      = .007;                // (.007) (7 mW) How do we get this? Should be on datasheet... but calc required? 7 milliwatt?
-    Pr      = pow(10, ((p_in-30)/10)); // (watts)
-    
-    // Free Space Loss Terms
-    f       = 2000000000;       // (Hz) This will be constant for a phone... but what to put for the FG
-    c       = 300000000;        // m/s
-    
-    r       = (c*(sqrt(Pt*Gt*Gr)/Pr))/(4*PI*f);
-    
-    //printf("\rRange  (meters) = %.3f\n\r",r);
-    //printf("Power    (watts) = %.4f\n\r",Pr);
-    printf("Voltage into mBed = %.4f\n\r",v1);
-    }
-}
-
-
-
-
-