annotate autocal/vcxomain.c @ 27:841dd03d5c85

fc-rfcal-vcxo: almost done
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 22 May 2017 23:10:34 +0000
parents a2e4da9d85cc
children ba4b6877e227
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module contains the main() function for fc-rfcal-vcxo.
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
27
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
5 #include <math.h>
21
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <rvinterf/l1tm.h>
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <rvinterf/exitcodes.h>
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "stdband.h"
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #define VCXOCAL_BAND 900
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #define VCXOCAL_BAND_RFPW RFPW_STD_BAND(6, 0)
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #define VCXOCAL_ARFCN 40
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
24
0b6881281d86 fc-rfcal-vcxo ready for first test
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
16 extern float vcxo_freq_meas();
0b6881281d86 fc-rfcal-vcxo ready for first test
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
17
0b6881281d86 fc-rfcal-vcxo ready for first test
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
18 static float freq_max_neg, freq_max_pos;
0b6881281d86 fc-rfcal-vcxo ready for first test
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
19 static float lin_a, lin_b, lin_a2, lin_b2;
26
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
20 static int zero_search_dac1, zero_search_dac2, zero_search_incr;
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
21 static float zero_search_freq1, zero_search_freq2;
27
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
22 static float dac_min, dac_max, dac_init;
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
23 static int dac_init_int;
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
24 static float Psi_sta, Psi_st;
24
0b6881281d86 fc-rfcal-vcxo ready for first test
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
25
23
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
26 prepare_rf_test_system()
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
27 {
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
28 char cmd[80];
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
29
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
30 printf("Preparing RF test system for VCXO calibration\n");
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
31 sprintf(cmd, "vcxo-cal-setup %d %d\n", VCXOCAL_BAND, VCXOCAL_ARFCN);
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
32 tsid_command(cmd);
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
33 return(0);
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
34 }
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
35
21
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 main(argc, argv)
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 char **argv;
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 {
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 socket_pathname_options(argc, argv);
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 connect_rvinterf_socket();
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 connect_tsid_socket();
23
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
42 prepare_rf_test_system();
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
43
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
44 printf("Putting the DUT into Test Mode\n");
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
45 do_tms(1);
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
46 do_rfpw(STD_BAND_FLAG, VCXOCAL_BAND_RFPW);
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
47 do_rfpw(TCH_ARFCN, VCXOCAL_ARFCN);
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
48 do_rfpw(AFC_ENA_FLAG, 0);
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
49 do_txpw(TX_PWR_LEVEL, 12);
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
50 printf("Starting RF Tx on the DUT\n");
9a9fd9ebe799 autocal/vcxomain.c: coming along
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
51 do_rfe(RX_TX_TCH);
21
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52
24
0b6881281d86 fc-rfcal-vcxo ready for first test
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
53 /* initial measurements at the DAC extremes */
0b6881281d86 fc-rfcal-vcxo ready for first test
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
54 freq_max_neg = vcxo_freq_meas(-2048, "max-neg");
0b6881281d86 fc-rfcal-vcxo ready for first test
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
55 freq_max_pos = vcxo_freq_meas(2048, "max-pos");
0b6881281d86 fc-rfcal-vcxo ready for first test
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
56 lin_a = (freq_max_pos - freq_max_neg) / 4096.0f;
0b6881281d86 fc-rfcal-vcxo ready for first test
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
57 lin_b = freq_max_pos - lin_a * 2048.0f;
26
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
58 zero_search_dac1 = -lin_b / lin_a;
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
59 zero_search_freq1 = vcxo_freq_meas(zero_search_dac1, "zero-search");
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
60
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
61 /* search for zero crossing */
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
62 if (zero_search_freq1 < 0)
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
63 zero_search_incr = 100;
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
64 else
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
65 zero_search_incr = -100;
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
66 for (;;) {
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
67 zero_search_dac2 = zero_search_dac1 + zero_search_incr;
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
68 zero_search_freq2 = vcxo_freq_meas(zero_search_dac2,
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
69 "zero-search");
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
70 if (zero_search_incr > 0 && zero_search_freq2 >= 0)
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
71 break;
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
72 if (zero_search_incr < 0 && zero_search_freq2 < 0)
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
73 break;
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
74 zero_search_dac1 = zero_search_dac2;
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
75 zero_search_freq1 = zero_search_freq2;
a2e4da9d85cc fc-rfcal-vcxo: search for zero crossing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
76 }
21
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77
27
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
78 /* second linear approximation */
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
79 lin_a2 = (zero_search_freq2 - zero_search_freq1) /
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
80 (float)(zero_search_dac2 - zero_search_dac1);
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
81 lin_b2 = zero_search_freq2 - lin_a2 * zero_search_dac2;
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
82
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
83 /* DAC settings */
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
84 dac_min = (-13500.0f - lin_b) / lin_a;
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
85 dac_max = (13500.0f - lin_b) / lin_a;
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
86 dac_init = -lin_b2 / lin_a2;
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
87 dac_init_int = (int) dac_init;
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
88
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
89 /* check the frequency offset at the final DAC value */
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
90 vcxo_freq_meas(dac_init_int, "zero-check");
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
91
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
92 /* done with the measurements and the Tx */
24
0b6881281d86 fc-rfcal-vcxo ready for first test
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
93 printf("Stopping RF Tx on the DUT\n");
0b6881281d86 fc-rfcal-vcxo ready for first test
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
94 do_rfe(STOP_ALL);
27
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
95
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
96 /* Psi computations */
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
97 Psi_sta = 2.0f * (float)M_PI * lin_a / 270833.0f;
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
98 Psi_st = Psi_sta * 0.8f;
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
99
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
100 /* afcparams output TBD */
841dd03d5c85 fc-rfcal-vcxo: almost done
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
101
24
0b6881281d86 fc-rfcal-vcxo ready for first test
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
102 exit(0);
21
a3f48378658d autocal: beginning of fc-rfcal-vcxo
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 }