[分享] 用Python控制硬件 - 低电压启动与可靠性测试

pengshulin   2019-12-6 12:02 楼主

转载自:《用Python控制硬件46-低电压启动与可靠性测试》

 

产品研发阶段,有时需要了解在低电压供电时,设备能否依旧正常启动并工作,可以搭建如下的测试系统:

1、控制可编程电源输出测量电压。

2、使用光耦隔离数字IO板,检测被测系统的上电反馈,比如之前介绍的4款实验板,启动后LED灯都会0.5Hz频率闪烁,可以将LED的控制PIN脚接入光耦输入。

3、如果被测系统需要额外的启动开关按钮,可以将光耦输出到按钮信号线上,模拟开机动作。如果系统比较特殊,需要按下特殊功能键才能检测到反馈,也可以用此方法。

4、使用Shell Lab软件脚本控制测试整个流程,或者直接编写命令行下的Python脚本。

图中的DIO控制器是之前介绍的简易实验板+底板构成,可以控制8个光耦输入和8个光耦输出。

用实验板举例,按上面方式进行测试:

下面的代码输出正常工作电压,反复开关,检测实验板能否正常启动:

VOLTAGE = 5.0  # Volt
CURRENT = 5.0  # Amp
DETECT_PIN = '1.8'  # PB8 to detect LED feedback
DETECT_TIMEOUT = 5  # 检测超时 in seconds
DETECT_DEBOUNCE = 0.4  # 去抖动 in seconds

dio = Mcush.Mcush('/dev/ttyACM1')
dio.pinInput(DETECT_PIN)

power = Korad.KA3005P(PORT)
power.output( VOLTAGE, CURRENT )
v, a = power.getSetting()
info( 'Set: %.2f V / %.2f A'% (v, a) )

counter, counter_succ, counter_err = 0, 0, 0
while True:
    # power off
    power.outputDisable()
    time.sleep(0.5)  # wait for voltage drop down
    # power on
    power.outputEnable()
    # detect with timeout and debounce
    detected = False
    t0 = time.time()
    while time.time() < t0 + DETECT_TIMEOUT:
        t1 = time.time()
        while True:
            pin = not dio.pinRead(DETECT_PIN)
            if pin:
                if time.time() > t0 + DETECT_DEBOUNCE:
                    detected = True
            else:
                break
        if detected:
            break
    if detected:
        counter_succ += 1
    else:
        counter_err += 1
    counter += 1

    info( 'Count: %d  Succ: %d  Err: %d'% (counter,
            counter_succ, counter_err) )

测试状态计数值显示在底部:

下面脚本输出从低到高线性增加的电压,监测是否能否启动工作:

VOLTAGE_MIN = 1.0  # Volt
VOLTAGE_MAX = 5.0  # Volt
VOLTAGE_STEP = 20  # steps number
CURRENT = 5.0  # Amp
DETECT_PIN = '1.8'  # PB8 to detect LED feedback
DETECT_TIMEOUT = 5  # in seconds
DETECT_DEBOUNCE = 0.4  # in seconds

dio = Mcush.Mcush('/dev/ttyACM1')
dio.pinInput(DETECT_PIN)

power = Korad.KA3005P(PORT)
power.outputDisable()

p = getPlotPanel()
p.addPlot( 'result', 111, label_y='Succ', label_x='Voltage' )
p.setLimit( 'result', top=1.1, left=VOLTAGE_MIN, right=VOLTAGE_MAX, auto=False )
p.setLinestyle( 'result', ['-o'] )

volt_list = linspace(VOLTAGE_MIN, VOLTAGE_MAX, num=VOLTAGE_STEP)

for volt in volt_list:
    # output voltage
    power.output( volt, CURRENT )
    v, a = power.getSetting()
    info( 'Set: %.2f V / %.2f A'% (v, a) )

    # detect with timeout and debounce
    detected = False
    t0 = time.time()
    while time.time() < t0 + DETECT_TIMEOUT:
        t1 = time.time()
        while True:
            pin = not dio.pinRead(DETECT_PIN)
            if pin:
                if time.time() > t0 + DETECT_DEBOUNCE:
                    detected = True
            else:
                break
        if detected:
            break
    # 绘图输出结果,1-正常 0-异常
    p.addData( 'result', int(detected), volt )

    # power off
    power.outputDisable()
    time.sleep(0.5)  # wait for voltage drop down

缩小范围1.5V~2.0V,细化一下:

可以清楚地看到,板子在1.8V以下无法启动。

此实验只是演示作用(实验板通常稳定5V供电),在电池供电的手持设备测试中更具有实际意义。

 

回复评论

暂无评论,赶紧抢沙发吧
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复