高中生
最后登录1970-1-1
在线时间 小时
注册时间2014-5-9
|
不明白“ IC1的捕获寄存器捕获PWM的高电平周期”这句话在哪个里面体现了? 我只配置了通道2的输入捕获功能呀,为什么 通道1TIM_GetCapture1(TIM2)捕获了?- /* TIM2 configuration: PWM Input mode ------------------------
- The external signal is connected to TIM2 CH2 pin (PA.01),
- The Rising edge is used as active edge,
- The TIM2 CCR2 is used to compute the frequency value
- The TIM2 CCR1 is used to compute the duty cycle value
- ------------------------------------------------------------ */
- TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
- TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
- TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
- TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
- TIM_ICInitStructure.TIM_ICFilter = 0x0;
- TIM_PWMIConfig(TIM2, &TIM_ICInitStructure);
- /* Select the TIM2 Input Trigger: TI2FP2 */
- TIM_SelectInputTrigger(TIM2, TIM_TS_TI2FP2);
- /* Select the slave Mode: Reset Mode */
- TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);
- /* Enable the Master/Slave Mode */
- TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);
- /* TIM enable counter */
- TIM_Cmd(TIM2, ENABLE);
- /* Enable the CC2 Interrupt Request */
- TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);
复制代码- void TIM2_IRQHandler(void)
- {
- /* Clear TIM2 Capture compare interrupt pending bit */
- TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
- /* Get the Input Capture value */
- IC2Value = TIM_GetCapture2(TIM2);
- if (IC2Value != 0)
- {
- /* Duty cycle computation */
- DutyCycle = (TIM_GetCapture1(TIM2) * 100) / IC2Value;
- /* Frequency computation */
- Frequency = 72000000 / IC2Value;
- }
- else
- {
- DutyCycle = 0;
- Frequency = 0;
- }
- }
复制代码 |
|