@@ -307,7 +307,7 @@ def _configure_registers(self, p1, p2, p3):
307
307
self ._si5351 ._write_u8 (self ._base + 6 , (p2 & 0x0000FF00 ) >> 8 )
308
308
self ._si5351 ._write_u8 (self ._base + 7 , (p2 & 0x000000FF ))
309
309
310
- def configure_integer (self , pll , divider ):
310
+ def configure_integer (self , pll , divider , inverted = False ):
311
311
"""Configure the clock output with the specified PLL source
312
312
(should be a PLL instance on the SI5351 class) and specific integer
313
313
divider. This is the most accurate way to set the clock output
@@ -329,17 +329,24 @@ def configure_integer(self, pll, divider):
329
329
# Clock not inverted, powered up
330
330
control |= pll .clock_control_enabled
331
331
control |= 1 << 6 # Enable integer mode.
332
+ if inverted :
333
+ control |= 0b00010000 # Bit 4 of the control register = CLKx_INV
334
+ else :
335
+ control &= 0b11101111 # Make sure to turn it off if not inverted
332
336
self ._si5351 ._write_u8 (self ._control , control )
333
337
# Store the PLL and divisor value so frequency can be calculated.
334
338
self ._pll = pll
335
339
self ._divider = divider
336
340
337
- def configure_fractional (self , pll , divider , numerator , denominator ):
341
+ def configure_fractional (
342
+ self , pll , divider , numerator , denominator , inverted = False
343
+ ):
338
344
"""Configure the clock output with the specified PLL source
339
345
(should be a PLL instance on the SI5351 class) and specifiec
340
346
fractional divider with numerator/denominator. Again this is less
341
347
accurate but has a wider range of output frequencies.
342
348
"""
349
+ # pylint: disable=too-many-arguments
343
350
if divider >= 2049 or divider <= 3 :
344
351
raise Exception ("Divider must be in range 3 to 2049." )
345
352
if denominator > 0xFFFFF or denominator <= 0 : # Prevent divide by zero.
@@ -366,6 +373,10 @@ def configure_fractional(self, pll, divider, numerator, denominator):
366
373
control = 0x0F # 8mA drive strength, MS0 as CLK0 source,
367
374
# Clock not inverted, powered up
368
375
control |= pll .clock_control_enabled
376
+ if inverted :
377
+ control |= 0b00010000 # Bit 4 of the control register = CLKx_INV
378
+ else :
379
+ control &= 0b11101111 # Make sure to turn it off if not inverted
369
380
self ._si5351 ._write_u8 (self ._control , control )
370
381
# Store the PLL and divisor value so frequency can be calculated.
371
382
self ._pll = pll
@@ -441,3 +452,14 @@ def outputs_enabled(self, val):
441
452
self ._write_u8 (_SI5351_REGISTER_3_OUTPUT_ENABLE_CONTROL , 0xFF )
442
453
else :
443
454
self ._write_u8 (_SI5351_REGISTER_3_OUTPUT_ENABLE_CONTROL , 0x00 )
455
+ self .reset_plls ()
456
+
457
+ def reset_plls (self ):
458
+ """Reset both PLLs. This is required when the phase between clocks
459
+ needs to be non-random.
460
+
461
+ See e.g.
462
+
463
+ https://groups.io/g/BITX20/topic/si5351a_facts_and_myths/5430607
464
+ """
465
+ self ._write_u8 (_SI5351_REGISTER_177_PLL_RESET , (1 << 7 ) | (1 << 5 ))
0 commit comments