tim4.c 738 B

12345678910111213141516171819202122232425262728
  1. #include "hal/hal.h"
  2. #include "hal/tim4.h"
  3. #include "stm32f3xx_ll_tim.h"
  4. static TIM_HandleTypeDef timx;
  5. void TIM4_Init(void){
  6. timx.Instance = TIM6;
  7. timx.Init.Prescaler = 7200; //72000000 / 7200 = 10000 // 10us
  8. timx.Init.Period = 100; //10ms
  9. timx.Init.RepetitionCounter = 0;
  10. timx.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  11. if (HAL_TIM_Base_Init(&timx) != HAL_OK)
  12. {
  13. Error_Handler();
  14. }
  15. }
  16. void TIM4_Enable(void){
  17. LL_TIM_SetCounter( timx.Instance, 0);
  18. LL_TIM_EnableCounter(timx.Instance);
  19. LL_TIM_ClearFlag_UPDATE(timx.Instance);
  20. LL_TIM_EnableIT_UPDATE(timx.Instance);
  21. HAL_NVIC_EnableIRQ(TIM6_DAC1_IRQn);
  22. }
  23. void TIM4_Disable(void){
  24. LL_TIM_DisableCounter(timx.Instance);
  25. HAL_NVIC_DisableIRQ(TIM6_DAC1_IRQn);
  26. }