fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. #define POLY_PWM_PERIOD (1500)
  5.  
  6. int main(void) {
  7. // your code goes here
  8. static int rate1 = 0;
  9. static int32_t phaseAccumEL;
  10. static int32_t phaseAccumAZ;
  11. phaseAccumAZ = (127 << 25) | 0x3F;
  12. int rate = rate1;
  13. phaseAccumEL += rate;
  14. uint32_t phase_accum_el_uint = phaseAccumEL;
  15. const uint32_t accum_el_upper = phase_accum_el_uint >> 24;
  16. const int32_t adjustEL = (int8_t)accum_el_upper;
  17. phase_accum_el_uint &= (1 << 24) - 1;
  18. phaseAccumEL = phase_accum_el_uint;
  19. uint32_t PWM_CPRDUPD1 = POLY_PWM_PERIOD - adjustEL;
  20.  
  21. phaseAccumAZ += rate;
  22. uint32_t phase_accum_az_uint = phaseAccumAZ;
  23. const uint32_t accum_az_upper = phase_accum_az_uint >> 25;
  24. // Extract the upper bits and wrap them around to the range [-64, 63].
  25. int32_t adjustAZ = accum_az_upper & 0x7F; // Mask to 7 bits (0-127)
  26. if (adjustAZ >= 64)
  27. {
  28. adjustAZ -= 128; // Wrap around to negative range if >= 64
  29. }
  30. phase_accum_az_uint &= (1 << 25) - 1;
  31. phaseAccumAZ = phase_accum_az_uint;
  32. uint32_t PWM_CPRDUPD0 = (POLY_PWM_PERIOD / 2) - adjustAZ;
  33. printf("%u", PWM_CPRDUPD0);
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
751