Beaglebone black PWM using C

前端 未结 2 1730
甜味超标
甜味超标 2021-01-22 18:38

I wrote a sample pwm function in C for beaglebone black. Whenever I make a function call in other modules or in main(), I end up in segmentation fault. Kindly help where I am ma

2条回答
  •  春和景丽
    2021-01-22 19:19

    I have just successfully enabled 4 PWM outputs on BeagleBone Black using C, so I can hopefully give you some legit advices.

    Using files under /sys/devices/ocp.3/ directory (known as the Device Tree Overlay) for PWM is not a good idea for two reasons:

    • The last two digits of PWM pin directory name are arbitrary, e.g. pwm_test_P8_13.xx, a potential cause for segmentation fault since you don't check for fopen status. However, fopen does not allow wildcard in the specified path. My workaround, which was not clean at all, was to call echo /sys/devices/ocp.3/pwm_test_P8_13.*/ with popen to retrieve the correct full path for the PWM pin directory.
    • There are only two PWM modules on BeagleBone Black, and the DTO prevents you from using more than one PWM pin per module. Consequently, if you try to modify the period of a pin from command line, a write error may return. If you then type dmesg | tail, you may see the following message:

      [ 1406.652632] ehrpwm 48304200.ehrpwm: Period value conflicts with channel 1
      [ 1406.660047] pwm_test pwm_test_P8_19.11: pwm_config() failed

    As such, I used the files under /sys/class/pwm/ instead. You still need to write am33xx_pwm and the PWM pins you plan to use to the file /sys/devices/bone_capemgr.9/slots. Then, you go to directory /sys/class/pwm/, write digit (0-7) to the file export, then modify the file under generated directory pwm?, where ? is the digit written to export. The following table shows each digit and their corresponding pin(s):

    enter image description here

    Here is the tutorial I referred to.

    Hope this helps!

提交回复
热议问题