logo

PWM口占空比只能整数吗?不能是小数?

2023-03-02 08:51
8
祸榊
543131e7-c224-446d-a7c4-6f88138936a9.png
2023-03-02 20:14
I
网红小智智 星瞳科技

PWM占空比只能是整数。

2023-03-03 13:06
8
祸榊

如果我想输出一个周期20ms,0.5ms高电平的PWM怎么做呢?

2023-03-06 19:23
I
网红小智智 星瞳科技
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)