使用TIM10,能夠進(jìn)入比較中斷,進(jìn)不了更新中斷
void?TIM10_CC_IRQHandler(void)?__attribute__((interrupt("WCH-Interrupt-fast"))); void?TIM10_UP_IRQHandler(void)?__attribute__((interrupt("WCH-Interrupt-fast"))); uint32_t?RPM?=?0; uint8_t?TimeOutNum=0; void?RPM_Sensor_Init(?u16?arr,?u16?psc?) { ????GPIO_InitTypeDef?GPIO_InitStructure={0}; ????TIM_ICInitTypeDef?TIM_ICInitStructure={0}; ????TIM_TimeBaseInitTypeDef?TIM_TimeBaseInitStructure={0}; ????NVIC_InitTypeDef?NVIC_InitStructure={0}; ????RCC_APB2PeriphClockCmd(?RCC_APB2Periph_GPIOB?|?RCC_APB2Periph_TIM10,?ENABLE?); ????GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_8; ????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_IN_FLOATING; ????GPIO_Init(?GPIOB,?&GPIO_InitStructure); ????GPIO_ResetBits(?GPIOB,?GPIO_Pin_8?); ????TIM_TimeBaseInitStructure.TIM_Period?=?arr; ????TIM_TimeBaseInitStructure.TIM_Prescaler?=?psc; ????TIM_TimeBaseInitStructure.TIM_ClockDivision?=?TIM_CKD_DIV1; ????TIM_TimeBaseInitStructure.TIM_CounterMode?=?TIM_CounterMode_Up; ????TIM_TimeBaseInitStructure.TIM_RepetitionCounter?=??0x00; ????TIM_TimeBaseInit(?TIM10,?&TIM_TimeBaseInitStructure); ????TIM_ICInitStructure.TIM_Channel?=?TIM_Channel_1; ????TIM_ICInitStructure.TIM_ICPrescaler?=?TIM_ICPSC_DIV1; ????TIM_ICInitStructure.TIM_ICFilter?=?0x00; ????TIM_ICInitStructure.TIM_ICPolarity?=?TIM_ICPolarity_Rising; ????TIM_ICInitStructure.TIM_ICSelection?=?TIM_ICSelection_DirectTI; ????TIM_PWMIConfig(?TIM10,?&TIM_ICInitStructure?); ????NVIC_InitStructure.NVIC_IRQChannel?=?TIM10_CC_IRQn; ????NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority?=?2; ????NVIC_InitStructure.NVIC_IRQChannelSubPriority?=?0; ????NVIC_InitStructure.NVIC_IRQChannelCmd?=?ENABLE; ????NVIC_Init(&NVIC_InitStructure); ????TIM_ITConfig(?TIM10,?TIM_IT_CC1,?ENABLE?); ????TIM_ITConfig(?TIM10,?TIM_IT_Update,?ENABLE?); ????TIM_SelectInputTrigger(?TIM10,?TIM_TS_TI1FP1?); ????TIM_SelectSlaveMode(?TIM10,?TIM_SlaveMode_Reset?); ????TIM_SelectMasterSlaveMode(?TIM10,?TIM_MasterSlaveMode_Enable?); ????TIM_Cmd(?TIM10,?ENABLE?); } void?TIM10_CC_IRQHandler(void) { ????if(?TIM_GetITStatus(?TIM10,?TIM_IT_CC1?)?!=?RESET?) ????{ ????????RPM?=?(uint32_t)(1000000/TIM_GetCapture1(?TIM10?)*60); ????????TimeOutNum?=?0; ????????TIM_ClearITPendingBit(?TIM10,?TIM_IT_CC1); ????} } void?TIM10_UP_IRQHandler(void) { ????if?(TIM_GetITStatus(TIM10,?TIM_IT_Update)?==?SET) ????{ ????????TIM_ClearITPendingBit(TIM10,?TIM_IT_Update); ????????TimeOutNum++; ????????if?(TimeOutNum>5)?RPM=0; ????} }
熱門產(chǎn)品 :
CH390:以太網(wǎng)控制器芯片