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

Commit

Permalink
Add: INA288
Browse files Browse the repository at this point in the history
  • Loading branch information
ruben-iteng committed Sep 6, 2024
1 parent eec3a53 commit ec70f51
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 0 deletions.
80 changes: 80 additions & 0 deletions src/faebryk/library/INA228.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# This file is part of the faebryk project
# SPDX-License-Identifier: MIT

import logging

import faebryk.library._F as F
from faebryk.core.module import Module
from faebryk.libs.library import L
from faebryk.libs.units import P

logger = logging.getLogger(__name__)


class INA228(Module):
def set_address(self, address: int = 0x00) -> None:
"""Set the I2C address of the INA228"""
# allias
gnd = self.power.lv
vs = self.power.hv
sda = self.i2c.sda
scl = self.i2c.scl

address_map = {
0b0000: (gnd, gnd),
0b0001: (gnd, vs),
0b0010: (gnd, sda),
0b0011: (gnd, scl),
0b0100: (vs, gnd),
0b0101: (vs, vs),
0b0110: (vs, sda),
0b0111: (vs, scl),
0b1000: (sda, gnd),
0b1001: (sda, vs),
0b1010: (sda, sda),
0b1011: (sda, scl),
0b1100: (scl, gnd),
0b1101: (scl, vs),
0b1110: (scl, sda),
0b1111: (scl, scl),
}
address |= 0b1000000
# address looks like 0b100xxxx

a1_connect, a0_connect = address_map.get(address, (gnd, gnd))
self.address_config_pin[0].connect(a0_connect)
self.address_config_pin[1].connect(a1_connect)

# ----------------------------------------
# modules, interfaces, parameters
# ----------------------------------------
i2c: F.I2C
power: F.ElectricPower
address_config_pin = L.list_field(2, F.ElectricLogic)
alert: F.ElectricLogic
bus_voltage_sense: F.Electrical
differential_input: F.DifferentialPair

# ----------------------------------------
# traits
# ----------------------------------------
designator_prefix = L.f_field(F.has_designator_prefix_defined)("U")
datasheet = L.f_field(F.has_datasheet_defined)(
"https://www.ti.com/lit/ds/symlink/ina228.pdf"
)

@L.rt_field
def single_electric_reference(self):
return F.has_single_electric_reference_defined(
F.ElectricLogic.connect_all_module_references(self)
)

def __preinit__(self):
# ------------------------------------
# connections
# ------------------------------------

# ------------------------------------
# parametrization
# ------------------------------------
self.power.voltage.merge(F.Range(2.7 * P.V, 5.5 * P.V))
79 changes: 79 additions & 0 deletions src/faebryk/library/INA228_ReferenceDesign.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# This file is part of the faebryk project
# SPDX-License-Identifier: MIT

import logging

import faebryk.library._F as F
from faebryk.core.module import Module
from faebryk.libs.library import L
from faebryk.libs.units import P

logger = logging.getLogger(__name__)


class INA228_ReferenceDesign(Module):
# ----------------------------------------
# modules, interfaces, parameters
# ----------------------------------------
shunt: F.Resistor
ina288: F.INA228

pwr_load: F.ElectricPower
pwr_source: F.ElectricPower

# ----------------------------------------
# traits
# ----------------------------------------
@L.rt_field
def can_bridge(self):
(F.can_bridge_defined(self.pwr_load, self.pwr_source))

@L.rt_field
def single_electric_reference(self):
return F.has_single_electric_reference_defined(
F.ElectricLogic.connect_all_module_references(self, gnd_only=True)
)

def __init__(self, filtered: bool = False):
super().__init__()
self._filtered = filtered

def __preinit__(self):
# ----------------------------------------
# parametrization
# ----------------------------------------
self.shunt.resistance.merge(15 * P.mohm)
self.shunt.rated_power.merge(2 * P.W)
# TODO: calculate according to datasheet p36

if self._filtered:
filter_cap = F.Capacitor()
filter_resistors = L.list_field(2, F.Resistor)

filter_cap.capacitance.merge(0.1 * P.uF)
filter_cap.rated_voltage.merge(170 * P.V)
for res in filter_resistors:
res.resistance.merge(10 * P.kohm)
# TODO: auto calculate, see: https://www.ti.com/lit/ug/tidu473/tidu473.pdf

# ----------------------------------------
# connections
# ----------------------------------------
self.pwr_load.hv.connect_via(self.shunt, self.pwr_source.hv)
self.ina288.bus_voltage_sense.connect(self.pwr_load.hv)
if self._filtered:
self.pwr_load.hv.connect_via(filter_cap, self.pwr_source.hv)
self.ina288.differential_input.n.connect_via(
filter_resistors[1], self.pwr_load.hv
)
self.ina288.differential_input.p.connect_via(
filter_resistors[0], self.pwr_source.hv
)
else:
self.ina288.differential_input.n.connect(self.pwr_load.hv)
self.ina288.differential_input.p.connect(self.pwr_source.hv)

# decouple power rail
self.ina288.power.get_trait(F.can_be_decoupled).decouple().capacitance.merge(
0.1 * P.uF
)
2 changes: 2 additions & 0 deletions src/faebryk/library/_F.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
from faebryk.library.Logic74xx import Logic74xx
from faebryk.library.BH1750FVI_TR import BH1750FVI_TR
from faebryk.library.EEPROM import EEPROM
from faebryk.library.INA228 import INA228
from faebryk.library.ISO1540 import ISO1540
from faebryk.library.M24C08_FMN6TP import M24C08_FMN6TP
from faebryk.library.OLED_Module import OLED_Module
Expand All @@ -195,6 +196,7 @@
from faebryk.library.USB3_IF import USB3_IF
from faebryk.library.can_switch_power_defined import can_switch_power_defined
from faebryk.library.CD4011 import CD4011
from faebryk.library.INA228_ReferenceDesign import INA228_ReferenceDesign
from faebryk.library.RS232_3D5R_Tranceiver import RS232_3D5R_Tranceiver
from faebryk.library.CBM9002A_56ILG import CBM9002A_56ILG
from faebryk.library.CH340x import CH340x
Expand Down

0 comments on commit ec70f51

Please sign in to comment.