Skip to content

Commit e6a7bf7

Browse files
Suke0811ducky64
andauthored
Pmos (#328)
- Add: PMOS and PMOS reverse charger protection in the lib - Add: test_protected_charger --- ### related issues #323 --------- Co-authored-by: Richard Lin <[email protected]>
1 parent 2c84e6c commit e6a7bf7

File tree

7 files changed

+5256
-1
lines changed

7 files changed

+5256
-1
lines changed

electronics_lib/PowerConditioning.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional, cast
22

33
from electronics_abstract_parts import *
4+
from electronics_model.PassivePort import PassiveAdapterVoltageSink, PassiveAdapterVoltageSource
45

56

67
class Supercap(DiscreteComponent, FootprintBlock): # TODO actually model supercaps and parts selection
@@ -263,3 +264,116 @@ def connected_from(self, gnd: Optional[Port[VoltageLink]] = None, pwr_hi: Option
263264
if pwr_lo is not None:
264265
cast(Block, builder.get_enclosing_block()).connect(pwr_lo, self.pwr_lo)
265266
return self
267+
268+
269+
class PmosReverseProtection(PowerConditioner, KiCadSchematicBlock, Block):
270+
"""Reverse polarity protection using a PMOS. This method has lower power loss over diode-based protection.
271+
100R-330R is good but 1k-50k can be used for continuous load.
272+
Ref: https://components101.com/articles/design-guide-pmos-mosfet-for-reverse-voltage-polarity-protection
273+
"""
274+
275+
@init_in_parent
276+
def __init__(self, gate_resistor: RangeLike = 10 * kOhm(tol=0.05), rds_on: RangeLike = (0, 0.1) * Ohm):
277+
super().__init__()
278+
self.gnd = self.Port(Ground.empty(), [Common])
279+
self.pwr_in = self.Port(VoltageSink.empty())
280+
self.pwr_out = self.Port(VoltageSource.empty())
281+
282+
self.gate_resistor = self.ArgParameter(gate_resistor)
283+
self.rds_on = self.ArgParameter(rds_on)
284+
285+
def contents(self):
286+
super().contents()
287+
output_current_draw = self.pwr_out.link().current_drawn
288+
self.fet = self.Block(Fet.PFet(
289+
drain_voltage=(0, self.pwr_out.link().voltage.upper()),
290+
drain_current=output_current_draw,
291+
gate_voltage=(- self.pwr_out.link().voltage.upper(), self.pwr_out.link().voltage.upper()),
292+
rds_on=self.rds_on,
293+
))
294+
295+
self.res = self.Block(Resistor(self.gate_resistor))
296+
# TODO: generate zener diode for high voltage applications
297+
# self.diode = self.Block(ZenerDiode(self.clamp_voltage))
298+
299+
self.import_kicad(
300+
self.file_path("resources", f"{self.__class__.__name__}.kicad_sch"),
301+
conversions={
302+
'pwr_in': VoltageSink(
303+
current_draw=output_current_draw,
304+
),
305+
'pwr_out': VoltageSource(
306+
voltage_out=self.pwr_in.link().voltage,
307+
),
308+
'gnd': Ground(),
309+
})
310+
311+
312+
class PmosChargerReverseProtection(PowerConditioner, KiCadSchematicBlock, Block):
313+
"""Charging capable a battery reverse protection using PMOS transistors. The highest battery voltage is bounded by the
314+
transistors' Vgs/Vds. There is also a rare case when this circuit being disconnected when a charger is connected first.
315+
But always reverse protect. R1 and R2 are the pullup bias resistors for mp1 and mp2 PFet.
316+
More info at: https://www.edn.com/reverse-voltage-protection-for-battery-chargers/
317+
"""
318+
319+
@init_in_parent
320+
def __init__(self, r1_val: RangeLike = 100 * kOhm(tol=0.01), r2_val: RangeLike = 100 * kOhm(tol=0.01),
321+
rds_on: RangeLike = (0, 0.1) * Ohm):
322+
super().__init__()
323+
324+
self.gnd = self.Port(Ground.empty(), [Common])
325+
self.pwr_out = self.Port(VoltageSource.empty(), doc="Power output for a load which will be also reverse protected from the battery")
326+
self.pwr_in = self.Port(VoltageSink.empty(), doc="Power input from the battery")
327+
self.chg_in = self.Port(VoltageSink.empty(), doc="Charger input to charge the battery. Must be connected to pwr_out.")
328+
self.chg_out = self.Port(VoltageSource.empty(), doc="Charging output to the battery chg port. Must be connected to pwr_in,")
329+
330+
self.r1_val = self.ArgParameter(r1_val)
331+
self.r2_val = self.ArgParameter(r2_val)
332+
self.rds_on = self.ArgParameter(rds_on)
333+
334+
def contents(self):
335+
super().contents()
336+
self.r1 = self.Block(Resistor(resistance=self.r1_val))
337+
self.r2 = self.Block(Resistor(resistance=self.r2_val))
338+
339+
batt_voltage = self.pwr_in.link().voltage.hull(self.chg_in.link().voltage).hull(self.gnd.link().voltage)
340+
341+
# taking the max of the current for the both direction. 0 lower bound
342+
batt_current = self.pwr_out.link().current_drawn.hull(self.chg_out.link().current_drawn).hull((0, 0))
343+
power = batt_current * batt_current * self.rds_on
344+
r1_current = batt_voltage / self.r1.resistance
345+
346+
# Create the PMOS transistors and resistors based on the provided schematic
347+
self.mp1 = self.Block(Fet.PFet(
348+
drain_voltage=batt_voltage, drain_current=r1_current,
349+
gate_voltage=(-batt_voltage.upper(), batt_voltage.upper()),
350+
rds_on=self.rds_on,
351+
))
352+
self.mp2 = self.Block(Fet.PFet(
353+
drain_voltage=batt_voltage, drain_current=batt_current,
354+
gate_voltage=(- batt_voltage.upper(), batt_voltage.upper()),
355+
rds_on=self.rds_on,
356+
power=power
357+
))
358+
359+
chg_in_adapter = self.Block(PassiveAdapterVoltageSink())
360+
setattr(self, '(adapter)chg_in', chg_in_adapter) # hack so the netlister recognizes this as an adapter
361+
self.connect(self.mp1.source, chg_in_adapter.src)
362+
self.connect(self.chg_in, chg_in_adapter.dst)
363+
364+
chg_out_adapter = self.Block(PassiveAdapterVoltageSource())
365+
setattr(self, '(adapter)chg_out', chg_out_adapter) # hack so the netlister recognizes this as an adapter
366+
self.connect(self.r2.b, chg_out_adapter.src)
367+
self.connect(self.chg_out, chg_out_adapter.dst)
368+
369+
self.import_kicad(
370+
self.file_path("resources", f"{self.__class__.__name__}.kicad_sch"),
371+
conversions={
372+
'pwr_in': VoltageSink(
373+
current_draw=batt_current
374+
),
375+
'pwr_out': VoltageSource(
376+
voltage_out=batt_voltage
377+
),
378+
'gnd': Ground(),
379+
})

electronics_lib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
from .SwitchedCap_TexasInstruments import Lm2664
6969
from .BuckConverter_Custom import CustomSyncBuckConverterIndependent
7070
from .BuckBoostConverter_Custom import CustomSyncBuckBoostConverterPwm
71-
from .PowerConditioning import BufferedSupply, Supercap, SingleDiodePowerMerge, DiodePowerMerge, PriorityPowerOr
71+
from .PowerConditioning import BufferedSupply, Supercap, SingleDiodePowerMerge, DiodePowerMerge, PriorityPowerOr, PmosReverseProtection, PmosChargerReverseProtection
7272
from .LedDriver_Al8861 import Al8861
7373
from .ResetGenerator_Apx803s import Apx803s
7474
from .BootstrapVoltageAdder import BootstrapVoltageAdder

0 commit comments

Comments
 (0)