使用 Python 计算 NCP380 Ilim 电阻
问题
你想为具有自定义电流限制的 NCP380 限流器 IC 计算 Ilim 电阻的正确值。
解决方案
此脚本不仅使用数据手册中的公式计算理论电阻值,还执行范围检查(NCP380 仅支持 0.1 到 2.1 安培的电流)并计算最接近的 E96 电阻值。
为了运行脚本,你需要将 Resistors.py 放在同一目录中(详情请参见此之前的文章)。
compute_ncp380.py
#!/usr/bin/env python3
"""
计算 NCP380 限流电阻 ValueError 的脚本
参见 http://www.onsemi.com/pub_link/Collateral/NCP380-D.PDF 第 17 页
基于 Resistors.py,参见
https://techoverflow.net/2015/05/19/finding-the-nearest-e96-resistor-value-in-python/
"""
from UliEngineering.Electronics.Resistors import *
from UliEngineering.EngineerIO import format_value
__author__ = "Uli Koehler"
__license__ = "CC0 1.0 Universal"
__version__ = "1.0"
def computeNCP380AdjResistor(ilim):
"""给定 Ilim 值(安培),
计算 NCP380 调节电阻的精确值"""
#检查限制
if ilim < 0.100: print("警告:NCP380 不支持低于 100 毫安的电流")
elif ilim > 2.1: print("警告:NCP380 不支持高于 2.1 安培的电流")
#根据数据手册中的方程 5 计算电阻
rlim = -5.2959 * ilim**5 + 45.256 * ilim**4 - 155.25 * ilim**3 + 274.39 * ilim**2 - 267.6 * ilim + 134.21
return rlim * 1000.0 #方程给出千欧
# 用法示例:计算 Ilim=0.23A 的 E96 Rlim
if __name__ == "__main__":
# 计算理论值
rlim = computeNCP380AdjResistor(0.23) #安培
# 计算最接近的实际值
actual_rlim = nearest_resistor(rlim, sequence=e96)
# 打印结果
print("理论 rlim 值:%s" % (format_value(rlim, "Ω")))
print("最接近的 E96 值:%s" % (format_value(actual_rlim, "Ω")))Check 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