STM32F407-14.3.7-01PWM输入模式

PWM 输入模式 


此模式是输入捕获模式的一个特例。其实现步骤与输入捕获模式基本相同,仅存在以下不同之处:
 
例如,可通过以下步骤对应用于 TI1① 的 PWM 的周期(位于 TIMx_CCR1⑨ 寄存器中)和占空 比(位于 TIMx_CCR2⑮ 寄存器中)进行测量(取决于 CK_INT① 频率和预分频器的值): 
● IC1⑦ 与 IC2⑬ 两个信号被映射至同一个 TI1① 输入。 
● IC1⑦ 与 IC2⑬ 这两个信号在边沿处有效,但极性相反。 
● 选择TI1FP 与 TI2FP 中的 TI1FP④ 信号作为触发输入(也可选择TI2FP),并将从模式控制器配置为复位模式。 
● 向 TIMx_CCMR1 寄存器中的 CC1S② 位写入 01,选择 TIMx_CCR1 的有效输入: TI1①。 
● 向 CC1P 位和 CC1NP③ 位写入 “0” (上升沿有效)。选择 TI1FP1④ 的有效极性 : 上升沿有效(用于 TIMx_CCR1⑨ 中捕获上升沿时的计数值 和 TIMx_CNT⑯ 计数器清零): 
● 向 TIMx_CCMR1 寄存器中的 CC2S⑪ 位写入 10,选择 TIMx_CCR2 的有效输入: TI1①。 
● 向 CC2P 位和 CC2NP⑫ 位写入 “1” (下降沿有效)。选择 TI1FP2 的有效极性 : 下降沿有效(用于 TIMx_CCR2⑮ 中捕获下降沿时的计数值)。 
● 选择有效触发输入:向 TIMx_SMCR 寄存器中的 TS⑤ 位写入 101(选择 TI1FP1)。 
● 向 TIMx_SMCR 寄存器中的 SMS⑥ 位写入 100 , 将从模式控制器配置为复位模式。 
● 向 TIMx_CCER 寄存器中的 CC1E⑧ 位和 CC2E⑭ 位写入“1” , 使能捕获。 
根据F103的库函数TIM_PWMIConfig()微调了数据手册中框图的位置关系.

TIM_PWMIConfig()函数

/*	stm32f10x_tim.h 中宏定义 */
#define  TIM_ICPolarity_Rising             ((uint16_t)0x0000)
#define  TIM_ICPolarity_Falling            ((uint16_t)0x0002)#define TIM_ICSelection_DirectTI           ((uint16_t)0x0001) /*!< TIM Input 1, 2, 3 or 4 is selected to be connected to IC1, IC2, IC3 or IC4, respectively */
#define TIM_ICSelection_IndirectTI         ((uint16_t)0x0002) /*!< TIM Input 1, 2, 3 or 4 is selected to be connected to IC2, IC1, IC4 or IC3, respectively. *//*	stm32f10x_tim.c 中PWMIConfig定义 */
/*** @brief  Configures the TIM peripheral according to the specified*         parameters in the TIM_ICInitStruct to measure an external PWM signal.* @param  TIMx: where x can be  1, 2, 3, 4, 5, 8, 9, 12 or 15 to select the TIM peripheral.* @param  TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure*         that contains the configuration information for the specified TIM peripheral.* @retval None*/
void TIM_PWMIConfig(TIM_TypeDef *TIMx, TIM_ICInitTypeDef *TIM_ICInitStruct)
{uint16_t icoppositepolarity = TIM_ICPolarity_Rising;uint16_t icoppositeselection = TIM_ICSelection_DirectTI;/* Check the parameters */assert_param(IS_TIM_LIST6_PERIPH(TIMx));/*互补极性设置*//* Select the Opposite Input Polarity */if (TIM_ICInitStruct->TIM_ICPolarity == TIM_ICPolarity_Rising){icoppositepolarity = TIM_ICPolarity_Falling;}else{icoppositepolarity = TIM_ICPolarity_Rising;}/*交叉通道设置*//* Select the Opposite Input */if (TIM_ICInitStruct->TIM_ICSelection == TIM_ICSelection_DirectTI){icoppositeselection = TIM_ICSelection_IndirectTI;}else{icoppositeselection = TIM_ICSelection_DirectTI;}/*分别配置IC1,IC2通道*/if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_1){/* TI1 Configuration */TI1_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection,TIM_ICInitStruct->TIM_ICFilter);/* Set the Input Capture Prescaler value */TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);/* TI2 Configuration */TI2_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->TIM_ICFilter);/* Set the Input Capture Prescaler value */TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);}else{/* TI2 Configuration */TI2_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection,TIM_ICInitStruct->TIM_ICFilter);/* Set the Input Capture Prescaler value */TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);/* TI1 Configuration */TI1_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->TIM_ICFilter);/* Set the Input Capture Prescaler value */TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);}
}

TI1_Config (函数)

/*	通道 1 配置*/
/*** @brief  Configure the TI1 as Input.* @param  TIMx: where x can be 1 to 17 except 6 and 7 to select the TIM peripheral.* @param  TIM_ICPolarity : The Input Polarity.*   This parameter can be one of the following values:*     @arg TIM_ICPolarity_Rising*     @arg TIM_ICPolarity_Falling* @param  TIM_ICSelection: specifies the input to be used.*   This parameter can be one of the following values:*     @arg TIM_ICSelection_DirectTI: TIM Input 1 is selected to be connected to IC1.*     @arg TIM_ICSelection_IndirectTI: TIM Input 1 is selected to be connected to IC2.*     @arg TIM_ICSelection_TRC: TIM Input 1 is selected to be connected to TRC.* @param  TIM_ICFilter: Specifies the Input Capture Filter.*   This parameter must be a value between 0x00 and 0x0F.* @retval None*/
static void TI1_Config(TIM_TypeDef *TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,uint16_t TIM_ICFilter)
{uint16_t tmpccmr1 = 0, tmpccer = 0;/* Disable the Channel 1: Reset the CC1E Bit */TIMx->CCER &= (uint16_t) ~((uint16_t)TIM_CCER_CC1E);tmpccmr1 = TIMx->CCMR1;tmpccer = TIMx->CCER;/* Select the Input and set the filter */tmpccmr1 &= (uint16_t)(((uint16_t) ~((uint16_t)TIM_CCMR1_CC1S)) & ((uint16_t) ~((uint16_t)TIM_CCMR1_IC1F)));tmpccmr1 |= (uint16_t)(TIM_ICSelection | (uint16_t)(TIM_ICFilter << (uint16_t)4));if ((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM2) || (TIMx == TIM3) ||(TIMx == TIM4) || (TIMx == TIM5)){/* Select the Polarity and set the CC1E Bit */tmpccer &= (uint16_t) ~((uint16_t)(TIM_CCER_CC1P));tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)TIM_CCER_CC1E);}else{/* Select the Polarity and set the CC1E Bit */tmpccer &= (uint16_t) ~((uint16_t)(TIM_CCER_CC1P | TIM_CCER_CC1NP));tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)TIM_CCER_CC1E);}/* Write to TIMx CCMR1 and CCER registers */TIMx->CCMR1 = tmpccmr1;TIMx->CCER = tmpccer;
}

TI2_Config (函数)

/*	通道2配置*/
/*** @brief  Configure the TI2 as Input.* @param  TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15 to select the TIM peripheral.* @param  TIM_ICPolarity : The Input Polarity.*   This parameter can be one of the following values:*     @arg TIM_ICPolarity_Rising*     @arg TIM_ICPolarity_Falling* @param  TIM_ICSelection: specifies the input to be used.*   This parameter can be one of the following values:*     @arg TIM_ICSelection_DirectTI: TIM Input 2 is selected to be connected to IC2.*     @arg TIM_ICSelection_IndirectTI: TIM Input 2 is selected to be connected to IC1.*     @arg TIM_ICSelection_TRC: TIM Input 2 is selected to be connected to TRC.* @param  TIM_ICFilter: Specifies the Input Capture Filter.*   This parameter must be a value between 0x00 and 0x0F.* @retval None*/
static void TI2_Config(TIM_TypeDef *TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,uint16_t TIM_ICFilter)
{uint16_t tmpccmr1 = 0, tmpccer = 0, tmp = 0;/* Disable the Channel 2: Reset the CC2E Bit */TIMx->CCER &= (uint16_t) ~((uint16_t)TIM_CCER_CC2E);tmpccmr1 = TIMx->CCMR1;tmpccer = TIMx->CCER;tmp = (uint16_t)(TIM_ICPolarity << 4);/* Select the Input and set the filter */tmpccmr1 &= (uint16_t)(((uint16_t) ~((uint16_t)TIM_CCMR1_CC2S)) & ((uint16_t) ~((uint16_t)TIM_CCMR1_IC2F)));tmpccmr1 |= (uint16_t)(TIM_ICFilter << 12);tmpccmr1 |= (uint16_t)(TIM_ICSelection << 8);if ((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM2) || (TIMx == TIM3) ||(TIMx == TIM4) || (TIMx == TIM5)){/* Select the Polarity and set the CC2E Bit */tmpccer &= (uint16_t) ~((uint16_t)(TIM_CCER_CC2P));tmpccer |= (uint16_t)(tmp | (uint16_t)TIM_CCER_CC2E);}else{/* Select the Polarity and set the CC2E Bit */tmpccer &= (uint16_t) ~((uint16_t)(TIM_CCER_CC2P | TIM_CCER_CC2NP));tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)TIM_CCER_CC2E);}/* Write to TIMx CCMR1 and CCER registers */TIMx->CCMR1 = tmpccmr1;TIMx->CCER = tmpccer;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/236425.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

rabbitmq消息队列实验

实验目的&#xff1a;实现异步通信 实验条件&#xff1a; 主机名 IP地址 组件 test1 20.0.0.10 rabbitmq服务 test2 20.0.0.20 rabbitmq服务 test3 20.0.0.30 rabbitmq服务 实验步骤&#xff1a; 1、安装rabbitmq服务 2、erlang进入命令行&#xff0c;查看版本 …

IDEA导入JavaWeb项目(非Maven)

IDEA导入JavaWeb(非Maven)项目教程 运行教程 亲爱的粉丝们&#xff0c;我深知你们对IDEA导入JAVAWeb工程的迫切需求。在这个充满竞争的时代&#xff0c;每一个项目都离不开高效的沟通。过程中需要对应的环境适配和软件…

提升Jmeter测试效率的9种参数化方法!

jmeter工具无论做接口测试还是性能测试&#xff0c;参数化都是一个必须掌握且非常有用的知识点。参数化的使用场景: 1&#xff09;多个请求都是同一个ip地址&#xff0c;若服务器地址更换了&#xff0c;则脚本需要更改每个请求的ip 2&#xff09;注册账号&#xff0c;不允许账…

计算机网络HTTP篇

目录 一、HTTP基本概念 二、GET 与 POST 2.1、GET 与 POST 有什么区别&#xff1f; 2.2、GET 和 POST 方法都是安全和幂等的吗&#xff1f; 三、HTTP 缓存 3.1、强制缓存&#xff1a; 3.2、协商缓存 四、HTTP 特性 4.1、HTTP/1.1 4.1.1、HTTP/1.1 的优点 4.1.2、HTT…

OSError: We couldnt connect to ‘https://huggingface.co‘

最近在做NerF类的数字人口型算法。需要加载一些huggingface上面的模型&#xff0c;但是无法连接上&#xff0c;如下图所示 于是先科学上网&#xff0c;打开https://huggingface.co/models 然后搜索提到的无法加载的模型&#xff0c;比如这里是cpierse/wav2vec2-large-xlsr-53-…

Unity DOTS《群体战斗弹幕游戏》核心技术分析之3D角色动画

最近DOTS发布了正式的版本, 我们来分享现在流行基于群体战斗的弹幕类游戏&#xff0c;实现的核心原理。今天给大家介绍大规模战斗群体3D角色的动画如何来实现。 DOTS 对角色动画支持的局限性 截止到Unity DOTS发布的版本1.0.16,目前还是无法很好的支持3D角色动画。在DOTS 的b…

周报:css相关扩展知识

目录 1. 扩展知识&#xff1a;浮动盒子的排列位置 浮动盒子常见排列特点&#xff1a; 浮动盒子扩展特点&#xff1a; 2.扩展知识:行高的取值 line-height常见取值&#xff1a; 行高的取值的方式&#xff1a; 两个方式的区别&#xff1a; 3.扩展知识&#xff1a;body背景…

鸿蒙系统开发手册 - HarmonyOS内核驱动层源码分析

众所周知系统定义HarmonyOS是一款“面向未来”、面向全场景&#xff08;移动办公、运动健康、社交通信、媒体娱乐等&#xff09;的分布式操作系统。在传统的单设备系统能力的基础上&#xff0c;HarmonyOS提出了基于同一套系统能力、适配多种终端形态的分布式理念&#xff0c;能…

深度学习手势检测与识别算法 - opencv python 计算机竞赛

文章目录 0 前言1 实现效果2 技术原理2.1 手部检测2.1.1 基于肤色空间的手势检测方法2.1.2 基于运动的手势检测方法2.1.3 基于边缘的手势检测方法2.1.4 基于模板的手势检测方法2.1.5 基于机器学习的手势检测方法 3 手部识别3.1 SSD网络3.2 数据集3.3 最终改进的网络结构 4 最后…

Gitee 之初体验(上)

我们在项目开发或者自己学习的时候&#xff0c;总会存在这样的问题&#xff1a; 在一台电脑上编写完代码&#xff0c;想要再另外一台电脑上再去写&#xff0c;再或者和其他人一起协作等等场合&#xff0c;代码传来传去很麻烦。 这个时候&#xff0c;我们就可以去使用代码管理工…

K8s 多租户方案的挑战与价值

在当今企业环境中&#xff0c;随着业务的快速增长和多样化&#xff0c;服务器和云资源的管理会越来越让人头疼。K8s 虽然很强大&#xff0c;但在处理多个部门或团队的业务部署需求时&#xff0c;如果缺乏有效的多租户支持&#xff0c;在效率和资源管理方面都会不尽如人意。 本…

Jvm常见问题

1. 为什么用元空间替换永久代 避免OOM异常&#xff1a;永久代中存放了很多JVM需要的类信息&#xff0c;这些数据大多数是不会被清理的&#xff0c;所以Full GC往往无法回收多少空间。而永久代的空间是有限的&#xff0c;如果经常加载新的类进来或者频繁的创建和删除类&#xf…