//==============================================================================
// TIMER16用于频率检测
//==============================================================================
void STM32G0_TIM16_INPUT_Init(void)
{
LL_TIM_InitTypeDef TIM_InitStruct = {0};
LL_TIM_IC_InitTypeDef TIM_IC_InitStruct = {0};
LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_TIM16);
//TIM16基本配置-------------
TIM_InitStruct.Prescaler = 6400 - 1;//分频后的时钟为:64000000/6400=10KHZ=0.1mS
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
TIM_InitStruct.Autoreload = 0xFFFF;
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
TIM_InitStruct.RepetitionCounter = 0;
LL_TIM_Init (TIM16, &TIM_InitStruct);
//TIM16输入配置------------
LL_TIM_SetRemap (TIM16, LL_TIM_TIM16_TI1_RMP_GPIO);//输入选择=GPIO(TIM16_CH1)
TIM_IC_InitStruct.ICActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;//输入
TIM_IC_InitStruct.ICFilter = LL_TIM_IC_FILTER_FDIV1;//滤波
TIM_IC_InitStruct.ICPolarity = LL_TIM_IC_POLARITY_FALLING;//下降沿
TIM_IC_InitStruct.ICPrescaler = LL_TIM_ICPSC_DIV1;//分频
LL_TIM_IC_Init (TIM16, LL_TIM_CHANNEL_CH1, &TIM_IC_InitStruct);
LL_TIM_CC_EnableChannel (TIM16, LL_TIM_CHANNEL_CH1); //使能TIM16_CH1
LL_TIM_EnableCounter (TIM16); //使能定时器计数
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|