你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

通用定时器的PWM输入捕捉模式下四个通道能同时进行捕捉?

[复制链接]
布衣灬强 提问时间:2015-1-30 21:21 /
通用定时器的PWM输入捕捉模式下,定时器的四个通道能同时进行PWM捕捉么?
收藏 1 评论6 发布时间:2015-1-30 21:21

举报

6个回答
hmillionaire 回答时间:2015-1-30 22:32:43
我感觉不能,应该有时间先后顺序,这是我的想法,嘿嘿,菜鸟的想法。我渴望找出答案
lkl0305 回答时间:2015-1-31 09:12:40
楼主实验一下啊
holts1 回答时间:2015-1-31 09:21:15
可  以的
布衣灬强 回答时间:2015-1-31 09:49:22
  1. void TIM_Config(void)
  2. {
  3.         GPIO_InitTypeDef GPIO_InitStructure;
  4.         NVIC_InitTypeDef NVIC_InitStructure;
  5.         TIM_ICInitTypeDef  TIM_ICInitStructure;

  6.         /* TIM4 clock enable */
  7.         RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);

  8.         /* GPIOB clock enable */
  9.         RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

  10.         /* TIM4 chennel2 configuration : PB.07 */
  11.         GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_6;
  12.         GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
  13.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  14.         GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  15.         GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP ;
  16.         GPIO_Init(GPIOB, &GPIO_InitStructure);
  17.        
  18.         GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_7;
  19.         GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
  20.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  21.         GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  22.         GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP ;
  23.         GPIO_Init(GPIOB, &GPIO_InitStructure);
  24.        
  25.         GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_8;
  26.         GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
  27.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  28.         GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  29.         GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP ;
  30.         GPIO_Init(GPIOB, &GPIO_InitStructure);
  31.        
  32.         GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_9;
  33.         GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
  34.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  35.         GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  36.         GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP ;
  37.         GPIO_Init(GPIOB, &GPIO_InitStructure);
  38.        
  39.         /* Connect TIM pin to AF2 */
  40.         GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_TIM4);
  41.         GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_TIM4);
  42.         GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_TIM4);
  43.         GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_TIM4);
  44.        
  45.         /* Enable the TIM4 global Interrupt */
  46.         NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
  47.         NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  48.         NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  49.         NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  50.         NVIC_Init(&NVIC_InitStructure);
  51.        
  52.         TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
  53.         TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
  54.         TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  55.         TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  56.         TIM_ICInitStructure.TIM_ICFilter = 0x0;

  57.         TIM_PWMIConfig(TIM4, &TIM_ICInitStructure);

  58.         /* Select the TIM4 Input Trigger: TI2FP2 */
  59.         TIM_SelectInputTrigger(TIM4, TIM_TS_TI2FP2);

  60.         /* Select the slave Mode: Reset Mode */
  61.         TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_Reset);
  62.         TIM_SelectMasterSlaveMode(TIM4,TIM_MasterSlaveMode_Enable);

  63.         /* TIM enable counter */
  64.         TIM_Cmd(TIM4, ENABLE);

  65.         /* Enable the CC2 Interrupt Request */
  66.         TIM_ITConfig(TIM4, TIM_IT_CC1, ENABLE);

  67. }
复制代码

  1. void TIM4_IRQHandler(void)
  2. {
  3.   RCC_ClocksTypeDef RCC_Clocks;
  4.   RCC_GetClocksFreq(&RCC_Clocks);

  5.   /* Clear TIM4 Capture compare interrupt pending bit */
  6.   TIM_ClearITPendingBit(TIM4, TIM_IT_CC2);

  7.   /* Get the Input Capture value */
  8.   IC2Value = TIM_GetCapture2(TIM4);

  9.   if (IC2Value != 0)
  10.   {
  11.     /* Duty cycle computation */
  12.     DutyCycle = (TIM_GetCapture1(TIM4) * 100) / IC2Value;

  13.     /* Frequency computation
  14.        TIM4 counter clock = (RCC_Clocks.HCLK_Frequency)/2 */

  15.     Frequency = (RCC_Clocks.HCLK_Frequency)/2 / IC2Value;
  16.   }
  17.   else
  18.   {
  19.     DutyCycle = 0;
  20.     Frequency = 0;
  21.   }
  22. }
复制代码
布衣灬强 回答时间:2015-1-31 09:50:15

这样配置后TIM_GetCapture2(TIM4)一直是0。
布衣灬强 回答时间:2015-1-31 09:52:17
布衣灬强 发表于 2015-1-31 09:50
这样配置后TIM_GetCapture2(TIM4)一直是0。

B9是通道4

所属标签

相似问题

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
微信公众号二维码 微信公众号
手机版二维码 手机版