timer.c 784 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "timer.h"
  2. #include "read.h"
  3. bool Start_80_hz = false;
  4. bool Start_10_hz = false;
  5. bool Start_5_hz = false;
  6. bool Start_1_hz = false;
  7. // 12.5ms进一次中断
  8. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  9. {
  10. static uint8_t time_count = 0;
  11. Start_80_hz = true;
  12. time_count++;
  13. if (time_count % 8 == 0)
  14. {
  15. Start_10_hz = true;
  16. }
  17. if (time_count % 26 == 0)
  18. {
  19. Start_5_hz = true;
  20. }
  21. if (time_count % 80 == 0)
  22. {
  23. Start_1_hz = true;
  24. time_count = 0;
  25. }
  26. }
  27. void delay_us(uint16_t us)
  28. {
  29. HAL_TIM_Base_Start(&htim3);
  30. __HAL_TIM_SET_COUNTER(&htim3, 0); // 清零计数
  31. us = (us > 4) ? (us - 2) : 1;
  32. while (us > __HAL_TIM_GET_COUNTER(&htim3))
  33. ;
  34. HAL_TIM_Base_Stop(&htim3);
  35. }