void Init_TIM2(void)
{
//计数器禁止、ARR预装载禁止、向上计数、边沿对齐模式
TIM2->CR1 = BIT2;
//禁止TIM2所有中断
TIM2->IER = 0;//禁止中断
TIM2->CCMR1 = 0x01;//TIM2的CH1CH2CH3通道配置为输入
TIM2->CCMR2 = 0x01;
TIM2->CCMR3 = 0x01;
#define IC_FILTER (u8)(5 << 4)
TIM2->CCMR1 |= IC_FILTER; //输入捕获滤波器
TIM2->CCMR2 |= IC_FILTER;
TIM2->CCMR3 |= IC_FILTER;
//prescale = div3
@ 16MHz -> 0.5us/count * 24MHz -> 0.33us/count
TIM2->PSCR = 0;
TIM2->ARRH=0xff;//计数周期设为最大
TIM2->ARRL=0xff;
TIM2->CCER1 |= 0x01;//TIM2的CH1CH2CH3通道使能捕获功能
TIM2->CCER1 |= 0x10;
TIM2->CCER2 |= 0x01;
TIM2->CR1 |= 0x01;//使能TIM2定时器
}
此帖出自
小平头技术问答
一周热门 更多>