我的捕捉程序始终无法进入中断,确信有pwm信号在捕捉的TIM4 的四通道,求指教!
#include "stm32f10x_mincludes.h"
u16 sCapTim4Count;
//Capture initialize
void SFVD_CAPInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
TIM_ICInitTypeDef TIM4_ICInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_ResetBits(GPIOB,GPIO_Pin_9);
TIM_TimeBaseStructure.TIM_Period=0xffff;
TIM_TimeBaseStructure.TIM_Prescaler=72-1;
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4,&TIM_TimeBaseStructure);
TIM4_ICInitStructure.TIM_Channel=TIM_Channel_4;
TIM4_ICInitStructure.TIM_ICFilter=0x00;
TIM4_ICInitStructure.TIM_ICPolarity=TIM_ICPolarity_Rising;
TIM4_ICInitStructure.TIM_ICPrescaler=TIM_ICPSC_DIV1;
TIM4_ICInitStructure.TIM_ICSelection=TIM_ICSelection_DirectTI;
TIM_ICInit(TIM4,&TIM4_ICInitStructure);
NVIC_InitStructure.NVIC_IRQChannel=TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_ITConfig(TIM4,TIM_IT_CC4,ENABLE);
TIM_Cmd(TIM4,ENABLE);
}
void TIM4_IRQHandler(void)
{
if (TIM_GetITStatus(TIM4, TIM_IT_CC4) != RESET)//2¶»ñ4·¢éú2¶»ñê¼t
{
if(_b1sCapState)
{
_b1sCapState=0;
sCapTim4Count=TIM_GetCapture4(TIM4);
TIM_SetCounter(TIM4,0);
}
}
TIM_ClearITPendingBit(TIM4, TIM_IT_CC4); //Çå3yÖD¶Ï±ê־λ
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>