logo

如何使用openmv实现pwm输入捕获功能,进行占空比和周期的测量?

2022-10-24 22:29
5
sktc

如何使用openmv实现pwm输入捕获功能,进行占空比和周期的测量?

求程序代码,联系方式 企鹅758978342 必有重谢

2022-10-27 20:55
I
网红小智智 星瞳科技

https://docs.singtown.com/micropython/zh/latest/openmvcam/library/machine.html#machine.time_pulse_us

这个函数可以计算出脉宽时间。

参考:https://forum.micropython.org/viewtopic.php?t=7067

2022-10-28 15:07
5
sktc

我需要一个完整例程代码,STM32板级芯片复杂,不知道如何用它完整的实现读入PWM波和测量占空比的过程,查阅了大量资料,你们的相关教程只有输出的没有读入的。你的回答只是提供一个函数,没有说明它的使用条件,并且关于函数的参数和用法介绍也是相当的敷衍。

希望您提供一个完整的历程代码以供参考。

2022-10-28 16:40
5
sktc

@kidswong999

d3e2884a-1c24-48a4-a9a2-6cedbb03e8cf.png

Pin.board.X4 这在板子上应该连接哪个引脚?

下面这段函数的作用是什么?为什么PW要进行计算后在传回给函数?

a686dc44-2feb-46bd-aeb0-3d15df43c5e1.png
2022-10-28 21:57
I
网红小智智 星瞳科技

那个IC的例子我跑不起来,所以我重新写了一个OpenMV可以用的。

原理:利用引脚边沿中断,计算时间。

用杜邦线把P7和P8连起来,P7生成PWM脉冲,P8读取PWM脉冲

import micropython
micropython.alloc_emergency_exception_buf(100)

from pyb import Pin, Timer, ExtInt
import pyb

t4 = Timer(4, freq=1000) # Frequency in Hz
pwm_gen = t4.channel(1, Timer.PWM, pin=Pin("P7"), pulse_width_percent=10)


high_start = 0
high_end = 0
pulse_high_width = 0
pulse_low_width = 0

pin_read = Pin('P8')

def cb(tim):
    global high_start
    global high_end
    global pulse_high_width
    global pulse_low_width
    # Read the GPIO pin to figure out if this was a rising or falling edge
    if pin_read.value():
        # Rising edge - start of the pulse
        high_start = pyb.micros()
        pulse_low_width = high_start - high_end
    else:
        # Falling edge - end of the pulse
        high_end = pyb.micros()
        pulse_high_width = high_end - high_start
        
        
ext = ExtInt(pin_read, ExtInt.IRQ_RISING_FALLING, Pin.PULL_NONE, cb)

while True:
    pyb.delay(200)
    print(", pulse_high_width = %d, pulse_low_width = %d" % ( pulse_high_width, pulse_low_width))
2022-10-29 01:44
5
sktc

@kidswong999

谢谢!