diff rfcal/vcxo-manual/genparams.c @ 182:9099a35a705f

manual VCXO calibration code: fc-vcxo-param utility written
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Apr 2017 07:33:38 +0000
parents
children b8599a1d5813
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rfcal/vcxo-manual/genparams.c	Wed Apr 12 07:33:38 2017 +0000
@@ -0,0 +1,79 @@
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "meas.h"
+
+struct meas meas[4];
+float lin_a, lin_b, lin_a2, lin_b2;
+float dac_min, dac_max, dac_init;
+float Psi_sta, Psi_st;
+
+write_output(filename)
+	char *filename;
+{
+	FILE *outf;
+
+	if (filename) {
+		outf = fopen(filename, "w");
+		if (!outf) {
+			perror(filename);
+			exit(1);
+		}
+	} else
+		outf = stdout;
+
+	fputs("rf_table afcparams\n\n", outf);
+	/* Psi parameters */
+	fprintf(outf, "%10u\t# Psi_sta_inv\n", (unsigned)(1.0f / Psi_sta));
+	fprintf(outf, "%10u\t# Psi_st\n", (unsigned)(Psi_st * 65536.0f));
+	fprintf(outf, "%10u\t# Psi_st_32\n",
+		(unsigned)(Psi_st * 65536.0f * 65536.0f));
+	fprintf(outf, "%10u\t# Psi_st_inv\n\n", (unsigned)(1.0f / Psi_st));
+	/* DAC settings */
+	fprintf(outf, "%10d\t# DAC_INIT * 8\n", (int)(dac_init * 8.0f));
+	fprintf(outf, "%10d\t# DAC_MIN * 8\n", (int)(dac_min * 8.0f));
+	fprintf(outf, "%10d\t# DAC_MAX * 8\n", (int)(dac_max * 8.0f));
+	fprintf(outf, "%10d\t# snr_thr\n", 2560);
+	/* rfpw 10 setting in a comment line */
+	fprintf(outf, "\n# DAC_INIT: rfpw 10 %d\n", (int)dac_init);
+
+	if (filename)
+		fclose(outf);
+}
+
+main(argc, argv)
+	char **argv;
+{
+	float pi;
+
+	if (argc < 2 || argc > 3) {
+		fprintf(stderr, "usage: %s meas-file [outfile]\n", argv[0]);
+		exit(1);
+	}
+	read_meas_file(argv[1], meas, 4);
+
+	/* first linear approximation */
+	lin_a = (float)(meas[1].freq_offset - meas[0].freq_offset) /
+		(float)(meas[1].dac_value - meas[0].dac_value);
+	lin_b = (float)meas[1].freq_offset - lin_a * meas[1].dac_value;
+
+	/* second linear approximation */
+	lin_a2 = (float)(meas[3].freq_offset - meas[2].freq_offset) /
+		(float)(meas[3].dac_value - meas[2].dac_value);
+	lin_b2 = (float)meas[3].freq_offset - lin_a * meas[2].dac_value;
+
+	/* DAC settings */
+	dac_min = (-13500.0f - lin_b) / lin_a;
+	dac_max = (13500.0f - lin_b) / lin_a;
+	dac_init = -lin_b2 / lin_a2;
+
+	/* Psi computations */
+	pi = acos(-1.0);
+	Psi_sta = 2.0f * pi * (float)(meas[1].freq_offset - meas[0].freq_offset)
+		/ ((float)(meas[1].dac_value - meas[0].dac_value) * 270833.0f);
+	Psi_st = Psi_sta * 0.8f;
+
+	/* spit it all out */
+	write_output(argv[2]);
+	exit(0);
+}