Universal timer capture inputs STM32F103ZET6

1, general purpose timer input capture Features

  General purpose timer input capture mode may be used to measure the pulse width or the measurement frequency.

  STM32 Each timer has four general-purpose input capture channels, respectively TIMx_CH1, TIMx_CH2, TIMx_CH3, TIMx_CH4.

  STM32 edge signal by detecting the passage, at the time (rising or falling variation) edge signal changes, the current timer counter value (the value of the register TIMx_CNT) stored in the corresponding channel capture / compare register TIMx_CCRx inside, by two edge signal recording time, frequency or pulse width is calculated.

2, general purpose timer input capture Comments  

  General block diagram of the timer as follows:

  The red box is part of a general purpose timer input capture function.

  TIMx_CH1, TIMx_CH2, TIMx_CH3, TIMx_CH4 corresponding to the four general-purpose timer input capture channels.

  It can be seen from the block diagram of a general-purpose timer input capture Each channel structures are similar.

  In an example, after CH1, general purpose timer signal generated by TIMx_CH1 pin TI1, TI1 through the filter, the signal to the edge detector, the edge detector detects an accurate edge signal, and generating TI1FP1 TI1FP2 signals (both actually the same signal, but not the same as the output of the path), on TI1FP1 signal to IC1, IC1 after prescaler capturing signal is generated, the current value of the timer counter at this time is latched to the capture / compare register, Further CC1IF TIMx_SR status flag register is set to 1, if the channel is enabled input capture interrupt function, an interrupt is generated.

  In the block diagram in red, TI1 input may choose different TIMx_CH1, TIMx_CH2, TIMx_CH3 or three channels, this function seems to be advanced Hall sensor timer function, here do not control, when used as input capture function on T1 The default selection TIMx_CH1 input just fine.

  Input filter:

  Input capture channels by setting TIMx_CCMRx capture / compare mode register ICxF [3: 0] bits to configure the filter.

  这里需要注意的是,输入捕获有4个通道,而捕获/比较模式寄存器只有两个,分别是TIMx_CCMR1和TIMx_CCMR2,通道1由TIMx_CCMR1的低8位配置;通道2由TIMx_CCMR1的高8位配置;通道3由TIMx_CCMR2的低8位配置;通道4由TIMx_CCMR2的高8位配置。

  还要注意的是,捕获/比较模式寄存器在不同状态下时,配置的功能是不一样,如果通道被配置成输出,那么捕获/比较模式寄存器是用来配置输出功能;如果通道被配置成输入,则捕获/比较模式寄存器是用来配置输入功能。捕获/比较模式寄存器TIMx_CCMRx的CCxS[1:0]位用来配置通道是输出还是输入。当CCxS[1:0] = 00时,通道被配置为输出。当CCxS[1:0] != 0时,通道被配置为输入。  

  下图是通道1的IC1F[3:0]位的寄存器说明图:


  图中的FCK_INT是定时器的输入频率,一般是MCU的主频(要看具体的设置)。而FDTS是根据TIMx_CR1控制寄存器的bit9~bit8位CKD[1:0]的值来确定:

  当CKD = 00时,FDTS = FCK_INT。

  当CKD = 00时,FDTS = 2*FCK_INT。

  当CKD = 00时,FDTS = 4*FCK_INT。

  图中的N是指滤波长度,假设IC1F[3:0] = 0011,并设置IC1映射到通道1上,且为上升沿触发,那么在捕获到上升沿的时候,再以FCK_INT的频率,连续采样8次通道1的电平,如果都是高电平,则说明这是一个有效的触发信号。

  滤波器可以滤除哪些脉宽低于一定时间的脉冲信号,从而达到滤波的效果,当然也可以选择不滤波。

  边沿检测器:

  边沿检测器可以检测信号是上升沿还是下降沿,只有跟设定的边沿对得上的信号才能触发输入捕获功能。

  边沿检测器可以设定为上升沿触发或是下降沿触发,这是通过捕获/比较使能寄存器TIMx_CCER的CCxP位来选择的。

  同样CCxP的位在通道位输入和输出是具有不同的配置功能。当通道设为输入时,CCxP用来设置边沿检测器。

  当CCxP = 0是,输入捕获是在上升沿的时候触发。

  当CCxP = 1时,输入捕获是在下降沿的时候触发。

  TIxFPx信号:

  从通用定时器框图中可以看到,信号在经过输入滤波器和边沿检测器之后,每个通道都会产生2个信号:

  通道1:TI1FP1和TI1FP2。

  通道2:TI2FP1和TI2FP2

  通道3:TI3FP1和TI3FP2

  通道4:TI4FP1和TI4FP2

  其实TIxFP1和TIxFP2的信号是同一个,但是他们输出的方向不一样,所以用不同的名称来区分,从图中可以看出:

  TI1FP1作为输入源提供给IC1,而TI1FP2作为输入源提供给IC2。

  TI2FP1作为输入源提供给IC2,而TI2FP2作为输入源提供给IC1。

  TI3FP1作为输入源提供给IC3,而TI3FP2作为输入源提供给IC4。

  TI4FP1作为输入源提供给IC4,而TI4FP2作为输入源提供给IC3。 

  也就是说TIMx_CH1和TIMx_CH2的输入信号是可以交互到IC1和IC2的;TIMx_CH3和TIMx_CH4的输入信号也可以交互到IC3和IC4。

  具体ICx的输入源的选择是通过捕获/比较寄存器TIMx_CCMRx的CCxS[1:0]位决定的,比如IC1的输入源的选择:

  当CC1S[1:0] = 00时,通道1被配置为输出。

  当CC1S[1:0] = 01时,通道1被配置为输入,IC1的输入源选择TI1FP1。

  当CC1S[1:0] = 10时,通道1被配置为输入,IC1的输入源选择TI2FP2。

  当CC1S[1:0] = 11时,通道1被配置为输入,IC1的输入源选择TRC。

  其它通道的配置也是类似的,可以参照着查看参考手册。

  预分频器:

  输入捕获的预分频器是通过TIMx_CCMRx的ICxPSC[1:0]位配置的。

  当ICxPSC[1:0] = 00时,无预分频,捕获输入口上检测到的灭一个边沿都触发一次捕获。

  当ICxPSC[1:0] = 01时,捕获输入口上检测到2个边沿才触发一次捕获。

  当ICxPSC[1:0] = 10时,捕获输入口上检测到4个边沿才触发一次捕获。

  当ICxPSC[1:0] = 11时,捕获输入口上检测到8个边沿才触发一次捕获。

  捕获输入中断:

  

 

Guess you like

Origin www.cnblogs.com/h1019384803/p/11297118.html