There are some different ways to generate PWM signals on CORE9G25 module. This article illustrates how to use the Generic PWM framework driver for Atmel Timer Counter Block available inside the Kernel 3.11.

To include this driver in your Kernel select this item during the Linux Kernel configuration (make menuconfig).

Device Drivers  ---> 
  [*] Pulse-Width Modulation (PWM) Support  --->
    <*>   Atmel TC Block PWM support 

A Timer Counter Block provides 6 PWM devices grouped by 2. Devices in the same group must have the same period.

The GPIO pin used for PWM signals are:

Aria pin Atmel name pwm# Group Timer Signal at91sam9x5.dtsi def
N4 PC2 pwm0 0 TIOA3 pinctrl_tcb1_tioa0
N5 PC3 pwm1 0 TIOB3 pinctrl_tcb1_tiob0
N7 PC5 pwm2 1 TIOA4 pinctrl_tcb1_tioa1
N8 PC6 pwm3 1 TIOB4 pinctrl_tcb1_tiob1
N14 PC12 pwm4 2 TIOA5 pinctrl_tcb1_tioa2
N15 PC13 pwm5 2 TIOB5 pinctrl_tcb1_tiob2

The node to add inside the at91-CORE9G25.dts file is:

pwm {
        compatible = "atmel,tcb-pwm";
        #pwm-cells = <3>;
        tc-block = <1>;
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_tcb1_tioa0
                     &pinctrl_tcb1_tioa1
                     &pinctrl_tcb1_tioa2
                     &pinctrl_tcb1_tiob0
                     &pinctrl_tcb1_tiob1
                     &pinctrl_tcb1_tiob2>;
        status = "okay";
};

The pinctrl configuration is responsible for setting up the GPIO output which definition is in arch/arm/boot/dts/at91sam9x5.dtsi.

If don't need to use all the 6 PWM signals remove the pinctrl_tcb1_tioXX simbols from pinctrl-0 definitions related to the GPIO line to set free.

User space sysfs interface

Up to 6 pmw channels can be exported before using them:

~# echo 0 > /sys/class/pwm/pwmchip0/export
~# echo 1 > /sys/class/pwm/pwmchip0/export
~# echo 2 > /sys/class/pwm/pwmchip0/export
~# echo 3 > /sys/class/pwm/pwmchip0/export
~# echo 4 > /sys/class/pwm/pwmchip0/export
~# echo 5 > /sys/class/pwm/pwmchip0/export

To unexport:

~# echo 0 > /sys/class/pwm/pwmchip0/unexport
~# echo 1 > /sys/class/pwm/pwmchip0/unexport
~# echo 2 > /sys/class/pwm/pwmchip0/unexport
~# echo 3 > /sys/class/pwm/pwmchip0/unexport
~# echo 4 > /sys/class/pwm/pwmchip0/unexport
~# echo 5 > /sys/class/pwm/pwmchip0/unexport

For any exported channel a directory called pwmX wil be created with the following structure:

/sys/class/pwm/pwmchip0/pwmX/
      |-- duty_cycle (r/w) duty cycle (in nanoseconds)
      |-- enable     (r/w) enable/disable PWM
      |-- period     (r/w) period (in nanoseconds)
      |-- polarity   (r/w) polarity of PWM
      |-- power
      `-- uevent

The follow example illustrate how enable a PWM signale with a period of 1mS with a 0.5mS of duty cycle:

~# echo 1000000 > /sys/class/pwm/pwmchip0/export/pwm0/period
~# echo 500000 > /sys/class/pwm/pwmchip0/export/pwm0/duty_cycle
~# echo 1 > /sys/class/pwm/pwmchip0/export/pwm0/enable

Related links

Documentation Terms of Use
The Acme Systems srl provides this Debian system development and user manual.
The origin of these doc came from the website: http://www.acmesystems.it
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Creative Commons License

关注我们: 微博

销售邮箱:market@armdevs.com
技术支持: support@armdevs.com
销售电话: +86-755-29638421


核风在线支持>
在线时间:09:00-18:00
Copyright @ 2014 to 2020 - 核风智能技术有限公司