当前位置: 首页 > news >正文

stm32f10x tim.h定时器结构体

定时器结构体

TIM_TimeBaseInitTypeDef;定时的基本应用

TIM_OCInitTypeDef;比较输出,compare->用于pwm,初始化调用该结构体

TIM_ICInitTypeDef;输入捕获,用于测量脉冲宽度

在此路径下可查看timebase的应用实例

D:\STM32开发用资料\STM32官方固件库\STM32F10x_StdPeriph_Lib_V3.5.0\STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\TIM\TimeBase

/** ****************************************************************************** * @file TIM/TimeBase/main.c * @author MCD Application Team * @version V3.5.0 * @date 08-April-2011 * @brief Main program body ****************************************************************************** * @attention * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2> ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f10x.h" /** @addtogroup STM32F10x_StdPeriph_Examples * @{ */ /** @addtogroup TIM_TimeBase * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; __IO uint16_t CCR1_Val = 40961; __IO uint16_t CCR2_Val = 27309; __IO uint16_t CCR3_Val = 13654; __IO uint16_t CCR4_Val = 6826; uint16_t PrescalerValue = 0; /* Private function prototypes -----------------------------------------------*/ void RCC_Configuration(void); void GPIO_Configuration(void); void NVIC_Configuration(void); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* System Clocks Configuration */ RCC_Configuration(); /* NVIC Configuration */ NVIC_Configuration(); /* GPIO Configuration */ GPIO_Configuration(); /* --------------------------------------------------------------- TIM2 Configuration: Output Compare Timing Mode: TIM2 counter clock at 6 MHz CC1 update rate = TIM2 counter clock / CCR1_Val = 146.48 Hz CC2 update rate = TIM2 counter clock / CCR2_Val = 219.7 Hz CC3 update rate = TIM2 counter clock / CCR3_Val = 439.4 Hz CC4 update rate = TIM2 counter clock / CCR4_Val = 878.9 Hz --------------------------------------------------------------- */ /* Compute the prescaler value */ PrescalerValue = (uint16_t) (SystemCoreClock / 12000000) - 1; /* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); /* Prescaler configuration */ TIM_PrescalerConfig(TIM2, PrescalerValue, TIM_PSCReloadMode_Immediate); /* Output Compare Timing Mode configuration: Channel1 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR1_Val; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC1Init(TIM2, &TIM_OCInitStructure); TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable); /* Output Compare Timing Mode configuration: Channel2 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR2_Val; TIM_OC2Init(TIM2, &TIM_OCInitStructure); TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Disable); /* Output Compare Timing Mode configuration: Channel3 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR3_Val; TIM_OC3Init(TIM2, &TIM_OCInitStructure); TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Disable); /* Output Compare Timing Mode configuration: Channel4 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR4_Val; TIM_OC4Init(TIM2, &TIM_OCInitStructure); TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Disable); /* TIM IT enable */ TIM_ITConfig(TIM2, TIM_IT_CC1 | TIM_IT_CC2 | TIM_IT_CC3 | TIM_IT_CC4, ENABLE); /* TIM2 enable counter */ TIM_Cmd(TIM2, ENABLE); while (1); } /** * @brief Configures the different system clocks. * @param None * @retval None */ void RCC_Configuration(void) { /* PCLK1 = HCLK/4 */ RCC_PCLK1Config(RCC_HCLK_Div4); /* TIM2 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); /* GPIOC clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); } /** * @brief Configure the GPIO Pins. * @param None * @retval None */ void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; /* GPIOC Configuration:Pin6, 7, 8 and 9 as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); } /** * @brief Configure the nested vectored interrupt controller. * @param None * @retval None */ void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; /* Enable the TIM2 global Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ while (1) {} } #endif /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
http://www.cnnetsun.cn/news/105101.html

相关文章:

  • B站视频下载神器:BiliDownloader完整使用教程
  • 年底电商大促攻坚战:DooTask如何成为业绩冲刺的“秘密武器”?
  • 26、深入探究文件操作与库I/O函数
  • 29、SH编程与EXT2文件系统详解
  • 揭秘企业级Agent日志难题:如何用Docker日志快速定位生产事故根源
  • 【Cirq实战优化秘籍】:3步配置函数提示提升编码速度200%
  • 免费压缩工具7-Zip:让硬盘空间管理变得如此简单
  • .NET Windows Desktop Runtime 终极指南:快速构建现代化Windows应用
  • Quartz定时任务集成使用指南:从基础到实战
  • 【量子计算入门必备技能】:如何在VSCode中高效搭建并管理Qiskit项目?
  • 35岁被大厂裁员,我却靠这三大“狠招”半年后涨薪50%再战字节!
  • 【专家级调试技巧】:如何在Azure QDK中实现精准断点控制?
  • 思源宋体WOFF2压缩优化:算法原理与工程实践深度解析
  • GLSL PathTracer 项目全面深度解析:架构、原理与核心技术
  • 量子计算工程师私藏技法(电路可视化缩放全揭秘)
  • 揭秘Q#程序测试盲区:为何你的VSCode没有显示代码覆盖率?
  • 为什么顶尖量子工程师都在用VSCode做数据可视化?这4个理由让你无法忽视
  • 基于SpringBoot的日用品仓储管理系统的设计与实现(程序+文档+讲解)
  • 金仓新势力:三重革新打破兼容局限,引领数据库技术新方向
  • Mini Pupper四足机器人开发指南:从硬件部署到ROS应用
  • Yuzu模拟器终极配置指南:3步解决卡顿闪退难题
  • 50、网络故障排查工具与方法全解析
  • 如何将量子计算镜像性能提升200%?,基于真实实验数据的调优方案
  • Cirq代码补全进阶指南(函数提示使用全解析)
  • STM32 USB摄像头连接技术深度解析
  • 从开发到上线:多模态Agent Docker存储配置全流程(附最佳实践模板)
  • 【AI工程化落地必看】:多模态Agent Docker测试用例设计的8项军规
  • 第十九篇:多租户架构:数据隔离与资源配额
  • VLN-CE视觉语言导航实战:从零开始构建智能导航系统
  • 中国电力招标网:开启能源行业高质量发展的“金钥匙”