Jump to content

Quick BeagleBone Black PWM commands

Recommended Posts

From phys-x.org.


So a big thanks for how to write PWM on the BeagleBone Black forums.  It just goes to show how we need to get more tutorials and examples on the web for programming the BeagleBone Black.  So I adapted the post here:


to write a 50 Hz signal with 50% duty cycle, units when you right to file are in nanoseconds.

If it is the first time you are setting things up you need to setup the filesystem, note specific numbers will change so please double check your directory structure

# echo am33xx_pwm > /sys/devices/bone_capemgr.9/slots

Note this will be for pin 13 on header P8

# echo bone_pwm_P8_13 > /sys/devices/bone_capemgr.9/slots

Now write out the period and duty.  Clearly this would be easy in python, c++, etc., just seems a pain to make a general purpose library.

# echo 20000000 > /sys/devices/ocp.2/pwm_test_P8_13.15/period

so  20000000= 0.02 seconds

# echo 10000000 > /sys/devices/ocp.2/pwm_test_P8_13.15/duty

so  10000000 = 0.01 seconds


Link to post
Share on other sites
  • 2 months later...

You could possibly have the device tree file written exactly how you want, and loaded from uEnv.txt file through $optargs . . . hold on a second let me find an example.




Had to fire up my BBB . . .


I disable the HDMI stuff on the BBB at boot.


To enable a device tree overlay . . 
I dont know of any proper overlay names off the top of my head . . . I'd use one of the HDMI over lays from above, but these are already loaded by default through am335x-boneblack.dtb I believe(and I would not want to give anyone the wrong impression that it would work ).
Link to post
Share on other sites

If you mean about the uEnv.txt file.


uEnv.txt file is located in the /boot/uboot directory on the first partition of the eMMC, or uSD card that some people boot from. uEnv,txt is used by u-boot, to accomplish several possible things, but it does not really need to be used in some cases. Well technically, there are default settings that are hard coded into the u-boot.img file that can be overridden by making changes to uEnv.txt.


$optargs is the u-boot environment variable for the variables that are passed to the kernel. So if you hear someone talking about passing parameters to the kernel. This is how it is done using u-boot.


Also, in this context think of u-boot for the Beaglebone black, as an equivalent to a PC's BIOS, for the PC. The Beaglebone black has no BIOS, but does need to know some BIOS like things at start up. Like how to initialize various aspects of the hardware.


in what order does the hardware need to be initialized ?

Where does / can the BBB boot from ?

Does it need an IP Address before loading the kernel / root file system ?

Does it need to start the on-board USB before loading anything ?

Where in memory does it load the kernel into ?


These questions and more can be "answered" by u-boot before the kernel even starts to load.


Hopefully that did not make the confusion worse lol.

Link to post
Share on other sites

To answer your original question from 30,000 feet. There are three ways that I can think of.


1) like stated above load device tree blob through uEnv.txt.

2) Run an init script at boot that performs the commands for you at boot time.

3) In the case where you may only want to run these commands when a specific user logs in, you can put this into a specific users .bashrc file.


Granted, there may be potential permissions issues on the second two options, but I * think * this could be solved by putting the given user in a group appropriate for those given commands. My Linux knowledge in this area is a but "fuzzy".




Actually the permissions issue would only be for the last case.

Link to post
Share on other sites

I think the permission idea is good for my scenario.


It is possible that there will be a few users of the BBB once I'm done with it, and I don't want any of them to easily be able to make any changes. 


The script at boot time is good too, and sounds easy enough.  The GPIO pins I will be using will remain constant, so this may be the way I go for pin declarations. 



Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...