脉冲宽度调制(PWM)#

介绍#

脉冲宽度调制 (PWM) 通过 3 线端口输出定时脉冲信号,使 V5 大脑能够通过每 16 毫秒 (ms) 改变脉冲宽度(占空比)来控制传统的 电机控制器或伺服电机。

注意: Pwm 对象生成原始 RC 型 PWM 波形:

  • 0% 输出产生 1.5 毫秒的脉冲。

  • 100% 输出产生 2.0 毫秒的脉冲。

  • -100% 输出产生 1.0 毫秒的脉冲。

本页面使用 pwm_a 作为示例 PWM 输出名称。您可以根据需要将其替换为您自己配置的名称。

以下是可用方法列表:

  • value – 返回 PWM 输出的当前值。

  • state – 设置 PWM 输出值。

构造函数 – 手动初始化和配置 PWM 输出。

  • Pwm – 创建一个 PWM 输出。

价值#

value 返回 PWM 输出值(范围从 -100 到 100),以百分比表示。

Usage:
pwm_a.value()

参数

描述

此方法没有参数。

状态#

state 将 PWM 输出的状态设置为百分比。

Usage:
pwm_a.state(value)

参数

描述

value

PWM 输出值设置范围为 -100 到 100。

构造函数#

构造函数用于创建 Pwm 对象,这些对象是配置 PWM 输出所必需的。

Pwm#

Pwm 产生 PWM 输出。

Usage:
Pwm(port)

范围

描述

port

The 3-Wire Port that the PWM output is connected to:

  • On the V5 Brain – brain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expander – expander.a where expander is the name of the expander instance.

# Create a PWM output in Port A
pwm_a = Pwm(brain.three_wire_port.a)