maincpp.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * maincpp.cpp
  3. *
  4. * Created on: 22 Jun 2022
  5. * Author: garth
  6. */
  7. #include "main.h"
  8. #include "gpio.h"
  9. #include "tim.h"
  10. #include "extra.h"
  11. //#include "STM_ENC28_J60.h"
  12. volatile uint16_t pwm1freq = 0;
  13. volatile uint16_t pwm1freqnew = 100;
  14. volatile uint16_t pwm2freq = 0;
  15. volatile uint16_t pwm2freqnew = 10000;
  16. volatile uint16_t val;
  17. volatile uint32_t pwm1counter;
  18. volatile uint32_t pwm1period;
  19. void maincpp()
  20. {
  21. HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
  22. // HAL_TIM_Base_Start_IT(&htim17);
  23. while(1)
  24. {
  25. if(pwm1freq != pwm1freqnew)
  26. {
  27. pwm1freq = pwm1freqnew;
  28. // val = (map(pwm1freq, 1, 10000, 10000, 1))-1;
  29. htim1.Instance->CCR1 = (pwm1freq/2);
  30. htim1.Instance->ARR = pwm1freq;
  31. }
  32. if(pwm2freq != pwm2freqnew)
  33. {
  34. val = (360000/pwm2freqnew)-1;
  35. pwm1freqnew = val;
  36. pwm2freq = pwm2freqnew;
  37. }
  38. }
  39. }
  40. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  41. {
  42. /* Prevent unused argument(s) compilation warning */
  43. if(htim->Instance == TIM17)
  44. {
  45. pwm1counter++;
  46. if(pwm1counter >= pwm1period)
  47. {
  48. HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
  49. pwm1counter = 0;
  50. }
  51. }
  52. /* NOTE : This function should not be modified, when the callback is needed,
  53. the HAL_TIM_PeriodElapsedCallback could be implemented in the user file
  54. */
  55. }