用STM8S105来测试脉冲宽度,TIM1_CH1脚,程序如下 :
TIM1_CCMR1 |= 0x31; //翻转。当TIM1_CCR1=TIM1_CNT时,翻转OC1REF的电平。CC1通道被配置为输入,IC1映射在TI1FP1上;
TIM1_PSCRH = 0; //预分频器高8位
TIM1_PSCRL = 0;
TIM1_SMCR |= 0x54; // 滤波后的定时器输入1(TI1FP1) 复位模式 – 在选中的触发输入(TRGI)的上升沿时重新初始化计数器,并且产生一个更新寄存器的信号。
TIM1_CCER1 |= 0x01; //捕获使能。
TIM1_CR1 |= 0x01; //开始计数
if( TIM1_SR1_CC1IF == 1 )
{
TIM1_SR1_CC1IF=0;
temp = TIM1_CCR1H;
temp = ( tempt << 8) + TIM1_CCR1L;
}
如果TIM1_CCR1H,TIM1_CCR1L数据没读出来前,又发生捕获完成时,这时读取的TIM1_CCR1H,TIM1_CCR1L是哪个的时间值???
|