TIM Exported Functions
- group TIM_Exported_Functions
Functions
-
void TIM_DeInit(void)
Deinitialize the TIMx peripheral registers to their default reset values.
Example usage
void driver_timer_init(void) { TIM_DeInit(); }
- 返回:
None.
-
void TIM_TimeBaseInit(TIM_TypeDef *TIMx, TIM_TimeBaseInitTypeDef *TIM_TimeBaseInitStruct)
Initialize the TIMx time base unit peripheral according to the specified parameters in TIM_TimeBaseInitStruct.
Example usage
void driver_timer_init(void) { RCC_PeriphClockCmd(APBPeriph_TIMER, APBPeriph_TIMER_CLOCK, ENABLE); TIM_TimeBaseInitTypeDef TIM_InitStruct; TIM_StructInit(&TIM_InitStruct); TIM_InitStruct.TIM_PWM_En = PWM_DISABLE; TIM_InitStruct.TIM_Period = 1000000 - 1 ; TIM_InitStruct.TIM_Mode = TIM_Mode_UserDefine; TIM_TimeBaseInit(TIMER_NUM, &TIM_InitStruct); }
- 参数:
TIMx – [in] where x can be 2 to 5 to select the TIM peripheral.
TIM_TimeBaseInitStruct – [in] Pointer to a TIM_TimeBaseInitTypeDef structure that contains the configuration information for the selected TIM peripheral.
- 返回:
None.
-
void TIM_StructInit(TIM_TimeBaseInitTypeDef *TIM_TimeBaseInitStruct)
Fill each TIM_InitStruct member with its default value.
Example usage
void driver_timer_init(void) { RCC_PeriphClockCmd(APBPeriph_TIMER, APBPeriph_TIMER_CLOCK, ENABLE); TIM_TimeBaseInitTypeDef TIM_InitStruct; TIM_StructInit(&TIM_InitStruct); TIM_InitStruct.TIM_PWM_En = PWM_DISABLE; TIM_InitStruct.TIM_Period = 1000000 - 1; TIM_InitStruct.TIM_Mode = TIM_Mode_UserDefine; TIM_TimeBaseInit(TIM4, &TIM_InitStruct); }
- 参数:
TIM_TimeBaseInitStruct – [in] Pointer to a TIM_TimeBaseInitTypeDef structure which will be initialized.
- 返回:
None.
-
void TIM_Cmd(TIM_TypeDef *TIMx, FunctionalState NewState)
Enable or disable the specified TIM peripheral.
Example usage
void driver_timer_init(void) { RCC_PeriphClockCmd(APBPeriph_TIMER, APBPeriph_TIMER_CLOCK, ENABLE); TIM_TimeBaseInitTypeDef TIM_InitStruct; TIM_StructInit(&TIM_InitStruct); TIM_InitStruct.TIM_PWM_En = PWM_DISABLE; TIM_InitStruct.TIM_Period = 1000000 - 1; TIM_InitStruct.TIM_Mode = TIM_Mode_UserDefine; TIM_TimeBaseInit(TIM4, &TIM_InitStruct); TIM_Cmd(TIM4, ENABLE); }
- 参数:
TIMx – [in] Where x can be 2 to 5 to select the TIMx peripheral.
NewState – [in] New state of the TIMx peripheral. This parameter can be: ENABLE or DISABLE.
- 返回:
None.
-
void TIM_INTConfig(TIM_TypeDef *TIMx, FunctionalState NewState)
Enable or disable the specified TIMx interrupt.
Example usage
void driver_timer_init(void) { RCC_PeriphClockCmd(APBPeriph_TIMER, APBPeriph_TIMER_CLOCK, ENABLE); TIM_TimeBaseInitTypeDef TIM_InitStruct; TIM_StructInit(&TIM_InitStruct); TIM_InitStruct.TIM_PWM_En = PWM_DISABLE; TIM_InitStruct.TIM_Period = 1000000 - 1; TIM_InitStruct.TIM_Mode = TIM_Mode_UserDefine; TIM_TimeBaseInit(TIM4, &TIM_InitStruct); TIM_ClearINT(TIM4); TIM_INTConfig(TIM4, ENABLE); }
- 参数:
TIMx – [in] Where x can be 2 to 5 to select the TIMx peripheral.
NewState – [in] New state of the TIMx peripheral. This parameter can be: ENABLE or DISABLE.
- 返回:
None.
-
void TIM_ChangePeriod(TIM_TypeDef *TIMx, uint32_t period)
Change TIM period value.
Example usage
void timer_demo(void) { uint32_t new_period = 1000000 - 1; TIM_Cmd(TIM4, DISABLE); TIM_ChangePeriod(TIM4, new_period); }
- 参数:
TIMx – [in] Where x can be 2 to 5 to select the TIMx peripheral.
period – [in] Period value to be changed.
- 返回:
None.
-
void TIM_PWMChangeFreqAndDuty(TIM_TypeDef *TIMx, uint32_t high_count, uint32_t low_count)
Change PWM freq and duty according high_cnt and low_cnt.
Example usage
void timer_demo(void) { uint32_t high_count = 1000000 - 1; uint32_t low_count = 1000000 - 1; TIM_Cmd(TIM4, DISABLE); TIM_ChangePeriod(TIM4, high_count, low_count); }
- 参数:
TIMx – [in] Where x can be 2 to 5 to select the TIMx peripheral.
high_count – [in] This parameter can be 0x00~0xFFFFFFFF.
low_count – [in] This parameter can be 0x00~0xFFFFFFFF.
- 返回:
None.
-
uint32_t TIM_GetCurrentValue(TIM_TypeDef *TIMx)
Get TIMx current value when timer is running.
Example usage
void timer_demo(void) { uint32_t cur_value = TIM_GetCurrentValue(TIM4); }
- 参数:
TIMx – [in] Where x can be 2 to 5 to select the TIMx peripheral.
- 返回:
The counter value.
-
ITStatus TIM_GetINTStatus(TIM_TypeDef *TIMx)
Check whether the TIM interrupt has occurred or not.
Example usage
void timer_demo(void) { ITStatus int_status = TIM_GetINTStatus(TIM4); }
- 参数:
TIMx – [in] Where x can be 2 to 5 to select the TIMx peripheral.
- 返回:
The new state of the TIM_IT(SET or RESET).
-
void TIM_ClearINT(TIM_TypeDef *TIMx)
Clear TIM interrupt.
Example usage
void timer_demo(void) { TIM_ClearINT(TIM4); }
- 参数:
TIMx – [in] Where x can be 2 to 5 to select the TIMx peripheral.
- 返回:
None.
-
ITStatus TIM_GetOperationStatus(TIM_TypeDef *TIMx)
Check whether the TIM is in operation or not.
Example usage
void timer_demo(void) { ITStatus intstatus = TIM_GetOperationStatus(TIM4); }
- 参数:
TIMx – [in] Where x can be 2 to 5 to select the TIMx peripheral.
- 返回:
The new state of the timer operation status (SET or RESET).
-
void TIM_PWMComplOutputEMCmd(PWM_TypeDef *PWMx, FunctionalState NewState)
PWM complementary output emergency stop and resume. PWM_P emergency stop level state is configured by PWM_Stop_State_P, PWM_N emergency stop level state is configured by PWM_Stop_State_N.
Example usage
void board_pwm_init(void) { Pad_Config(P0_1, PAD_PINMUX_MODE, PAD_IS_PWRON, PAD_PULL_NONE, PAD_OUT_ENABLE, PAD_OUT_HIGH); Pad_Config(P0_2, PAD_PINMUX_MODE, PAD_IS_PWRON, PAD_PULL_NONE, PAD_OUT_ENABLE, PAD_OUT_HIGH); Pad_Config(P2_2, PAD_PINMUX_MODE, PAD_IS_PWRON, PAD_PULL_NONE, PAD_OUT_ENABLE, PAD_OUT_HIGH); Pinmux_Config(P0_1, PWM_OUT_PIN_PINMUX); Pinmux_Config(P0_2, PWM_OUT_P_PIN_PINMUX); Pinmux_Config(P2_2, PWM_OUT_N_PIN_PINMUX); } void driver_pwm_init(void) { RCC_PeriphClockCmd(APBPeriph_TIMER, APBPeriph_TIMER_CLOCK, ENABLE); TIM_TimeBaseInitTypeDef TIM_InitStruct; TIM_StructInit(&TIM_InitStruct); TIM_InitStruct.TIM_Mode = TIM_Mode_UserDefine; TIM_InitStruct.TIM_PWM_En = PWM_ENABLE; TIM_InitStruct.TIM_PWM_High_Count = PWM_HIGH_COUNT; TIM_InitStruct.TIM_PWM_Low_Count = PWM_LOW_COUNT; TIM_InitStruct.PWM_Stop_State_P = PWM_STOP_AT_HIGH; TIM_InitStruct.PWM_Stop_State_N = PWM_STOP_AT_LOW; TIM_InitStruct.PWMDeadZone_En = DEADZONE_ENABLE; //enable to use pwn p/n output TIM_InitStruct.PWM_Deazone_Size = 255; TIM_TimeBaseInit(TIM2, &TIM_InitStruct); TIM_Cmd(TIM2, ENABLE); } void pwm_demo(void) { board_pwm_init(); driver_pwm_init(); //Add delay. TIM_PWMComplOutputEMCmd(PWM2,ENABLE); }
备注
To use this function, need to configure the corresponding timer. PWM2 ->> TIM2.
- 参数:
PWMx – [in] PWM2.
NewState – [in] New state of complementary output. DISABLE: Resume PWM complementary output. ENABLE: PWM complementary output emergency stop.
- 返回:
None.
-
void TIM_PWMDZBypassCmd(PWM_TypeDef *PWMx, FunctionalState NewState)
Enable or disable bypass dead zone function of PWM complementary output. After enabling, PWM_P = ~PWM_N.
Example usage
void driver_pwm_init(void) { RCC_PeriphClockCmd(APBPeriph_TIMER, APBPeriph_TIMER_CLOCK, ENABLE); TIM_TimeBaseInitTypeDef TIM_InitStruct; TIM_StructInit(&TIM_InitStruct); TIM_InitStruct.TIM_Mode = TIM_Mode_UserDefine; TIM_InitStruct.TIM_PWM_En = PWM_ENABLE; TIM_InitStruct.TIM_PWM_High_Count = PWM_HIGH_COUNT; TIM_InitStruct.TIM_PWM_Low_Count = PWM_LOW_COUNT; TIM_InitStruct.PWM_Stop_State_P = PWM_STOP_AT_HIGH; TIM_InitStruct.PWM_Stop_State_N = PWM_STOP_AT_LOW; TIM_InitStruct.PWMDeadZone_En = DEADZONE_ENABLE; //enable to use pwn p/n output TIM_InitStruct.PWM_Deazone_Size = 255; TIM_TimeBaseInit(TIM2, &TIM_InitStruct); TIM_Cmd(TIM2, ENABLE); TIM_PWMDZBypassCmd(PWM2, ENABLE); }
备注
To use this function, need to configure the corresponding timer. PWM2 ->> TIM2.
- 参数:
PWMx – [in] PWM2.
NewState – [in] New state of the PWMx peripheral. DISABLE: Disable bypass dead zone function. ENABLE: Enable bypass dead zone function.
- 返回:
None.
-
void TIM_PWMChangeDZClockSrc(PWM_TypeDef *PWMx, FunctionalState NewState)
Change the PWM dead time clock source.
Example usage
void driver_pwm_init(void) { RCC_PeriphClockCmd(APBPeriph_TIMER, APBPeriph_TIMER_CLOCK, ENABLE); //Open 5M clock source. RCC_ClockSrc5MCmd(); TIM_TimeBaseInitTypeDef TIM_InitStruct; TIM_StructInit(&TIM_InitStruct); TIM_InitStruct.TIM_Mode = TIM_Mode_UserDefine; TIM_InitStruct.TIM_PWM_En = PWM_ENABLE; TIM_InitStruct.TIM_PWM_High_Count = PWM_HIGH_COUNT; TIM_InitStruct.TIM_PWM_Low_Count = PWM_LOW_COUNT; TIM_InitStruct.PWM_Stop_State_P = PWM_STOP_AT_HIGH; TIM_InitStruct.PWM_Stop_State_N = PWM_STOP_AT_LOW; TIM_InitStruct.PWMDeadZone_En = DEADZONE_ENABLE; //enable to use pwn p/n output TIM_InitStruct.PWM_Deazone_Size = PWM_DEAD_ZONE_SIZE; TIM_TimeBaseInit(TIM2, &TIM_InitStruct); //Use 5M clock source. TIM_PWMChangeDZClockSrc(PWM2,ENABLE); TIM_Cmd(TIM2, ENABLE); }
备注
To use this function, need to configure the corresponding timer. PWM2 ->> TIM2.
- 参数:
PWMx – [in] PWM2.
NewState – [in] New state of the PWMx peripheral. DISABLE: Use 32k clock source. ENABLE: Use 5M clock source.
- 返回:
None.
-
void PWM_Deadzone_EMStop(PWM_TypeDef *PWMx)
PWM complementary output emergency stop.
- 参数:
PWMx – [in] PWM2.
- 返回:
None.
-
FlagStatus TIM_GetPWMOutputStatus(TIM_TypeDef *TIMx)
Get PWM current output status.
- 参数:
TIMx – where x can be 2 to 5 to select the TIMx peripheral.
- 返回:
The output state of the timer(SET: High or RESET: Low).
-
void TIM_DeInit(void)