Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit 8c164e3

Browse files
authored
Deprecate use of physical ranges (#125)
1 parent ca5689c commit 8c164e3

9 files changed

Lines changed: 49 additions & 54 deletions

File tree

bom/helpers.zen

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
load("../utils.zen", "e96", "e24")
44
load(
55
"../units.zen",
6-
"ResistanceRange",
6+
"Resistance",
77
"Voltage",
8-
"VoltageRange",
98
"Power",
109
"Capacitance",
11-
"Resistance",
1210
"Impedance",
1311
"Current",
1412
"Frequency",
@@ -188,7 +186,7 @@ def resistor_series(manufacturer, series, resistance_range, max_v, power, tolera
188186
return {
189187
"manufacturer": manufacturer,
190188
"series": series,
191-
"resistance_range": ResistanceRange(resistance_range),
189+
"resistance_range": Resistance(resistance_range),
192190
"max_v": Voltage(max_v),
193191
"power": Power(power),
194192
"tolerance": tolerance,
@@ -321,7 +319,7 @@ def led(color: str, voltage_range: str, mpn: str, manufacturer: str) -> dict:
321319
"""
322320
return {
323321
"color": color,
324-
"forward_voltage": VoltageRange(voltage_range),
322+
"forward_voltage": Voltage(voltage_range),
325323
"mpn": mpn,
326324
"manufacturer": manufacturer,
327325
}
@@ -390,14 +388,10 @@ def tvs(standoff_voltage: str, clamping_voltage: str, peak_pulse_power: str, mpn
390388
"""
391389
# Use ranges for all values to support flexible matching
392390
standoff_val = (
393-
VoltageRange(standoff_voltage)
394-
if "to" in standoff_voltage
395-
else VoltageRange(standoff_voltage + " to " + standoff_voltage)
391+
Voltage(standoff_voltage) if "to" in standoff_voltage else Voltage(standoff_voltage + " to " + standoff_voltage)
396392
)
397393
clamping_val = (
398-
VoltageRange(clamping_voltage)
399-
if "to" in clamping_voltage
400-
else VoltageRange(clamping_voltage + " to " + clamping_voltage)
394+
Voltage(clamping_voltage) if "to" in clamping_voltage else Voltage(clamping_voltage + " to " + clamping_voltage)
401395
)
402396
power_val = Power(peak_pulse_power)
403397

bom/match_generics.zen

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ load("manufactuers/wurth_electronik.zen", "WURTH_ELEKTRONIK_WR_PHD")
77
load(
88
"../units.zen",
99
"Voltage",
10-
"VoltageRange",
1110
"Resistance",
12-
"ResistanceRange",
1311
"Capacitance",
1412
"Power",
1513
"Current",

bom/test/test_match_Tvs.zen

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
load("../../generics/Tvs.zen", "Package", "Direction")
44
load("../../interfaces.zen", "Power", "Ground")
5-
load("../../units.zen", "VoltageRange")
5+
load("../../units.zen", "Voltage")
66
load("../match_generics.zen", "assign_house_parts")
77

88
Tvs = Module("../../generics/Tvs.zen")
99

1010
gnd = Ground("GND")
11-
vcc = Power("VCC", voltage=VoltageRange("3.3V"))
11+
vcc = Power("VCC", voltage=Voltage("3.3V"))
1212

1313
# Test cases: (direction, package, reverse_standoff_voltage)
1414
TVS_TEST_CASES = [
@@ -39,7 +39,7 @@ for id, (direction, package, standoff_voltage) in enumerate(TVS_TEST_CASES):
3939
name=f"D{id}",
4040
direction=direction,
4141
package=package,
42-
reverse_standoff_voltage=VoltageRange(standoff_voltage),
42+
reverse_standoff_voltage=Voltage(standoff_voltage),
4343
A=gnd,
4444
K=vcc,
4545
)
@@ -48,7 +48,7 @@ for id, (direction, package, standoff_voltage) in enumerate(TVS_TEST_CASES):
4848
name=f"D{id}",
4949
direction=direction,
5050
package=package,
51-
reverse_standoff_voltage=VoltageRange(standoff_voltage),
51+
reverse_standoff_voltage=Voltage(standoff_voltage),
5252
A=Net(f"LINE_A_{id}"),
5353
K=Net(f"LINE_B_{id}"),
5454
)

checks.zen

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
load("units.zen", "VoltageRange")
1+
load("units.zen", "Voltage")
22
load("interfaces.zen", "Power")
33

44
Severity = enum("error", "warning", "advice")
55

66

77
def voltage_within(
8-
within: str | VoltageRange, name: str = "voltage_check", severity: Severity = Severity("error")
8+
within: str | Voltage, name: str = "voltage_check", severity: Severity = Severity("error")
99
) -> typing.Callable:
10-
def ensure_voltage_within(_module, net_name: str, voltage: VoltageRange, within: str | VoltageRange):
11-
within = VoltageRange(within)
10+
def ensure_voltage_within(_module, net_name: str, voltage: Voltage, within: str | Voltage):
11+
within = Voltage(within)
1212
# drop nominal in within:
13-
within = VoltageRange(min=within.min, max=within.max)
13+
within = Voltage(min=within.min, max=within.max)
1414
# ensure voltage is within within
1515
err_msg = "Voltage range " + str(voltage) + " of " + net_name + " is not within " + str(within)
1616
check(voltage in within, err_msg)

generics/Tvs.zen

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
load("../units.zen", "PowerRange", "Voltage", "VoltageRange", "CurrentRange")
1+
load("../units.zen", "Power", "Voltage")
2+
Watts = Power
23
load("../interfaces.zen", "Power", "Ground")
34
load("../utils.zen", "format_value")
45

@@ -10,21 +11,21 @@ load("../utils.zen", "format_value")
1011
Package = enum("DO-219AB", "DO-214AC", "DO-214AA", "DO-214AB")
1112
Direction = enum("Unidirectional", "Bidirectional")
1213

13-
USB_5V_STANDOFF_VOLTAGE = VoltageRange("5 to 6V")
14+
USB_5V_STANDOFF_VOLTAGE = Voltage("5 to 6V")
1415

1516
package = config("package", Package, default=Package("DO-219AB"))
1617
direction = config("direction", Direction, default=Direction("Unidirectional"))
1718
# 8/20 μs waveform acc. IEC 61000-4-5
18-
reverse_standoff_voltage = config("reverse_standoff_voltage", VoltageRange, default=USB_5V_STANDOFF_VOLTAGE)
19-
reverse_clamping_voltage = config("reverse_clamping_voltage", VoltageRange, optional=True)
20-
peak_pulse_power = config("peak_pulse_power", PowerRange, optional=True)
19+
reverse_standoff_voltage = config("reverse_standoff_voltage", Voltage, default=USB_5V_STANDOFF_VOLTAGE)
20+
reverse_clamping_voltage = config("reverse_clamping_voltage", Voltage, optional=True)
21+
peak_pulse_power = config("peak_pulse_power", Watts, optional=True)
2122

2223
mpn = config("mpn", str, optional=True)
2324
manufacturer = config("manufacturer", str, optional=True)
2425

2526
if direction == Direction("Unidirectional"):
2627
A = io("A", Ground)
27-
K = io("K", Power, default=Power("VCC", voltage=VoltageRange("5V")))
28+
K = io("K", Power, default=Power("VCC", voltage=Voltage("5V")))
2829
else:
2930
A = io("A", Net)
3031
K = io("K", Net)

generics/test/test_Tvs.zen

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""Comprehensive test for TVS Diode component."""
22

3+
load("../../units.zen", "Power", "Voltage")
4+
Watts = Power
35
load("../../interfaces.zen", "Power", "Ground")
4-
load("../../units.zen", "PowerRange", "Voltage", "VoltageRange")
56
load("../../bom/match_generics.zen", "assign_house_parts")
67

78
Tvs = Module("../Tvs.zen")
89

9-
vcc = Power("VCC", voltage=VoltageRange("3.3V"))
10+
vcc = Power("VCC", voltage=Voltage("3.3V"))
1011
gnd = Ground("GND")
1112

1213
# Test all Package values
@@ -16,8 +17,8 @@ for package in Tvs.Package.values():
1617
Tvs(
1718
name=name,
1819
package=package,
19-
peak_pulse_power=PowerRange("800 to 1200W"),
20-
reverse_clamping_voltage=VoltageRange("9 to 12V"),
20+
peak_pulse_power=Watts("800 to 1200W"),
21+
reverse_clamping_voltage=Voltage("9 to 12V"),
2122
A=gnd,
2223
K=vcc,
2324
)
@@ -27,9 +28,9 @@ for package in Tvs.Package.values():
2728
Tvs(
2829
name="D_TVS_3V3",
2930
package="DO-219AB",
30-
peak_pulse_power=PowerRange("400 to 600W"),
31-
reverse_standoff_voltage=VoltageRange("3.3V"),
32-
reverse_clamping_voltage=VoltageRange("6 to 8V"),
31+
peak_pulse_power=Watts("400 to 600W"),
32+
reverse_standoff_voltage=Voltage("3.3V"),
33+
reverse_clamping_voltage=Voltage("6 to 8V"),
3334
A=gnd,
3435
K=vcc,
3536
)
@@ -38,9 +39,9 @@ Tvs(
3839
Tvs(
3940
name="D_TVS_12V",
4041
package="DO-214AC",
41-
peak_pulse_power=PowerRange("1200 to 1500W"),
42-
reverse_standoff_voltage=VoltageRange("12V"),
43-
reverse_clamping_voltage=VoltageRange("19 to 21V"),
42+
peak_pulse_power=Watts("1200 to 1500W"),
43+
reverse_standoff_voltage=Voltage("12V"),
44+
reverse_clamping_voltage=Voltage("19 to 21V"),
4445
A=gnd,
4546
K=vcc,
4647
)

interfaces.zen

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
load("units.zen", "VoltageRange", "Impedance")
1+
load("units.zen", "Voltage", "Impedance")
22

33
Power = builtin.net_type(
44
"Power",
55
symbol=field(Symbol, default=Symbol(library="@kicad-symbols/power.kicad_sym", name="VCC")),
6-
voltage=VoltageRange,
6+
voltage=Voltage,
77
)
88

99
Ground = builtin.net_type(
1010
"Ground",
1111
symbol=field(Symbol, default=Symbol(library="@kicad-symbols/power.kicad_sym", name="GND")),
12-
voltage=field(VoltageRange, default=VoltageRange("0V")),
12+
voltage=field(Voltage, default=Voltage("0V")),
1313
)
1414

1515
NotConnected = builtin.net_type("NotConnected")

test/test_checks.zen

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
load("../checks.zen", "voltage_within")
2-
load("../interfaces.zen", "Power", "VoltageRange")
2+
load("../interfaces.zen", "Power")
3+
load("../units.zen", "Voltage")
34

45
# Test 3.3V rail with tolerance
5-
v3v3 = Power("3V3", voltage=VoltageRange("3.3V 1%"))
6+
v3v3 = Power("3V3", voltage=Voltage("3.3V 1%"))
67
# Check if 3.3V +/- 1% is within 3.3V +/- 5%
78
check_3v3 = voltage_within("3.3V 5%")
89
check_3v3(v3v3)
910

1011
# Test 5V rail with explicit range
11-
v5 = Power("5V", voltage=VoltageRange("5V"))
12+
v5 = Power("5V", voltage=Voltage("5V"))
1213
# Check if 5V is within 4.5V to 5.5V (using +/- 10% notation)
1314
check_5v = voltage_within("5V 10%")
1415
check_5v(v5)
1516

1617
# Test with tighter tolerance on the rail than the check
17-
v1v8 = Power("1V8", voltage=VoltageRange("1.8V 1%"))
18+
v1v8 = Power("1V8", voltage=Voltage("1.8V 1%"))
1819
check_1v8 = voltage_within("1.8V 5%")
1920
check_1v8(v1v8)
2021

units.zen

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ Energy = builtin.physical_value("J")
1717
MagneticFlux = builtin.physical_value("Wb")
1818
Conductance = builtin.physical_value("S")
1919

20-
VoltageRange = builtin.physical_range("V")
21-
CurrentRange = builtin.physical_range("A")
22-
ResistanceRange = builtin.physical_range("Ohm")
23-
CapacitanceRange = builtin.physical_range("F")
24-
InductanceRange = builtin.physical_range("H")
25-
FrequencyRange = builtin.physical_range("Hz")
26-
TemperatureRange = builtin.physical_range("K")
27-
TimeRange = builtin.physical_range("s")
28-
PowerRange = builtin.physical_range("W")
20+
VoltageRange = Voltage
21+
CurrentRange = Current
22+
ResistanceRange = Resistance
23+
CapacitanceRange = Capacitance
24+
InductanceRange = Inductance
25+
FrequencyRange = Frequency
26+
TemperatureRange = Temperature
27+
TimeRange = Time
28+
PowerRange = Power
2929

3030

3131
def unit(spec, type):

0 commit comments

Comments
 (0)