
PWM占空比只能是整数。
如果我想输出一个周期20ms,0.5ms高电平的PWM怎么做呢?
import time
from pyb import Pin, Timer
tim = Timer(4, freq=50)
ch1 = tim.channel(1, Timer.PWM, pin=Pin("P7"))
pulse_width = int(tim.period()*0.125)
ch1.pulse_width(pulse_width)
while (True):
time.sleep_ms(1000)