Skip to content

Commit 391a40e

Browse files
nkpro2000srbessman
authored andcommitted
Add frequency_to_prescaler
1 parent bc44d11 commit 391a40e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pslab/bus/spi.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
0
2020
"""
2121

22+
import numpy as np
2223
import sys
24+
from itertools import product
2325
from typing import List, Tuple
2426

2527
import pslab.protocol as CP
@@ -98,6 +100,17 @@ def _frequency(cls) -> float:
98100
def _clock_phase(cls) -> int:
99101
return (cls._clock_edge ^ 1) & 1
100102

103+
@classmethod
104+
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))
108+
109+
frequencys = np.array(frequencys)
110+
idx = np.abs(frequencys - frequency).argmin()
111+
112+
return divmod(idx, len(cls._SPRE_MAP))
113+
101114
@staticmethod
102115
def _save_config(
103116
primary_prescaler: int,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy