-
Notifications
You must be signed in to change notification settings - Fork 12
Prefer lower e-series values for resistors and capacitors #430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c33cb89
e5654d3
7463605
a51b72e
b7d197d
dea419b
862732b
9f2768b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,11 +2,14 @@ | |||||
| import math | ||||||
| from abc import ABCMeta, abstractmethod | ||||||
| from collections import deque | ||||||
| from typing import Sequence, Optional, TypeVar, Tuple, List, Generic, Type | ||||||
| from typing import Sequence, Optional, TypeVar, Tuple, List, Generic, Type, Union, overload | ||||||
|
|
||||||
| from ..electronics_model import * | ||||||
|
|
||||||
|
|
||||||
| SeriesDefaultType = TypeVar('SeriesDefaultType') | ||||||
|
|
||||||
|
|
||||||
| class ESeriesUtil: | ||||||
| """Helper methods for working with the E series of preferred numbers.""" | ||||||
| @staticmethod | ||||||
|
|
@@ -59,9 +62,10 @@ def choose_preferred_number(cls, within: Range, series: Sequence[float], toleran | |||||
|
|
||||||
| ROUND_DIGITS = 5 | ||||||
|
|
||||||
| SERIES_MAX = 192 | ||||||
|
|
||||||
| E24_DIFF = { # series as difference from prior series | ||||||
| 1: [1.0], | ||||||
| 3: [2.2, 4.7], | ||||||
| 3: [1.0, 2.2, 4.7], | ||||||
| 6: [1.5, 3.3, 6.8], | ||||||
| 12: [1.2, 1.8, 2.7, 3.9, 5.6, 8.2], | ||||||
| 24: [1.1, 1.3, 1.6, 2.0, 2.4, 3.0, 3.6, 4.3, 5.1, 6.2, 7.5, 9.1], | ||||||
|
|
@@ -87,26 +91,36 @@ def choose_preferred_number(cls, within: Range, series: Sequence[float], toleran | |||||
| } | ||||||
|
|
||||||
| SERIES = { # whole series in zigzag order | ||||||
| 1: list(itertools.chain(E24_DIFF[1])), | ||||||
| 3: list(itertools.chain(E24_DIFF[1], E24_DIFF[3])), | ||||||
| 6: list(itertools.chain(E24_DIFF[1], E24_DIFF[3], E24_DIFF[6])), | ||||||
| 12: list(itertools.chain(E24_DIFF[1], E24_DIFF[3], E24_DIFF[6], E24_DIFF[12])), | ||||||
| 24: list(itertools.chain(E24_DIFF[1], E24_DIFF[3], E24_DIFF[6], E24_DIFF[12], E24_DIFF[24])), | ||||||
| 3: list(itertools.chain(E24_DIFF[3])), | ||||||
| 6: list(itertools.chain(E24_DIFF[3], E24_DIFF[6])), | ||||||
| 12: list(itertools.chain(E24_DIFF[3], E24_DIFF[6], E24_DIFF[12])), | ||||||
| 24: list(itertools.chain(E24_DIFF[3], E24_DIFF[6], E24_DIFF[12], E24_DIFF[24])), | ||||||
|
|
||||||
| # These are E192 without the E24 series | ||||||
| 48: list(itertools.chain(E192_DIFF[48])), | ||||||
| 96: list(itertools.chain(E192_DIFF[48], E192_DIFF[96])), | ||||||
| 192: list(itertools.chain(E192_DIFF[48], E192_DIFF[96], E192_DIFF[192])), | ||||||
|
|
||||||
| # These are E24 + E192, prioritizing E24 | ||||||
| 2448: list(itertools.chain(E24_DIFF[1], E24_DIFF[3], E24_DIFF[6], E24_DIFF[12], E24_DIFF[24], | ||||||
| E192_DIFF[48])), | ||||||
| 2496: list(itertools.chain(E24_DIFF[1], E24_DIFF[3], E24_DIFF[6], E24_DIFF[12], E24_DIFF[24], | ||||||
| E192_DIFF[48], E192_DIFF[96])), | ||||||
| 24192: list(itertools.chain(E24_DIFF[1], E24_DIFF[3], E24_DIFF[6], E24_DIFF[12], E24_DIFF[24], | ||||||
| E192_DIFF[48], E192_DIFF[96], E192_DIFF[192])), | ||||||
| } | ||||||
|
|
||||||
| # reverse mapping of value to series, reverse SERIES so lower series preferred | ||||||
| VALUE_SERIES = {v: k for k, series in reversed(SERIES.items()) for v in series} | ||||||
|
|
||||||
| @classmethod | ||||||
| @overload | ||||||
| def series_of(cls, value: float) -> Optional[int]: ... | ||||||
| @classmethod | ||||||
| @overload | ||||||
| def series_of(cls, value: float, *, default: SeriesDefaultType) -> Union[int, SeriesDefaultType]: ... | ||||||
|
|
||||||
| @classmethod | ||||||
| def series_of(cls, value: float, *, default: Optional[SeriesDefaultType] = None) -> Union[None, int, SeriesDefaultType]: | ||||||
| """Returns the E-series that contains the given value, or None if not found. | ||||||
| Performs limited rounding to account for floating point issues.""" | ||||||
| if value <= 0: | ||||||
| return default | ||||||
| normalized_value = value * math.pow(10, -math.floor(math.log10(value))) | ||||||
|
||||||
| normalized_value = value * math.pow(10, -math.floor(math.log10(value))) | |
| normalized_value = abs(value) * math.pow(10, -math.floor(math.log10(abs(value)))) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -94,12 +94,12 @@ def contents(self): | |||||
| self.iref_res = self.Block(Resistor(resistance=560*kOhm(tol=0.05))) # TODO dynamic sizing | ||||||
| self.connect(self.iref_res.a, self.device.iref) | ||||||
| self.connect(self.iref_res.b.adapt_to(Ground()), self.gnd) | ||||||
| self.vcomh_cap = self.Block(DecouplingCapacitor((2.2*.8, 20)*uFarad)).connected(self.gnd, self.device.vcomh) | ||||||
| self.vcomh_cap = self.Block(DecouplingCapacitor((2.2*.8, 10)*uFarad)).connected(self.gnd, self.device.vcomh) | ||||||
|
|
||||||
| self.vdd_cap1 = self.Block(DecouplingCapacitor(capacitance=0.1*uFarad(tol=0.2))).connected(self.gnd, self.pwr) | ||||||
| self.vdd_cap2 = self.Block(DecouplingCapacitor(capacitance=4.7*uFarad(tol=0.2))).connected(self.gnd, self.pwr) | ||||||
|
|
||||||
| self.vcc_cap1 = self.Block(DecouplingCapacitor(capacitance=0.1*uFarad(tol=0.2)))\ | ||||||
| .connected(self.gnd, self.device.vcc) | ||||||
| self.vcc_cap2 = self.Block(DecouplingCapacitor(capacitance=(4.7*.8, 20)*uFarad))\ | ||||||
| self.vcc_cap2 = self.Block(DecouplingCapacitor(capacitance=4.7*uFarad(tol=0.2)))\ | ||||||
|
||||||
| self.vcc_cap2 = self.Block(DecouplingCapacitor(capacitance=4.7*uFarad(tol=0.2)))\ | |
| self.vcc_cap2 = self.Block(DecouplingCapacitor(capacitance=(4.7*0.8, 20)*uFarad))\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
reversed()function returns an iterator, not a reversed dictionary view. When used withdict.items(), this will fail at runtime with a TypeError because iterators don't have anitems()method. You need to usereversed(list(SERIES.items()))instead.Example fix: