File tree Expand file tree Collapse file tree 1 file changed +17
-8
lines changed Expand file tree Collapse file tree 1 file changed +17
-8
lines changed Original file line number Diff line number Diff line change 19
19
0
20
20
"""
21
21
22
- import numpy as np
23
22
import sys
24
- from itertools import product
25
23
from typing import List , Tuple
26
24
27
25
import pslab .protocol as CP
@@ -102,14 +100,25 @@ def _clock_phase(cls) -> int:
102
100
103
101
@classmethod
104
102
def _get_prescaler (cls , frequency : float ) -> Tuple [int ]:
105
- frequencys = []
106
- for p , s in product (cls ._PPRE_MAP , cls ._SPRE_MAP ):
107
- frequencys .append (CP .CLOCK_RATE / (p * s ))
103
+ min_diff = CP .CLOCK_RATE # highest
104
+ # minimum frequency
105
+ ppre = 0
106
+ spre = 0
108
107
109
- frequencys = np . array ( frequencys )
110
- idx = np . abs ( frequencys - frequency ). argmin ()
108
+ for p in range ( len ( cls . _PPRE_MAP )):
109
+ for s in range ( len ( cls . _SPRE_MAP )):
111
110
112
- return divmod (idx , len (cls ._SPRE_MAP ))
111
+ freq = CP .CLOCK_RATE / (cls ._PPRE_MAP [p ] * cls ._SPRE_MAP [s ])
112
+ if frequency >= freq :
113
+
114
+ diff = frequency - freq
115
+ if min_diff > diff :
116
+ # better match
117
+ min_diff = diff
118
+ ppre = p
119
+ spre = s
120
+
121
+ return ppre , spre
113
122
114
123
@staticmethod
115
124
def _save_config (
You can’t perform that action at this time.
0 commit comments