PWM Extra Tutorial

Discussion in 'UDOO NEO' started by Matt_Neo, Jul 11, 2019.

  1. Matt_Neo

    Matt_Neo UDOOer

    Joined:
    Jun 14, 2019
    Messages:
    9
    Likes Received:
    1
    Hi,

    This is intended to be helpful for those who are exploring Neo and who aren't experts, as a bridge between what's in the Udoo Docs section and what's actually needed to get the PWM running on the Linux side.

    One big key which I didn't see mentioned anywhere else is that the PMW numbers you need to specify in the Linux CLI *DO NOT* match to the PWM numbers in the pin map or any of the other documentation. If you have mapped the two PWM outputs assigned to Linux/A9 by default in the device tree (PWM2 and PWM5) then following the instructions at https://www.udoo.org/docs-neo/Hardware_&_Accessories/PWM.html

    echo 0 > /sys/class/pwm/pwmchip0/export
    echo 1000000 > /sys/class/pwm/pwmchip0/pwm0/period
    echo 300000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
    echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable

    This will enable the PWM output on PWM2 (pin 35)
    Note that you may have to start by typing "Sudo -i" if you're like me and the system was for some reason denying you permission to export the PWM.

    Then if you want output from PWM5, you change all the "pwmchip0" to "pwmchip1"
    echo 0 > /sys/class/pwm/pwmchip1/export
    echo 1000000 > /sys/class/pwm/pwmchip1/pwm0/period
    echo 300000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
    echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable

    I assume if you only mapped PWM5 in the device tree then "pwmchip0" would actually correspond to PWM5 in that case.
     
    waltervl likes this.

Share This Page