本帖最后由 zhpg009 于 2012-4-25 18:12 编辑
TIM1使能之后,当捕获到一个上升沿时,也就是发生了一个输入捕获事件,如果设置了中断,则会产生一个中断,此时计数器TIM2_CNT被传到TIM1_CCR1寄存器中并进行比较,我是用TIM1进行捕获脉冲个数,用TIM2进行计数。TIM2定时为1s 。
我想问的是,它们之间在比较什么? 比较大小吗?? 还是比较看他们的值是否匹配?? TIM1_CCR1是存放当前捕获的脉冲个数的吗??
假设,TIM2_CNT计数的周期为0.1ms(频率为10KHZ),且TIM2_CNT当前的值为10,
当发生捕获事件后,TIM2_CNT的值会被传到TIM1_CCR1(TIM1_CCR1当前捕获的脉冲个数的为10)中与其进行比较,匹配之后进入TIM1中断,记下脉冲的个数NUM值。然后TIM1继续捕获,当TIM2定时1S到了之后,TIM1捕获到多少个脉冲?????
void TIMER1_Configration(void)
{
TIM_ICInitTypeDef TIM_ICInitStructure;
/*定时器1捕获设置,每4个事件触发一次捕获*/
TIM_ICInitStructure.TIM_Channel =TIM_Channel_1;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV4;
TIM_ICInitStructure.TIM_ICFilter = 0;
TIM_ICInit(TIM1,&TIM_ICInitStructure);
TIM_ClearFlag(TIM1, TIM_FLAG_Update);
TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE);
TIM_Cmd(TIM1, ENABLE);
}
void TIMER2_Configration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Prescaler = 7199;
TIM_TimeBaseStructure.TIM_Period = 10000;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM2, ENABLE);
} |