我PWM输入捕获不了,总是乱码一堆,贴代码:
void PWM_cap()
{
TIM_ICInitTypeDef timic;
GPIO_InitTypeDef gpio;
TIM_TimeBaseInitTypeDef timebase;
NVIC_InitTypeDef nvic;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,ENABLE);
gpio.GPIO_Mode = GPIO_Mode_IN_FLOATING;
gpio.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOA,&gpio);
timebase.TIM_Period = 0xffff;
timebase.TIM_Prescaler = 71;
timebase.TIM_ClockDivision = 0;
timebase.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM5,&timebase);
timic.TIM_Channel = TIM_Channel_1;
timic.TIM_ICFilter = 0;
timic.TIM_ICPolarity = TIM_ICPolarity_Falling;
timic.TIM_ICPrescaler = TIM_ICPSC_DIV1;
timic.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_PWMIConfig(TIM5,&timic);
nvic.NVIC_IRQChannel = TIM5_IRQn;
nvic.NVIC_IRQChannelPreemptionPriority = 0;
nvic.NVIC_IRQChannelSubPriority = 0;
nvic.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvic);
TIM_Cmd(TIM5,ENABLE);
TIM_ITConfig(TIM5,TIM_IT_CC1,ENABLE);
}
void TIM5_IRQHandler()
{
int pl,zkb;
pl = TIM_GetCapture1(TIM5);
zkb = TIM_GetCapture2(TIM5);
zkb = zkb *100/pl;
pl = 1000000/pl;
Nokia_5110_int2str(zkb,0,0);
Nokia_5110_int2str(pl,0,2);
Nokia_5110_int2str(123,0,5);
pl=0;
zkb=0;
TIM_ClearITPendingBit(TIM3, TIM_IT_CC1);
}
哪位朋友能给指点一下. |