annotate autocal/txlevels.c @ 102:80281b67511f

fc-rfcal-txband: fixed bug in the corner case when the target power level is above the highest basis point
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 12 Aug 2017 08:47:09 +0000
parents b0618796d28d
children 7ad0495991ed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
82
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * The calibration of Tx power levels is implemented here.
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
101
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
5 #include <math.h>
82
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <rvinterf/l1tm.h>
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <rvinterf/exitcodes.h>
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "txband.h"
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 extern double tx_power_meas();
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern vout_t dbm_to_vout();
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern struct txcal_band *txcal_band;
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern struct tx_basis_point tx_basis[MAX_BASIS_POINTS];
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern unsigned num_basis_points;
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 extern struct tx_level tx_levels[MAX_TX_LEVELS];
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 unsigned
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
21 find_apc_for_target(target_dbm, pslope)
82
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 double target_dbm;
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
23 vout_t *pslope;
82
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 {
102
80281b67511f fc-rfcal-txband: fixed bug in the corner case when
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
25 vout_t target_vout, slope;
82
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 unsigned n;
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 int apc_delta;
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 target_vout = dbm_to_vout(target_dbm);
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 for (n = 0; n < num_basis_points - 1; n++)
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (target_vout < tx_basis[n+1].vout)
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 break;
102
80281b67511f fc-rfcal-txband: fixed bug in the corner case when
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
33 if (n == num_basis_points - 1)
80281b67511f fc-rfcal-txband: fixed bug in the corner case when
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
34 slope = tx_basis[n-1].slope;
80281b67511f fc-rfcal-txband: fixed bug in the corner case when
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
35 else
80281b67511f fc-rfcal-txband: fixed bug in the corner case when
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
36 slope = tx_basis[n].slope;
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
37 if (pslope)
102
80281b67511f fc-rfcal-txband: fixed bug in the corner case when
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
38 *pslope = slope;
80281b67511f fc-rfcal-txband: fixed bug in the corner case when
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
39 apc_delta = (target_vout - tx_basis[n].vout) / slope;
82
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 return tx_basis[n].apc + apc_delta;
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 }
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
42
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
43 calibrate_tx_levels()
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
44 {
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
45 unsigned plnum, plidx, apc;
101
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
46 double target, meas, error;
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
47 int nanflag = 0, errflag = 0;
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
48
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
49 printf("Calibrating Tx power levels\n");
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
50 printf("Starting RF Tx on the DUT\n");
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
51 do_rfe(RX_TX_TCH);
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
52
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
53 for (plnum = txcal_band->start_plnum; plnum <= txcal_band->end_plnum;
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
54 plnum++) {
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
55 do_txpw(TX_PWR_LEVEL, plnum);
84
a2d4cab0a592 fc-rfcal-txband: works after a couple of bugfixes
Mychaela Falconia <falcon@freecalypso.org>
parents: 83
diff changeset
56 plidx = plnum - txcal_band->start_plnum;
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
57 target = tx_levels[plidx].target;
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
58 apc = find_apc_for_target(target, &tx_levels[plidx].slope);
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
59 tx_levels[plidx].apc = apc;
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
60 do_txpw(TX_APC_DAC, apc);
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
61 usleep(20000);
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
62 meas = tx_power_meas();
101
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
63 if (isnan(meas))
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
64 nanflag = 1;
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
65 error = meas - target;
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
66 if (error < -2.0 || error > 2.0)
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
67 errflag = 1;
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
68 printf(
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
69 "Tx power level #%u: target %.1f dBm, APC=%u, meas %.2f dBm (%+.2f)\n",
101
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
70 plnum, target, apc, meas, error);
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
71 }
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
72
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
73 printf("Stopping RF Tx on the DUT\n");
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
74 do_rfe(STOP_ALL);
101
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
75 if (nanflag) {
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
76 printf("Error: got NaN power measurement, aborting\n");
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
77 exit(ERROR_TARGET);
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
78 }
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
79 if (errflag) {
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
80 printf("Error: Tx power off by more than 2 dBm, aborting\n");
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
81 exit(ERROR_TARGET);
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
82 }
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
83 return(0);
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
84 }