定时器时钟模式1、2与主从模式

很多初学者在初学定时器时经常被时钟模式1和时钟模式2,主从模式这三个概念混淆。网上繁多的资料也让大家看的云里雾里,下面我将通俗介绍一下什么是时钟模式1、时钟模式2,主从模式。

上图摘自STM32F10xxx参考手册的通用定时器。定时器的时钟来源有以下几路:

1.内部时钟(CK_INT)

2.外部触发输入(TIMx_ETR)

3.内部触发输入(ITRx)

4.捕获输入(TIx)

所谓时钟模式1就是走TIMx_ETR、ITRx、TIx再到时基单元一路(红笔标出)

时钟模式2就是仅仅走TIMx_ETR一路到时基单元(蓝笔标出)

不难看出TIMx_ETR同时可以配置时钟模式1和时钟模式2,但是我们为了防止占用通道,我们往往将其配置为时钟模式2

主从模式则是需要选择主定时器和从定时器

输出TRGO的为主定时器,库函数中TRGO可以由以下几个条件触发产生 

  /*  - For all TIMx
  *     @arg TIM_TRGOSource_Reset:  The UG bit in the TIM_EGR register is used as the trigger output (TRGO).
  *     @arg TIM_TRGOSource_Enable: The Counter Enable CEN is used as the trigger output (TRGO).
  *     @arg TIM_TRGOSource_Update: The update event is selected as the trigger output (TRGO).
  *
  *  - For all TIMx except TIM6 and TIM7
  *     @arg TIM_TRGOSource_OC1: The trigger output sends a positive pulse when the CC1IF flag
  *                              is to be set, as soon as a capture or compare match occurs (TRGO).
  *     @arg TIM_TRGOSource_OC1Ref: OC1REF signal is used as the trigger output (TRGO).
  *     @arg TIM_TRGOSource_OC2Ref: OC2REF signal is used as the trigger output (TRGO).
  *     @arg TIM_TRGOSource_OC3Ref: OC3REF signal is used as the trigger output (TRGO).
  *     @arg TIM_TRGOSource_OC4Ref: OC4REF signal is used as the trigger output (TRGO)./

所输出的TGGO信号会去向其他定时器的TIx,有一张相关定时器的对应表,大家可以自行在手册上查找。

选择触发源和从模式的为从定时器

选择触发源即选择谁作为TRGI输入,下面是可以作为TRGI输入的参数

 / * @param  TIM_InputTriggerSource: The Input Trigger source.
  *   This parameter can be one of the following values:
  *     @arg TIM_TS_ITR0: Internal Trigger 0
  *     @arg TIM_TS_ITR1: Internal Trigger 1
  *     @arg TIM_TS_ITR2: Internal Trigger 2
  *     @arg TIM_TS_ITR3: Internal Trigger 3
  *     @arg TIM_TS_TI1F_ED: TI1 Edge Detector
  *     @arg TIM_TS_TI1FP1: Filtered Timer Input 1
  *     @arg TIM_TS_TI2FP2: Filtered Timer Input 2
  *     @arg TIM_TS_ETRF: External Trigger input*/

选择完触发源后需要选择从模式,即该TRGO会触发什么事件,下面是可以作为从模式的参数

  /*     @arg TIM_SlaveMode_Reset: Rising edge of the selected trigger signal (TRGI) re-initializes
  *                               the counter and triggers an update of the registers.
  *     @arg TIM_SlaveMode_Gated:     The counter clock is enabled when the trigger signal (TRGI) is high.
  *     @arg TIM_SlaveMode_Trigger:   The counter starts at a rising edge of the trigger TRGI.
  *     @arg TIM_SlaveMode_External1: Rising edges of the selected trigger (TRGI) clock the counter.

大家看到这里可能有些懵逼,我总结一下:

时钟模式1和2就是两类不同的时钟输入方法

主模式输出TRGO至另一个从模式的ITRx,以完成定时器级联功能。但是从模式的触发源不一定是上一个定时器的TRGO,也可以是其他信号。所以当我们选择一个定时器为从模式,不一定要有主模式的定时器的配置,只是单单希望利用一下从模式的功能比如复位、门控和触发功能也是未尝不可的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值