logic.c 950 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "stm32f0xx_hal.h"
  2. #include "logic.h"
  3. #include "pwm_in.h"
  4. #include "gpio.h"
  5. #include "pwm_out.h"
  6. static uint8_t step_number = 0;
  7. //
  8. void logic_main(void)
  9. {
  10. if (get_button())
  11. {
  12. gpio_set_output(true);
  13. HAL_Delay(1000);
  14. logic_set_out_pwm();
  15. HAL_Delay(500);
  16. gpio_set_output(false);
  17. tim_pwm_pulse_idle();
  18. set_button(false);
  19. }
  20. }
  21. //
  22. void logic_set_out_pwm(void)
  23. {
  24. switch (step_number)
  25. {
  26. case 0:
  27. tim_pwm_out_set_pulse(PWM_OUT_CH_1, 1300);
  28. break;
  29. case 1:
  30. tim_pwm_out_set_pulse(PWM_OUT_CH_2, 1300);
  31. break;
  32. case 2:
  33. tim_pwm_out_set_pulse(PWM_OUT_CH_1, 1850);
  34. break;
  35. case 3:
  36. tim_pwm_out_set_pulse(PWM_OUT_CH_2, 1850);
  37. break;
  38. default : break;
  39. }
  40. step_number = step_number == 3 ? 0 : step_number + 1;
  41. }