rv1106 PWM控制
功能 | 引脚 | 编号 | 功能 |
---|---|---|---|
AL_LED | pin74 | 34 | PWM0_M0 /CPU_AVS /VI_CIF_D0_M1 /GPIO1_A2_d |
W_LED | pin77 | 41 | UART4_RX_M0/PWM3_IR_M1/GPIO1_B0_d |
IR_LED | pin78 | 40 | UART4_TX_M0/PWM7_IR_M1/SPI1_CS1_M0/VI_CIF_D1_M1/GPIO1_B1_d |
CDS | pin22 | 145 | SARADC_IN1/PWM1_M1/GPI4_C1_z |
修改设备树
修改设备树,添加PWM0_M0 , PWM3_IR_M1, PWM7_IR_M1
注意 rv1106g2-ipc.dtsi的vdd-arm已经占用PWM0_M0,要将其取消
vdd_arm: vdd-arm {
// compatible = "pwm-regulator";
// pwms = <&pwm0 0 5000 1>;
compatible = "regulator-fixed";
regulator-name = "vdd_arm";
regulator-min-microvolt = <724000>;
regulator-max-microvolt = <1078000>;
regulator-init-microvolt = <950000>;
regulator-always-on;
regulator-boot-on;
regulator-settling-time-up-us = <250>;
};
在rv1106g2-ipc.dts中添加各个pwm
&pinctrl {
sdmmc {
/omit-if-no-ref/
sdmmc_pwren: sdmmc-pwren {
rockchip,pins = <0 RK_PA1 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
pwm0 {
/omit-if-no-ref/
pwm0m0_pins: pwm0m0-pins {
rockchip,pins =
/* pwm0_m0 */
<1 RK_PA2 1 &pcfg_pull_none>;
};
};
pwm3 {
/omit-if-no-ref/
pwm3m1_pins: pwm3m1-pins {
rockchip,pins =
/* pwm3_ir_m1 */
<1 RK_PB0 2 &pcfg_pull_none>;
};
};
pwm7 {
/omit-if-no-ref/
pwm7m1_pins: pwm7m1-pins {
rockchip,pins =
/* pwm7_ir_m1 */
<1 RK_PB1 2 &pcfg_pull_none>;
};
};
};
&pwm0 {
status = "okay";
pinctrl-0 = <&pwm0m1_pins>;
};
&pwm3 {
status = "okay";
pinctrl-0 = <&pwm3m1_pins>;
};
&pwm7 {
status = "okay";
pinctrl-0 = <&pwm7m1_pins>;
};
重新生成固件,烧录后进入sys
[root@luckfox root]# cd /sys/class/pwm/
[root@luckfox pwm]# ls
pwmchip0 pwmchip3 pwmchip7
已经可以见到pwm0,pwm3, pwm7
通过sysfs对pwm操作
导出pwm0m0
[root@luckfox pwm]# echo 0 > ./pwmchip0/export
[root@luckfox pwm]# ls ./pwmchip0/
device export npwm power pwm0 subsystem uevent unexport
可见pwm0的pwm0已经导出
[root@luckfox pwm0]# ls ./ -al
total 0
drwxr-xr-x 3 root root 0 Mar 13 17:44 .
drwxr-xr-x 4 root root 0 Mar 13 17:44 ..
-r--r--r-- 1 root root 4096 Mar 13 17:46 capture
-rw-r--r-- 1 root root 4096 Mar 13 17:46 duty_cycle
-rw-r--r-- 1 root root 4096 Mar 13 17:46 enable
-r--r--r-- 1 root root 4096 Mar 13 17:46 output_type
-rw-r--r-- 1 root root 4096 Mar 13 17:46 period
-rw-r--r-- 1 root root 4096 Mar 13 17:46 polarity
drwxr-xr-x 2 root root 0 Mar 13 17:46 power
-rw-r--r-- 1 root root 4096 Mar 13 17:46 uevent
[root@luckfox pwm0]# cat ./capture
cat: read error: Function not implemented
[root@luckfox pwm0]# cat ./duty_cycle
0 #1的时间
[root@luckfox pwm0]# cat ./enable
0 #开启
[root@luckfox pwm0]# cat ./output_type
fixed
[root@luckfox pwm0]# cat ./period
0 #周期时间 ns计算 如1000hz周期时间为1000000
[root@luckfox pwm0]# cat ./polarity
inversed #极性 反相,值越大,高电平越少
测试
[root@luckfox pwm0]# echo 1000000 > ./period #设置频率为1KHZ
[root@luckfox pwm0]# echo normal > ./polarity #设置极性为正常,duty_cycle越大越亮
[root@luckfox pwm0]# echo 1 > ./enable #打开PWM0M0输出
[root@luckfox pwm0]# echo 300000 > ./duty_cycle # %30占空比
[root@luckfox pwm0]# echo 500000 > ./duty_cycle # %50占空比
[root@luckfox pwm0]# echo 700000 > ./duty_cycle # %70占空比
[root@luckfox pwm0]# echo 900000 > ./duty_cycle # %90占空比
[root@luckfox pwm0]# echo 1000000 > ./duty_cycle # %100占空比
随着duty_cycle的变大,LED越亮。