飞凌嵌入式
直播中

华仔stm32

3年用户 2960经验值
擅长:嵌入式技术
私信 关注
[技术]

【飞凌RK3568开发板试用体验】调试硬件PWM记

准备驱动电机,前面在YU6LL上用IO模拟的,会出现波形失真的现象,这次准备用硬件pwm进行调试。前面偿试了好多次没有成功,这次在飞凌王老师的指点下,成功开启了。这里记录一下。

修改设备树

从原理图上看出开发板引出了几路pwm。能方便做排针引线的pwm14、pwm3。这两组分别是给两个显示做背光调试的。
修改文件:OK3568-linux-source/kernel/arch/arm64/boot/dts/rockchip/OK3568-C-common.dtsi
注释掉pwms =<&pwm14 0 2000 0>这一行。
image.png
在OK3568-C-soure下单独编译kernel
./build.sh kernel
在kernel目录下生成boot.img。把boot.img拷到win上面,打开烧写工具,进行烧写模式,增加一项烧写:
image.png

手工驱动PWM

下载后重启成功,用cat /sys/kernel/debug/pwm/察看到pwm设备情况:

[root@ok3568:/]# cat /sys/kernel/debug/pwm
platform/fe700020.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: inverse

platform/fe6e0010.pwm, 1 PWM device
 pwm-0   (dsi1-backlight      ): requested period: 20000 ns duty: 0 ns polarity: normal

platform/fdd70030.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: inverse

根据手册的提示pwm14为pwmchip2,进入/sys/class/pwm/pwmchip2
echo 0 > export
然后进入pwm0目录,逐步进行频率、占空比、使能、查看pwm信息等操作,具体如下:

[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2]# cd pwm0
[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2/pwm0]# echo 10000 >
 period
[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2/pwm0]# cat /sys/ker
nel/debug/pwm
platform/fe700020.pwm, 1 PWM device
 pwm-0   (sysfs               ): requested period: 10000 ns duty: 0 ns polarity: inverse

platform/fe6e0010.pwm, 1 PWM device
 pwm-0   (dsi1-backlight      ): requested period: 20000 ns duty: 0 ns polarity: normal

platform/fdd70030.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: inverse
[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2/pwm0]# echo 5000 >
duty_cycle
[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2/pwm0]# cat /sys/ker
nel/debug/pwm
platform/fe700020.pwm, 1 PWM device
 pwm-0   (sysfs               ): requested period: 10000 ns duty: 5000 ns polarity: inverse

platform/fe6e0010.pwm, 1 PWM device
 pwm-0   (dsi1-backlight      ): requested period: 20000 ns duty: 0 ns polarity: normal

platform/fdd70030.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: inverse
[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2/pwm0]# echo normal
> polarity
[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2/pwm0]# cat /sys/ker
nel/debug/pwm
platform/fe700020.pwm, 1 PWM device
 pwm-0   (sysfs               ): requested period: 10000 ns duty: 5000 ns polarity: normal

platform/fe6e0010.pwm, 1 PWM device
 pwm-0   (dsi1-backlight      ): requested period: 20000 ns duty: 0 ns polarity: normal

platform/fdd70030.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: inverse
[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2/pwm0]# echo 1 > ena
ble
[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2/pwm0]# cat /sys/ker
nel/debug/pwm
platform/fe700020.pwm, 1 PWM device
 pwm-0   (sysfs               ): requested enabled period: 10000 ns duty: 5000 ns polarity: normal

platform/fe6e0010.pwm, 1 PWM device
 pwm-0   (dsi1-backlight      ): requested period: 20000 ns duty: 0 ns polarity: normal

platform/fdd70030.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: inverse

到此看到pwm14已经配置好100KHZ占空比为50%的信号输出。用万用表量了一下,电压为1.66V,用示波器测量也是正确的
51bf62c37689c2ab52c7abeb1d7f463.jpg

至此,已经成功驱动pwm。
这次再次感谢飞凌的技术指导,非常专业的公司!

更多回帖

发帖
×
20
完善资料,
赚取积分