AM335X PWMSS 驱动指导

news/2024/11/8 9:40:28/

脉宽调制子系统(Pluse-Width Modulation SubSystem--PWMSS)由增强高分辨率脉宽调制器(eHRPWM),强采集(eCAP),强正交编码脉冲(eQEP)三个模块构成。

eHRPWM

       eHRPWM是一个比较实用的外围设备,它可以在最小的CPU开销下产生复杂的脉宽波形。一个完整的ePWM模块由两路PWM输出组成,EPWMA和EPWMB。

1, 专用的16位time-base用作周期或是频率控制

2, 两路PWM输出能按下面的方式配置:

1, 两个独立的PWM输出用作单沿操作

2, 两个独立的PWM输出用作双沿对称操作

3, 一个独立的PWM输出用作双沿对称操作

3, 可编程的中断事件,并且是最小的CPU开销

 

eCAP

eCAP模块既可以用作PWM功能,也可用作采集功能。

1, 专用的外部PIN脚

2, 32位Time Base计数器

3, 4*32位时间戳采集寄存器(CAP1-CAP4)

4, 预缩放的输入采集信号

5, 中断功能可以由任意四个采集事件触发

当前PWM驱动只能支持下面特性:

1, eHRPWMg与eCAP可以支持

2, eCAP只能支持PWM模式


PWMSS软件架构如下图:


驱动的配置:

选择eHRPWM驱动

Device Drivers ---><*> PWM Support ---><*> Davinci eHRPWM support  
选择eCAP驱动

         Device Drivers ---><*> PWM Support ---><*> eCAP PWM support   
大家还要注意PIN脚模式的选择和配置,否则驱动控制不了PIN脚

eHRPWM

eHRPWM can be controlled from the user space through SYSFS interface. SYSFS interface for eHRPWM is available at

/sys/class/pwm/ehrpwm.i:j

Where,

‘i’ is the eHRPWM instance
‘j’ is the eHRPWM ouptut 0 or 1[Each instance of eHRPWM has 2 channel outputs] 

Various SYSFS Attributes 

2 types of SYSFS attributes are available

  1. Request and Control attributes
  2. Configuration attributes

Note

  • Below examples uses eHRPWM instance 2 and output channel 0 (i = 2, j = 0).

Type 1 attributes

  • request Attribute.

Request PWM-SS for permission to use the module. Writing 1 to the request attribute Acquires the device and writing 0 to the request attribute Frees/Releases the device. Before performing any operations, device has to be requested first.

Example

  • Request the Device:
target$ echo 1 > /sys/class/pwm/ehrpwm.2:0/request
  • free the device:
target$ echo 0 > /sys/class/pwm/ehrpwm.2:0/request
  • run Attribute

Start or Stop the PWM Module. 0 – Stop Module, 1 – Start module.

Example

  • Start the PWM
target$ echo 1 > /sys/class/pwm/ehrpwm.2:0/run
  • Stop the PWM
target$ echo 0 > /sys/class/pwm/ehrpwm.2:0/run

CAUTION
Before enabling the module, the module needs to be configured using below configuration attributes. Else proper operation is not assured.

Type 2 attributes

i.Setting the Period
Following attributes set the period of the PWM waveform.

  • frequency Attribute

Enter the period in HZ. Once the frequency is configured, make sure to set the duty cycle value.

Example
Setup PWM to generate a pwm signal of 100 HZ with 50% duty cycle.

target$ echo 100 > /sys/class/pwm/ehrpwm.2:0/period_freq
target$ echo 50 > /sys/class/pwm/ehrpwm.2:0/duty_percent
  • period_ns Attribute

Enter the period in nano seconds value.

Example
if the period is 1 sec , enter

target$ echo 1000000000 > /sys /class/pwm/ehrpwm.2:0/period_ns

ii.Setting the Duty
Following attributes set the duty of the PWM waveform.

  • duty_percent Attribute

Enter the Duty cycle value in percentage.

Example
To configure for 50% duty cycle, enter

target$ echo 50 > /sys/class/pwm/ehrpwm.2:0/duty_percent
  • duty_ns Attribute

duty_ns takes the duty cycle value in nano seconds.

Example
To configure for 0.5s, enter

target$ echo 500000000 > /sys /class/pwm/ehrpwm.2:0/duty_ns

iii.Setting the Polarity

  • Polarity Attribute.

Setup Signal Polarity

Example
To set the polarity to Active High, Enter

target$ echo 1 > /sys /class/pwm/ehrpwm.2:0/polarity

Example
To set the polarity to Active Low, Enter

target$ echo 0 > /sys /class/pwm/ehrpwm.2:0/polarity

Example Configuration:
Following example shows steps to configure the PWM for 100 HZ with 50% duty cycle.

target$ echo 1 >  /sys/class/pwm/ehrpwm.2:0/request
target$ echo 100 > /sys/class/pwm/ehrpwm.2:0/period_freq
target$ echo 50 > /sys/class/pwm/ehrpwm.2:0/duty_percent
target$ echo 1 > /sys/class/pwm/ehrpwm.2:0/run

Issuing above commands will generate PWM wave. This can be verified by probing to eHRPWM pin.

IMPORTANT

  1. To change the frequency, first stop the PWM waveform, reset the duty to zero and then follow the last 3 steps in the above Example Configuration. 
  2. eHRPWM 2 instance channel 1 pwm pin is hooked to Haptics AM335x EVM. Changing the duty percentage/frequency will affect the speed of the Haptics.


Controlling haptics

Haptics on Evaluation Module can be controlled through eHRPWM sysfs interface. 

IMPORTANT

In order to run Haptics using eHRPWM interface, the Evaluation Module needs to be in Profile 4.
target$ echo 1 > /sys/class/pwm/ehrpwm.2:1/request
target$ echo 250 > /sys/class/pwm/ehrpwm.2:1/period_freq
target$ echo 50 > /sys/class/pwm/ehrpwm.2:1/duty_percent
target$ echo 1 > /sys/class/pwm/ehrpwm.2:1/run

eCAP

The current release of the driver supports only PWM mode. eCAP can be controlled from the user space through SYSFS interface. SYSFS interface for eCAP is available at

target$ cat /sys/class/pwm/ecap.i

Where,

‘i’ is the eCAP instance. 

Various SYSFS Attributes 

2 types of SYSFS attributes are available

  1. Request and Control attributes
  2. Configuration attributes

Note

  • Below examples uses eCAP instance 0 (i = 0).

Type 1 attributes

  • request Attribute.

Request PWM-SS for permission to use the module. Writing 1 to the request attribute Acquires the device and writing 0 to the request attribute Frees/Releases the device. Before performing any operations, device has to be requested first.


Example

  • Request the Device:
target$ echo 1 > /sys/class/pwm/ecap.0/request
  • free the device:
target$ echo 0 > /sys/class/pwm/ecap.0/request
  • run Attribute

Start or Stop the PWM Module. 0 – Stop Module, 1 – Start module.

Example

  • Start the PWM
target$ echo 1 > /sys/class/pwm/ecap.0/run
  • Stop the PWM
target$ echo 0 > /sys/class/pwm/ecap.0/run

CAUTION
Before enabling the module, the module needs to be configured using below configuration attributes. Else proper operation is not assured.


Type 2 attributes

i.Setting the Period
Following attributes set the period of the PWM waveform.

  • frequency Attribute

Enter the period in HZ. Once the frequency is configured, make sure to set the duty cycle value.

Example
Setup PWM to generate a pwm signal of 100 HZ with 50% duty cycle.

target$ echo 100 > /sys/class/pwm/ecap.0/period_freq
target$ echo 50 > /sys/class/pwm/ecap.0/duty_percent 
  • period_ns Attribute

Enter the period in nano seconds value.

Example
if the period is 1 sec , enter

target$ echo 1000000000 > /sys /class/pwm/ecap.0/period_ns 

ii.Setting the Duty
Following attributes set the duty of the PWM waveform.

  • duty_percent Attribute

Enter the Duty cycle value in percentage.

Example
To configure for 50% duty cycle, enter

target$ echo 50 > /sys/class/pwm/ecap.0/duty_percent
  • duty_ns Attribute

duty_ns takes the duty cycle value in nano seconds.

Example
To configure for 0.5s, enter

target$ echo 500000000 > /sys /class/pwm/ecap.0/duty_ns

iii.Setting the Polarity

  • Polarity Attribute.

Setup Signal Polarity

Example
To set the polarity to Active High, Enter

target$ echo 1 > /sys /class/pwm/ecap.0/polarity


Example
To set the polarity to Active Low, Enter

target$ echo 0 > /sys /class/pwm/ecap.0/polarity

Example Configuration:
Following example shows steps to configure the PWM for 100 HZ with 50% duty cycle.

target$ echo 1 > /sys/class/pwm/ecap.0/request
target$ echo 100 > /sys/class/pwm/ecap.0/period_freq
target$ echo 50 > /sys/class/pwm/ecap.0/duty_percent
target$ echo 1 > /sys/class/pwm/ecap.0/run

Issuing above commands will generate PWM wave. This can be verified by probing to eCAP pin.

IMPORTANT

  1. To change the frequency, first stop the PWM waveform, reset the duty to zero and then follow the last 3 steps in the above Example Configuration.
  2. In this EVM, eCAP instance 0 pin is hooked to backlight of the LCD. Changing the duty percentage will affect the brightness of the LCD screen.


Controlling backlight

Following are the 2 procedures to vary brightness of the LCD screen.

i. Setting duty percentage of pwm wave from eCAP sysfs files

target$ echo val > /sys/class/pwm/ecap.0/duty_percent

'val' can range from 0 to 100.
ii. Setting brightness from backlight sysfs files

target$ echo val > /sys/class/backlight/pwm-backlight/brightness


http://www.ppmy.cn/news/709591.html

相关文章

AM335x TP驱动解析

文章目录 1. 电阻屏原理2. ADC2.1 Device&#xff1a;2.2 Driver&#xff1a; 3. TouchSceen3.1 Device3.2 Driver3.3 uDev 4. KeyBoard4.1 Device4.2 Driver 5. InputDevice5.1 Input字符设备5.2 input_register_device()5.3 input_register_handler()5.4 input_attach_handle…

H264和X264究竟有什么区别?

H264隶属于MPEG-4编码,是一种高运算量的编码格式,H264的优点是在目前影视文件中容量最小的RAW,缺点是编码时需要大量运算时间,H264支援硬件加速,H264支持自变速满帧技术(15fps-6000fps),H264编码的文件最大特征是后缀名为.h264。 X264是H264的另外一种开源编码格式,其开头的&qu…

Keil MDK 5 仿真STM32F4报错no ‘read‘ permission

问题描述 MDK软件模拟仿真提示没有读写权限&#xff0c;只能单步运行。error提示&#xff1a; *** error 65: access violation at 0x40023C00 : no read permission 关于Keil MDK 5 仿真STM32F4报错no ‘read’ permission的解决方法 Vision 调试器为所有 ARM7、ARM9、Corte…

Bitbucket 新版本的安全限制

新版本的安全限制 是继续按照他给的第二个链接进入Bitbucket仓库后台添加App密码&#xff0c;也就是每个仓库需要单独的秘密码&#xff0c;这样的话就更加安全。 生产新密码&#xff1a; 这一坨务必要妥善保存&#xff0c;因为一旦点了关闭之后你就再也没有机会看到这个密码了…

Vue--简单实现微博发布功能和实现tab栏

1、微博发布功能 html 代码&#xff1a; <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>Document…

用HTML+CSS做一个漂亮简单的个人网页~个人相册介绍个人主页模板(6个页面) ~学生HTML个人网页作业作品~...

用HTMLCSS做一个漂亮简单的个人网页 ~ 个人相册介绍个人主页模板(6个页面) 学生HTML个人网页作业作品 临近期末, 你还在为HTML网页设计结课作业,老师的作业要求感到头大&#xff1f;HTML网页作业无从下手&#xff1f;网页要求的总数量太多&#xff1f;没有合适的模板&#xff1…

粤嵌Gec6818---小项目功能实现(RFID+图片显示+音乐+视频)

项目设计开发环境&#xff1a; &#xff08;1&#xff09;VMware Workstation Pro软件 &#xff08;2&#xff09;ubuntu12 .04 &#xff08;能交叉编译就行&#xff09; &#xff08;3&#xff09;SecureCRT &#xff08;4&#xff09;代码编译器&#xff08;notepad/Vis…

css经典布局

css经典布局 1.三列布局&#xff08;浮动&#xff0c;但是中间列在最下面&#xff0c;最后加载不好&#xff09; <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"…