博士
最后登录1970-1-1
在线时间 小时
注册时间2015-3-6
|
发表于 2015-12-21 08:36:15
|
显示全部楼层
这是F4的程序,你看看F1的兼不兼容
然后在中断服务函数中使用TIM_GetCapture1、TIM_GetCapture2获取计数值
- static void TIM_PWMINPUT_Config(void)
- {
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_ICInitTypeDef TIM_ICInitStructure;
-
- // 开启TIMx_CLK,x[1,8]
- RCC_APB2PeriphClockCmd(ADVANCE_TIM_CLK, ENABLE);
- TIM_TimeBaseStructure.TIM_Period = 0xFFFF-1;
- // 高级控制定时器时钟源TIMxCLK = HCLK=180MHz
- // 设定定时器频率为=TIMxCLK/(TIM_Prescaler+1)=100KHz
- TIM_TimeBaseStructure.TIM_Prescaler = 1800-1;
- // 计数方式
- TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
- // 初始化定时器TIMx, x[1,8]
- TIM_TimeBaseInit(ADVANCE_TIM, &TIM_TimeBaseStructure);
-
- /* IC1捕获:上升沿触发 TI1FP1 */
- TIM_ICInitStructure.TIM_Channel = ADVANCE_IC1PWM_CHANNEL;
- TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
- TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
- TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
- TIM_ICInitStructure.TIM_ICFilter = 0x0;
- TIM_PWMIConfig(ADVANCE_TIM, &TIM_ICInitStructure);
-
- /* IC2捕获:下降沿触发 TI1FP2 */
- TIM_ICInitStructure.TIM_Channel = ADVANCE_IC2PWM_CHANNEL;
- TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
- TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_IndirectTI;
- TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
- TIM_ICInitStructure.TIM_ICFilter = 0x0;
- TIM_PWMIConfig(ADVANCE_TIM, &TIM_ICInitStructure);
-
- /* 选择定时器输入触发: TI1FP1 */
- TIM_SelectInputTrigger(ADVANCE_TIM, TIM_TS_TI1FP1);
- /* 选择从模式: 复位模式 */
- TIM_SelectSlaveMode(ADVANCE_TIM, TIM_SlaveMode_Reset);
- TIM_SelectMasterSlaveMode(ADVANCE_TIM,TIM_MasterSlaveMode_Enable);
- /* 使能高级控制定时器 */
- TIM_Cmd(ADVANCE_TIM, ENABLE);
- /* 使能捕获/比较2中断请求 */
- TIM_ITConfig(ADVANCE_TIM, TIM_IT_CC1, ENABLE);
- }
复制代码 |
|