You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在BeagleBone Black Wireless(4.14内核)配置PWM?

BeagleBone Black Wireless (Kernel 4.14.37-ti-r46) PWM Configuration

Hey there, I've tackled this exact problem on the BBBW running kernel 4.14.x—those old bone_capemgr and slots file tricks are totally outdated now. Let's walk through the modern, working way to set up PWM:

1. First, Know Your PWM-Capable Pins

Not all pins support PWM, so start with a quick reference for common ones on BBBW:

  • P8_13 → ehrpwm1A (maps to pwmchip0 channel 0)
  • P8_19 → ehrpwm1B (maps to pwmchip0 channel 1)
  • P9_14 → ehrpwm0A (maps to pwmchip1 channel 0)
  • P9_16 → ehrpwm0B (maps to pwmchip1 channel 1)

These are the most commonly used channels, but you can cross-reference the full BBBW pinout if you need others.

2. Configure the Pin for PWM (Using config-pin)

The config-pin tool is the new standard for pin muxing on BBB post-4.14 kernels—it replaces the old slots system. Here's how to use it:

  • First, ensure the tool is installed (it’s default on most BBB images, but if missing):
    sudo apt update && sudo apt install bb-cape-overlays
    
  • Set your target pin to PWM mode. For example, to enable P8_13:
    sudo config-pin P8_13 pwm
    
  • Verify success by checking the PWM sysfs directory:
    ls /sys/class/pwm/
    
    You should see pwmchip0 (for ehrpwm1) appear if you configured P8_13/P8_19.

3. Control PWM via SysFS Interface

Once the pin is muxed, adjust PWM parameters through the sysfs interface. Let’s use P8_13 (pwmchip0 channel 0) as an example:

  1. Export the PWM channel (make it accessible in sysfs):
    sudo echo 0 > /sys/class/pwm/pwmchip0/export
    
  2. Set the period (total cycle time in nanoseconds—1ms = 1,000,000ns):
    sudo echo 1000000 > /sys/class/pwm/pwm0/period
    
  3. Set the duty cycle (active time in nanoseconds—50% duty cycle here):
    sudo echo 500000 > /sys/class/pwm/pwm0/duty_cycle
    
  4. Enable the PWM output:
    sudo echo 1 > /sys/class/pwm/pwm0/enable
    

To turn it off later:

sudo echo 0 > /sys/class/pwm/pwm0/enable
sudo echo 0 > /sys/class/pwm/pwmchip0/unexport

4. Make PWM Settings Persist on Boot

If you want the PWM pin to be configured automatically every time the board starts:

  • Option 1: Use U-Boot overlays
    Edit /boot/uEnv.txt with sudo, uncomment or add these lines (adjust the overlay name based on your PWM channel):

    enable_uboot_overlays=1
    uboot_overlay_addr0=/lib/firmware/am335x-pwm1.dtbo
    

    This loads the PWM1 overlay (for P8_13/P8_19) on boot. Then add your sysfs commands to /etc/rc.local (before exit 0) to set period/duty cycle/enable.

  • Option 2: Run config-pin on boot
    Add the config-pin command and sysfs steps to /etc/rc.local (run with sudo, or as root):

    sleep 5  # Give system time to initialize
    config-pin P8_13 pwm
    echo 0 > /sys/class/pwm/pwmchip0/export
    echo 1000000 > /sys/class/pwm/pwm0/period
    echo 500000 > /sys/class/pwm/pwm0/duty_cycle
    echo 1 > /sys/class/pwm/pwm0/enable
    

Troubleshooting Tips

  • Permission denied errors: Always use sudo for sysfs commands, or switch to root with sudo su.
  • PWM chip not appearing: Double-check that you’re using a PWM-capable pin, and that the config-pin command ran without errors.
  • Overlay not loading: Verify the overlay file exists at /lib/firmware/am335x-pwmX.dtbo (replace X with your PWM channel number).

内容的提问来源于stack exchange,提问作者dgund

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:45:13