Friday, September 19, 2014

PWM0 on Debian Jessie with SAMA5D3 XPLAIN board

A previous post setups a fresh debian jessie install but the PWM wasn't working.  In order to get it to work I had to swap the kernel configuration file as follows:


--- Pulse-Width Modulation (PWM) Support
    <*> Atmel PWM support
    < > Atmel HLCDC PWM support 
    < > Atmel TC Block PWM support 
    < > Freescale FlexTimer Module (FTM) PWM support 
    < > NXP PCA9685 PWM driver


* means you want it built in to the kernel, m means you want it set up as a module.

After that I was able to find the directory pwmchip0 in /sys/class/pwm

To use the PWM you do the following:

For any PWM line you want to use you have to export it:

~# echo 0 > /sys/class/pwm/pwmchip0/export

To use that line as generic GPIO you can unexport it.  For the exported channel a directory called pwm0 is created. In that directory you will find different files that setup different features of the PWM.

For example to setup the PWM with a 1 mS period and 0.5 mS duty cycle do the following:

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


I found that the PWM0H pin was PA20, and PWM0L was PA21 on the XPLAIN board.

Good luck.

No comments:

Post a Comment