-
Notifications
You must be signed in to change notification settings - Fork 1
/
synthesizers.hpp
50 lines (41 loc) · 1.1 KB
/
synthesizers.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once
#include "common.hpp"
#include "board.hpp"
namespace synthesizers {
// initialize and configure si5351
bool si5351_setup();
// set si5351 frequency for tx and rx port.
// returns 0 if one output divider changed;
// returns 1 if two output dividers changed;
// returns 2 if pll updated.
int si5351_set(uint32_t rxFreqHz, uint32_t txFreqHz);
// freqHz must be a multiple of freqStepHz
template<class T>
static void adf4350_set(T& adf4350, freqHz_t freqHz, uint32_t freqStepHz) {
int O = 1;
int R = 1; // adf4350 reference divide
if(freqHz > 2200000000)
O = 1;
else if(freqHz > 1100000000)
O = 2;
else if(freqHz > 550000000)
O = 4;
else if(freqHz > 275000000)
O = 8;
else if(freqHz > 137500000)
O = 16;
else if(freqHz > 68750000)
O = 32;
else //if(freqHz > 34375000)
O = 64;
uint64_t N = freqHz*O/freqStepHz;
uint32_t modulus = board::xtalFreqHz/R/freqStepHz;
adf4350.R = R;
adf4350.O = O;
adf4350.N = N / modulus;
adf4350.numerator = N - (adf4350.N * modulus);
adf4350.denominator = modulus;
adf4350.sendConfig();
adf4350.sendN();
}
}