





















配置
使用
echo 2 > export
cd pwm2
echo 1000000 > period #可配置,周期
echo 500000 > duty_cycle #可配置,占空比
echo 1 > enable #开始
#echo normal > polarity #可配置,极性,默认normal
echo 0 > enable #停止
cd .. #回到pwmchip0
echo 2 > unexport
local PWM = Periphery.PWM
local PWM_Chip_Channel=PWM(0,2)
-- PWM_CHIP, PWM_CHANNEL
PWM_Chip_Channel.frequency = 1000000
PWM_Chip_Channel.duty_cycle = 0.5
PWM_Chip_Channel:enable()
--
PWM_Chip_Channel:disable()
PWM_Chip_Channel:close()
Name: pwm
Info: Configures a single PWM channel
Legal pin,function combinations for each channel:
PWM0: 12,4(Alt0) 18,2(Alt5) 40,4(Alt0) 52,5(Alt1)
PWM1: 13,4(Alt0) 19,2(Alt5) 41,4(Alt0) 45,4(Alt0) 53,5(Alt1)
N.B.:
1) Pin 18 is the only one available on all platforms, and
it is the one used by the I2S audio interface.
Pins 12 and 13 might be better choices on an A+, B+ or Pi2.
2) The onboard analogue audio output uses both PWM channels.
3) So be careful mixing audio and PWM.
4) Currently the clock must have been enabled and configured
by other means.
Load: dtoverlay=pwm,<param>=<val>
Params: pin Output pin (default 18) - see table
func Pin function (default 2 = Alt5) - see above
clock PWM clock frequency (informational)
Name: pwm-2chan
Info: Configures both PWM channels
Legal pin,function combinations for each channel:
PWM0: 12,4(Alt0) 18,2(Alt5) 40,4(Alt0) 52,5(Alt1)
PWM1: 13,4(Alt0) 19,2(Alt5) 41,4(Alt0) 45,4(Alt0) 53,5(Alt1)
N.B.:
1) Pin 18 is the only one available on all platforms, and
it is the one used by the I2S audio interface.
Pins 12 and 13 might be better choices on an A+, B+ or Pi2.
2) The onboard analogue audio output uses both PWM channels.
3) So be careful mixing audio and PWM.
4) Currently the clock must have been enabled and configured
by other means.
Load: dtoverlay=pwm-2chan,<param>=<val>
Params: pin Output pin (default 18) - see table
pin2 Output pin for other channel (default 19)
func Pin function (default 2 = Alt5) - see above
func2 Function for pin2 (default 2 = Alt5)
clock PWM clock frequency (informational)
Name: pwm-gpio
Info: Configures the software PWM GPIO driver
Load: dtoverlay=pwm-gpio,<param>=<val>
Params: gpio Output pin (default 4)
"/sys/class/pwm/pwmchip0/"为逻辑路径,
cat /sys/kernel/debug/pwm中的"1: platform/1f00098000.pwm");cat /sys/kernel/debug/pwm中的"1: platform/1f0009c000.pwm")。故,不可依赖路径名称"pwmchip0"。
cat /sys/kernel/debug/pwm可以查看所有pwm的配置,如
0: platform/1f00098000.pwm, npwm: 4
pwm-0 ((null) ):
requested configuration: disabled, 0/0 ns, normal polarity
actual configuration: disabled, 0/0 ns, normal polarity
pwm-1 ((null) ):
requested configuration: disabled, 0/0 ns, normal polarity
actual configuration: disabled, 0/0 ns, normal polarity
pwm-2 (sysfs ): requested
requested configuration: enabled, 121568/1000000 ns, normal polarity
actual configuration: disabled, 0/0 ns, normal polarity
pwm-3 ((null) ):
requested configuration: disabled, 0/0 ns, normal polarity
actual configuration: disabled, 0/0 ns, normal polarity
1: platform/1f0009c000.pwm, npwm: 4
pwm-0 ((null) ):
requested configuration: disabled, 0/0 ns, normal polarity
actual configuration: disabled, 0/0 ns, normal polarity
pwm-1 ((null) ):
requested configuration: disabled, 0/0 ns, normal polarity
actual configuration: disabled, 0/0 ns, normal polarity
pwm-2 ((null) ):
requested configuration: disabled, 0/0 ns, normal polarity
actual configuration: disabled, 0/0 ns, normal polarity
pwm-3 (cooling_fan ): requested
requested configuration: disabled, 0/41566 ns, inverse polarity, usage_power
actual configuration: disabled, 0/0 ns, normal polarity
其中:
用gpioinfo -c 0 18检查"gpiochip0"\line 18——GPIO18的配置,有:"gpiochip0 18 "GPIO18" input"(而非'gpiochip0 18 "GPIO18" PWM0_CHAN2')
用pinctrl 18检查有:"18: a3 pd | lo // GPIO18 = PWM0_CHAN2"。
使用pinctrl funcs查看GPIO支持的功能,(用pinctrl funcs | grep PWM筛选)。
其中GPIO12、13、14、15、18、19支持硬件PWM。(软PWM见"/boot/firmware/overlays/README"中的"pwm-gpio")
"PWM0_CHAN2"对应
支持的PWM针脚,可参考PWM at Raspberry Pi GPIO Pinout
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。