nv_storage.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef _NV_Storage_H__
  2. #define _NV_Storage_H__
  3. #include "os/os_types.h"
  4. #include "foc/core/PMSM_FOC_Core.h"
  5. #include "foc/commands.h"
  6. #pragma pack (push,1)
  7. typedef struct {
  8. float s_PhaseCurrLim;
  9. float s_maxDCVol;
  10. float s_minDCVol;
  11. float s_maxRPM;
  12. float s_maxEpmRPM;
  13. float s_maxEpmPhaseCurrLim;
  14. float s_maxTorque;
  15. float s_PhaseCurreBrkLim;
  16. float s_iDCeBrkLim;
  17. float s_LimitiDC;
  18. float n_currentBand; //电流环带宽
  19. float n_minThroVol;
  20. float n_maxThroVol;
  21. u8 n_brkShutPower;
  22. u8 n_autoHold;
  23. pid_conf_t pid_conf[PID_Max_id];
  24. u16 crc16;
  25. }foc_params_t;
  26. typedef struct {
  27. u8 poles;
  28. float r;
  29. float ld;
  30. float lq;
  31. float flux_linkage;
  32. float back_emf;
  33. s32 hall_table[8];
  34. float offset;
  35. float est_pll_band; //normal工作模式下的pll带宽
  36. float pos_lock_pll_band; //电机锁定模式下的pll带宽
  37. u16 crc16;
  38. }motor_params_t;
  39. #define MAX_TRQ_POINTS 60
  40. #define MAX_SPD_POINTS 100
  41. #define TBL_TRQ_INTVAL 10
  42. #define TBL_SPD_INTVAL 100
  43. struct lut_dq {
  44. s16 d;
  45. s16 q;
  46. };
  47. typedef struct {
  48. struct lut_dq dq[MAX_TRQ_POINTS][MAX_SPD_POINTS];
  49. u16 magic;
  50. u16 crc16;
  51. }torque_lut_t;
  52. #pragma pack(pop)
  53. #define motorParam_idx_0 3
  54. #define motorParam_idx_1 (motorParam_idx_0 + 1)
  55. #define focParam_idx_0 (motorParam_idx_0 + 2)
  56. #define focParam_idx_1 (motorParam_idx_0 + 3)
  57. #define trq_Tbl_idx (focParam_idx_1 + 1)
  58. #define trq_Tbl_size (30)
  59. void nv_storage_init(void);
  60. motor_params_t *nv_get_motor_params(void);
  61. foc_params_t *nv_get_foc_params(void);
  62. void nv_save_angle_offset(float offset);
  63. void nv_save_motor_params(void);
  64. void nv_read_motor_params(void);
  65. void nv_save_foc_params(void);
  66. void nv_read_foc_params(void);
  67. void nv_save_hall_table(s32 *hall_table);
  68. void nv_set_pid(u8 id, pid_conf_t *pid);
  69. void nv_get_pid(u8 id, pid_conf_t *pid);
  70. void nv_set_hwbrake_mode(u8 mode);
  71. void nv_set_throttle_vol(float min, float max);
  72. void nv_set_ebrake_current(float phase_curr, float dc_curr);
  73. torque_lut_t *nv_get_trq_tlb(void);
  74. #endif /* _NV_Storage_H__ */