Python-script för att ta reda på en spänningsdelares värden
Postat: 8 maj 2010, 14:56:12
Jag vet inte hur ni andra går till väga, men många gånger har jag varit i situationen då jag behöver en spänningsdelare med vissa kriterier. Exempelvis får strömmen inte överstiga ett visst värde, och ibland har jag behövt kompromissa med referensvärdet och strömmen. Jag tröttnade till slut på att räkna manuellt fram och tillbaka och skrev därför ett Python-script som frågar efter nyckeldata och travar sen igenom en hel E-serie för att leta fram lämpliga värden, där man till slut får dem presenterade överskådligt.
Nedan är ett par testkörningar som visar hur det funkar. Om någon är intresserad av scriptet så säg till.
Körning med standardvärden (de som står inom parentes vid prompterna)
Dålig upplösning på E6-serien ger inga värden
E48 ger fin precision
Test med E96
Nedan är ett par testkörningar som visar hur det funkar. Om någon är intresserad av scriptet så säg till.
Kod: Markera allt
>>> ## working on region in file /usr/tmp/python-20506Vrc...
Voltage Divisor(tm), v0.01a
U
|
R1
|
+--- U_ref
|
R2
|
GND
--------------------
1 = E6
2 = E12 (default)
3 = E24
4 = E48
5 = E96
Select E-series:
Select U [V] (5):
Select wanted U_ref [V] (2.75):
Select max deviation from U_ref [V] (0.5):
Select I_max [mA] (50):
Select I_min [mA] (1):
To get U_ref = 2.73V, choose one of these 26 values from E12:
R1 = 100 R2 = 120 (I_tot = 22.73 mA)
R1 = 120 R2 = 120 (I_tot = 20.83 mA)
R1 = 150 R2 = 150 (I_tot = 16.67 mA)
R1 = 150 R2 = 180 (I_tot = 15.15 mA)
R1 = 180 R2 = 180 (I_tot = 13.89 mA)
R1 = 220 R2 = 220 (I_tot = 11.36 mA)
R1 = 270 R2 = 270 (I_tot = 9.26 mA)
R1 = 330 R2 = 330 (I_tot = 7.58 mA)
R1 = 330 R2 = 390 (I_tot = 6.94 mA)
R1 = 390 R2 = 390 (I_tot = 6.41 mA)
R1 = 390 R2 = 470 (I_tot = 5.81 mA)
R1 = 470 R2 = 470 (I_tot = 5.32 mA)
R1 = 470 R2 = 560 (I_tot = 4.85 mA)
R1 = 560 R2 = 560 (I_tot = 4.46 mA)
R1 = 560 R2 = 680 (I_tot = 4.03 mA)
R1 = 680 R2 = 680 (I_tot = 3.68 mA)
R1 = 680 R2 = 820 (I_tot = 3.33 mA)
R1 = 820 R2 = 820 (I_tot = 3.05 mA)
R1 = 820 R2 = 1000 (I_tot = 2.75 mA)
R1 = 1000 R2 = 1000 (I_tot = 2.50 mA)
R1 = 1000 R2 = 1200 (I_tot = 2.27 mA)
R1 = 1200 R2 = 1200 (I_tot = 2.08 mA)
R1 = 1500 R2 = 1500 (I_tot = 1.67 mA)
R1 = 1500 R2 = 1800 (I_tot = 1.52 mA)
R1 = 1800 R2 = 1800 (I_tot = 1.39 mA)
R1 = 2200 R2 = 2200 (I_tot = 1.14 mA)
Kod: Markera allt
1 = E6
2 = E12 (default)
3 = E24
4 = E48
5 = E96
Select E-series: 1
Select U [V] (5): 7.15
Select wanted U_ref [V] (2.75): 3.3
Select max deviation from U_ref [V] (0.5): 0.25
Select I_max [mA] (50): 80
Select I_min [mA] (1): 5
Found no good values.
Kod: Markera allt
1 = E6
2 = E12 (default)
3 = E24
4 = E48
5 = E96
Select E-series: 4
Select U [V] (5): 7.15
Select wanted U_ref [V] (2.75): 3.3
Select max deviation from U_ref [V] (0.5): 0.2
Select I_max [mA] (50): 2.05
Select I_min [mA] (1): 1.95
To get U_ref = 3.15V, choose one of these 3 values from E48:
R1 = 1960 R2 = 1540 (I_tot = 2.04 mA)
R1 = 1960 R2 = 1620 (I_tot = 2.00 mA)
R1 = 2050 R2 = 1540 (I_tot = 1.99 mA)
Kod: Markera allt
1 = E6
2 = E12 (default)
3 = E24
4 = E48
5 = E96
Select E-series: 5
Select U [V] (5):
Select wanted U_ref [V] (2.75):
Select max deviation from U_ref [V] (0.5):
Select I_max [mA] (50): 51
Select I_min [mA] (1): 49
To get U_ref = 2.71V, choose one of these 14 values from E96:
R1 = 45 R2 = 53 (I_tot = 50.56 mA)
R1 = 45 R2 = 54 (I_tot = 49.90 mA)
R1 = 46 R2 = 52 (I_tot = 50.66 mA)
R1 = 46 R2 = 53 (I_tot = 50.00 mA)
R1 = 46 R2 = 54 (I_tot = 49.36 mA)
R1 = 47 R2 = 51 (I_tot = 50.71 mA)
R1 = 47 R2 = 52 (I_tot = 50.10 mA)
R1 = 47 R2 = 53 (I_tot = 49.46 mA)
R1 = 48 R2 = 51 (I_tot = 50.10 mA)
R1 = 48 R2 = 52 (I_tot = 49.50 mA)
R1 = 49 R2 = 49 (I_tot = 50.92 mA)
R1 = 49 R2 = 51 (I_tot = 49.90 mA)
R1 = 49 R2 = 52 (I_tot = 49.31 mA)
R1 = 51 R2 = 49 (I_tot = 49.90 mA)