Can anyone explain how this file convert DEC to Hex Value?

TTN_FREQS = {0: (0xd9, 0x06, 0x8b), # 868.1 MHz
1: (0xd9, 0x13, 0x58), # 868.3 MHz
2: (0xd9, 0x20, 0x24), # 868.5 MHz
3: (0xd8, 0xc6, 0x8b), # 867.1 MHz
4: (0xd8, 0xd3, 0x58), # 867.3 MHz
5: (0xd8, 0xe0, 0x24), # 867.5 MHz
6: (0xd8, 0xec, 0xf1), # 867.7 MHz
7: (0xd8, 0xf9, 0xbe)} # 867.9 MHz

For example, if I want the #1 freq to be 923.2 Mhz, how can I write it in Hex?

That Python code does not appear to accept the frequency as a float, such as 868.1Mhz, looks like the calculation to split the frequency into the 3 register values has been manually calculated outside and given as three bytes in a table. But then I am not a Python expert.

The frequency on an SX1276 is a 24bit value spread across 3 x 8 bit registers. The total HEX value is;

Value in HEX = frequencyhz / 61.03515625

So for 868.1Mhz;

Value in HEX = 868100000 / 61.03515625 = 14222950 = 0xD90666

1 Like

Look close.
868.1Mhz in table is 0xD9068B not 0xD90666.

Yes, I spotted that, there is a 2258hz difference.

I will leave you to work out which one is actually correct …

Thank. Yes, it is just 2.2Khz deference.
I think it should work.

Just curious: does anyone know what this 61.035 signifies?

Searching for the values from the code, such as 0xd9068b, I see things like:

Also, I read in slightly related search results:

It took a while to find the conversion formula for those three byte numbers in the DavisRFM69.h file.

The formula is:

Frequency (Hz) = (HEX) Frequency DavisRFM69.h * 32,000,000 / (2^19)

FSTEP = FXOSC/2^19

Indeed, (32 × 1000 × 1000) / (0.5 × 1024 × 1024) = 61.03515625. But what does it do?

61.03515625 is the frequency step, for the standard 32Mhz crystal.

Its in the datasheet …

1 Like

And in case your wondering, the equivalent conversion for the SX126x devices is;

0.95367431640625

The frequency on these devices is stored as a 32bit value across 4 x 8 byte registers.

1 Like

For a bandwidth of 125000hz, as used on TTN, the specified capture range of 25% of the bandwidth is 31250hz, i.e. if RX and TX are apart by this then there is no guaranteed reception.

In practice it seems that you can get problems around the 22% of bandwidth range.

The frequency tolerance of the crystals used on typical SX127x modules can lead to same temperature variation of maybe 16000hz between modules @ 868Mhz so still well within the 31250hz specified.

Note however that for the devices that can operate at 7800hz bandwidth, such as the SX126x modules that have a TCXO, 25% of bandwith is only 1950hz. Thats within the scope of the TCXO, but the base calculation needs to be a bit more accurate that a 2258hz difference.