STM32 3.5库函数应用整理(5)

2018-12-08 20:30

? ? ? TIM_IT_COM: TIM Commutation Interrupt source TIM_IT_Trigger: TIM Trigger Interrupt source TIM_IT_Break: TIM Break Interrupt source

Note:

? ? ? ? ?

TIM6 and TIM7 can generate only an update interrupt.

TIM9, TIM12 and TIM15 can have only TIM_IT_Update, TIM_IT_CC1, TIM_IT_CC2 or TIM_IT_Trigger. TIM10, TIM11, TIM13, TIM14, TIM16 and TIM17 can have TIM_IT_Update or TIM_IT_CC1. TIM_IT_Break is used only with TIM1, TIM8 and TIM15.

TIM_IT_COM is used only with TIM1, TIM8, TIM15, TIM16 and TIM17.

uint16_t TIM_GetPrescaler() 时基单元的预分频数 TIM_ICInit(); 输入捕获初始化

TIM_ICInitStruct 结构体

Data Fields

uint16_t

#define TIM_Channel_1 ((uint16_t)0x0000) #define TIM_Channel_2 ((uint16_t)0x0004) #define TIM_Channel_3 ((uint16_t)0x0008) TIM_Channel #define TIM_Channel_4 ((uint16_t)0x000C) 0x0 and 0xF 之间 #define TIM_ICPolarity_BothEdge ((uint16_t)0x000A) #define TIM_ICPolarity_Falling ((uint16_t)0x0002) uint16_t TIM_ICFilter uint16_t TIM_ICPolarity #define TIM_ICPolarity_Rising ((uint16_t)0x0000) #define TIM_ICPSC_DIV1 ((uint16_t)0x0000) #define TIM_ICPSC_DIV2 ((uint16_t)0x0004) #define TIM_ICPSC_DIV4 ((uint16_t)0x0008) uint16_t TIM_ICPrescaler #define TIM_ICPSC_DIV8 ((uint16_t)0x000C) #define TIM_ICSelection_DirectTI ((uint16_t)0x0001) #define TIM_ICSelection_IndirectTI ((uint16_t)0x0002) uint16_t TIM_ICSelection #define TIM_ICSelection_TRC ((uint16_t)0x0003 TIM_ICStructInit ()

初始化配置结构体

TIM_InternalClockConfig(TIM1);

关闭从模式,一旦开启CEN,直接使用系统时钟

TIM_ITConfig (TIM1,TIM_IT_Update,ENABLE); 中断配置

TIMx,:

where x can be 1 to 17 to select the TIMx peripheral.

TIM_IT,: specifies the TIM interrupts sources to be enabled or disabled. This parameter can be any combination

of the following values:

? ? ? ? ? ? ? ?

TIM_IT_Update: TIM update Interrupt source

TIM_IT_CC1: TIM Capture Compare 1 Interrupt source TIM_IT_CC2: TIM Capture Compare 2 Interrupt source TIM_IT_CC3: TIM Capture Compare 3 Interrupt source TIM_IT_CC4: TIM Capture Compare 4 Interrupt source TIM_IT_COM: TIM Commutation Interrupt source TIM_IT_Trigger: TIM Trigger Interrupt source TIM_IT_Break: TIM Break Interrupt source

Note:

? ? ? ? ?

TIM6 and TIM7 can only generate an update interrupt.

TIM9, TIM12 and TIM15 can have only TIM_IT_Update, TIM_IT_CC1, TIM_IT_CC2 or TIM_IT_Trigger. TIM10, TIM11, TIM13, TIM14, TIM16 and TIM17 can have TIM_IT_Update or TIM_IT_CC1. TIM_IT_Break is used only with TIM1, TIM8 and TIM15.

TIM_IT_COM is used only with TIM1, TIM8, TIM15, TIM16 and TIM17.

Parameters:

NewState,: new state of the TIM interrupts. This parameter can be: ENABLE or DISABLE.

TIM_ITRxExternalClockConfig (TIM1,)

TIMx,:

TIM_TS_ITR0,: TIM_TS_ITR1,: TIM_TS_ITR2,: TIM_TS_ITR3,:

where x can be 1, 2, 3, 4, 5, 9, 12 or 15 to select the TIM peripheral. Internal Trigger 0 Internal Trigger 1 Internal Trigger 2 Internal Trigger 3

TIM_ITRSource,: Trigger source. This parameter can be one of the following values:

TIM_OC1Init (TIM1,...); TIM_OCInitStruct 结构体

Data Fields

uint16_t

define TIM_OCIdleState_Reset ((uint16_t)0x0000)

TIM_OCIdleState #define TIM_OCIdleState_Set ((uint16_t)0x0100) 空闲时输出电平状态 uint16_t #define TIM_OCMode_Active ((uint16_t)0x0010) #define TIM_OCMode_Inactive ((uint16_t)0x0020) #define TIM_OCMode_PWM1 ((uint16_t)0x0060) #define TIM_OCMode_PWM2 ((uint16_t)0x0070) #define TIM_OCMode_Timing ((uint16_t)0x0000) TIM_OCMode #define TIM_OCMode_Toggle ((uint16_t)0x0030) #define TIM_OCNIdleState_Reset ((uint16_t)0x0000) 定时器输出模式选择 uint16_t TIM_OCNIdleState #define TIM_OCNIdleState_Set ((uint16_t)0x0200) #define TIM_OCNPolarity_High ((uint16_t)0x0000) 空闲互补输出口的电平状态 uint16_t TIM_OCNPolarity #define TIM_OCNPolarity_Low ((uint16_t)0x0008) #define TIM_OCPolarity_High ((uint16_t)0x0000) 输出比较极性,就是比较匹配输出的有效电平 uint16_t TIM_OCPolarity #define TIM_OCPolarity_Low ((uint16_t)0x0002) #define TIM_OutputNState_Disable ((uint16_t)0x0000) uint16_t TIM_OutputNState #define TIM_OutputNState_Enable ((uint16_t)0x0004) #define TIM_OutputState_Disable ((uint16_t)0x0000) 使能互补输出 uint16_t TIM_OutputState #define TIM_OutputState_Enable ((uint16_t)0x0001) This parameter can be a number between 0x0000 and 0xFFFF 使能输出 定时周期 uint16_t TIM_Pulse TIM_OC1PreloadConfig ()

默认disable,写入CCRx的值立即生效;当enable时,写入CCRx的值在下一个更新事件的时候写入影子寄存器 TIMx,:

where x can be 1 to 17 except 6 and 7 to select the TIM peripheral.

TIM_OCPreload,: new state of the TIMx peripheral Preload register This parameter can be one of the following values:

? ?

TIM_OCPreload_Enable

TIM_OCPreload_Disable

TIM_OCStructInit (&TIMx_OCInitStructure)

比较输出结构体填入缺省值

TIM_PrescalerConfig (TM1,分频值,TIM_PSCReloadMode_Update)

参数:最后一个参数是选择更改的分频值立即生效还是在下一个更新事件发生时,默认更新事件发生 TIM_PSCReloadMode_Update: The Prescaler is loaded at the update event.

TIM_PSCReloadMode_Immediate: The Prescaler is loaded immediately.

计数器的时钟频率(CK_CNT)等于fCK_PSC/( PSC[15:0]+1)。

TIM_PWMIConfig (TIMx,&TIM_ICInitStruct )

用输入捕获结构体配置定时器来测量外部的PWM信号,同TIM_ICInit();

Data Fields

uint16_t

#define TIM_Channel_1 ((uint16_t)0x0000) #define TIM_Channel_2 ((uint16_t)0x0004) #define TIM_Channel_3 ((uint16_t)0x0008)

TIM_Channel #define TIM_Channel_4 ((uint16_t)0x000C) between 0x0 and 0xF #define TIM_ICPolarity_BothEdge ((uint16_t)0x000A) #define TIM_ICPolarity_Falling ((uint16_t)0x0002) 注意,STM32的定时器输入和输出复用一个管脚 输入捕获硬件滤波器 uint16_t TIM_ICFilter uint16_t TIM_ICPolarity #define TIM_ICPolarity_Rising ((uint16_t)0x0000) #define TIM_ICPSC_DIV1 ((uint16_t)0x0000) #define TIM_ICPSC_DIV2 ((uint16_t)0x0004) #define TIM_ICPSC_DIV4 ((uint16_t)0x0008) 捕获上升沿还是下降沿还是都捕获 uint16_t TIM_ICPrescaler #define TIM_ICPSC_DIV8 ((uint16_t)0x000C) #define TIM_ICSelection_DirectTI ((uint16_t)0x0001) #define TIM_ICSelection_IndirectTI ((uint16_t)0x0002) 分频(分频和上面的硬件滤波不一样,硬件滤波是指,你大致知道信号的频率为多少KHZ,当产生GHZ的信号肯定是杂波,所以可以硬件就把这样的波滤掉,减少软件代码的开销) uint16_t TIM_ICSelection #define TIM_ICSelection_TRC ((uint16_t)0x0003) IC1信号的来源

TIM_SelectCOM (TIMx,ENABLE)

更新COM事件,用于电机的统一换向

TIM_SelectHallSensor (TIMx,ENABLE)

霍尔传感器接口,打开后三路异或后输入

TIM_SelectInputTrigger (TIMx,source)

TIMx,:

where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15 to select the TIM peripheral.

TIM_InputTriggerSource,: The Input Trigger source. This parameter can be one of the following values:

? ? ? ? ? ? ? ?

TIM_TS_ITR0: Internal Trigger 0 TIM_TS_ITR1: Internal Trigger 1 TIM_TS_ITR2: Internal Trigger 2 TIM_TS_ITR3: Internal Trigger 3

TIM_TS_TI1F_ED: TI1 Edge Detector TIM_TS_TI1FP1: Filtered Timer Input 1 TIM_TS_TI2FP2: Filtered Timer Input 2 TIM_TS_ETRF: External Trigger input

选择输入触发方式

TIM_SelectOCxM ();

TIM_OC1Init包括这个作用 TIMx,:

where x can be 1 to 17 except 6 and 7 to select the TIM peripheral.

TIM_Channel,: specifies the TIM Channel This parameter can be one of the following values:

? ? ? ?

TIM_Channel_1: TIM Channel 1 TIM_Channel_2: TIM Channel 2 TIM_Channel_3: TIM Channel 3 TIM_Channel_4: TIM Channel 4

TIM_OCMode,: specifies the TIM Output Compare Mode. This parameter can be one of the following values:

? ? ?

TIM_OCMode_Timing TIM_OCMode_Active TIM_OCMode_Toggle

? ? ? ? TIM_OCMode_PWM1 TIM_OCMode_PWM2 TIM_ForcedAction_Active TIM_ForcedAction_InActive

TIM_TimeBaseInit (TIMx,TIM_TimeBaseInitStruct) 时基单元配置函数 参数:

Data Fields

uint16_t

#define TIM_CKD_DIV1 ((uint16_t)0x0000) #define TIM_CKD_DIV2 ((uint16_t)0x0100)

TIM_ClockDivision #define TIM_CKD_DIV4 ((uint16_t)0x0200) #define TIM_CounterMode_CenterAligned1 ((uint16_t)0x0020) #define TIM_CounterMode_CenterAligned2 ((uint16_t)0x0040) #define TIM_CounterMode_CenterAligned3 ((uint16_t)0x0060) #define TIM_CounterMode_Down ((uint16_t)0x0010) uint16_t TIM_CounterMode #define TIM_CounterMode_Up ((uint16_t)0x0000) between 0x0000 and 0xFFFF between 0x0000 and 0xFFFF 0x00 and 0xFF 计数模式选择 计数器的周期值 配置预分频值 计数重复次数 uint16_t TIM_Period uint16_t TIM_Prescaler uint8_t TIM_RepetitionCounter


STM32 3.5库函数应用整理(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:PEP小学五年级英语上册堂堂清课课练习题资料

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: