# HG changeset patch # User Mychaela Falconia # Date 1491982418 0 # Node ID 9099a35a705f58d4aebf9812d9064dc38a6bf3df # Parent dcab0be3f67a05517f5fb583a7a53d2166749f98 manual VCXO calibration code: fc-vcxo-param utility written diff -r dcab0be3f67a -r 9099a35a705f .hgignore --- a/.hgignore Wed Apr 12 06:45:45 2017 +0000 +++ b/.hgignore Wed Apr 12 07:33:38 2017 +0000 @@ -28,6 +28,7 @@ ^miscutil/imei-luhn$ ^rfcal/vcxo-manual/fc-vcxo-linear$ +^rfcal/vcxo-manual/fc-vcxo-param$ ^ringtools/fc-e1decode$ ^ringtools/fc-e1gen$ diff -r dcab0be3f67a -r 9099a35a705f rfcal/vcxo-manual/Makefile --- a/rfcal/vcxo-manual/Makefile Wed Apr 12 06:45:45 2017 +0000 +++ b/rfcal/vcxo-manual/Makefile Wed Apr 12 07:33:38 2017 +0000 @@ -1,15 +1,19 @@ CC= gcc CFLAGS= -O2 -PROGS= fc-vcxo-linear +PROGS= fc-vcxo-linear fc-vcxo-param INSTBIN=/opt/freecalypso/bin LINEAR_OBJS= linear.o readmeas.o +GENPARAMS_OBJS= genparams.o readmeas.o all: ${PROGS} fc-vcxo-linear: ${LINEAR_OBJS} ${CC} ${CFLAGS} -o $@ ${LINEAR_OBJS} +fc-vcxo-param: ${GENPARAMS_OBJS} + ${CC} ${CFLAGS} -o $@ ${GENPARAMS_OBJS} + install: mkdir -p ${INSTBIN} install -c ${PROGS} ${INSTBIN} diff -r dcab0be3f67a -r 9099a35a705f rfcal/vcxo-manual/genparams.c --- /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 +#include +#include +#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); +}