野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12987|回复: 1

STM32捕获周期问题

[复制链接]
发表于 2014-11-3 13:01:53 | 显示全部楼层 |阅读模式
不明白“ IC1的捕获寄存器捕获PWM的高电平周期”这句话在哪个里面体现了? 我只配置了通道2的输入捕获功能呀,为什么 通道1TIM_GetCapture1(TIM2)捕获了?
  1. /* TIM2 configuration: PWM Input mode ------------------------
  2.      The external signal is connected to TIM2 CH2 pin (PA.01),
  3.      The Rising edge is used as active edge,
  4.      The TIM2 CCR2 is used to compute the frequency value
  5.      The TIM2 CCR1 is used to compute the duty cycle value
  6.   ------------------------------------------------------------ */

  7.   TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
  8.   TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
  9.   TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  10.   TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  11.   TIM_ICInitStructure.TIM_ICFilter = 0x0;

  12.   TIM_PWMIConfig(TIM2, &TIM_ICInitStructure);

  13.   /* Select the TIM2 Input Trigger: TI2FP2 */
  14.   TIM_SelectInputTrigger(TIM2, TIM_TS_TI2FP2);

  15.   /* Select the slave Mode: Reset Mode */
  16.   TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);

  17.   /* Enable the Master/Slave Mode */
  18.   TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);

  19.   /* TIM enable counter */
  20.   TIM_Cmd(TIM2, ENABLE);

  21.   /* Enable the CC2 Interrupt Request */
  22.   TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);
复制代码
  1. void TIM2_IRQHandler(void)
  2. {
  3.   /* Clear TIM2 Capture compare interrupt pending bit */
  4.   TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);

  5.   /* Get the Input Capture value */
  6.   IC2Value = TIM_GetCapture2(TIM2);

  7.   if (IC2Value != 0)
  8.   {
  9.     /* Duty cycle computation */
  10.     DutyCycle = (TIM_GetCapture1(TIM2) * 100) / IC2Value;

  11.     /* Frequency computation */
  12.     Frequency = 72000000 / IC2Value;
  13.   }
  14.   else
  15.   {
  16.     DutyCycle = 0;
  17.     Frequency = 0;
  18.   }
  19. }
复制代码
回复

使用道具 举报

 楼主| 发表于 2014-11-3 13:02:41 | 显示全部楼层
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
这个是用来映射管脚跟寄存器的吗? 文档上面说 每个定时器有四个输入捕获通道IC1、IC2、IC3、IC4。且IC1 IC2一组,IC3 IC4一组。并且可是设置管脚和寄存器的对应关系
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-9-23 02:18 , Processed in 0.033607 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表