Tuesday, April 22, 2014

Setting Up PWM for BeagleBone Black

BeagleBone Black Pin-modes




As can be seen on the BBB, it has a number of usable pins at your disposal. Through further inspection I found out that one pin can have up to seven different modes. For instance one pin can be used for regular GPIO, PWM, UART, or I2c; this is done by pin-muxing. So through multiplexing the different modes can be set. Because the BBB does not POST at boot the only way to initialize hardware capabilities is through Device Tree Overlays (DTO).  A DTO can be considered the equivalent of a driver. I am not sure if this is correct, but I am just stating what I have gathered from it through my own research. The best resource I have found with working with the BBB is on Derek Molloys site. I wouldn't have been able to get as far as I have in such a short time with watching his videos. A link will be posted I really recommend going there for more cool things BBB.


Setting up PWM 


To activate the pins the device tree overlays must be added to:

                    /sys/devices/bone_capemgr.8/slots

To see what pins can be used go to:

                   /lib/firmware

For most applications it would be nice to keep from having to do this manually every time you turn your BBB on. To do this, change the uEnv.txt file inside /media/BEAGLEBONE. An example of what I added to it to run three PWM pins can be seen in Figure 1. Additionally, If you are using a pin that by default is set for HDMI out, you will have to mount the file path manually. Both steps will be in Figure 1.

Figure 1: Mounting filepath, and changing file

 To make it easier to access my Pins and Slots I made multiple shortcuts by modifying the .profile inside the /etc directory. I did this by exporting the file path into a user defined name, see Figure 2.

Figure 2: Adding shortcuts in .Profile

With these modifications everything should be set at boot-up. To check the pins you can set the period and duty cycle to the shortcuts by echoing a value for each. Every servo is a little different, so the values can change. In the first video I show setting the period and duty cycle. The values will be close so they are a good reference.




Resources:

Derek Molloys BeagleBone Black site

 

2 comments:

  1. can u share circuit diagram. I am confused, all site says that we need to be extra careful using pwm pins for amount of current source or sink need to be very low plus voltage should be also low. I donot see any voltage regulator or transistor in your project

    ReplyDelete
    Replies
    1. The BBB seems to be more than capable of controlling standard servos without a voltage regulator or transistor. If you are using DC motors or stepper motors that will be different. I do not have a circuit diagram, really all it is is the PWM pin from the BBB to the signal line for the servo. And the "black" and "red" wire from the servo to ground and 5V.

      Delete