我用TIME2的CH2做输入捕获,数据不对,请大家帮我看一下初始化对不!谢谢!
int main(void)
{
#ifdef DEBUG
debug();
#endif
/* System Clocks Configuration */
RCC_Configuration();
/* NVIC configuration */
NVIC_Configuration();
/* Configure the GPIO ports */
GPIO_Configuration();
//TIM2输出初始化
TIM_TimeBaseInitStruct.TIM_Period = 9999; //周期0~FFFF
TIM_TimeBaseInitStruct.TIM_Prescaler = 5; //时钟分频
TIM_TimeBaseInitStruct.TIM_ClockDivision = 0; //时钟分割
TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;//模式
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseInitStruct);//基本初始化
//TIM2通道的捕捉初始化
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;//通道选择
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling ;//上降沿
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;//管脚与寄存器对应关系
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;//分频器
TIM_ICInitStructure.TIM_ICFilter = 0x4; //滤波设置,经历几个周期跳变认定波形稳定0x0~0xF
TIM_ICInit(TIM2, &TIM_ICInitStructure); //初始化
TIM_SelectInputTrigger(TIM2, TIM_TS_TI2FP2); //选择时钟触发源
TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);//触发方式
TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable); //启动定时器的被动触发
TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE); //打开中断
TIM_Cmd(TIM2, ENABLE); //启动TIM2
while(1)
{}
}
可以进入中断。是不是进入中断就可以读CCR1的数(即:上升沿的时间)?
我读CCR1都是0,但是CCR2有值。
我上面的程序如何算TIME2的时钟,我不会,能说仔细一点,谢谢!我是按本网站程序改的。 |