From 853c02962020173fd993abfdb5576e11ace91a36 Mon Sep 17 00:00:00 2001 From: napowderly Date: Thu, 29 Feb 2024 11:50:38 -0800 Subject: [PATCH] add equations support to leds, regulators and vdivs --- leds.ato | 20 +++++++++++++++++--- regulators.ato | 14 ++++++++++++-- resistors.ato | 1 + vdivs.ato | 16 +++++++++++++++- 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/leds.ato b/leds.ato index 3701024..ddd69a9 100644 --- a/leds.ato +++ b/leds.ato @@ -14,6 +14,14 @@ module LEDIndicator: resistor = new Resistor led = new LED resistor.package = "0402" + current: current + v_in: voltage + + # Default value + current = 1mA to 5mA + + assert (v_in - led.v_f) / resistor.value within current + assert current < led.i_max # Connect power power.vcc ~ input @@ -26,24 +34,26 @@ module LEDIndicatorRed from LEDIndicator: led -> _KT_0603R #Assuming 3.3v input, 2V forward voltage, 5mA current - resistor.value = 270ohms +/- 20% + # resistor.value = 270ohms +/- 20% module LEDIndicatorGreen from LEDIndicator: led -> _KT_0603G #Assuming 3.3v input, 2.75V forward voltage, 5mA current - resistor.value = 110ohms +/- 20% + # resistor.value = 110ohms +/- 20% module LEDIndicatorBlue from LEDIndicator: led -> _KT_0603B #Assuming 3.3v input, 2.9V forward voltage, 5mA current - resistor.value = 82ohms +/- 20% + # resistor.value = 82ohms +/- 20% component _KT_0603B from LED: # component Blue light 0603 footprint = "LED0603-RD" mpn = "C2288" + v_f = 2.9V + i_max = 20mA # pins signal cathode ~ pin 1 signal anode ~ pin 2 @@ -53,6 +63,8 @@ component _KT_0603G: footprint = "LED0603-RD" mpn = "C12624" designator_prefix = "LED" + v_f = 2.75V + i_max = 20mA # pins signal anode ~ pin 2 signal cathode ~ pin 1 @@ -61,6 +73,8 @@ component _KT_0603R: # component KT-0603R footprint = "LED0603-RD" mpn = "C2286" + v_f = 2V + i_max = 20mA # pins signal cathode ~ pin 1 signal anode ~ pin 2 diff --git a/regulators.ato b/regulators.ato index 588aa5a..ad44f48 100644 --- a/regulators.ato +++ b/regulators.ato @@ -1,5 +1,5 @@ import Power from "interfaces.ato" -import VDiv from "vdivs.ato" +import _VDiv from "vdivs.ato" module Regulator: power_in = new Power @@ -8,7 +8,17 @@ module Regulator: power_in.gnd ~ power_out.gnd module AdjustableRegulator from Regulator: - feedback_div = new VDiv + # using vanilla voltage divider without equations + feedback_div = new _VDiv + v_ref: voltage + i_q: current + r_total: resistance + v_in: voltage + v_out: voltage + + + assert v_ref * (1 + feedback_div.r_top.value / feedback_div.r_bottom.value) within v_out + assert v_out / (feedback_div.r_top.value + feedback_div.r_bottom.value) within i_q module Buck from AdjustableRegulator: # regulator parameters diff --git a/resistors.ato b/resistors.ato index 3ca0f71..f4f8cb0 100644 --- a/resistors.ato +++ b/resistors.ato @@ -7,6 +7,7 @@ component Resistor: designator_prefix = "R" mpn = "generic_resistor" type = "resistor" + value: resistance # Equations # R = V/I diff --git a/vdivs.ato b/vdivs.ato index a8c223f..80ce6c3 100644 --- a/vdivs.ato +++ b/vdivs.ato @@ -2,7 +2,21 @@ import Resistor from "resistors.ato" import Power from "interfaces.ato" import Pair from "interfaces.ato" -module VDiv: +module VDiv from _VDiv: + r_total: resistance + # ratio: None + v_in: voltage + v_out: voltage + i_q: current + + # assert r_top.value / r_bottom.value within ratio + assert r_top.value + r_bottom.value within r_total + assert v_in * r_bottom.value / (r_top.value + r_bottom.value) within v_out + # assert v_in * r_total within i_q + + + +module _VDiv: signal top signal out signal bottom