A Clark
/
RF_ID
Log Test Code
Fork of VoltageThreshold by
AntennaLog.cpp@3:9b47638100af, 2014-04-08 (annotated)
- Committer:
- ajclark2
- Date:
- Tue Apr 08 21:01:31 2014 +0000
- Revision:
- 3:9b47638100af
Log Test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ajclark2 | 3:9b47638100af | 1 | #include "mbed.h" |
ajclark2 | 3:9b47638100af | 2 | #define PI 3.1415 |
ajclark2 | 3:9b47638100af | 3 | #include "C12832.h" |
ajclark2 | 3:9b47638100af | 4 | |
ajclark2 | 3:9b47638100af | 5 | LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
ajclark2 | 3:9b47638100af | 6 | |
ajclark2 | 3:9b47638100af | 7 | C12832 lcd(p5, p7, p6, p8, p11); |
ajclark2 | 3:9b47638100af | 8 | |
ajclark2 | 3:9b47638100af | 9 | Timer t; |
ajclark2 | 3:9b47638100af | 10 | |
ajclark2 | 3:9b47638100af | 11 | AnalogIn ain_v1(p19); // Input voltage from antenna |
ajclark2 | 3:9b47638100af | 12 | |
ajclark2 | 3:9b47638100af | 13 | // Global variables declared |
ajclark2 | 3:9b47638100af | 14 | float v1, m, b, p_in, Pt, Gt, Gr, Pr, f, c, r; |
ajclark2 | 3:9b47638100af | 15 | float lv_r[250], lv_v1[250]; |
ajclark2 | 3:9b47638100af | 16 | int k; |
ajclark2 | 3:9b47638100af | 17 | |
ajclark2 | 3:9b47638100af | 18 | int main() |
ajclark2 | 3:9b47638100af | 19 | { |
ajclark2 | 3:9b47638100af | 20 | |
ajclark2 | 3:9b47638100af | 21 | // Open logging file |
ajclark2 | 3:9b47638100af | 22 | FILE *fp = fopen("/local/mBedOutp.m", "w"); |
ajclark2 | 3:9b47638100af | 23 | |
ajclark2 | 3:9b47638100af | 24 | //logging setup |
ajclark2 | 3:9b47638100af | 25 | for(k=0;k<250;k++) |
ajclark2 | 3:9b47638100af | 26 | { |
ajclark2 | 3:9b47638100af | 27 | lv_r[k] = 0.0; |
ajclark2 | 3:9b47638100af | 28 | lv_v1[k] = 0.0; |
ajclark2 | 3:9b47638100af | 29 | } |
ajclark2 | 3:9b47638100af | 30 | k = 0; |
ajclark2 | 3:9b47638100af | 31 | |
ajclark2 | 3:9b47638100af | 32 | t.start(); |
ajclark2 | 3:9b47638100af | 33 | while(k<250) |
ajclark2 | 3:9b47638100af | 34 | { |
ajclark2 | 3:9b47638100af | 35 | // Voltage to Power calculations |
ajclark2 | 3:9b47638100af | 36 | 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. |
ajclark2 | 3:9b47638100af | 37 | b = 2.095; // (volts) Direct function generator measurement |
ajclark2 | 3:9b47638100af | 38 | m = .0316; // volts/dBm (Calculated at 2000 MHz and 0 and -40 dBm) |
ajclark2 | 3:9b47638100af | 39 | p_in = (v1-b)/m; // Derived from v = m*p+b (linear relationship of voltage and power) |
ajclark2 | 3:9b47638100af | 40 | |
ajclark2 | 3:9b47638100af | 41 | // Range equation Terms |
ajclark2 | 3:9b47638100af | 42 | Pt = .0398; //(watts or 1mW or 0 dBm) Power Transmitted. This is ~16 dBm (.0398 watts) for an iphone 5 |
ajclark2 | 3:9b47638100af | 43 | Gt = 1; // Unitless (1 for FG) Shouldn't both of these gains be 'directive' gains, not power gains |
ajclark2 | 3:9b47638100af | 44 | Gr = .007; // (.007) (7 mW) How do we get this? 7 milliwatt? |
ajclark2 | 3:9b47638100af | 45 | Pr = pow(10, ((p_in-30)/10)); // (watts) |
ajclark2 | 3:9b47638100af | 46 | |
ajclark2 | 3:9b47638100af | 47 | // Free Space Loss Terms |
ajclark2 | 3:9b47638100af | 48 | f = 2400000000; // (Hz) This will be constant for a phone... but what to put for the FG |
ajclark2 | 3:9b47638100af | 49 | c = 300000000; // m/s |
ajclark2 | 3:9b47638100af | 50 | |
ajclark2 | 3:9b47638100af | 51 | r = (c*(sqrt(Pt*Gt*Gr)/Pr))/(4*PI*f); |
ajclark2 | 3:9b47638100af | 52 | |
ajclark2 | 3:9b47638100af | 53 | printf("\rRange (meters) = %.3f\n\r",r); |
ajclark2 | 3:9b47638100af | 54 | //printf("Power (watts) = %.3f\n\r",Pr); |
ajclark2 | 3:9b47638100af | 55 | printf("Voltage into mBed = %.4f\n\r",v1); |
ajclark2 | 3:9b47638100af | 56 | //printf("%.4f\n\r",v1); |
ajclark2 | 3:9b47638100af | 57 | |
ajclark2 | 3:9b47638100af | 58 | lcd.cls(); |
ajclark2 | 3:9b47638100af | 59 | lcd.locate(0,3); |
ajclark2 | 3:9b47638100af | 60 | lcd.printf("Voltage (volts) = %.4f",v1); |
ajclark2 | 3:9b47638100af | 61 | |
ajclark2 | 3:9b47638100af | 62 | lcd.locate(0,15); |
ajclark2 | 3:9b47638100af | 63 | lcd.printf("Range (meters) = %.4f",r); |
ajclark2 | 3:9b47638100af | 64 | |
ajclark2 | 3:9b47638100af | 65 | //LOG stuff |
ajclark2 | 3:9b47638100af | 66 | if(k<250) |
ajclark2 | 3:9b47638100af | 67 | { lv_r[k] = r; |
ajclark2 | 3:9b47638100af | 68 | lv_v1[k] = v1; |
ajclark2 | 3:9b47638100af | 69 | k++; |
ajclark2 | 3:9b47638100af | 70 | } |
ajclark2 | 3:9b47638100af | 71 | |
ajclark2 | 3:9b47638100af | 72 | } // End of while======================================================= |
ajclark2 | 3:9b47638100af | 73 | |
ajclark2 | 3:9b47638100af | 74 | if(1) |
ajclark2 | 3:9b47638100af | 75 | { |
ajclark2 | 3:9b47638100af | 76 | |
ajclark2 | 3:9b47638100af | 77 | for(k=0;k<250;k++) |
ajclark2 | 3:9b47638100af | 78 | { fprintf(fp,"lv.r(%d,1) = %.3f;\n",k+1,lv_r[k]); |
ajclark2 | 3:9b47638100af | 79 | fprintf(fp,"lv.v1(%d,1) = %.4f;\n",k+1,lv_v1[k]); |
ajclark2 | 3:9b47638100af | 80 | } |
ajclark2 | 3:9b47638100af | 81 | |
ajclark2 | 3:9b47638100af | 82 | }// End of IF loop |
ajclark2 | 3:9b47638100af | 83 | |
ajclark2 | 3:9b47638100af | 84 | fclose(fp); |
ajclark2 | 3:9b47638100af | 85 | } // End of main loop======================================================= |