comparison autocal/vcxomain.c @ 26:a2e4da9d85cc

fc-rfcal-vcxo: search for zero crossing implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 22 May 2017 22:27:22 +0000
parents 0b6881281d86
children 841dd03d5c85
comparison
equal deleted inserted replaced
25:5226dbaa5333 26:a2e4da9d85cc
14 14
15 extern float vcxo_freq_meas(); 15 extern float vcxo_freq_meas();
16 16
17 static float freq_max_neg, freq_max_pos; 17 static float freq_max_neg, freq_max_pos;
18 static float lin_a, lin_b, lin_a2, lin_b2; 18 static float lin_a, lin_b, lin_a2, lin_b2;
19 static int center_search_start; 19 static int zero_search_dac1, zero_search_dac2, zero_search_incr;
20 static float zero_search_freq1, zero_search_freq2;
20 21
21 prepare_rf_test_system() 22 prepare_rf_test_system()
22 { 23 {
23 char cmd[80]; 24 char cmd[80];
24 25
48 /* initial measurements at the DAC extremes */ 49 /* initial measurements at the DAC extremes */
49 freq_max_neg = vcxo_freq_meas(-2048, "max-neg"); 50 freq_max_neg = vcxo_freq_meas(-2048, "max-neg");
50 freq_max_pos = vcxo_freq_meas(2048, "max-pos"); 51 freq_max_pos = vcxo_freq_meas(2048, "max-pos");
51 lin_a = (freq_max_pos - freq_max_neg) / 4096.0f; 52 lin_a = (freq_max_pos - freq_max_neg) / 4096.0f;
52 lin_b = freq_max_pos - lin_a * 2048.0f; 53 lin_b = freq_max_pos - lin_a * 2048.0f;
53 center_search_start = -lin_b / lin_a; 54 zero_search_dac1 = -lin_b / lin_a;
54 printf("Center search start DAC value: %d\n", center_search_start); 55 zero_search_freq1 = vcxo_freq_meas(zero_search_dac1, "zero-search");
55 vcxo_freq_meas(center_search_start, "center"); 56
56 vcxo_freq_meas(center_search_start - 100, "center-delta"); 57 /* search for zero crossing */
57 vcxo_freq_meas(center_search_start + 100, "center+delta"); 58 if (zero_search_freq1 < 0)
59 zero_search_incr = 100;
60 else
61 zero_search_incr = -100;
62 for (;;) {
63 zero_search_dac2 = zero_search_dac1 + zero_search_incr;
64 zero_search_freq2 = vcxo_freq_meas(zero_search_dac2,
65 "zero-search");
66 if (zero_search_incr > 0 && zero_search_freq2 >= 0)
67 break;
68 if (zero_search_incr < 0 && zero_search_freq2 < 0)
69 break;
70 zero_search_dac1 = zero_search_dac2;
71 zero_search_freq1 = zero_search_freq2;
72 }
58 73
59 printf("Stopping RF Tx on the DUT\n"); 74 printf("Stopping RF Tx on the DUT\n");
60 do_rfe(STOP_ALL); 75 do_rfe(STOP_ALL);
61 exit(0); 76 exit(0);
62 } 77 }