[pwm]PWM的输入捕捉模式
对于stm32来说,输入捕捉模式有两种:
- 普通输入捕捉模式:经常用来测量脉冲宽度和频率,例如测量脉冲宽度,TIM5_CH1来捕获高电平脉宽,首先先设置输入捕获为上升沿触发,然后记录下发生上升沿时TIM5_CNT值。再然后,设置捕获信号为下降沿,在下降沿到来的时候,记录下此时的TIM5_CNT值。这样一来,两次TIM5_CNT值只差即为脉冲宽度。只设置上升沿触发则可以捕获信号周期。
- PWM输入捕捉模式:pwm输入捕获模式是普通输入模式一种特殊应用,是将TIMx输入映射了两个ICx信号(输入捕获装置IC1和IC2),其中一个捕获上升沿,另一个捕获下降沿。这样可以在中断中去读上升沿和下降沿对应寄存器中的计数,从而得出周期和占空比。其中一个捕获通道计算两次都是上升沿的时间,即周期T;而另一个通道则计算一次下降沿和之前上升沿之差,这样得到高电平时长,从而可以求得周期T和占空比。
stm32输入捕获模式简介:http://www.cnblogs.com/wangh0802PositiveANDupward/archive/2013/01/03/2843058.html
stm32 pwm输入捕获模式简介:http://www.51hei.com/bbs/dpj-41774-1.html
-----------------------------------------------------------------------------------------------------------------------------------------
PWM常用来做电机控制、LED背光亮度调节、开关电源等。
Linux pwm driver with sysfs
TI linux pwm user guide: http://processors.wiki.ti.com/index.php/Linux_Core_PWM_User%27s_Guide#eHRPWM
Freescale: https://support.bluetechnix.at/wiki/Linux_Software_User_Manual_(i.MX6)#PWM
Gateworks: http://trac.gateworks.com/wiki/linux/pwm
对于TI的pwm来说
- 首先配置内核支持pwm模块,其中eHRPWM:Enhanced High Resolution PWM, eCAP:Enhanced Capture.
Procedure to build eHRPWM driver
Device Drivers --->
<*> Pulse Width Modulation(PWM) Support --->
<*> eHRPWM PWM support
Procedure to build eCAP driver
Device Drivers --->
<*> Pulse Width Modulation(PWM) Support --->
<*> eCAP PWM support
- 其次,申请channel
Request the Device:
target$ echo > /sys/class/pwm/pwmchip0/export
free the device:
target$ echo > /sys/class/pwm/pwmchip0/unexport
- 使能/失能通道,注意:在使能前需要先设置下面参数,如周期和占空比
Enable the PWM
target$ echo > /sys/class/pwm/pwmchip0/pwm0/enable
Disable the PWM
target$ echo > /sys/class/pwm/pwmchip0/pwm0/enable
- 设置周期/占空比/极性
i.Setting the Period
Following attributes set the period of the PWM waveform.
period Attribute
Enter the period in nano seconds value. Example
if the period is sec , enter target$ echo > /sys /class/pwm/pwmchip0/pwm0/period
ii.Setting the Duty
Following attributes set the duty of the PWM waveform. duty_cycle Attribute
Enter the Duty cycle value in nanoseconds. target$ echo val > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
iii.Setting the Polarity
Polarity Attribute.
Setup Signal Polarity Example
To set the polarity to Active High, Enter target$ echo > /sys /class/pwm/pwmchip0/pwm0/polarity
这样就完成了pwm的设置。
那sysfs和kernel中的驱动文件是怎么匹配起来的?
主要有3个文件:在drivers/pwm下得sysfs.c/core.c/pwm-imx.c
举个period的例子:
-->static DEVICE_ATTR(period, 0644, pwm_period_show, pwm_period_store) //sysfs.c
-->pwm_period_store(...) //sysfs.c
-->pwm_config(...) //core.c
-->pwm->chip->ops->config(...) //core.c
-->imx_pwm_config(...) //pwm-imx.c
-->imx_pwm_config_v1(imx1) or imx_pwm_config_v2(imx27在dts中Imx6使用)
这样就和驱动文件关联起来了。
[pwm]PWM的输入捕捉模式的更多相关文章
- STM32输入捕获模式设置并用DMA接收数据
参考: STM32的PWM输入模式设置并用DMA接收数据 Input capture mode The input stage samples the corresponding TIx input ...
- (stm32f103学习总结)—输入捕获模式
一.输入捕获介绍 在定时器中断实验章节中我们介绍了通用定时器具有多种功能,输入捕获就是其中一种.STM32F1 除了基本定时器 TIM6 和 TIM7,其他定时器都具有输入捕获功能.输入捕获可以对输入 ...
- occ添加新的捕捉模式
Load (theSelection, theShape, theType, theDeflection, theDeviationAngle, isAutoTriangulation, thePri ...
- mysql \c 终止 mysql输入语句模式
\c 遇到这种情况怎么退出mysql 输入语句模式? mysql> select -> 输入\c退出 mysql> select -> \c mysql> 另外一种情况 ...
- STM32(9)——通用定时器作为输入捕捉
通用定时器作为输入捕获的使用.我们将用 TIM5 的通道 1 (PA0)来做输入捕获,捕获 PA0 上高电平的脉宽(用 WK_UP 按键输入高电平),通过串口打印高电平脉宽时间 输入捕获简介 输入捕获 ...
- 【翻译自mos文章】OGG的集成捕捉模式支持Oracle database标准版么?
OGG的集成捕捉模式支持Oracle database标准版么? 来源于: Does OGG 11.2.1 Integrated Capture Work with Oracle Database S ...
- 说说M451例程之PWM的寄存器讲解
M451提供了两路PWM发生器.每路PWM支持6通道PWM输出或输入捕捉.有一个12位的预分频器把时钟源分频后输入给16位的计数器,另外还有一个16位的比较器.PWM计数器支持向上,向下,上下计数方式 ...
- 说说M451例程之PWM
/**************************************************************************//** * @file main.c * @ve ...
- ADC配置成定时器触发的启发
百度文库:https://wenku.baidu.com/view/99d39413f78a6529647d5344.html STM32关于使用定时器触发ADC转换的解决办法和详细说明 本人在使用S ...
随机推荐
- PyDev:warning: Debugger speedups using cython not foun
在eclipse下调试代码开始时总提示一个警告: warning: Debugger speedups using cython not found. Run '"C:\Python36\p ...
- Android面试,BroadCastReceiver的两种注册方式的异同
在Android手机应用程序中开发中,需要用到BroadcastReceiver来监听广播的消息.在自定义好BroadcastReceiver ,需要对其进行注册,注册有两种方法: 一种是在代码当中注 ...
- 自定义错误信息并写入到Elmah
在ap.net Web项目中一直使用Elmah进行日志记录, 但一直有一个问题困扰我很久,那就是我如何自己生成一个错误并记录到Elmah里去. 你知道有时你需要在项目中生成一个错误用于一些特殊的需求 ...
- [ACM] POJ 2524 Ubiquitous Religions (并查集)
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 23093 Accepted: ...
- Token_使用JWT生成token
1.token三部分 header { "typ": "JWT", "alg": "HS256" } paylo ...
- log4j.properties 详解与配置步骤总结
先提供一个项目中使用log4j.properties配置 #log4j.rootLogger=WARN, stdout, file log4j.rootLogger=INFO,console,dail ...
- js看起来比较怪异的写法 (综合)
1.$(function() {}中$是什么意思? <script type="text/javascript"> $(function(){ $("#tre ...
- iOS-字符串拼接
// // main.m // /* 将两个字符串 NSString * str1 = @"123"; NSString * str2 = @"abc"; 拼接 ...
- shiny安装使用入门
下载最新版R(至少3.2.5版本),在CRAN上下载: 打开R install.packages("shiny")#安装shiny包 library(shiny)#如果出现warn ...
- Openerp 中打开 URL 的三种 方法
来自:http://shine-it.net/index.php/topic,8013.0.html 最近总结了,Openerp 中打开 URL 的三种 方法: 一.在form view 添加 < ...