飞凌国产芯片系列经验分享|A40i开发板应用笔记-PWM 的应用

本文讲解了国产A40i 开发板PWM的应用,本篇文章主要适用于飞凌 OKA40i 平台 Linux3.10.65 操作系统,其他arm 平台也可以参考,但是不同平台之间会存在差异,请自行修改以适应自己的使用。 写本文章的主要目的是协助客户加速产品的研发速度,由于水平有限, 不提供任何的完整性、可靠性等保证,软件版本更新之后,有些位置名称等内容可能会及时更新,修改方法请参考使用。
硬件产品介绍:
A40i
A40i: https://www.forlinx.com/product/58.html

一、PWM的应用
1、pwm的添加

增加一路 pwm,以 pwm4 为例说明,其他方法类似,只做为参考。

arch/arm/boot/dts/sun8iw11p1.dtsi

中添加

pwm = &pwm;
pwm0 = &pwm0;
pwm4 = &pwm4;
pwm: pwm@01c23400 {
compatible = “allwinner,sunxi-pwm”;
reg = <0x0 0x01c23400 0x0 0x154>;
pwm-number = <1>;
pwm-base = <0x4>;
pwms = <&pwm4>;
};
pwm4: pwm4@01c23400 {
compatible = “allwinner,sunxi-pwm4”;
pinctrl-names = “active”, “sleep”;
reg_base = <0x01c23400>;
reg_peci_offset = <0x00>;
reg_peci_shift = <0x04>;
reg_peci_width = <0x01>;
reg_pis_offset = <0x04>;
reg_pis_shift = <0x04>;
reg_pis_width = <0x01>;
reg_crie_offset = <0x10>;
reg_crie_shift = <0x08>;
reg_crie_width = <0x01>;
reg_cfie_offset = <0x10>;
reg_cfie_shift = <0x09>;
reg_cfie_width = <0x01>;
reg_cris_offset = <0x14>;
reg_cris_shift = <0x08>;
reg_cris_width = <0x01>;
reg_cfis_offset = <0x14>;
reg_cfis_shift = <0x09>;
reg_cfis_width = <0x01>;
reg_clk_src_offset = <0x28>;
reg_clk_src_shift = <0x07>;
reg_clk_src_width = <0x02>;
reg_bypass_offset = <0x28>;
reg_bypass_shift = <0x05>;
reg_bypass_width = <0x01>;
reg_clk_gating_offset = <0x28>;
reg_clk_gating_shift = <0x04>;
reg_clk_gating_width = <0x01>;
reg_clk_div_m_offset = <0x28>;
reg_clk_div_m_shift = <0x00>;
reg_clk_div_m_width = <0x04>;
reg_pdzintv_offset = <0x38>;
reg_pdzintv_shift = <0x08>;
reg_pdzintv_width = <0x08>;
reg_dz_en_offset = <0x38>;
reg_dz_en_shift = <0x00>;
reg_dz_en_width = <0x01>;
reg_enable_offset = <0x40>;
reg_enable_shift = <0x04>;
reg_enable_width = <0x01>;
reg_cap_en_offset = <0x44>;
reg_cap_en_shift = <0x04>;
reg_cap_en_width = <0x01>;
reg_period_rdy_offset = <0xe0>;
reg_period_rdy_shift = <0x0b>;
reg_period_rdy_width = <0x01>;
reg_pul_start_offset = <0xe0>;
reg_pul_start_shift = <0x0a>;
reg_pul_start_width = <0x01>;
reg_mode_offset = <0xe0>;
reg_mode_shift = <0x09>;
reg_mode_width = <0x01>;
reg_act_sta_offset = <0xe0>;
reg_act_sta_shift = <0x08>;
reg_act_sta_width = <0x01>;
reg_prescal_offset = <0xe0>;
reg_prescal_shift = <0x00>;
reg_prescal_width = <0x08>;
reg_entire_offset = <0xe4>;
reg_entire_shift = <0x10>;
reg_entire_width = <0x10>;
reg_active_offset = <0xe4>;
reg_active_shift = <0x00>;
reg_active_width = <0x10>;
}

按手册 PWM 修改对应的寄存器。

修改 sys_config.fex 中 twi2_used=0 且增加

[pwm4]
pwm_used = 1
pwm_positive = port:PB20<4><0>
[pwm4_suspend]
pwm_positive = port:PB20<7><0>

编译镜像并烧写

2、PWM的测试

echo 0 >/sys/class/pwm/pwmchip4/export
echo 1000000 > /sys/class/pwm/pwmchip4/pwm0/period
echo 500000 > /sys/class/pwm/pwmchip4/pwm0/duty_cycle
echo 1 > /sys/class/pwm/pwmchip4/pwm0/enable

测量得到频率为 1K 方波

echo 0 > /sys/class/pwm/pwmchip4/pwm0/enable
echo 208333> /sys/class/pwm/pwmchip4/pwm0/duty_cycle
echo 416667 > /sys/class/pwm/pwmchip4/pwm0/period
echo 1 > /sys/class/pwm/pwmchip4/pwm0/enable

测量得到频率为 2.4K 方波

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值