The--PWM of Beaglebone learning

Source: Internet
Author: User

Opening first to spit the trough beaglebone .... Version of all kinds of chaos, drive all kinds of disorderly =.=
1. About the driving disorder, the author wants to use the PWM module, although Beaglebone comes with, but did not give a description of the document AH. All by groping! And some places are not right.
2. About the version ... Beaglebone is not backwards compatible with this saying? Has installed Debian 7.5,debian 7.8,debian 7.9,debian 8.3. 7.5 PWM driver and the back is completely different, not compatible AH Hello!
PS. It is strongly recommended to pack 7.5. Because most of the online tutorials are based on Debian 7.5,,, for beginners
3. About the source code,, the official website provides the mirror Beaglebone official website The latest image and the GitHub Source Library Beaglebone The official GitHub library, matches not to feed! This thought of the official did not give the driver instructions, that the source of the download is not finished! There's at least one document in there. And then it was too young, and GitHub didn't have 7.1 after that. Depressed. That's the only one.

The Spit is over.

Objective
It is strongly recommended to write your own PWM driver, not recommended by the official. In addition, the author uses the image is Debian 7.5, the high version is not guaranteed to be compatible. Download link Beaglebone is included.

Beagleboneblack PWM Drive Usage:
1. Load the PWM driver
2. Load the specified PWM module
3. Control PWM by overwriting files

Let's say a few paths:
1./sys/devices/bone_capemgr.9/
Beaglebone Cape Configuration Path, there is a slots (slot) file below, what drivers need to load the Part-number write in.
2./SYS/CLASS/PWM
Beaglebone PWM configuration path, the PWM driver will be generated after the corresponding PWM module in the folder, by modifying the corresponding file to control the PWM
3./lib/firmware
Beaglebone Peripheral Library (driver), full of DTB files to configure Peripherals

Next step: BEAGLEBONEPWM Resources at a glance

One, load PWM drive
Enter the peripheral library directory/lib/firmware, run

-l | grep pwm

All PWM-related device tree files are available

You can see all the pin-related files besides Am33xx_pwm-00a0.dtbo.
This AM33XX**.DTBO equivalent to the total PWM specification, regardless of which PWM is called to load it first, the rest of which pin to load which the pin driver is good. For example, to use the p8_13 port PWM, you need to load the Am33xx_pwm-00a0.dtbo and Bone_pwm_p8_13-00a0.dtbo two files.
but! But! But! (Important words three times!!!) Load the AM33XX_PWM first, then go to/SYS/CLASS/PWM to load the specified PWM device, and then come back to load the bone_pwm_p8_13!
The egg ache is here, the driver has the bug does not follow this order to load will have the problem!!!
The loading process is as follows:
Switch to the/SYS/DEVICES/BONE_CAPEMGR.9 directory and run

echo am33xx_pwm > slots

Can. Can call

cat slots

To see if the load succeeds, if the following appears, proves successful

Two-load specified PWM device
Cut to the "/SYS/CLASS/PWM" path, similar to the IO control, the export file to write the output, the corresponding module will be transferred from the kernel, want to cancel the Unexport to write.
For example, the P8_13 port corresponds to the PWM6 module, so just go to export to write 6:

echo6export


Restart the current folder under LS, will be more than a PWM6 folder

At this point the PWM device has finished loading.
A separate PWM device and pin table is attached:

PS. P8.34 36 45 46 and P9.28 29 31 are not available by default and should be used to change pin mappings. The authorities did not provide any change, and the need for self-study

Third, back to load the specified pin PWM drive
Operation the same:
Switch to the/SYS/DEVICES/BONE_CAPEMGR.9 directory and run

echo bone_pwm_P8_13 > slots

Can.

Iv. operation of PWM
Go back to the "/SYS/CLASS/PWM" path and go to the PWM6 folder. LS can get


which
Period_ns is the cycle
Duty_ns is the duty ratio
Run is enable switch, 0 off 1 Open

For example, the control motor needs 10KHz, half-speed rotation, then you can:

root@beaglebone:/sys/class/pwm/pwm6# echo 100000 > period_ns root@beaglebone:/sys/class/pwm/pwm6# echo 50000 > duty_ns root@beaglebone:/sys/class/pwm/pwm6# echo 1 > run

The above, all other operations can also be done in the C language, using the C language of the file operation (open (), read (), write (), etc.) to replace the command line "Echo >" function. Refer to another post on the UART, which has a C language version of Beaglebone serial Operation C language version

The--PWM of Beaglebone learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.