Created
December 22, 2020 18:06
-
-
Save cibomahto/ba82444b7a5abfeb87514d3c4921998d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# Common resistor values for 5% | |
resistor_vals_E24 = np.array([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]) | |
# Common resistor values for 1% | |
resistor_vals_E96 = np.array([1.00, 1.02, 1.05, 1.07, 1.10, 1.13, 1.15, 1.18, 1.21, 1.24, 1.27, 1.30, 1.33, 1.37, 1.40, 1.43, 1.47, 1.50, 1.54, 1.58, 1.62, 1.65, 1.69, 1.74, 1.78, 1.82, 1.87, 1.91, 1.96, 2.00, 2.05, 2.10, 2.15, 2.21, 2.26, 2.32, 2.37, 2.43, 2.49, 2.55, 2.61, 2.67, 2.74, 2.80, 2.87, 2.94, 3.01, 3.09, 3.16, 3.24, 3.32, 3.40, 3.48, 3.57, 3.65, 3.74, 3.83, 3.92, 4.02, 4.12, 4.22, 4.32, 4.42, 4.53, 4.64, 4.75, 4.87, 4.99, 5.11, 5.23, 5.36, 5.49, 5.62, 5.76, 5.90, 6.04, 6.19, 6.34, 6.49, 6.65, 6.81, 6.98, 7.15, 7.32, 7.50, 7.68, 7.87, 8.06, 8.25, 8.45, 8.66, 8.87, 9.09, 9.31, 9.53, 9.76]) | |
def BL9352A_resistor_calc(Vout, resistor_vals): | |
# Generate a big array of all resistor values over some decades | |
vals = np.empty(1) | |
for decade in [1000,10000,100000]: | |
vals = np.append(vals, resistor_vals*decade) | |
solutions = [] | |
for rtop in vals: | |
for rbot in vals: | |
Vout_actual =(rtop/rbot+1)*0.795 | |
err_abs = abs((Vout_actual-Vout)/Vout) | |
solutions.append([rtop,rbot,Vout_actual,err_abs]) | |
solutions.sort(key = lambda x: x[3]) | |
for solution in solutions[0:10]: | |
print("rtop:{:.2f} rbot:{:.2f} vout:{:.2f} error:{:.2f}%".format(solution[0], solution[1], solution[2], solution[3]*100)) | |
Vout = 3.3 | |
BL9352A_resistor_calc(Vout, resistor_vals_E24) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment