Example: 50-Arduino-Boards/Portenta-H7/50-Board-Control/pwm_control.py
# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# PWM 控制示例
#
# This example shows how to do PWM with your OpenMV Cam.
#
#
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# !!! NOTE !!!
# 这是使用视觉防护罩时唯一可用的空闲引脚。
# 使用视觉防护罩时,请勿使用其他任何引脚。
# PWM7/PH15
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
import time
from pyb import Pin, Timer
class PWM:
def __init__(self, pin, tim, ch):
self.pin = pin
self.tim = tim
self.ch = ch
pwms = {
# 'PWM1' : PWM('PA8', 1, 1), # TIM1 is Reserved.
"PWM2": PWM("PC6", 3, 1),
"PWM3": PWM("PC7", 3, 2),
# 'PWM4' : PWM('PG7', 0, 0), # HRTIM not supported.
"PWM5": PWM("PJ11", 8, 2),
"PWM6": PWM("PK1", 8, 3),
"PWM7": PWM("PH15", 8, 3),
}
# 在以下 PWM 上生成一个 1KHz 的方波,占空比为 50%。
for k, pwm in pwms.items():
tim = Timer(pwm.tim, freq=1000) # 频率(Hz)
ch = tim.channel(pwm.ch, Timer.PWM, pin=Pin(pwm.pin), pulse_width_percent=50)
while True:
time.sleep_ms(1000)