Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Library: Remove Constant for physical params (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
iopapamanoglou authored Sep 11, 2024
1 parent 9096ef0 commit 22bdbd6
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 39 deletions.
42 changes: 25 additions & 17 deletions src/faebryk/library/CBM9002A_56ILG_Reference_Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,31 @@ class CBM9002A_56ILG_Reference_Design(Module):
Minimal working example for the CBM9002A_56ILG
"""

class ResetCircuit(Module):
"""low-pass and protection for reset"""

diode: F.Diode
cap: F.Capacitor
logic: F.ElectricLogic

def __preinit__(self):
self.logic.signal.connect_via(self.diode, self.logic.reference.hv)
self.logic.pulled.pull(up=True)
self.logic.signal.connect_via(self.cap, self.logic.reference.lv)

self.cap.capacitance.merge(F.Range.from_center_rel(1 * P.uF, 0.05))

self.diode.forward_voltage.merge(F.Range(715 * P.mV, 1.5 * P.V))
self.diode.reverse_leakage_current.merge(F.Range.upper_bound(1 * P.uA))
self.diode.current.merge(F.Range.from_center_rel(300 * P.mA, 0.05))
self.diode.max_current.merge(F.Range.lower_bound(1 * P.A))

# ----------------------------------------
# modules, interfaces, parameters
# ----------------------------------------
mcu: F.CBM9002A_56ILG
reset_diode: F.Diode
reset_lowpass_cap: F.Capacitor
oscillator: F.Crystal_Oscillator
reset_circuit: ResetCircuit

PA = L.list_field(8, F.ElectricLogic)
PB = L.list_field(8, F.ElectricLogic)
Expand Down Expand Up @@ -47,32 +65,22 @@ class CBM9002A_56ILG_Reference_Design(Module):
# connections
# ----------------------------------------
def __preinit__(self):
gnd = self.vcc.lv
self.connect_interfaces_by_name(self.mcu, allow_partial=True)

self.reset.signal.connect_via(
self.reset_lowpass_cap, gnd
) # TODO: should come from a low pass for electric logic
self.reset.pulled.pull(up=True)
self.reset.signal.connect_via(self.reset_diode, self.vcc.hv)

# crystal oscillator
self.oscillator.power.connect(self.vcc)
self.oscillator.n.connect(self.xtalin)
self.oscillator.p.connect(self.xtalout)

self.reset_circuit.logic.connect(self.mcu.reset)

# ----------------------------------------
# Parameters
# ----------------------------------------
self.reset_lowpass_cap.capacitance.merge(F.Constant(1 * P.uF))

self.oscillator.crystal.frequency.merge(F.Constant(24 * P.Mhertz))
self.oscillator.crystal.frequency.merge(
F.Range.from_center_rel(24 * P.Mhertz, 0.05)
)
self.oscillator.crystal.frequency_tolerance.merge(
F.Range.upper_bound(20 * P.ppm)
)

# TODO: just set to a 1N4148
self.reset_diode.forward_voltage.merge(715 * P.mV)
self.reset_diode.reverse_leakage_current.merge(1 * P.uA)
self.reset_diode.current.merge(300 * P.mA)
self.reset_diode.max_current.merge(1 * P.A)
2 changes: 1 addition & 1 deletion src/faebryk/library/QWIIC.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class QWIIC(Module):

def __preinit__(self):
# set constraints
self.power.voltage.merge(F.Constant(3.3 * P.V))
self.power.voltage.merge(F.Range.from_center_rel(3.3 * P.V, 0.05))
# TODO: self.power.source_current.merge(F.Constant(226 * P.mA))

designator_prefix = L.f_field(F.has_designator_prefix_defined)("J")
Expand Down
30 changes: 20 additions & 10 deletions src/faebryk/library/RS485_Bus_Protection.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def __init__(self, termination: bool = True, polarization: bool = True) -> None:
def __preinit__(self):
if self._termination:
termination_resistor = self.add(F.Resistor(), name="termination_resistor")
termination_resistor.resistance.merge(F.Constant(120 * P.ohm))
termination_resistor.resistance.merge(
F.Range.from_center_rel(120 * P.ohm, 0.05)
)
self.rs485_out.diff_pair.p.connect_via(
termination_resistor, self.rs485_out.diff_pair.n
)
Expand All @@ -67,23 +69,31 @@ def __preinit__(self):
polarization_resistors[1], self.power.lv
)

self.current_limmiter_resistors[0].resistance.merge(F.Constant(2.7 * P.ohm))
self.current_limmiter_resistors[0].resistance.merge(
F.Range.from_center_rel(2.7 * P.ohm, 0.05)
)
# TODO: set power dissipation of resistor to 2W
self.current_limmiter_resistors[1].resistance.merge(F.Constant(2.7 * P.ohm))
self.current_limmiter_resistors[1].resistance.merge(
F.Range.from_center_rel(2.7 * P.ohm, 0.05)
)
# TODO: set power dissipation of resistor to 2W

self.gnd_couple_resistor.resistance.merge(F.Constant(1 * P.Mohm))
self.gnd_couple_capacitor.capacitance.merge(F.Constant(1 * P.uF))
self.gnd_couple_resistor.resistance.merge(
F.Range.from_center_rel(1 * P.Mohm, 0.05)
)
self.gnd_couple_capacitor.capacitance.merge(
F.Range.from_center_rel(1 * P.uF, 0.05)
)
self.gnd_couple_capacitor.rated_voltage.merge(F.Range.lower_bound(2 * P.kV))

self.tvs.reverse_working_voltage.merge(F.Constant(8.5 * P.V))
# self.tvs.max_current.merge(F.Constant(41.7*P.A))
self.tvs.reverse_working_voltage.merge(F.Range.from_center_rel(8.5 * P.V, 0.05))
# self.tvs.max_current.merge(F.Range.from_center_rel(41.7*P.A, 0.05))
# self.tvs.forward_voltage.merge(F.Range(9.44*P.V, 10.40*P.V))

for diode in self.clamping_diodes:
diode.forward_voltage.merge(F.Constant(1.1 * P.V))
diode.max_current.merge(F.Constant(1 * P.A))
diode.reverse_working_voltage.merge(F.Constant(1 * P.kV))
diode.forward_voltage.merge(F.Range.from_center_rel(1.1 * P.V, 0.05))
diode.max_current.merge(F.Range.from_center_rel(1 * P.A, 0.05))
diode.reverse_working_voltage.merge(F.Range.from_center_rel(1 * P.kV, 0.05))

# connections
# earth connections
Expand Down
13 changes: 9 additions & 4 deletions src/faebryk/library/SCD40.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ class _scd4x_esphome_config(F.has_esphome_config.impl()):

def get_config(self) -> dict:
val = self.update_interval.get_most_narrow()
assert isinstance(val, F.Constant), "No update interval set!"
assert isinstance(val, F.Constant)

obj = self.obj
assert isinstance(obj, SCD40)
obj = self.get_obj(SCD40)

i2c = F.is_esphome_bus.find_connected_bus(obj.i2c)

Expand All @@ -45,6 +44,12 @@ def get_config(self) -> dict:
]
}

def is_implemented(self):
return (
isinstance(self.update_interval.get_most_narrow(), F.Constant)
and super().is_implemented()
)

esphome_config: _scd4x_esphome_config

# interfaces
Expand All @@ -66,7 +71,7 @@ def attach_to_footprint(self):
)

def __preinit__(self):
self.power.voltage.merge(F.Constant(3.3 * P.V))
self.power.voltage.merge(F.Range.from_center_rel(3.3 * P.V, 0.05))
self.i2c.terminate()
self.power.decoupled.decouple()
self.i2c.frequency.merge(
Expand Down
2 changes: 1 addition & 1 deletion src/faebryk/library/USB_C_5V_PSU.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class USB_C_5V_PSU(Module):
configuration_resistors = L.list_field(
2,
lambda: F.Resistor().builder(
lambda r: r.resistance.merge(F.Constant(5.1 * P.kohm))
lambda r: r.resistance.merge(F.Range.from_center_rel(5.1 * P.kohm, 0.05))
),
)

Expand Down
2 changes: 1 addition & 1 deletion src/faebryk/library/USB_C_PSU_Vertical.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __preinit__(self):
for res in self.configuration_resistors:
res.resistance.merge(5.1 * P.kohm)
self.fuse.fuse_type.merge(F.Fuse.FuseType.RESETTABLE)
self.fuse.trip_current.merge(F.Constant(1 * P.A))
self.fuse.trip_current.merge(F.Range.from_center_rel(1 * P.A, 0.05))

# alliases
vcon = self.usb_connector.vbus
Expand Down
13 changes: 8 additions & 5 deletions src/faebryk/library/XL_3528RGBW_WS2812B.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ class _ws2812b_esphome_config(F.has_esphome_config.impl()):
update_interval: F.TBD

def get_config(self) -> dict:
assert isinstance(
self.update_interval, F.Constant
), "No update interval set!"
assert isinstance(self.update_interval, F.Constant)

obj = self.obj
assert isinstance(obj, XL_3528RGBW_WS2812B), "This is not a WS2812B RGBW!"
obj = self.get_obj(XL_3528RGBW_WS2812B)

data_pin = F.is_esphome_bus.find_connected_bus(obj.di.signal)

Expand All @@ -35,6 +32,12 @@ def get_config(self) -> dict:
]
}

def is_implemented(self):
return (
isinstance(self.update_interval.get_most_narrow(), F.Constant)
and super().is_implemented()
)

# interfaces

power: F.ElectricPower
Expand Down

0 comments on commit 22bdbd6

Please sign in to comment.