# HG changeset patch # User Mychaela Falconia # Date 1495492042 0 # Node ID a2e4da9d85cc1ea46540e2afebefd97c4a71b188 # Parent 5226dbaa5333a67d2261b80125846bf420f91ba1 fc-rfcal-vcxo: search for zero crossing implemented diff -r 5226dbaa5333 -r a2e4da9d85cc autocal/vcxomain.c --- a/autocal/vcxomain.c Mon May 22 22:09:59 2017 +0000 +++ b/autocal/vcxomain.c Mon May 22 22:27:22 2017 +0000 @@ -16,7 +16,8 @@ static float freq_max_neg, freq_max_pos; static float lin_a, lin_b, lin_a2, lin_b2; -static int center_search_start; +static int zero_search_dac1, zero_search_dac2, zero_search_incr; +static float zero_search_freq1, zero_search_freq2; prepare_rf_test_system() { @@ -50,11 +51,25 @@ freq_max_pos = vcxo_freq_meas(2048, "max-pos"); lin_a = (freq_max_pos - freq_max_neg) / 4096.0f; lin_b = freq_max_pos - lin_a * 2048.0f; - center_search_start = -lin_b / lin_a; - printf("Center search start DAC value: %d\n", center_search_start); - vcxo_freq_meas(center_search_start, "center"); - vcxo_freq_meas(center_search_start - 100, "center-delta"); - vcxo_freq_meas(center_search_start + 100, "center+delta"); + zero_search_dac1 = -lin_b / lin_a; + zero_search_freq1 = vcxo_freq_meas(zero_search_dac1, "zero-search"); + + /* search for zero crossing */ + if (zero_search_freq1 < 0) + zero_search_incr = 100; + else + zero_search_incr = -100; + for (;;) { + zero_search_dac2 = zero_search_dac1 + zero_search_incr; + zero_search_freq2 = vcxo_freq_meas(zero_search_dac2, + "zero-search"); + if (zero_search_incr > 0 && zero_search_freq2 >= 0) + break; + if (zero_search_incr < 0 && zero_search_freq2 < 0) + break; + zero_search_dac1 = zero_search_dac2; + zero_search_freq1 = zero_search_freq2; + } printf("Stopping RF Tx on the DUT\n"); do_rfe(STOP_ALL);