changeset 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 5226dbaa5333
children 841dd03d5c85
files autocal/vcxomain.c
diffstat 1 files changed, 21 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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);