PWM — 脉冲宽度调制是一种模拟控制方式

class PWM(...)

使用示例::(python)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# coding=utf-8
# This is a sample Python script.
from driver import PWM

print("-------------------pwm test--------------------")
pwm = PWM()
pwm.open("pwm3")
duty = pwm.getDuty()
freq = pwm.getFreq()
print(duty)
print(freq)
pwm.setConfig(3250000, 0.5)
duty = pwm.getDuty()
freq = pwm.getFreq()
print(duty)
print(freq)
pwm.close()
print("-------------------pwm end--------------------")

配置信息::(json)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# coding=utf-8
# This is a sample cjson file.
{
  "io": {
    "pwm0": {
      "type": "PWM",
      "port": 0
    },
    "pwm1": {
      "type": "PWM",
      "port": 1
    },
    "pwm2": {
      "type": "PWM",
      "port": 2
    },
    "pwm3": {
      "type": "PWM",
      "port": 3
    }
  },
  "debugLevel": "DEBUG"
}

操作函数

open(jsonConfigPath, type)

打开PWM并根据json文件配置PWM实例

close()

关闭pwm实例

setConfig(freq, duty)

设置PWM参数,同时会启动PWM输出

getDuty()

获取PWM duty参数

getFreq()

获取PWM频率参数

close()

关闭pwm实例