Difference between revisions of "PB:Enabling and disabling I/O"

From Klaus' wiki
Jump to: navigation, search
(Enabling PWM)
(Enabling PWM)
Line 13: Line 13:
The IO is available through a virtual filesystem starting in /sys.
The IO is available through a virtual filesystem starting in /sys.
==Enabling PWM==
==Setting up and Enabling PWM==
Switch to user '''root'''.
Switch to user '''root'''.

Revision as of 10:00, 11 March 2018

Over at Adafruit is a great introduction to the Device Tree, that is used on BeagleBones.

BeagleBone black originally came with a kernel 3.8 which had a Device Tree Overlay (DTO) and a capemanager. But in the newer kernels, at time of writing 4.9, the DTO has been completely reorganised and there is no need for at capemanager any more. Find your kernel version by typing in uname -r.

If you are running kernel 3.8.x please follow these guidelines Example One and Example two and the instructions given in Derek Molloys book Exploring BeagleBone Black.

For kernels newer or equal to 4.9 follow the guideline below.

Rober Nelson has written a short guide to enable a few of the most used IO's. The rest should be deductable if you combine the pin configuration seen below and the commands given.

PocketBeagle pinout.png

The IO is available through a virtual filesystem starting in /sys.

Setting up and Enabling PWM

Switch to user root.

] $ su -

The utility config-pin can setup the configuration.

The PB has two PWM chips on board. Chip0 and Chip1 each carrying two PWM channels.

In order to send pwm output from PWM A on Chip0 through the pinmux to pin 1,36 issue these commands:

[ ✓ root@beaglebone [~] $  config-pin p1_36 pwm
[ ✓ root@beaglebone [~] $  config-pin -q p1_36 
P1_36 Mode: pwm

The output using the -q option show you the current configuration.

After the config-pin utility has been executed change to this directory

] $ cd /sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip0/

In order to enable Chip0 perform

] $ echo 0 > export

Now the chip0 is enabled which will reveal a pwm0 directory in current directory.

Change into the directory pwm0 and list the files available.

[ ✗ root@beaglebone [pwm0] $  ll
total 0
drwxr-xr-x 3 root root    0 Mar  9 10:51 .
drwxrwxr-x 4 root pwm     0 Mar  9 10:50 ..
-r--r--r-- 1 root root 4.0K Mar  9 10:51 capture
-rw-r--r-- 1 root root 4.0K Mar  9 11:05 duty_cycle
-rw-r--r-- 1 root root 4.0K Mar  9 10:56 enable
-rw-r--r-- 1 root root 4.0K Mar  9 11:04 period
-rw-r--r-- 1 root root 4.0K Mar  9 10:51 polarity
drwxr-xr-x 2 root root    0 Mar  9 10:51 power
-rw-r--r-- 1 root root 4.0K Mar  9 10:51 uevent

provided you've made an alias called ll in root home directory in the file .bashrc - otherwise use ls -al

Write the desired period time for the pwm signal into period

Write the desired duty cycle into duty_cycle

Write a "1" into the enable file in order to enable the pwm. Use 0 (Zero) to disable the pwm again.


An example:

[ ✓ root@beaglebone [pwm0] $  echo 1000000000 > period 
[ ✓ root@beaglebone [pwm0] $  echo 500000000 > duty_cycle 
[ ✓ root@beaglebone [pwm0] $  echo 1 > enable

The is the result:

PWM 1 second period 50 percent duty cycle.png

Of course the enabling can happen at any time desirable after you've set-up period and duty cycle, so you can set-up the polarity, period and duty cycle when ever convenient and enable when needed. Writing a 0 into enable disables the output again.

NOTICE: The two PWM outputs from one PWM chip shall run with the same period, but can run with different duty cycle. Below is P1,36 and P1,33 running the same period but different duty cycle. The period was set on pwm0 in this case and it cannot be changes in pwm1.

PWM 1 second period 20 percent duty cycle.png