nv_storage.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. u32 n_acc_time;
  24. u32 n_dec_time;
  25. u32 n_ebrk_time;
  26. u8 n_FwEnable;
  27. pid_conf_t pid_conf[PID_Max_id];
  28. u16 crc16;
  29. }foc_params_t;
  30. typedef struct {
  31. u8 mot_nr;
  32. u8 poles;
  33. float r;
  34. float ld;
  35. float lq;
  36. float flux_linkage;
  37. float back_emf;
  38. s32 hall_table[8];
  39. float offset;
  40. float est_pll_band; //normal工作模式下的pll带宽
  41. float pos_lock_pll_band; //电机锁定模式下的pll带宽
  42. u16 crc16;
  43. }motor_params_t;
  44. #define MAX_TRQ_POINTS 60
  45. #define MAX_SPD_POINTS 100
  46. #define TBL_TRQ_INTVAL 10
  47. #define TBL_SPD_INTVAL 100
  48. struct lut_dq {
  49. s16 d;
  50. s16 q;
  51. };
  52. typedef struct {
  53. struct lut_dq dq[MAX_TRQ_POINTS][MAX_SPD_POINTS];
  54. u16 magic;
  55. u16 crc16;
  56. }torque_lut_t;
  57. #pragma pack(pop)
  58. #define motorParam_idx_0 3
  59. #define motorParam_idx_1 (motorParam_idx_0 + 1)
  60. #define focParam_idx_0 (motorParam_idx_0 + 2)
  61. #define focParam_idx_1 (motorParam_idx_0 + 3)
  62. #define trq_Tbl_idx (focParam_idx_1 + 1)
  63. #define trq_Tbl_size (30)
  64. void nv_storage_init(void);
  65. motor_params_t *nv_get_motor_params(void);
  66. foc_params_t *nv_get_foc_params(void);
  67. void nv_save_angle_offset(float offset);
  68. void nv_save_motor_params(void);
  69. void nv_read_motor_params(void);
  70. void nv_save_foc_params(void);
  71. void nv_read_foc_params(void);
  72. void nv_save_hall_table(s32 *hall_table);
  73. void nv_set_pid(u8 id, pid_conf_t *pid);
  74. void nv_get_pid(u8 id, pid_conf_t *pid);
  75. void nv_set_hwbrake_mode(u8 mode);
  76. void nv_set_throttle_vol(float min, float max);
  77. void nv_set_ebrake_current(float phase_curr, float dc_curr);
  78. torque_lut_t *nv_get_trq_tlb(void);
  79. #endif /* _NV_Storage_H__ */