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):
164
164
div_range = range (2 , 130 , 2 )
165
165
div_frac = Fraction (self ._osc_base_freq , self .osc_frequency )
166
166
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 ):
168
171
achievable = (
169
172
min ((frac for frac in div_range if frac > div_frac ), default = None ),
170
173
max ((frac for frac in div_range if frac < div_frac ), default = None )
@@ -178,7 +181,7 @@ def _osc_div(self):
178
181
f"achievable frequencies are " +
179
182
", " .join (str (self ._osc_base_freq // frac ) for frac in achievable if frac ))
180
183
181
- return div_frac . numerator
184
+ return int ( div_frac )
182
185
183
186
# Common templates
184
187
You can’t perform that action at this time.
0 commit comments