设置PWM频率为50HZ,一个周期就是20ms,用ch1.pulse_width_percent(5)即为5%的占空比,也就是1ms;那么如果用ch1.pulse_width(),相同的占空比需要设置括号内的数字为多少?
我的初始化代码如下
import time
from pyb import Pin, Timer
tim = Timer(4, freq=50)#Time4;50HZ
ch1 = tim.channel(1, Timer.PWM, pin=Pin("P7"), pulse_width_percent=0)
ch2 = tim.channel(2, Timer.PWM, pin=Pin("P8"), pulse_width=0)
while (True):直接运行一下就知道了。
import time
from pyb import Pin, Timer
tim = Timer(4, freq=50)#Time4;50HZ
ch1 = tim.channel(1, Timer.PWM, pin=Pin("P7"), pulse_width_percent=5)
print(ch1.pulse_width())不同的硬件还不一样。
1920
864