FreeCalypso > hg > freecalypso-tools
changeset 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 | dcab0be3f67a |
children | 0518ed1d0dc8 |
files | .hgignore rfcal/vcxo-manual/Makefile rfcal/vcxo-manual/genparams.c |
diffstat | 3 files changed, 85 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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$
--- 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}
--- /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); +}