-
Notifications
You must be signed in to change notification settings - Fork 7
/
helper_conversions.py
77 lines (57 loc) · 2.06 KB
/
helper_conversions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from pathlib import Path
from configparser import ConfigParser
'''
Helper Conversion Functions
'''
# Read configuration
config = ConfigParser()
config.read(Path(__file__).with_name('config.ini'))
config = config['Configuration']
def get_ohms_per_mm(trace_width_mm: float, exterior_layer: bool) -> float:
'''
Parameters:
- Width of PCB trace in mm
- Boolean whether the trace is on PCB exterior layer
Returns: ohms per mm of trace length
'''
if trace_width_mm <= 0:
return float("nan")
thickness_m = get_trace_thickness(exterior_layer)
p = config.getfloat("CopperResistivity")
ohms_per_mm = p / (thickness_m * trace_width_mm)
return ohms_per_mm
def get_trace_thickness(exterior_layer: bool) -> float:
'''
Parameters:
- Boolean whether the trace is on PCB exterior layer
Returns: Thickness of trace (in meters)
'''
if exterior_layer:
oz_thickness = config.getfloat("OuterLayerThickness")
else:
oz_thickness = config.getfloat("InnerLayerThickness")
m_per_oz = config.getfloat("TraceThicknessPerOz") / 1000
thickness_m = oz_thickness * m_per_oz
return thickness_m
def int_ohms_from_ext_ohms(exterior_resistance: float) -> float:
'''
Parameters:
- Resistance per spiral on the exterior layer
Returns: Resistance (in ohms) per inner spiral required to meet total resistance config
'''
return (
(config.getfloat("Resistance") - 2 * exterior_resistance) /
(config.getint("NumberOfLayers") - 2)
)
def spacing_from_length(length_mm: float, resistance: float, exterior: bool) -> float:
'''
Parameters:
- Length of trace in mm
- Desired resistance in ohms
- Boolean whether the trace is on PCB exterior
Returns: Total spacing (in mm) between centers of adjacent traces
'''
thickness_m = get_trace_thickness(exterior)
p = config.getfloat("CopperResistivity")
trace_width_mm = (p * length_mm) / (thickness_m * resistance)
return trace_width_mm + config.getfloat("GapBetweenTraces")