FreeCalypso > hg > freecalypso-tools
comparison 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 |
comparison
equal
deleted
inserted
replaced
181:dcab0be3f67a | 182:9099a35a705f |
---|---|
1 #include <math.h> | |
2 #include <stdio.h> | |
3 #include <stdlib.h> | |
4 #include "meas.h" | |
5 | |
6 struct meas meas[4]; | |
7 float lin_a, lin_b, lin_a2, lin_b2; | |
8 float dac_min, dac_max, dac_init; | |
9 float Psi_sta, Psi_st; | |
10 | |
11 write_output(filename) | |
12 char *filename; | |
13 { | |
14 FILE *outf; | |
15 | |
16 if (filename) { | |
17 outf = fopen(filename, "w"); | |
18 if (!outf) { | |
19 perror(filename); | |
20 exit(1); | |
21 } | |
22 } else | |
23 outf = stdout; | |
24 | |
25 fputs("rf_table afcparams\n\n", outf); | |
26 /* Psi parameters */ | |
27 fprintf(outf, "%10u\t# Psi_sta_inv\n", (unsigned)(1.0f / Psi_sta)); | |
28 fprintf(outf, "%10u\t# Psi_st\n", (unsigned)(Psi_st * 65536.0f)); | |
29 fprintf(outf, "%10u\t# Psi_st_32\n", | |
30 (unsigned)(Psi_st * 65536.0f * 65536.0f)); | |
31 fprintf(outf, "%10u\t# Psi_st_inv\n\n", (unsigned)(1.0f / Psi_st)); | |
32 /* DAC settings */ | |
33 fprintf(outf, "%10d\t# DAC_INIT * 8\n", (int)(dac_init * 8.0f)); | |
34 fprintf(outf, "%10d\t# DAC_MIN * 8\n", (int)(dac_min * 8.0f)); | |
35 fprintf(outf, "%10d\t# DAC_MAX * 8\n", (int)(dac_max * 8.0f)); | |
36 fprintf(outf, "%10d\t# snr_thr\n", 2560); | |
37 /* rfpw 10 setting in a comment line */ | |
38 fprintf(outf, "\n# DAC_INIT: rfpw 10 %d\n", (int)dac_init); | |
39 | |
40 if (filename) | |
41 fclose(outf); | |
42 } | |
43 | |
44 main(argc, argv) | |
45 char **argv; | |
46 { | |
47 float pi; | |
48 | |
49 if (argc < 2 || argc > 3) { | |
50 fprintf(stderr, "usage: %s meas-file [outfile]\n", argv[0]); | |
51 exit(1); | |
52 } | |
53 read_meas_file(argv[1], meas, 4); | |
54 | |
55 /* first linear approximation */ | |
56 lin_a = (float)(meas[1].freq_offset - meas[0].freq_offset) / | |
57 (float)(meas[1].dac_value - meas[0].dac_value); | |
58 lin_b = (float)meas[1].freq_offset - lin_a * meas[1].dac_value; | |
59 | |
60 /* second linear approximation */ | |
61 lin_a2 = (float)(meas[3].freq_offset - meas[2].freq_offset) / | |
62 (float)(meas[3].dac_value - meas[2].dac_value); | |
63 lin_b2 = (float)meas[3].freq_offset - lin_a * meas[2].dac_value; | |
64 | |
65 /* DAC settings */ | |
66 dac_min = (-13500.0f - lin_b) / lin_a; | |
67 dac_max = (13500.0f - lin_b) / lin_a; | |
68 dac_init = -lin_b2 / lin_a2; | |
69 | |
70 /* Psi computations */ | |
71 pi = acos(-1.0); | |
72 Psi_sta = 2.0f * pi * (float)(meas[1].freq_offset - meas[0].freq_offset) | |
73 / ((float)(meas[1].dac_value - meas[0].dac_value) * 270833.0f); | |
74 Psi_st = Psi_sta * 0.8f; | |
75 | |
76 /* spit it all out */ | |
77 write_output(argv[2]); | |
78 exit(0); | |
79 } |