PWM

预备知识

定时器

定时器介绍 OpenMV定时器资源 Channel

PWM概念

方波 (duty circle) 脉宽调制, 占空比(pulse_width_percent)

source code

利用定时器, 设置占空比

# PWM Control Example
#
# This example shows how to do PWM with your OpenMV Cam.
# 该例程展示了如何使用OpenMV实现脉宽调制
import time
from pyb import Pin, Timer

# Frequency in Hz
# 设定定时器 频率为 1000 HZ
tim = Timer(4, freq=1000)

# Generate a 1KHz square wave on TIM4 with 50% and 75% duty cycles on channels 1 and 2, respectively.
# 利用TIM4生成的1K HZ的方波, 生成Channel1(50%占空比) Channel2(75%占空比)
ch1 = tim.channel(1, Timer.PWM, pin=Pin("P7"), pulse_width_percent=50)
ch2 = tim.channel(2, Timer.PWM, pin=Pin("P8"), pulse_width_percent=75)

while (True):
    # 空循环, 什么也不干
    time.sleep(1000)
Copyright 杭州云江科技有限公司 2017 all right reserved,powered by Gitbook该文件修订时间: 2018-04-02 09:53:12

results matching ""

    No results matching ""