Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- from typing import Tuple
- def voltage_divider(v_input: float, v_output: float, current: float) -> Tuple[float, float, float]:
- """
- Calculate a voltage divider.
- :param v_input: Input voltage in V
- :param v_output: Output voltage in V
- :param current: defined current in A
- :returns: r1, r2, v_output
- """
- R = v_input / current
- # e24 = [round(math.pow(10 ** x, 1/24), 1) for x in range(24)]
- e24 = [
- 1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0,
- 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3,
- 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1,
- ]
- r1 = R / v_input * (v_input - v_output)
- r2 = R - r1
- factor_1 = int(math.log10(r1))
- factor_2 = int(math.log10(r2))
- rr1, rr2 = 0, 0
- for res in e24:
- if res * 10 ** factor_1 <= r1:
- rr1 = res
- if res * 10 ** factor_2 <= r2:
- rr2 = res
- idx_1 = e24.index(rr1)
- idx_2 = e24.index(rr2)
- if idx_1 < len(e24):
- idx_1 += 1
- if idx_2 < len(e24):
- idx_2 += 1
- r1 = e24[idx_1] * 10 ** factor_1
- r2 = e24[idx_2] * 10 ** factor_2
- return r1, r2, v_input - v_input / (r1 + r2) * r1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement