comparison autocal/txlevels.c @ 83:45ef4a06edfc

fc-rfcal-txband: initial implementation complete, ready to test
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 15 Jul 2017 23:09:46 +0000
parents a094db1453b1
children a2d4cab0a592
comparison
equal deleted inserted replaced
82:a094db1453b1 83:45ef4a06edfc
15 extern struct tx_basis_point tx_basis[MAX_BASIS_POINTS]; 15 extern struct tx_basis_point tx_basis[MAX_BASIS_POINTS];
16 extern unsigned num_basis_points; 16 extern unsigned num_basis_points;
17 extern struct tx_level tx_levels[MAX_TX_LEVELS]; 17 extern struct tx_level tx_levels[MAX_TX_LEVELS];
18 18
19 unsigned 19 unsigned
20 find_apc_for_target(target_dbm) 20 find_apc_for_target(target_dbm, pslope)
21 double target_dbm; 21 double target_dbm;
22 vout_t *pslope;
22 { 23 {
23 vout_t target_vout; 24 vout_t target_vout;
24 unsigned n; 25 unsigned n;
25 int apc_delta; 26 int apc_delta;
26 27
27 target_vout = dbm_to_vout(target_dbm); 28 target_vout = dbm_to_vout(target_dbm);
28 for (n = 0; n < num_basis_points - 1; n++) 29 for (n = 0; n < num_basis_points - 1; n++)
29 if (target_vout < tx_basis[n+1].vout) 30 if (target_vout < tx_basis[n+1].vout)
30 break; 31 break;
32 if (pslope)
33 *pslope = tx_basis[n].slope;
31 apc_delta = (target_vout - tx_basis[n].vout) / tx_basis[n].slope; 34 apc_delta = (target_vout - tx_basis[n].vout) / tx_basis[n].slope;
32 return tx_basis[n].apc + apc_delta; 35 return tx_basis[n].apc + apc_delta;
33 } 36 }
37
38 calibrate_tx_levels()
39 {
40 unsigned plnum, plidx, apc;
41 double target, meas;
42
43 printf("Calibrating Tx power levels\n");
44 printf("Starting RF Tx on the DUT\n");
45 do_rfe(RX_TX_TCH);
46
47 for (plnum = txcal_band->start_plnum; plnum <= txcal_band->end_plnum;
48 plnum++) {
49 do_txpw(TX_PWR_LEVEL, plnum);
50 plidx = plnum = txcal_band->start_plnum;
51 target = tx_levels[plidx].target;
52 apc = find_apc_for_target(target, &tx_levels[plidx].slope);
53 tx_levels[plidx].apc = apc;
54 do_txpw(TX_APC_DAC, apc);
55 usleep(20000);
56 meas = tx_power_meas();
57 printf(
58 "Tx power level #%u: target %.1f dBm, APC=%u, meas %.2f dBm (%+.2f)\n",
59 plnum, target, apc, meas, meas - target);
60 }
61
62 printf("Stopping RF Tx on the DUT\n");
63 do_rfe(STOP_ALL);
64 return(0);
65 }