Difference between revisions of "PB:Enabling and disabling I/O"
Line 24: | Line 24: | ||
The PB has two PWM chips on board. Chip0 and Chip1 each carrying two PWM channels. | 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 from Chip0 through the pinmux to pin 1,36 issue | + | In order to send pwm output from PWM A from Chip0 through the pinmux to pin 1,36 issue these commands: |
<source lang=bash> | <source lang=bash> | ||
− | ] $ config-pin p1_36 pwm | + | [ ✓ root@beaglebone [~] $ config-pin p1_36 pwm |
+ | [ ✓ root@beaglebone [~] $ config-pin -q p1_36 | ||
+ | P1_36 Mode: pwm | ||
</source> | </source> | ||
+ | The output using the -q option show you the current configuration. | ||
After the config-pin utility has been executed change to this directory | After the config-pin utility has been executed change to this directory |
Revision as of 12:47, 9 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.
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.
The IO is available through a virtual filesystem starting in /sys.
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 from 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 a "1" into the enable file in order to enable the pwm.
Write the desired period time for the pwm signal into period
Write the desired duty cycle into duty_cycle
An example:
[ ✓ root@beaglebone [pwm0] $ echo 1 > enable [ ✓ root@beaglebone [pwm0] $ echo 1000000000 > period [ ✓ root@beaglebone [pwm0] $ echo 500000000 > duty_cycle
The is the result:
Of course the enabling can happen at any time desirable, 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.