我在调试stm32f030的捕获功能时,程序按照标准库写的,但不知为什么就是捕获50Hz的正弦信号时是不对的,捕获50Hz的方波是正确,求高手帮忙指导,谢谢,配置程序如下: void Capture_Configuration(void) { TIM_ICInitTypeDef TIM_ICInitStructure; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; /* TIM3 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); /* GPIOA clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* TIM3 channel 1 pin (PA6) configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Connect TIM pins to AF2 */ GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_1); TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = 0xFFFF; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); /* TIM1 configuration: Input Capture mode */ TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0x0; TIM_ICInit(TIM3, &TIM_ICInitStructure); /* TIM enable counter */ TIM_Cmd(TIM3, ENABLE); /* Enable the CC1 Interrupt Request */ TIM_ITConfig(TIM3, TIM_IT_CC1 | TIM_IT_Update, ENABLE); /* Enable the TIM3 global Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void TIM3_IRQHandler(void) { if(TIM_GetITStatus(TIM3, TIM_IT_Update) == SET) { /* Clear TIM3 Capture compare interrupt pending bit */ TIM_ClearITPendingBit(TIM3, TIM_IT_Update); luwCountOV++; StateFlg.bit.mubGridZeroFlg = 1; } if(TIM_GetITStatus(TIM3, TIM_IT_CC1) == SET) { /* Clear TIM3_CH1 Capture compare interrupt pending bit */ TIM_ClearITPendingBit(TIM3, TIM_IT_CC1); luwCaptureCnt1 = TIM_GetCapture1(TIM3); } } |
最用的电路板是有把正弦波转成方波的硬件电路的,但是我现在先调试就直接将正弦波加到pin脚上了,结果是不对的,但是加方波就是对的,以前我也是用正弦波直接调试stm32f302的,也是可以的,但不知为什么030的就不行,我就想是不是我的代码那里有问题。
最终用的电路板是有把正弦波转成方波的硬件电路的。