感谢,确实是我公式记错了,那大佬知道我为什么输入比较部分始终无法正确配置吗
- void Timer_Init()
- {
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
- GPIO_InitTypeDef GPIO_InitStruct;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 ;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStruct);
- TIM_InternalClockConfig(TIM3); // 开启内部时钟
- // 初始化TIM3的时基单元
- TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
- TIM_TimeBaseStructInit(&TIM_TimeBaseInitStruct);
- TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1; // 滤波的分频值
- TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInitStruct.TIM_Period = 65536-1;
- TIM_TimeBaseInitStruct.TIM_Prescaler = 72 - 1;
- TIM_TimeBaseInitStruct.TIM_RepetitionCounter = 0; // 高级定时器才用
- TIM_TimeBaseInit(TIM3, &TIM_TimeBaseInitStruct);
- // 初始化捕获输入
- TIM_ICInitTypeDef TIM_ICInitStruct;
- TIM_ICInitStruct.TIM_Channel = TIM_Channel_1; // 选择捕获通道
- TIM_ICInitStruct.TIM_ICFilter = 0xF; // 滤波
- TIM_ICInitStruct.TIM_ICPolarity = TIM_ICPolarity_Rising; // 捕获的极性
- TIM_ICInitStruct.TIM_ICPrescaler = TIM_ICPSC_DIV1;
- TIM_ICInitStruct.TIM_ICSelection = TIM_ICSelection_DirectTI; // 选择直连还是交叉(PWMI模式)
- TIM_PWMIConfig(TIM3, &TIM_ICInitStruct); // 配置为PWMI模式(捕获模式)
- //TIM_ICInit(TIM1, &TIM_ICInitStruct);
- TIM_SelectInputTrigger(TIM3, TIM_TS_TI1FP1);
- TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);
- TIM_Cmd(TIM3, ENABLE);
- }
复制代码 |