PWM使用说明

这篇文档主要介绍如何使用硬件PWM,VIM4PWM_F端口默认被其它功能占用,使用PWM_F端口前,请先修改如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
diff --git a/arch/arm64/boot/dts/amlogic/kvim4.dts b/arch/arm64/boot/dts/amlogic/kvim4.dts
--- a/arch/arm64/boot/dts/amlogic/kvim4.dts
+++ b/arch/arm64/boot/dts/amlogic/kvim4.dts
@@ -1749,13 +1749,13 @@
};
};

- bl1_pwm_off_pins:bl1_pwm_off_pin {
- mux {
- groups = "GPIOY_8";
- function = "gpio_periphs";
- output-low;
- };
- };


diff --git a/arch/arm64/boot/dts/amlogic/mesont7_an400-panel.dtsi b/arch/arm64/boot/dts/amlogic/mesont7_an400-panel.dtsi
--- a/arch/arm64/boot/dts/amlogic/mesont7_an400-panel.dtsi
+++ b/arch/arm64/boot/dts/amlogic/mesont7_an400-panel.dtsi
@@ -1442,13 +1442,13 @@

backlight1{
compatible = "amlogic, backlight-t7";
- status = "okay";
+ status = "disabled";
index = <1>;
key_valid = <0>;
pinctrl-names = "pwm_on",
"pwm_off";
- pinctrl-0 = <&pwm_f_pins>;
- pinctrl-1 = <&bl1_pwm_off_pins>;
pinctrl_version = <2>; /* for uboot */
interrupts = <0 197 1

PWM_F物理引脚确认

PWM使用

  • 申请PWM
    1
    root@Khadas:~# echo 1 > /sys/class/pwm/pwmchip4/export
  • 配置PWM周期
    1
    root@Khadas:~# echo 1000000 > /sys/class/pwm/pwmchip4/pwm1/period
  • 配置PWM占空比
    1
    root@Khadas:~# echo 500000 > /sys/class/pwm/pwmchip4/pwm1/duty_cycle
  • 使能PWM
    1
    root@Khadas:~# echo 1 > /sys/class/pwm/pwmchip4/pwm1/enable
  • 关闭PWM
    1
    root@Khadas:~# echo 0 > /sys/class/pwm/pwmchip4/pwm1/enable

如果你成功开启了硬件PWM,可以通过示波器看到波形:

pwm-Oscilloscope

注意

如果使用示波器去查看波形,记得板子和示波器需要共地。