etherkit / si5351-avr-tiny-minimal

A small but functional library for driving the Si5351 with AVR ATtiny microcontrollers with 8 kB of flash memory.
GNU General Public License v3.0
10 stars 1 forks source link

Can't set frequency below 1757.813 kHz with SI5351_OUTPUT_CLK_DIV_1 #3

Open moggen opened 6 years ago

moggen commented 6 years ago

I'm helping a friend to get 1749-1806kHz to be used for a Polyakov (RA3AAE) sub-harmonic mixer for 80m, but I ran into big problems in the lower end of the range.

Yes, I should be able to solve this using a divider and enter a multiple of the requested frequency, but it is not needed with the 5351, as it is able to go as far down as 500kHz with DIV_1 for PLL@900MHz.

I found out by bisecting that the frequency of 1757813Hz works but not 1757812Hz! It turns out to be the point where the frac.a value become 512 and greater.

Rev B of the 5351 supports up to 1800 as frac.a.

It is easily fixed. Current row 222 in si5351-avr-tiny-minimal.c:

ms_reg.p1 = 128 * frac.a + ((128 * frac.b) / frac.c) - 512;

Change to:

ms_reg.p1 = 128 * (uint32_t)frac.a + ((128 * frac.b) / frac.c) - 512;

128 * 512 is 65536 so my guess is that this part of the expression overflows the 16 bit logic inferred by the frac.a 16 bit size. I'm using avr-gcc (GCC) 4.9.2 on an Ubuntu 16.04 system. An alternative fix is to change the type of frac.a to uint32_t, but the suggested fix saves 2 bytes of memory.

73 de SA5MOG