generation.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include "config.h"
  3. #include <stdint.h>
  4. #define FXP_SCALING 4000
  5. #define DIV_ROUND(a,b) (((a)+(b)/2)/(b))
  6. static const int32_t MIN_FREQ1 = 7000;
  7. static const int32_t MAX_FREQ1 = 30000;
  8. static const int32_t MIN_FREQ3 = 1000000;
  9. static const int32_t MAX_FREQ3 = 3000000;
  10. static const int32_t MIN_D1D2 = 0.005 * FXP_SCALING;//0.5%
  11. static const int32_t MAX_D1D2 = 0.495 * FXP_SCALING;//49.5%
  12. static const int32_t MAX_PH3 = 3000;
  13. typedef enum {
  14. ENABLE_FORCE_NONE = 0,
  15. ENABLE_FORCE_ENABLE,
  16. ENABLE_FORCE_DISABLE
  17. } enable_force_t;
  18. typedef struct {
  19. uint32_t f1;//Hz
  20. uint32_t _period1;//steps
  21. uint32_t D1;//4000/100%
  22. uint32_t _duty1;//steps
  23. uint32_t D2;//4000/100%
  24. uint32_t _duty2;//steps
  25. uint32_t Ph2;//4000steps/360*
  26. uint32_t _phase2;//steps
  27. uint32_t Ph3;//4000steps/360*
  28. uint32_t f3;//Hz
  29. uint32_t _period3;//steps
  30. uint32_t D3;//*0.1%
  31. uint32_t N3;//n
  32. enable_force_t ena;
  33. } tweaked_params_s;
  34. typedef struct {
  35. union {
  36. uint32_t data[14];
  37. tweaked_params_s regs;
  38. };
  39. } tweaked_params_union_s;
  40. void init_params(tweaked_params_s * pParams);
  41. void validate_generation_values(tweaked_params_s * pParams);
  42. void update_three_signal_values();