Erweiterte LED-Vorwiderstand & Leistungsverlustberechnung mit Python
English
Deutsch
Das folgende Skript verwendet UliEngineering (Version 0.4.20+ erforderlich), um den Vorwiderstandswert und die Leistungsverlustberechnung für eine Vorwiderstands- und LED-Schaltung zu berechnen.
Es wählt auch den nächsten Standardwiderstand für dich aus und wiederholt die Berechnung mit diesem Widerstandswert.
Darüber hinaus berücksichtigt es die Toleranz des Widerstands für sowohl den LED-Strom als auch die Leistungsverlust des Widerstands und den Durchlassspannungsbereich der LED, sodass du niemals eine sichere Leistungsverlustgrenze überschreitest, selbst bei Bauteiltoleranzen.
led_series_calc.py
# Konfigurationsparameter
from UliEngineering.Electronics.LED import *
from UliEngineering.Electronics.Resistors import *
from UliEngineering.EngineerIO import *
### BEGINN DER KONFIGURATION ###
desired_led_current = "8mA"
vsupply = "3.3V"
vforward_min = "1.8V"
vforward_max = "2.4V"
# Typische Durchlassspannung ist oft der Durchschnitt von min und max
# (oder du kannst einen spezifischen typischen Wert eingeben, falls du einen hast)
vforward_min_val = normalize_numeric(vforward_min)
vforward_max_val = normalize_numeric(vforward_max)
vforward_typ_val = (vforward_min_val + vforward_max_val) / 2
vforward_typ = f"{vforward_typ_val}V"
tolerance = "1%" # typisch 1% oder 5%
# Wähle, ob der nächsthöhere oder niedrigere Standardwiderstandswert ausgewählt wird
# ("higher" ergibt weniger Strom, "lower" ergibt mehr Strom)
higher_or_lower_resistor = next_higher_resistor
### ENDE DER KONFIGURATION ###
print(f"LED Series Resistor calculation for a LED with Vf min..typ..max: {vforward_min}..{vforward_typ}..{vforward_max}")
print()
# Hilfsfunktion: Liste der Durchlassspannungen (min, typ, max)
vforward_vals = [vforward_min_val, vforward_typ_val, vforward_max_val]
# Ideale Vorwiderstände für min-, typ- und max-Durchlassspannungen berechnen
series_resistors = [led_series_resistor(vsupply, desired_led_current, vf) for vf in vforward_vals]
# Widerstandswerte für kompakte Ausgabe vorformatieren
series_resistors_fmt = [format_value(r, 'Ω') for r in series_resistors]
print(f"Ideal LED series resistor for {vsupply} and {desired_led_current}: {series_resistors_fmt[0]}..{series_resistors_fmt[1]}..{series_resistors_fmt[2]}")
# Leistungsverlust des idealen Widerstands für jede Durchlassspannung
powers_ideal = [led_series_resistor_power(vsupply, desired_led_current, vf) for vf in vforward_vals]
# Leistungswerte für kompakte Ausgabe vorformatieren
powers_ideal_fmt = [format_value(p, 'W') for p in powers_ideal]
print(f"Power dissipated by the ideal series resistor: {powers_ideal_fmt[0]}..{powers_ideal_fmt[1]}..{powers_ideal_fmt[2]}")
# Nächsthöheren Standard-E24-Widerstandswert ermitteln
print()
# Standardwiderstand basierend auf dem TYPISCHEN (mittleren) idealen Wert wählen
standard_series_resistor = higher_or_lower_resistor(series_resistors[1], sequence=e24)
standard_series_resistor_fmt = format_value(standard_series_resistor, 'Ω')
print(f"Next standard resistor value: {standard_series_resistor_fmt}")
# Tatsächlichen Strom durch LED & Vorwiderstand für min..typ..max bei Auswahl des nächsten Standardwiderstands berechnen
standard_currents = [led_series_resistor_current(vsupply, standard_series_resistor, vf) for vf in vforward_vals]
# Ströme für kompakte Ausgabe vorformatieren
standard_currents_fmt = [format_value(I, 'A') for I in standard_currents]
print(f"Current through the LED & series resistor: {standard_currents_fmt[0]}..{standard_currents_fmt[1]}..{standard_currents_fmt[2]}")
# Tatsächlichen Leistungsverlust im ausgewählten Standardwiderstand für jede Durchlassspannung berechnen
standard_powers = [power_dissipated_in_resistor_by_current(standard_series_resistor, I) for I in standard_currents]
# Pre-format powers for concise printing
standard_powers_fmt = [format_value(p, 'W') for p in standard_powers]
print(f"Power dissipated by the {standard_series_resistor_fmt} series resistor: {standard_powers_fmt[0]}..{standard_powers_fmt[1]}..{standard_powers_fmt[2]}")
# Maximal zulässigen Strom für den Vorwiderstand berechnen
max_current = led_series_resistor_maximum_current(resistance=standard_series_resistor, power_rating="250mW")
print(f"Maximum permissible current for the {standard_series_resistor_fmt} series resistor: {format_value(max_current, 'A')}")
# Leistungsverlust berechnen, wenn der Widerstand am unteren oder oberen Ende seiner Toleranz liegt
print()
# Toleranzgrenzen ermitteln
tolerance_bounds = resistor_tolerance(resistance=standard_series_resistor, tolerance=tolerance)
lowest_resistor_value = tolerance_bounds.lower
highest_resistor_value = tolerance_bounds.upper
lowest_resistor_value_fmt = format_value(lowest_resistor_value, 'Ω')
highest_resistor_value_fmt = format_value(highest_resistor_value, 'Ω')
# Unteres Ende (kleinerer Widerstand -> höherer Strom)
print(f"If the {standard_series_resistor_fmt} resistor is at the lower end of its {tolerance} tolerance ({lowest_resistor_value_fmt}):")
lowest_resistor_currents = [led_series_resistor_current(vsupply, lowest_resistor_value, vf) for vf in vforward_vals]
lowest_resistor_currents_fmt = [format_value(I, 'A') for I in lowest_resistor_currents]
print(f"Current through the LED & {lowest_resistor_value_fmt} series resistor: {lowest_resistor_currents_fmt[0]}..{lowest_resistor_currents_fmt[1]}..{lowest_resistor_currents_fmt[2]}")
lowest_resistor_powers = [power_dissipated_in_resistor_by_current(lowest_resistor_value, I) for I in lowest_resistor_currents]
lowest_resistor_powers_fmt = [format_value(p, 'W') for p in lowest_resistor_powers]
print(f"Power dissipated by the {lowest_resistor_value_fmt} series resistor: {lowest_resistor_powers_fmt[0]}..{lowest_resistor_powers_fmt[1]}..{lowest_resistor_powers_fmt[2]}")
# Oberes Ende (größerer Widerstand -> niedrigerer Strom)
print()
print(f"If the {standard_series_resistor_fmt} resistor is at the upper end of its {tolerance} tolerance ({highest_resistor_value_fmt}):")
highest_resistor_currents = [led_series_resistor_current(vsupply, highest_resistor_value, vf) for vf in vforward_vals]
highest_resistor_currents_fmt = [format_value(I, 'A') for I in highest_resistor_currents]
print(f"Current through the LED & {highest_resistor_value_fmt} series resistor: {highest_resistor_currents_fmt[0]}..{highest_resistor_currents_fmt[1]}..{highest_resistor_currents_fmt[2]}")
highest_resistor_powers = [power_dissipated_in_resistor_by_current(highest_resistor_value, I) for I in highest_resistor_currents]
highest_resistor_powers_fmt = [format_value(p, 'W') for p in highest_resistor_powers]
print(f"Power dissipated by the {highest_resistor_value_fmt} series resistor: {highest_resistor_powers_fmt[0]}..{highest_resistor_powers_fmt[1]}..{highest_resistor_powers_fmt[2]}")Beispielausgabe
led_resistor_output.txt
LED Series Resistor calculation for a LED with Vf min..typ..max: 1.8V..2.1V..2.4V
Ideal LED series resistor for 3.3V and 8mA: 187 Ω..150 Ω..112 Ω
Power dissipated by the ideal series resistor: 12.0 mW..9.60 mW..7.20 mW
Next standard resistor value: 150 Ω
Current through the LED & series resistor: 10.00 mA..8.00 mA..6.00 mA
Power dissipated by the 150 Ω series resistor: 15.0 mW..9.60 mW..5.40 mW
Maximum permissible current for the 150 Ω series resistor: 40.8 mA
If the 150 Ω resistor is at the lower end of its 1% tolerance (148 Ω):
Current through the LED & 148 Ω series resistor: 10.1 mA..8.08 mA..6.06 mA
Power dissipated by the 148 Ω series resistor: 15.2 mW..9.70 mW..5.45 mW
If the 150 Ω resistor is at the upper end of its 1% tolerance (152 Ω):
Current through the LED & 152 Ω series resistor: 9.90 mA..7.92 mA..5.94 mA
Power dissipated by the 152 Ω series resistor: 14.9 mW..9.50 mW..5.35 mWCheck out similar posts by category:
Electronics, Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow