STM32F407-14.3.7-01PWM输入模式

2023-12-01 13:04

本文主要是介绍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;
}

这篇关于STM32F407-14.3.7-01PWM输入模式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

Nginx location匹配模式与规则详解

《Nginxlocation匹配模式与规则详解》:本文主要介绍Nginxlocation匹配模式与规则,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、环境二、匹配模式1. 精准模式2. 前缀模式(不继续匹配正则)3. 前缀模式(继续匹配正则)4. 正则模式(大

使用Python实现一键隐藏屏幕并锁定输入

《使用Python实现一键隐藏屏幕并锁定输入》本文主要介绍了使用Python编写一个一键隐藏屏幕并锁定输入的黑科技程序,能够在指定热键触发后立即遮挡屏幕,并禁止一切键盘鼠标输入,这样就再也不用担心自己... 目录1. 概述2. 功能亮点3.代码实现4.使用方法5. 展示效果6. 代码优化与拓展7. 总结1.

Linux系统配置NAT网络模式的详细步骤(附图文)

《Linux系统配置NAT网络模式的详细步骤(附图文)》本文详细指导如何在VMware环境下配置NAT网络模式,包括设置主机和虚拟机的IP地址、网关,以及针对Linux和Windows系统的具体步骤,... 目录一、配置NAT网络模式二、设置虚拟机交换机网关2.1 打开虚拟机2.2 管理员授权2.3 设置子

SpringBoot如何通过Map实现策略模式

《SpringBoot如何通过Map实现策略模式》策略模式是一种行为设计模式,它允许在运行时选择算法的行为,在Spring框架中,我们可以利用@Resource注解和Map集合来优雅地实现策略模式,这... 目录前言底层机制解析Spring的集合类型自动装配@Resource注解的行为实现原理使用直接使用M

C#原型模式之如何通过克隆对象来优化创建过程

《C#原型模式之如何通过克隆对象来优化创建过程》原型模式是一种创建型设计模式,通过克隆现有对象来创建新对象,避免重复的创建成本和复杂的初始化过程,它适用于对象创建过程复杂、需要大量相似对象或避免重复初... 目录什么是原型模式?原型模式的工作原理C#中如何实现原型模式?1. 定义原型接口2. 实现原型接口3

大数据spark3.5安装部署之local模式详解

《大数据spark3.5安装部署之local模式详解》本文介绍了如何在本地模式下安装和配置Spark,并展示了如何使用SparkShell进行基本的数据处理操作,同时,还介绍了如何通过Spark-su... 目录下载上传解压配置jdk解压配置环境变量启动查看交互操作命令行提交应用spark,一个数据处理框架

Java实现状态模式的示例代码

《Java实现状态模式的示例代码》状态模式是一种行为型设计模式,允许对象根据其内部状态改变行为,本文主要介绍了Java实现状态模式的示例代码,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来... 目录一、简介1、定义2、状态模式的结构二、Java实现案例1、电灯开关状态案例2、番茄工作法状态案例

在JS中的设计模式的单例模式、策略模式、代理模式、原型模式浅讲

1. 单例模式(Singleton Pattern) 确保一个类只有一个实例,并提供一个全局访问点。 示例代码: class Singleton {constructor() {if (Singleton.instance) {return Singleton.instance;}Singleton.instance = this;this.data = [];}addData(value)

【测试】输入正确用户名和密码,点击登录没有响应的可能性原因

目录 一、前端问题 1. 界面交互问题 2. 输入数据校验问题 二、网络问题 1. 网络连接中断 2. 代理设置问题 三、后端问题 1. 服务器故障 2. 数据库问题 3. 权限问题: 四、其他问题 1. 缓存问题 2. 第三方服务问题 3. 配置问题 一、前端问题 1. 界面交互问题 登录按钮的点击事件未正确绑定,导致点击后无法触发登录操作。 页面可能存在

模版方法模式template method

学习笔记,原文链接 https://refactoringguru.cn/design-patterns/template-method 超类中定义了一个算法的框架, 允许子类在不修改结构的情况下重写算法的特定步骤。 上层接口有默认实现的方法和子类需要自己实现的方法