本帖最后由 yhm237705990 于 2021-7-3 10:44 编辑
初始化void FANTIMPUL_Configuration(void)
{
GPIO_InitType GPIO_InitStructure;
TMR_TimerBaseInitType TMR_TimeBaseStructure;
TMR_ICInitType TMR_ICInitStructure;
NVIC_InitType NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPERIPH_GPIOB,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_TMR14,ENABLE);
GPIO_PinAFConfig(GPIOB, GPIO_PinsSource1, GPIO_AF_0);
GPIO_InitStructure.GPIO_Pins = GPIO_Pins_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
GPIO_InitStructure.GPIO_Pull = GPIO_Pull_NOPULL;
GPIO_InitStructure.GPIO_OutType = GPIO_OutType_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
TMR_TimeBaseStructInit(&TMR_TimeBaseStructure);
TMR_TimeBaseStructure.TMR_Period = 0xFFFF;
TMR_TimeBaseStructure.TMR_DIV = SystemCoreClock/10000-1;
TMR_TimeBaseStructure.TMR_ClockDivision = TMR_CKD_DIV1;
TMR_TimeBaseStructure.TMR_CounterMode = TMR_CounterDIR_Up;
TMR_TimeBaseInit(TMR14,&TMR_TimeBaseStructure);
TMR_ICStructInit(&TMR_ICInitStructure);
TMR_ICInitStructure.TMR_Channel = TMR_Channel_1;
TMR_ICInitStructure.TMR_ICPolarity = TMR_ICPolarity_Rising;
TMR_ICInitStructure.TMR_ICSelection = TMR_ICSelection_DirectTI;
TMR_ICInitStructure.TMR_ICDIV = TMR_ICDIV_DIV1;
TMR_ICInitStructure.TMR_ICFilter = 0x0;
TMR_ICInit(TMR14, &TMR_ICInitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TMR14_GLOBAL_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TMR_INTConfig(TMR14, TMR_INT_Overflow,ENABLE);
TMR_INTConfig(TMR14, TMR_INT_CC1,ENABLE);
TMR_ClearITPendingBit(TMR14, TMR_INT_Overflow);
TMR_ClearITPendingBit(TMR14, TMR_INT_CC1);
TMR_Cmd(TMR14,ENABLE);
}
中断函数
void TMR14_GLOBAL_IRQHandler(void)
{
Frequency = 200;
TMR_GetCapture1(TMR14);
TMR_SetCounter(TMR14,0);
}
已知问题 1.按照上述代码运行后,串口通信未能正常工作,无法探知是否进入中断。
2.TMR_INTConfig(TMR14, TMR_INT_Overflow,ENABLE); 删除此行代码后,串口通信正常,但定时器不会进入中断。
待测信号为 PA1复用TMR15产生的250Hz 占空比50%的PWM波形
参照例程 AT32F4xx_StdPeriph_Lib_V1.3.0\Project\AT_START_F421\Examples\TMR\InputCapture\MDK_v5
新手一枚,还请大佬赐教
|