beaglebone php,Beaglebone Black开启PWM功能【酷】

2023-11-05 16:20

本文主要是介绍beaglebone php,Beaglebone Black开启PWM功能【酷】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

虽然本文讲的是开启PWM功能,但是其他模块的使用也是一样的,很有参考价值,百度搜不到,用必应bing才能更好的搜索外文,使用BBB好久了,才发现很多dts都有现成的,直接加载就好了(安装到slots槽中即可)。我是用最新的Debian系统,跟本文有点差异,但是本文很有参考价值。

另外备注:在将cape-universaln插入槽中(slots)后,在root@beaglebone:/sys/devices/platform/ocp/ocp:P9_14_pinmux中将P9_14设置为pwm模式(#config-pin

P9.14 pwm)后,需要在/sys/class/pwm/pwmchip2中echo 0 >

export,这里为什么是pwmchip2,因为pwmchip2的地址0x4830_2000对应的是PWM1,echo

0是开启EHRPWM1A,echo

1是开启EHRPWM1B。具体地址映射可参见AM335x参考手册memory

map部分。

a4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png

EHRPWM0A

P9_22,

P9_31

EHRPWM0B

P9_21,

P9_29

EHRPWM1A

P9_14,

P8_36

EHRPWM1B

P9_16,

P8_34

EHRPWM2A

P8_19,

P8_45

EHRPWM2B

P8_13,

P8_46

周期1秒,频率1Hz,注意单位都是ns。这样就成功了。

root@beaglebone:/sys/class/pwm/pwmchip2# echo 0

> export

root@beaglebone:/sys/class/pwm/pwmchip2# cd

pwm0/

root@beaglebone:/sys/class/pwm/pwmchip2/pwm0#

echo 1000000000 > period

root@beaglebone:/sys/class/pwm/pwmchip2/pwm0#

echo 500000000 > duty_cycle

root@beaglebone:/sys/class/pwm/pwmchip2/pwm0#

echo 1 > enable

These notes are based on the

3.8.13-bone70 complete installation as described over

at

Contents

Selecting Overlays to

use

Having being reading

numerous pages about Device Tree Overlays I finally came up with a

couple of solutions for how to enable the AM355 pinmux and setting

the correct modes in order to enable PWM output.

If you just need one or a

few PWM outputs you can generate overlay files over

at

If you want to enable a

complete set of facilities on the BBB you can jump down to

the

A common

preparation

If you frequently access the

/sys/devices/bone_capemgr.9/slots file it is highly recommended

that yo prepare an environment variable

called SLOTS.

In you ~/.bashrc add these

lines

export

SLOTS=/sys/devices/bone_capemgr.9/slots

export

PINS=/sys/kernel/debug/pinctrl/44e10800.pinmux/pins

The former set the

environment variable SLOTS to point to the slots file and the

latter sets the PINS environment variable to point to the file that

lists the pins assigned in the pinmux.

In order to immediately gain

effect of the new setting issue

root@beaglebone$] .

~/.bashrc

which will read the .bashrc

file from the home directory and execute whatever in there in the

current shell. Don't try to execute the .bashrc file because the

changes will only be seen shortly in the new shell (bash) that

executes the script.

At every login hereafter

SLOTS is set to point the correct directory.

Single PWM

Setup

Over

at this

page you can generate a device overlay file

for each PWM channel you want to use.

Giving Input to the

Configurator

For example in order to

enable PWM on P9 pin 14. See the figure below how to setup the

configurator where the output is pulled up - you may want to selct

a pull down instead.

From the generator you will

get an output like this:

/dts-v1/;

/plugin/;

/

{

compatible = "ti,beaglebone",

"ti,beaglebone-black";

part-number =

"BS_PWM_P9_14_0x16";

exclusive-use

=

"P9.14",

"ehrpwm1A";

fragment@0 {

target = ;

__overlay__ {

bs_pwm_P9_14_0x16: pinmux_bs_pwm_P9_14_0x16 {

pinctrl-single,pins = <0x048 0x16>;

};

};

};

fragment@1 {

target = ;

__overlay__ {

bs_pwm_test_P9_14 {

compatible = "pwm_test";

pwms = ;

pwm-names =

"PWM_P9_14";

pinctrl-names =

"default";

pinctrl-0 = ;

enabled = <1>;

duty = <0>;

status = "okay";

};

};

};

};

Save this in a file name as

suggested: bspwm_P9_14_16-00A0.dts

If you want the polarity to

initially set to 0 change the 1 to 0 in the line pwms so it looks

like this

pwms = ;

Compile and

Test

Compile it using this

command:

root@begalebone $]

dtc -O dtb -o bspwm_P9_14_16-00A0.dtbo -b 0 -@

bspwm_P9_14_16-00A0.dts

Copy the .dtbo file to

/lib/firmware

As instructed on the

generator page you can enable this ovelay by issuing these

commands:

root@beaglebone $]

grep -q am33xx_pwm $SLOTS || echo am33xx_pwm >

$SLOTS

root@beaglebone $]

echo bspwm_P9_14_16 > $SLOTS

Check if this works and you

can see the PWM device by issuing

root@beaglebone:~$]

ll /sys/devices/ocp.3/bs_pwm_test_P9_14.15/

and get this

output

total

0

drwxr-xr-x 3 root

root 0 May 31

09:34 .

drwxr-xr-x 42 root

root 0

Mar 1 21:19 ..

lrwxrwxrwx 1 root

root 0 May 31

09:37 driver ->

../../../bus/platform/drivers/pwm_test

-rw------- 1 root root 4096

May 31 09:37 duty

-r--r--r-- 1 root root 4096

May 31 09:37 modalias

-rw------- 1 root root 4096

May 31 09:37 period

-rw------- 1 root root 4096

May 31 09:37 polarity

drwxr-xr-x 2 root

root 0 May 31

09:37 power

-rw------- 1 root root 4096

May 31 09:37 run

lrwxrwxrwx 1 root

root 0 May 31

09:34 subsystem -> ../../../bus/platform

-rw-r--r-- 1 root root 4096

May 31 09:34 uevent

Finally create an

ini-script that will perform the enabling every times the BBB

boots.

In /etc/init.d

create a file enable-pwm with

this content

#!

/bin/sh

### BEGIN INIT

INFO

# Provides:

enable-pwm

# Required-Start:

$all

# Required-Stop:

$all

# Default-Start: 2

3 4 5

# Default-Stop: 0 1

6

#

Short-Description: Enables the PWM chips and connects it through

the pinmux

# Description:

Conneting the pwm output through the pinmux and enables the PWM

chip on board

### END INIT

INFO

case "$1"

in

start)

echo "Enabling PWM on P9 Pin 14"

grep -q am33xx_pwm /sys/devices/bone_capemgr.9/slots || echo

"am33xx_pwm" >

/sys/devices/bone_capemgr.9/slots

echo bspwm_P9_14_16 >

/sys/devices/bone_capemgr.9/slots

;;

stop)

#no-op

;;

*)

#no-op

;;

esac

exit

0

After creating the

file execute

root@beaglebone $]

chmod 755 enable-pwm

root@beaglebone $]

update-rc.d enable-pwm defaults

The first command set the

file permissions and the second updates the init system to execute

the file at a correct time depending on the information given in

the first part of the script.

Complete

Setup

This section describes a

setup of the complete - almost - IO system on the

BBB.

Preparing

In

/opt/source/beaglebone-universal-io you'll find some general device

drivers for the BBB.

Since BBB uses the FDT

(Flattened Device Tree), where a general driver performs the most

of the work, no special driver is needed for PWM.

There are two steps in

enabling a device:

1. Setup the multiplexing of

the pins (i.e. connect the internal device to a pin accessible on

the outside)

2. Setup the peripheral (the

internal device such as PWM, GPIO, etc.) to the pin assigned

above

Ensure that your general

pinmux is setup for defaults by ensuring that

the /sys/devices/ocp.N (with N

currently showing 3) exists. If not then perform:

root@beaglebone$]

cd /opt/source/beaglebone-universal-io

root@beaglebone$]

echo cape-universaln >

/sys/devices/bone_capemgr.*/slots

expect an output

with this included:

drwxr-xr-x 3 root

root 0 May 24

09:24 P8_07_pinmux.15

drwxr-xr-x 3 root

root 0 May 24

09:24 P8_08_pinmux.16

drwxr-xr-x 3 root

root 0 May 24

09:24 P8_09_pinmux.17

drwxr-xr-x 3 root

root 0 May 24

09:24 P8_10_pinmux.18

drwxr-xr-x 3 root

root 0 May 24

09:24 P8_11_pinmux.19

drwxr-xr-x 3 root

root 0 May 24

09:24 P8_12_pinmux.20

drwxr-xr-x 3 root

root 0 May 24

09:24 P8_13_pinmux.21

drwxr-xr-x 3 root

root 0 May 24

09:24 P8_14_pinmux.22

drwxr-xr-x 3 root

root 0 May 24

09:24 P8_15_pinmux.23

drwxr-xr-x 3 root

root 0 May 24

09:24 P8_16_pinmux.24

drwxr-xr-x 3 root

root 0 May 24

09:24 P8_17_pinmux.25

drwxr-xr-x 3 root

root 0 May 24

09:24 P8_18_pinmux.26

drwxr-xr-x 3 root

root 0 May 24

09:24 P8_19_pinmux.27

drwxr-xr-x 3 root

root 0 May 24

09:24 P8_26_pinmux.28

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_11_pinmux.29

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_12_pinmux.30

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_13_pinmux.31

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_14_pinmux.32

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_15_pinmux.33

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_16_pinmux.34

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_17_pinmux.35

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_18_pinmux.36

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_21_pinmux.37

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_22_pinmux.38

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_23_pinmux.39

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_24_pinmux.40

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_26_pinmux.41

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_27_pinmux.42

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_30_pinmux.43

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_41_pinmux.44

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_42_pinmux.46

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_91_pinmux.45

drwxr-xr-x 3 root

root 0 May 24

09:24 P9_92_pinmux.47

Connecting pins to the PWM

Chip

Now in order to connect the

PWM to a pin look up what pin PWM can be output to in the

cape-universaln-00A0.dts file. You'll find that you can connect

them to for instance P9.14, P9.16, P9.21, and

P9.22.

To convince yourself on your

choice issue this command:

root@beagelbone$]

config-pin -l P9.14

expect this

output:

default gpio

gpio_pu gpio_pd pwm

Now in order to enable the

pwm to the P9.14 pin issue:

root@begalebone$]

config-pin P9.14 pwm

To ensure yourself that

you've got the PWM connected to the pin issue

root@beaglebone$]

cat /sys/devices/ocp.3/P9_14_pinmux.32/state

expect this

output

pwm

Locate the PWM control

files

Now where are the

PWM?

Issue

root@beaglebone$]

ll /sys/class/pwm/

and expect

this

total 0

drwxr-xr-x 2 root

root 0

Jan 1 2000 .

drwxr-xr-x 59 root

root 0

Jan 1 2000 ..

--w------- 1 root root 4096

Jan 1 2000

export

lrwxrwxrwx 1 root

root 0 May 24

09:30 pwmchip0 ->

../../devices/ocp.3/48300000.epwmss/48300200.ehrpwm/pwm/pwmchip0

lrwxrwxrwx 1 root

root 0 May 24

09:30 pwmchip2 ->

../../devices/ocp.3/48300000.epwmss/48300100.ecap/pwm/pwmchip2

lrwxrwxrwx 1 root

root 0 May 24

09:30 pwmchip3 ->

../../devices/ocp.3/48302000.epwmss/48302200.ehrpwm/pwm/pwmchip3

lrwxrwxrwx 1 root

root 0 May 24

09:30 pwmchip5 ->

../../devices/ocp.3/48304000.epwmss/48304200.ehrpwm/pwm/pwmchip5

lrwxrwxrwx 1 root

root 0 May 24

09:30 pwmchip7 ->

../../devices/ocp.3/48304000.epwmss/48304100.ecap/pwm/pwmchip7

--w------- 1 root root 4096

Jan 1 2000

unexport

How to interpret this

output. First we'll have to look into this technical

document over the AM335x Sitara Processors.

(If the document is not available search for AM335 Sitara Processor

Technical Reference Manual - it's a ~22 MB

document).

Looking for address 48300000

in the memory map, you'll find this is in the L4_PER block, and

this is listed as the “PWM subsystem 0″, and 48300200 is the EHR0

PWM channel and 48300100 the eCAP0 PWM. Also, address 4830200 is

the “PWM subsystem 1″, and address 4830400 is the “PWM subsystem

2″.

Now, using the pin names

found from the BeagleBoard.org –

bone101 page served from the board, and

deductive reasoning you'll come up with the following maping of pin

to export number:

export number

pin name

pins

0

EHRPWM0A

P9.22,P9.31

1

EHRPWM0B

P9.21,P9.29

2

ECAPPWM0

P9.42

3

EHRPWM1A

P9.14,P8.36

4

EHRPWM1B

P9.16,P8.34

5

EHRPWM2A

P8.19,P8.45

6

EHRPWM2B

P8.13,P8.46

7

ECAPPWM2

P9.28

Enable the pin for the

PWM

Now we're ready to enable a

pwm for instance P9_14. This is done by looking up P9.14 in the

table above and see that it is export number 3. So

perform

root@beaglebone$]

echo 3 > /sys/class/pwm/export

NOTE here there needs to be

a space between 3 and >!

root@beaglebone$]

ls /sys/class/pwm/

will give you

this

export pwm3 pwmchip0 pwmchip2 pwmchip3 pwmchip5 pwmchip7 unexport

No issuing

root@begalebone$]

ll /sys/class/pwm/pwm3/

will

output

total 0

drwxr-xr-x 3 root

root 0 May 24

09:52 .

drwxr-xr-x 4 root

root 0 May 24

09:24 ..

lrwxrwxrwx 1 root

root 0 May 24

09:57 device -> ../../../48302200.ehrpwm

-rw-r--r-- 1 root

root 4096 May 24 09:57 duty_ns

-rw-r--r-- 1 root

root 4096 May 24 09:57 period_ns

-rw-r--r-- 1 root

root 4096 May 24 09:57 polarity

drwxr-xr-x 2 root

root 0 May 24

09:57 power

-rw-r--r-- 1 root

root 4096 May 24 09:57 run

lrwxrwxrwx 1 root

root 0 May 24

09:52 subsystem -> ../../../../../../class/pwm

-rw-r--r-- 1 root

root 4096 May 24 09:52 uevent

The files of interest here

are

the duty_ns, period_ns and polarity.

The polarity sets

the polarity of the output signal. Typically setup once at

initialisation.

The period_ns sets

the period time active for the PWM signal. In nano seconds.

Typically setup once at initialisation.

The duty_ns sets

the duty cycle for the PWM signal - i.e. the length of the period

time the PWM signal is active. In nano seconds. This one is

constantly updated with the desired duty cycle.

Control the

PWM

No you can control the PWM

from the command line or you can write a C/C++ program that will

open, write and close the above mentioned files in order to control

the PWM.

Set the Pinmux and Enable at

boot

If you want to enable the

PWM in a quick way create a script in /etc/init.d

called enable-pwm and put in this

text into the file

#! /bin/sh

### BEGIN INIT

INFO

# Provides:

enable-pwm

# Required-Start:

$all

# Required-Stop:

$all

# Default-Start: 2

3 4 5

# Default-Stop: 0 1

6

#

Short-Description: Enables the PWM chips and connects it through

the pinmux

# Description:

Connecting the pwm output through the pinmux and enables the PWM

chip on board

### END INIT

INFO

case “$1″

in

start)

# Add the BeagleBone overlay to the default setup

echo cape-universaln >

/sys/devices/bone_capemgr.9/slots

# Connect the P9.14 to the PWM

config-pin P9.14 pwm

# Now we are ready to enable the PWM chip

echo 3 > /sys/class/pwm/export

;;

stop)

#no-op

;;

*)

#no-op

;;

esac

exit

0

The first part after the

#!/bin/sh tells the systemd information about your

service.

Next comes the actual code

part, where the case switches on the first parameter to the script.

It can

be start or stop.

The start command will be handled in the

section start). Likewise goes for the stop

command.

In order to insert this as a

service in the systemd execute these

instructions:

root@beaglebone$]

chmod +x

enable-pwm ##

Give execute rights to the script

root@beaglebone$]

insserv -n enable-pwm ## Checks the

script

root@beaglebone$]

insserv

enable-pwm ## Actually inserts the script

Now reboot the system and

check if your PWM has be enables and routed to

P9_14.

Removing an entry from

slots

In the previous sections

echo'ing a value into /sys/devices/bone_capemgr.9/slots (typically

refered to as $SLOTS) enabled the device overlay. If the overlay

should be removed without rebooting then issue this

command

root@beaglebone$] cat

$SLOTS

This is a typical

output

0:

54:PF---

1:

55:PF---

2:

56:PF---

3:

57:PF---

4: ff:P-O-L

Bone-LT-eMMC-2G,00A0,Texas

Instrument,BB-BONE-EMMC-2G

5: ff:P-O-L

Bone-Black-HDMI,00A0,Texas

Instrument,BB-BONELT-HDMI

7: ff:P-O-L

Override Board Name,00A0,Override Manuf,DS1820

8: ff:P-O-L

Override Board Name,00A0,Override

Manuf,am33xx_pwm

9: ff:P-O-L

Override Board Name,00A0,Override

Manuf,bspwm_P9_14_16

If the bspwm_P9_14_16 is to

be removed issue

root@beaglebone$]

echo -9 > $SLOTS

root@beaglebone$]

cat $SLOTS

with this

result

0:

54:PF---

1:

55:PF---

2:

56:PF---

3:

57:PF---

4: ff:P-O-L

Bone-LT-eMMC-2G,00A0,Texas

Instrument,BB-BONE-EMMC-2G

5: ff:P-O-L

Bone-Black-HDMI,00A0,Texas

Instrument,BB-BONELT-HDMI

7: ff:P-O-L

Override Board Name,00A0,Override Manuf,DS1820

8: ff:P-O-L

Override Board Name,00A0,Override

Manuf,am33xx_pwm

这篇关于beaglebone php,Beaglebone Black开启PWM功能【酷】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/351035

相关文章

hadoop开启回收站配置

开启回收站功能,可以将删除的文件在不超时的情况下,恢复原数据,起到防止误删除、备份等作用。 开启回收站功能参数说明 (1)默认值fs.trash.interval = 0,0表示禁用回收站;其他值表示设置文件的存活时间。 (2)默认值fs.trash.checkpoint.interval = 0,检查回收站的间隔时间。如果该值为0,则该值设置和fs.trash.interval的参数值相等。

C++11第三弹:lambda表达式 | 新的类功能 | 模板的可变参数

🌈个人主页: 南桥几晴秋 🌈C++专栏: 南桥谈C++ 🌈C语言专栏: C语言学习系列 🌈Linux学习专栏: 南桥谈Linux 🌈数据结构学习专栏: 数据结构杂谈 🌈数据库学习专栏: 南桥谈MySQL 🌈Qt学习专栏: 南桥谈Qt 🌈菜鸡代码练习: 练习随想记录 🌈git学习: 南桥谈Git 🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈�

让树莓派智能语音助手实现定时提醒功能

最初的时候是想直接在rasa 的chatbot上实现,因为rasa本身是带有remindschedule模块的。不过经过一番折腾后,忽然发现,chatbot上实现的定时,语音助手不一定会有响应。因为,我目前语音助手的代码设置了长时间无应答会结束对话,这样一来,chatbot定时提醒的触发就不会被语音助手获悉。那怎么让语音助手也具有定时提醒功能呢? 我最后选择的方法是用threading.Time

Spring框架5 - 容器的扩展功能 (ApplicationContext)

private static ApplicationContext applicationContext;static {applicationContext = new ClassPathXmlApplicationContext("bean.xml");} BeanFactory的功能扩展类ApplicationContext进行深度的分析。ApplicationConext与 BeanF

JavaFX应用更新检测功能(在线自动更新方案)

JavaFX开发的桌面应用属于C端,一般来说需要版本检测和自动更新功能,这里记录一下一种版本检测和自动更新的方法。 1. 整体方案 JavaFX.应用版本检测、自动更新主要涉及一下步骤: 读取本地应用版本拉取远程版本并比较两个版本如果需要升级,那么拉取更新历史弹出升级控制窗口用户选择升级时,拉取升级包解压,重启应用用户选择忽略时,本地版本标志为忽略版本用户选择取消时,隐藏升级控制窗口 2.

Android 10.0 mtk平板camera2横屏预览旋转90度横屏拍照图片旋转90度功能实现

1.前言 在10.0的系统rom定制化开发中,在进行一些平板等默认横屏的设备开发的过程中,需要在进入camera2的 时候,默认预览图像也是需要横屏显示的,在上一篇已经实现了横屏预览功能,然后发现横屏预览后,拍照保存的图片 依然是竖屏的,所以说同样需要将图片也保存为横屏图标了,所以就需要看下mtk的camera2的相关横屏保存图片功能, 如何实现实现横屏保存图片功能 如图所示: 2.mtk

Spring+MyBatis+jeasyui 功能树列表

java代码@EnablePaging@RequestMapping(value = "/queryFunctionList.html")@ResponseBodypublic Map<String, Object> queryFunctionList() {String parentId = "";List<FunctionDisplay> tables = query(parent

PostgreSQL核心功能特性与使用领域及场景分析

PostgreSQL有什么优点? 开源和免费 PostgreSQL是一个开源的数据库管理系统,可以免费使用和修改。这降低了企业的成本,并为开发者提供了一个活跃的社区和丰富的资源。 高度兼容 PostgreSQL支持多种操作系统(如Linux、Windows、macOS等)和编程语言(如C、C++、Java、Python、Ruby等),并提供了多种接口(如JDBC、ODBC、ADO.NET等

寻迹模块TCRT5000的应用原理和功能实现(基于STM32)

目录 概述 1 认识TCRT5000 1.1 模块介绍 1.2 电气特性 2 系统应用 2.1 系统架构 2.2 STM32Cube创建工程 3 功能实现 3.1 代码实现 3.2 源代码文件 4 功能测试 4.1 检测黑线状态 4.2 未检测黑线状态 概述 本文主要介绍TCRT5000模块的使用原理,包括该模块的硬件实现方式,电路实现原理,还使用STM32类

nginx介绍及常用功能

什么是nginx nginx跟Apache一样,是一个web服务器(网站服务器),通过HTTP协议提供各种网络服务。 Apache:重量级的,不支持高并发的服务器。在Apache上运行数以万计的并发访问,会导致服务器消耗大量内存。操作系统对其进行进程或线程间的切换也消耗了大量的CPU资源,导致HTTP请求的平均响应速度降低。这些都决定了Apache不可能成为高性能WEB服务器  nginx: