Log Test Code

Dependencies:   C12832 mbed

Fork of VoltageThreshold by A Clark

Committer:
ajclark2
Date:
Wed Apr 02 12:26:31 2014 +0000
Revision:
2:d5b23f4e6884
Parent:
1:2178a66e1223
Connett

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ajclark2 0:e99407475b62 1 #include "mbed.h"
ajclark2 2:d5b23f4e6884 2 #define PI 3.1415
ajclark2 0:e99407475b62 3
ajclark2 2:d5b23f4e6884 4 Timer t;
ajclark2 2:d5b23f4e6884 5
ajclark2 2:d5b23f4e6884 6 AnalogIn ain_v1(p20); // Input voltage from antenna
ajclark2 2:d5b23f4e6884 7
ajclark2 0:e99407475b62 8
ajclark2 0:e99407475b62 9 int main()
ajclark2 0:e99407475b62 10 {
ajclark2 2:d5b23f4e6884 11 float v1, m, b, p_in, Pt, Gt, Gr, Pr, f, c, r;
ajclark2 0:e99407475b62 12
ajclark2 2:d5b23f4e6884 13 t.start();
ajclark2 2:d5b23f4e6884 14 while(t.read()<10.0)
ajclark2 2:d5b23f4e6884 15 {
ajclark2 1:2178a66e1223 16 // Voltage to Power calculations
ajclark2 2:d5b23f4e6884 17 v1 = ain_v1; // ain_v1; // Comes from mBed (Can adjust manually for now)
ajclark2 2:d5b23f4e6884 18 b = 2.095; // (volts) Direct function generator measurement
ajclark2 2:d5b23f4e6884 19 m = .0316; // volts/dBm (Calculated at 2000 MHz and 0 and -40 dBm)
ajclark2 2:d5b23f4e6884 20 p_in = (v1-b)/m; // Derived from v = m*p+b (linear relationship of voltage and power)
ajclark2 1:2178a66e1223 21
ajclark2 1:2178a66e1223 22 // Range equation Terms
ajclark2 2:d5b23f4e6884 23 Pt = .001; //(watts or 1mW or 0 dBm) Power Transmitted. This is ~16 dBm (.0398 watts) for an iphone 5
ajclark2 2:d5b23f4e6884 24 Gt = 1; // Unitless (1 for FG) Shouldn't both of these gains be 'directive' gains, not power gains
ajclark2 2:d5b23f4e6884 25 Gr = .007; // (.007) (7 mW) How do we get this? Should be on datasheet... but calc required? 7 milliwatt?
ajclark2 2:d5b23f4e6884 26 Pr = pow(10, ((p_in-30)/10)); // (watts)
ajclark2 0:e99407475b62 27
ajclark2 1:2178a66e1223 28 // Free Space Loss Terms
ajclark2 2:d5b23f4e6884 29 f = 2000000000; // (Hz) This will be constant for a phone... but what to put for the FG
ajclark2 2:d5b23f4e6884 30 c = 300000000; // m/s
ajclark2 2:d5b23f4e6884 31
ajclark2 2:d5b23f4e6884 32 r = (c*(sqrt(Pt*Gt*Gr)/Pr))/(4*PI*f);
ajclark2 0:e99407475b62 33
ajclark2 2:d5b23f4e6884 34 //printf("\rRange (meters) = %.3f\n\r",r);
ajclark2 2:d5b23f4e6884 35 //printf("Power (watts) = %.4f\n\r",Pr);
ajclark2 2:d5b23f4e6884 36 printf("Voltage into mBed = %.4f\n\r",v1);
ajclark2 2:d5b23f4e6884 37 }
ajclark2 0:e99407475b62 38 }
ajclark2 0:e99407475b62 39
ajclark2 0:e99407475b62 40
ajclark2 0:e99407475b62 41
ajclark2 1:2178a66e1223 42
ajclark2 1:2178a66e1223 43