annotate rfcal/vcxo-manual/linear.c @ 221:a46a68500517

rvinterf/Makefile: install include files in /opt/freecalypso/include/rvinterf
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 20 May 2017 20:04:35 +0000
parents dcab0be3f67a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
181
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <stdio.h>
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <stdlib.h>
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include "meas.h"
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 struct meas meas[2];
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 float lin_a, lin_b, target_off;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 int target_dac;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 main(argc, argv)
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 char **argv;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 {
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 if (argc < 2 || argc > 3) {
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 fprintf(stderr, "usage: %s meas-file [target]\n", argv[0]);
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 exit(1);
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 }
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 read_meas_file(argv[1], meas, 2);
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 if (argc > 2)
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 target_off = atof(argv[2]);
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 else
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 target_off = 0;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 lin_a = (float)(meas[1].freq_offset - meas[0].freq_offset) /
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 (float)(meas[1].dac_value - meas[0].dac_value);
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 lin_b = (float)meas[1].freq_offset - lin_a * meas[1].dac_value;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 target_dac = (target_off - lin_b) / lin_a;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 printf("%d\n", target_dac);
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 exit(0);
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }