File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -164,7 +164,10 @@ def _osc_div(self):
164164 div_range = range (2 , 130 , 2 )
165165 div_frac = Fraction (self ._osc_base_freq , self .osc_frequency )
166166
167- if div_frac .denominator != 1 or div_frac not in div_range :
167+ # Check that the requested frequency is within 50 ppm. This takes care of small mismatches
168+ # arising due to rounding. The tolerance of a typical crystal oscillator is 50 ppm.
169+ if (abs (round (div_frac ) - div_frac ) > Fraction (50 , 1_000_000 ) or
170+ int (div_frac ) not in div_range ):
168171 achievable = (
169172 min ((frac for frac in div_range if frac > div_frac ), default = None ),
170173 max ((frac for frac in div_range if frac < div_frac ), default = None )
@@ -178,7 +181,7 @@ def _osc_div(self):
178181 f"achievable frequencies are " +
179182 ", " .join (str (self ._osc_base_freq // frac ) for frac in achievable if frac ))
180183
181- return div_frac . numerator
184+ return int ( div_frac )
182185
183186 # Common templates
184187
You can’t perform that action at this time.
0 commit comments