soft_timer.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "soft_timer.h"
  2. #include "auto_pilot.h"
  3. #include "control_attitude.h"
  4. #include "control_rate.h"
  5. #include "control_throttle.h"
  6. #include "flight_mode.h"
  7. #include "hard_system_timer.h"
  8. #include "pilot_navigation.h"
  9. #include "soft_imu.h"
  10. #include "soft_motor_output.h"
  11. #include "soft_port_uart4.h"
  12. #include "soft_rc_input.h"
  13. #include "soft_time.h"
  14. #include "ver_config.h"
  15. void system_timer_initial(void) { system_timer_init(); }
  16. unsigned short hz_counts = 0;
  17. volatile bool hz_400_flag = false, hz_200_flag = false, hz_100_flag = false,
  18. hz_50_flag = false, hz_20_flag = false, hz_10_flag = false,
  19. hz_5_flag = false, hz_2_flag = false, hz_1_flag = false;
  20. void timer_hookfunction(void)
  21. {
  22. hz_counts++;
  23. hz_400_flag = true;
  24. // 只能用if 不能用else if
  25. // 200HZ中断
  26. if (hz_counts % 2 == 0)
  27. {
  28. hz_200_flag = true;
  29. }
  30. // 100HZ中断
  31. if (hz_counts % 4 == 0)
  32. {
  33. hz_100_flag = true;
  34. }
  35. // 50HZ中断
  36. if (hz_counts % 8 == 0)
  37. {
  38. // 获取平滑的目标航向, 因为SD卡的延迟, 需要放到此中断来做
  39. hz_50_flag = true;
  40. get_target_yaw_by_flight_mode(flight_mode, 0.02f);
  41. }
  42. // 20HZ中断
  43. if (hz_counts % 20 == 0)
  44. {
  45. hz_20_flag = true;
  46. }
  47. // 10HZ中断
  48. if (hz_counts % 40 == 0)
  49. {
  50. hz_10_flag = true;
  51. }
  52. // 5HZ中断
  53. if (hz_counts % 80 == 0)
  54. {
  55. hz_5_flag = true;
  56. }
  57. if (hz_counts % 200 == 0)
  58. {
  59. hz_2_flag = true;
  60. }
  61. // 1HZ中断
  62. if (hz_counts % 400 == 0)
  63. {
  64. hz_1_flag = true;
  65. hz_counts = 0;
  66. }
  67. }