fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #define POLY_PWM_PERIOD (5001)
  4. #define PWM_PERIOD (32767)
  5. #define SQRT3 (1.7320508076f)
  6. #define ONEBYSQ3_Q16 ((int) (65536 / SQRT3))
  7. #define ONEBYSQ3 ((65536 / SQRT3 / 65536))
  8. int main(void) {
  9. // your code goes here
  10. int32_t duty_cycle_input = 1000;
  11. int32_t duty_cycle_to_set = (POLY_PWM_PERIOD / 2) - (duty_cycle_input * (POLY_PWM_PERIOD / 2) / PWM_PERIOD);
  12. int32_t duty_cycle_to_set2 = (POLY_PWM_PERIOD / 2) - (duty_cycle_input * (POLY_PWM_PERIOD / 2 / PWM_PERIOD));
  13.  
  14. // printf("%d\n", duty_cycle_to_set);
  15. // printf("%d\n", duty_cycle_to_set2);
  16. int32_t phase1_current = 2250;
  17. int32_t phase2_current = 15;
  18. int32_t const beta = ((phase1_current + (2 * phase2_current)) * ONEBYSQ3_Q16) / 65536;
  19. int32_t const beta2 = (phase1_current + (2 * phase2_current)) * ONEBYSQ3;
  20. printf("%d\n", beta);
  21. printf("%d\n", beta2);
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
1316
1316